API reference

andrey.data.interventions.soft#

andrey.data.interventions.soft(*, shift=0.0, weight_scale=1.0, noise_scale=1.0, weights='keep')[source]#

Build a soft intervention: the variable’s mechanism changes, and its parents still act.

On a continuous variable, its noise is multiplied by noise_scale and moved by shift, and the weights of its parents are multiplied by weight_scale or drawn anew. On a discrete variable, soft() takes no arguments: every row of its conditional probability table is drawn anew, from the Dirichlet the sampler drew it from.

Parameters:
  • shift (float) – Added to the variable’s noise, in the units of the returned data, whatever the scale. Under the linear and additive-noise functionals it moves the variable’s mean by shift.

  • weight_scale (float) – Multiplies the weight of each of the variable’s parents; under the location-scale functional, its weights in the location and in the scale. A variable without parents has no weights to change.

  • noise_scale (float | Sequence[float]) – Multiplies the variable’s noise, so its noise standard deviation. A pair (low, high), low < high, multiplies the noise of each row by its own draw from U[low, high], so the noise follows a new distribution, a scale mixture of the one it had (Peters et al. 2016, Appendix G).

  • weights (str) – "redraw" draws the weight of each of the variable’s parents anew, each on its own, from the functional’s own weight distribution: magnitude U[weight_range], with a random sign, or positive when the functional draws positive weights. The new weights come from that weight_range, not from a range of their own as in Peters et al. (2016, Appendix G). Under the location-scale functional, the weights in the location and in the scale are drawn anew. A variable without parents has no weights to draw anew. The new weights are part of the model: samples with the same model seed draw the same ones. Each environment draws its own: the sample under do() and each environment of envs= draw different new weights for the same intervention, and the dataset’s params holds the weights without interventions. "redraw" takes weight_scale=1.

Return type:

SoftIntervention

Raises:

ValueError – If an argument is not finite, noise_scale is negative or a pair not ordered 0 <= low < high, weights is not "keep" or "redraw", or "redraw" is given with a weight_scale other than 1.

References

Peters, J., Buhlmann, P., and Meinshausen, N. (2016). Causal inference by using invariant prediction: identification and confidence intervals. Journal of the Royal Statistical Society, Series B, 78(5), 947-1012.

Examples

>>> from andrey.data.interventions import soft
>>> soft(shift=1.0)
SoftIntervention(shift=1.0, weight_scale=1.0, noise_scale=1.0, weights='keep')
>>> soft(noise_scale=(1.0, 3.0), weights="redraw")
SoftIntervention(shift=0.0, weight_scale=1.0, noise_scale=(1.0, 3.0), weights='redraw')