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_scaleand moved byshift, and the weights of its parents are multiplied byweight_scaleor 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 thescale. Under the linear and additive-noise functionals it moves the variable’s mean byshift.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 fromU[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: magnitudeU[weight_range], with a random sign, or positive when the functional draws positive weights. The new weights come from thatweight_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 underdo()and each environment ofenvs=draw different new weights for the same intervention, and the dataset’sparamsholds the weights without interventions."redraw"takesweight_scale=1.
- Return type:
- Raises:
ValueError – If an argument is not finite,
noise_scaleis negative or a pair not ordered0 <= low < high,weightsis not"keep"or"redraw", or"redraw"is given with aweight_scaleother 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')