Skip to main content

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

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

sns.set_theme(style="whitegrid")
plt = 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 × n");
plt;

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},
}

Metadata

Release files for bwd 0.2.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for bwd 0.2.0
File Size Uploaded
bwd-0.2.0.tar.gz 13.3 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for bwd 0.2.0
File Interpreter ABI Platform
bwd-0.2.0-py3-none-any.whl Python 3 none any Details

Total release size: 29.7 kB

Release files / bwd-0.2.0.tar.gz

Download URL bwd-0.2.0.tar.gz
Size 13.3 kB
Tags Source
SHA-256 checksum
How to use checksums
b47a2ce88f3d1c522ef961895e0a2d7d5722f4d2dd4e75d1700f7cae742ad8b9
BLAKE2b-256 checksum
How to use checksums
64af828effa5339d6d9509675ca13540bd98362f178afbd7335bec1489cbf9fd
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via poetry/2.2.1 CPython/3.14.0 Darwin/23.2.0

Release files / bwd-0.2.0-py3-none-any.whl

Download URL bwd-0.2.0-py3-none-any.whl
Size 16.4 kB
Tags Python 3
SHA-256 checksum
How to use checksums
85c3843642e025c9bd727dc0106c71c5407afdf7556a338d3b50c1d54959c022
BLAKE2b-256 checksum
How to use checksums
6ad6b64d3e04a90e7ed3e72425cce42aecb68aefa5b7384267a93f791ed77da5
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via poetry/2.2.1 CPython/3.14.0 Darwin/23.2.0

Release history Release notifications | RSS feed

This release

0.2.0 This release

2 release files

0.1.7

2 release files

0.1.6

2 release files

0.1.4

2 release files

0.1.3

2 release files

0.1.2

2 release files

0.1.1

2 release files

0.1.0

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page