Skip to main content

A clean implementation of the Balancing Walk Design for online experimental design from Arbour, Dimmery, Mai and Rao (2022)

Project description

Balancing Walk Design

Contributor Covenant deploy DOI PyPI

This package provides a reference implementation of the Balancing Walk Design. It relies on minimal dependencies and is intended to be an easy way to plug in advanced experimental designs into existing systems with little overhead.

More details on the design of the method on the About page and in the paper. An example of usage is below.

Installation

(packages not yet available)

With pip:

pip install bwd

Usage

A simple example of how to use BWD to balance a stream of covariate data follows:

from bwd import BWD
from numpy.random import default_rng
import numpy as np
rng = default_rng(2022)

n = 10000
d = 5
ate = 1
beta = rng.normal(size = d)

X = rng.normal(size = (n, d))

balancer = BWD(N = n, D = d)
A_bwd = []
A_rand = []
imbalance_bwd = np.array([[0] * d])
imbalance_rand = np.array([[0] * d])

increment_imbalance = lambda imba, a, x: np.concatenate([imba, imba[-1:, :] + (2 * a - 1) * x])

for x in X:
    # Assign with BWD
    a_bwd = balancer.assign_next(x)
    imbalance_bwd = increment_imbalance(imbalance_bwd, a_bwd, x)
    A_bwd.append(a_bwd)
    # Assign with Bernoulli randomization
    a_rand = rng.binomial(n = 1, p = 0.5, size = 1).item()
    imbalance_rand = increment_imbalance(imbalance_rand, a_rand, x)
    A_rand.append(a_rand)

# Outcomes are only realized at the conclusion of the experiment
eps = rng.normal(size=n)
Y_bwd = X @ beta + A_bwd * ate + eps
Y_rand = X @ beta + A_rand + ate + eps

We can see how imbalance progresses as a function of time:

import seaborn as sns
import pandas as pd

norm_bwd = np.linalg.norm(imbalance_bwd, axis = 1).tolist()
norm_rand = np.linalg.norm(imbalance_rand, axis = 1).tolist()

sns.relplot(
    x=list(range(n + 1)) * 2, y=norm_bwd + norm_rand,
    hue = ["BWD"] * (n + 1) + ["Random"] * (n + 1),
    kind="line", height=5, aspect=2,
).set_axis_labels("Iteration", "Imbalance");

png

It's clear from the above chart that using BWD keeps imbalance substantially more under control than standard methods of randomization.

Citation

APA

Arbour, D., Dimmery, D., Mai, T. & Rao, A.. (2022). Online Balanced Experimental Design. Proceedings of the 39th International Conference on Machine Learning, in Proceedings of Machine Learning Research 162:844-864 Available from https://proceedings.mlr.press/v162/arbour22a.html.

BibTeX


@InProceedings{arbour2022online,
  title = 	 {Online Balanced Experimental Design},
  author =       {Arbour, David and Dimmery, Drew and Mai, Tung and Rao, Anup},
  booktitle = 	 {Proceedings of the 39th International Conference on Machine Learning},
  pages = 	 {844--864},
  year = 	 {2022},
  editor = 	 {Chaudhuri, Kamalika and Jegelka, Stefanie and Song, Le and Szepesvari, Csaba and Niu, Gang and Sabato, Sivan},
  volume = 	 {162},
  series = 	 {Proceedings of Machine Learning Research},
  month = 	 {17--23 Jul},
  publisher =    {PMLR},
  pdf = 	 {https://proceedings.mlr.press/v162/arbour22a/arbour22a.pdf},
  url = 	 {https://proceedings.mlr.press/v162/arbour22a.html},
}

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

bwd-0.1.6.tar.gz (11.7 kB view details)

Uploaded Source

Built Distribution

bwd-0.1.6-py3-none-any.whl (13.9 kB view details)

Uploaded Python 3

File details

Details for the file bwd-0.1.6.tar.gz.

File metadata

  • Download URL: bwd-0.1.6.tar.gz
  • Upload date:
  • Size: 11.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.8.3 CPython/3.12.4 Darwin/23.2.0

File hashes

Hashes for bwd-0.1.6.tar.gz
Algorithm Hash digest
SHA256 a4f98effae300407e77603c3435b3c5f30d5d89314a1af2cd6424ed349ca9c9f
MD5 176fbe6d22582548f83b3304a82e30db
BLAKE2b-256 683d92e409f15c763589fd53faf73525e1681862c1e6214c84d73e57988d3a09

See more details on using hashes here.

File details

Details for the file bwd-0.1.6-py3-none-any.whl.

File metadata

  • Download URL: bwd-0.1.6-py3-none-any.whl
  • Upload date:
  • Size: 13.9 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.8.3 CPython/3.12.4 Darwin/23.2.0

File hashes

Hashes for bwd-0.1.6-py3-none-any.whl
Algorithm Hash digest
SHA256 4ca51ea6ed8f9efd4f12fd7a5ec09ca2ff4b2d0e1363098ede285fa7885ecbdc
MD5 a5847d37cad80f3f844541f1c1426a6e
BLAKE2b-256 372e9d662082e4ed0db8d537da423d1509c45fe4290ba8aa6f5a3e8a3b1054b3

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page