multi_bwd
Multi-treatment Balancing Walk Design implementation.
MultiBWD(N, D, delta=0.05, q=0.5, intercept=True, phi=1.0)
Bases: object
The Multi-treatment Balancing Walk Design with Restarts
This method implements an extension to the Balancing Walk Design to balance across multiple treatments. It accomplishes this by constructing a binary tree. At each node in the binary tree, it balanced between the treatment groups on the left and the right. Thus it ensures balance between any pair of treatment groups.
N : int Total number of points D : int Dimension of the data delta : float, optional Probability of failure, by default 0.05 q : float | Iterable[float], optional Target marginal probability of treatment. Can be a single float for binary treatment or an iterable of probabilities for multiple treatments, 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.0
Source code in src/bwd/multi_bwd.py
32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 | |
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 all BWD nodes in the tree
Returns:
| Type | Description |
|---|---|
dict
|
Dictionary mapping node indices to their states |
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/multi_bwd.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 |
|---|---|
int
|
Treatment assignment (treatment group index) |
Source code in src/bwd/multi_bwd.py
reset()
update_state(**node_state_dict)
Update the state of BWD nodes in the tree
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
**node_state_dict
|
dict
|
Dictionary mapping node indices (as strings) to state dictionaries |
{}
|