bwd_random
Balancing Walk Design with reversion to Bernoulli randomization.
BWDRandom(N, D, delta=0.05, q=0.5, intercept=True, phi=1)
Bases: object
The Balancing Walk Design with Reversion to Bernoulli Randomization
This is an algorithm from Arbour et al (2022). At each step, it adjusts randomization probabilities to ensure that imbalance tends towards zero. In particular, if current imbalance is w and the current covariate profile is \(x\), then the probability of treatment conditional on history will be:
\(q\) is the desired marginal probability, \(\phi\) is the parameter which controls robustness and \(\alpha\) is the normalizing constant which ensures the probability is well-formed.
If \(|x \cdot w| > \alpha\)
All future units will be assigned by complete randomization.
N : int Total number of points D : int Dimension of the data delta : float, optional Probability of failure, by default 0.05 q : float, optional Target marginal probability of treatment, by default 0.5 intercept : bool, optional Whether an intercept term be added to covariate profiles, by default True phi : float, optional Robustness parameter. A value of 1 focuses entirely on balance, while a value approaching zero does pure randomization, by default 1
Source code in src/bwd/bwd_random.py
definition
property
Get the definition parameters of the balancer
Returns:
| Type | Description |
|---|---|
dict
|
Dictionary containing N, D, delta, q, intercept, and phi |
state
property
Get the current state of the balancer
Returns:
| Type | Description |
|---|---|
dict
|
Dictionary containing w_i and iterations |
assign_all(X)
Assign all points
This assigns units to treatment in the offline setting in which all covariate profiles are available prior to assignment. The algorithm assigns as if units were still only observed in a stream.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
X
|
ndarray
|
Array of size n × d of covariate profiles |
required |
Returns:
| Type | Description |
|---|---|
ndarray
|
Array of treatment assignments |
Source code in src/bwd/bwd_random.py
assign_next(x)
Assign treatment to the next point
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
x
|
ndarray
|
Covariate profile of unit to assign treatment |
required |
Returns:
| Type | Description |
|---|---|
ndarray
|
Treatment assignment (0 or 1) |
Source code in src/bwd/bwd_random.py
reset()
Reset the balancer to initial state
Resets the imbalance vector to zeros, initializes alpha, and sets iterations to 0.
Source code in src/bwd/bwd_random.py
set_alpha(N)
Set normalizing constant for remaining N units
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
N
|
int
|
Number of units remaining in the sample |
required |
Raises:
| Type | Description |
|---|---|
SampleSizeExpendedError
|
If N is negative |