bandart 0.1.1 copy "bandart: ^0.1.1" to clipboard
bandart: ^0.1.1 copied to clipboard

Bandart (combination of "Bandits" and "Dart") is a library for bandit algorithms in Dart. It provides Bayesian Models for statistical analysis for the data..

Dart CI Coverage Status

Bandart (combination of "Bandits" and "Dart") is a library for bandit algorithms in Dart. It provides Bayesian Models for statistical analysis for the data.

Features #

  • Bandit algorithms:
    • Fixed Schedule
    • Thompson Sampling
  • Bayesian Models:
    • Beta Model: Approximating success probability using Beta Distributions
    • Gaussian Model: Approximating mean and variance using conjugate priors

Getting started #

Install the package using dart pub add bandart. Now you can use

import 'package:bandart/bandart.dart';

Usage #

Create A Fixed Schedule #

import 'package:bandart/bandart.dart';

int numberOfInterventions = 3;
var policy = FixedPolicy(numberofInterventions);
for (int i = 0; i < 10; i++) {
    print(policy.choseAction({"decisionPoint": i}))
}
// Prints 0, 1, 2, 0, 1, 2, 0, 1, 2, 0

Analyze data using Normal Model #

import 'package:bandart/bandart.dart';

var history = DataFrame(
      {'intervention': [0, 0, 1, 1], 'outcome': [1.0, 1.0, 2.0, 2.0]})

// Mean and L are priors for the normal model
var gaussianModel = GaussianModel(
    numberOfInterventions: 2, mean: 1.0, l: 1.0, random: Random(0))

gaussianModel.history = history

// Update the samples
gaussianModel.sample()

print(gaussianModel.maxProbabilities())
// Prints around [0.2, 0.8]

Create an adaptive schedule using Thompson Sampling #

import 'package:bandart/bandart.dart';

var history = DataFrame(
      {'intervention': [0, 0, 1, 1], 'outcome': [1.0, 1.0, 2.0, 2.0]})

// Mean and L are priors for the normal model
var gaussianModel = GaussianModel(
    numberOfInterventions: 2, mean: 1.0, l: 1.0, random: Random(0))

var policy = ThompsonSampling(numberOfInterventions: 2);

print(policy.choseAction({}, history));
// Prints either 0 or 1 (randomized), but will more often pick 1 as this is the intervention with the better history

Additional information #

Development #

Setup

Test can be run with dart test. Some tests need mock code generated by mockito. To update the mock code, run dart run build_runner build.

Goals

  • Performance: Since Dart is most often used for mobile development, the goal of the library is to support calculations fast enough to run on smartphones.
  • Seedability: When seeded with the same seed, the library should always return the same result.
  • Well tested
3
likes
150
points
95
downloads

Publisher

verified publisherdominikmeier.io

Weekly Downloads

Bandart (combination of "Bandits" and "Dart") is a library for bandit algorithms in Dart. It provides Bayesian Models for statistical analysis for the data..

Homepage

Documentation

API reference

License

BSD-3-Clause (license)

Dependencies

calc, collection, data, statistics

More

Packages that depend on bandart