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..

example/main.dart

// Create a simple adaptive simulation using a Gaussian Model
// Example can be run with dart run example/main.dart
// Example output:
// ```
// Chose intervention 0 and got outcome 0.3
// Chose intervention 1 and got outcome 0.9
// Chose intervention 1 and got outcome 0.9
// Chose intervention 1 and got outcome 0.9
// Chose intervention 1 and got outcome 0.9
// Chose intervention 0 and got outcome 0.3
// Chose intervention 1 and got outcome 0.9
// Chose intervention 1 and got outcome 0.9
// Chose intervention 1 and got outcome 0.9
// Chose intervention 1 and got outcome 0.9
// ```
// Intervention 1 is sampled more often, as it gets better outcomes.

import 'dart:math';

import 'package:bandart/bandart.dart';

void main() {
  var model = GaussianModel(
      numberOfInterventions: 2,
      mean: 0.0,
      l: 1.0,
      random: Random(42),
      sampleSize: 10000,
      alpha: 1.0,
      beta: 1.0);

  var policy = ThompsonSampling(model: model, random: Random(42));

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

  // Usually, new outcomes are measured outside, like click rates in an AB testing. For simplicity, we just use some random numbers here.
  final newOutcomesForInterventions = [0.3, 0.9];
  for (int i = 0; i < 10; i++) {
    // Select which action to chose:
    var intervention = policy.choseAction({}, history);
    var outcome = newOutcomesForInterventions[intervention];

    // Add datapoint
    history['intervention'].add(intervention);
    history['outcome'].add(outcome);
    print("Chose intervention $intervention and got outcome $outcome");
  }
}
2
likes
130
pub points
14%
popularity

Publisher

verified publisherdominikmeier.io

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