bwd


Namebwd JSON
Version 0.1.7 PyPI version JSON
download
home_pagehttps://ddimmery.github.io/balancer-package/
SummaryA clean implementation of the Balancing Walk Design for online experimental design from Arbour, Dimmery, Mai and Rao (2022)
upload_time2024-08-19 16:44:47
maintainerNone
docs_urlNone
authorDrew Dimmery
requires_python<4.0,>=3.9
licenseApache-2.0
keywords causal inference experimentation ab testing
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            # Balancing Walk Design

[![Contributor Covenant](https://img.shields.io/badge/Contributor%20Covenant-2.1-4baaaa.svg)](code_of_conduct.md)
[![deploy](https://github.com/ddimmery/balancer-package/actions/workflows/ci.yml/badge.svg)](https://github.com/ddimmery/balancer-package/actions/workflows/ci.yml)
[![DOI](https://zenodo.org/badge/493411416.svg)](https://zenodo.org/badge/latestdoi/493411416)
![PyPI](https://img.shields.io/pypi/v/bwd)

This package provides a reference implementation of the [Balancing Walk Design](https://arxiv.org/abs/2203.02025). 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](https://ddimmery.github.io/balancer-package/about/) and in the [paper](https://arxiv.org/abs/2203.02025). An [example of usage is below](#usage).

## Installation

(packages not yet available)

With `pip`:

```
pip install bwd
```


## Usage

A simple example of how to use [BWD](https://ddimmery.github.io/balancer-package/reference/balancer/bwd/) to balance a stream of covariate data follows:


```python
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:


```python
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](README_files/README_3_0.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},
}

```

            

Raw data

            {
    "_id": null,
    "home_page": "https://ddimmery.github.io/balancer-package/",
    "name": "bwd",
    "maintainer": null,
    "docs_url": null,
    "requires_python": "<4.0,>=3.9",
    "maintainer_email": null,
    "keywords": "causal inference, experimentation, ab testing",
    "author": "Drew Dimmery",
    "author_email": "drew.dimmery@gmail.com",
    "download_url": "https://files.pythonhosted.org/packages/c2/5a/0b35d55ea967334439a18587348b9e12bc05ee069cbc8a8c7d4537b6cb47/bwd-0.1.7.tar.gz",
    "platform": null,
    "description": "# Balancing Walk Design\n\n[![Contributor Covenant](https://img.shields.io/badge/Contributor%20Covenant-2.1-4baaaa.svg)](code_of_conduct.md)\n[![deploy](https://github.com/ddimmery/balancer-package/actions/workflows/ci.yml/badge.svg)](https://github.com/ddimmery/balancer-package/actions/workflows/ci.yml)\n[![DOI](https://zenodo.org/badge/493411416.svg)](https://zenodo.org/badge/latestdoi/493411416)\n![PyPI](https://img.shields.io/pypi/v/bwd)\n\nThis package provides a reference implementation of the [Balancing Walk Design](https://arxiv.org/abs/2203.02025). 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.\n\nMore details on the design of the method on the [About page](https://ddimmery.github.io/balancer-package/about/) and in the [paper](https://arxiv.org/abs/2203.02025). An [example of usage is below](#usage).\n\n## Installation\n\n(packages not yet available)\n\nWith `pip`:\n\n```\npip install bwd\n```\n\n\n## Usage\n\nA simple example of how to use [BWD](https://ddimmery.github.io/balancer-package/reference/balancer/bwd/) to balance a stream of covariate data follows:\n\n\n```python\nfrom bwd import BWD\nfrom numpy.random import default_rng\nimport numpy as np\nrng = default_rng(2022)\n\nn = 10000\nd = 5\nate = 1\nbeta = rng.normal(size = d)\n\nX = rng.normal(size = (n, d))\n\nbalancer = BWD(N = n, D = d)\nA_bwd = []\nA_rand = []\nimbalance_bwd = np.array([[0] * d])\nimbalance_rand = np.array([[0] * d])\n\nincrement_imbalance = lambda imba, a, x: np.concatenate([imba, imba[-1:, :] + (2 * a - 1) * x])\n\nfor x in X:\n    # Assign with BWD\n    a_bwd = balancer.assign_next(x)\n    imbalance_bwd = increment_imbalance(imbalance_bwd, a_bwd, x)\n    A_bwd.append(a_bwd)\n    # Assign with Bernoulli randomization\n    a_rand = rng.binomial(n = 1, p = 0.5, size = 1).item()\n    imbalance_rand = increment_imbalance(imbalance_rand, a_rand, x)\n    A_rand.append(a_rand)\n\n# Outcomes are only realized at the conclusion of the experiment\neps = rng.normal(size=n)\nY_bwd = X @ beta + A_bwd * ate + eps\nY_rand = X @ beta + A_rand + ate + eps\n```\n\nWe can see how imbalance progresses as a function of time:\n\n\n```python\nimport seaborn as sns\nimport pandas as pd\n\nnorm_bwd = np.linalg.norm(imbalance_bwd, axis = 1).tolist()\nnorm_rand = np.linalg.norm(imbalance_rand, axis = 1).tolist()\n\nsns.relplot(\n    x=list(range(n + 1)) * 2, y=norm_bwd + norm_rand,\n    hue = [\"BWD\"] * (n + 1) + [\"Random\"] * (n + 1),\n    kind=\"line\", height=5, aspect=2,\n).set_axis_labels(\"Iteration\", \"Imbalance\");\n```\n\n\n    \n![png](README_files/README_3_0.png)\n    \n\n\nIt's clear from the above chart that using BWD keeps imbalance substantially more under control than standard methods of randomization.\n\n## Citation\n#### APA\n> 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.\n\n#### BibTeX\n```\n\n@InProceedings{arbour2022online,\n  title = \t {Online Balanced Experimental Design},\n  author =       {Arbour, David and Dimmery, Drew and Mai, Tung and Rao, Anup},\n  booktitle = \t {Proceedings of the 39th International Conference on Machine Learning},\n  pages = \t {844--864},\n  year = \t {2022},\n  editor = \t {Chaudhuri, Kamalika and Jegelka, Stefanie and Song, Le and Szepesvari, Csaba and Niu, Gang and Sabato, Sivan},\n  volume = \t {162},\n  series = \t {Proceedings of Machine Learning Research},\n  month = \t {17--23 Jul},\n  publisher =    {PMLR},\n  pdf = \t {https://proceedings.mlr.press/v162/arbour22a/arbour22a.pdf},\n  url = \t {https://proceedings.mlr.press/v162/arbour22a.html},\n}\n\n```\n",
    "bugtrack_url": null,
    "license": "Apache-2.0",
    "summary": "A clean implementation of the Balancing Walk Design for online experimental design from Arbour, Dimmery, Mai and Rao (2022)",
    "version": "0.1.7",
    "project_urls": {
        "Homepage": "https://ddimmery.github.io/balancer-package/",
        "Repository": "https://github.com/ddimmery/balancer-package"
    },
    "split_keywords": [
        "causal inference",
        " experimentation",
        " ab testing"
    ],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "26d7df76b12cdcb3977a568390f553a4f5081275988912ed232eb5af2c0891e6",
                "md5": "0ffefdb041bd741c762e0b344f0cb310",
                "sha256": "1873267654210324f8d0f0ddf5924e8bd9ef3f73596346ac71251c8e3c688a5a"
            },
            "downloads": -1,
            "filename": "bwd-0.1.7-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "0ffefdb041bd741c762e0b344f0cb310",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": "<4.0,>=3.9",
            "size": 14085,
            "upload_time": "2024-08-19T16:44:45",
            "upload_time_iso_8601": "2024-08-19T16:44:45.616769Z",
            "url": "https://files.pythonhosted.org/packages/26/d7/df76b12cdcb3977a568390f553a4f5081275988912ed232eb5af2c0891e6/bwd-0.1.7-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "c25a0b35d55ea967334439a18587348b9e12bc05ee069cbc8a8c7d4537b6cb47",
                "md5": "a06052967c464e5006e8edfe60e68e6a",
                "sha256": "96afcf58dc9f56632bb5dfb8f625981b88cd2304374589c12aafe1951e3d6c00"
            },
            "downloads": -1,
            "filename": "bwd-0.1.7.tar.gz",
            "has_sig": false,
            "md5_digest": "a06052967c464e5006e8edfe60e68e6a",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": "<4.0,>=3.9",
            "size": 11832,
            "upload_time": "2024-08-19T16:44:47",
            "upload_time_iso_8601": "2024-08-19T16:44:47.758197Z",
            "url": "https://files.pythonhosted.org/packages/c2/5a/0b35d55ea967334439a18587348b9e12bc05ee069cbc8a8c7d4537b6cb47/bwd-0.1.7.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2024-08-19 16:44:47",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "github_user": "ddimmery",
    "github_project": "balancer-package",
    "travis_ci": false,
    "coveralls": false,
    "github_actions": true,
    "lcname": "bwd"
}
        
Elapsed time: 0.49108s