B2B#
- class mvpy.estimators.B2B(alphas: Tensor | ndarray | float | int = 1, **kwargs)[source]#
Implements a back-to-back regression to disentangle causal contributions of correlated features.
The back-to-back estimator is a two-step estimator that consists of a decoder and an encoder. Effectively, the idea is to split the data \(X\) and \(y\) into two folds, decode all features in fold a, then use predictions from the decoder to encode all true features from all predictions in fold b. Consequently, this allows us to obtain a disentangled estimate of the causal contribution of each feature.
In practice, this is implemented as:
\[\hat{G} = (Y^T Y + \alpha_Y)^{-1}Y^T X\]\[\hat{H} = (X^T X + \alpha_X)^{-1}X^T Y\hat{G}\]where \(\hat{G}\) is the decoder and \(\hat{H}\) is the encoder, and \(\alpha\) are regularisation parameters. Consequently, the diagonal of \(\hat{H}\) contains the estimated causal contributions of our features.
For more information on B2B regression, please see [1].
- Parameters:
- alphastorch.Tensor | np.ndarray, default=torch.tensor([1])
The penalties to use for estimation.
- fit_interceptbool, default=True
Whether to fit an intercept.
- normalisebool, default=True
Whether to normalise the data.
- alpha_per_targetbool, default=False
Whether to use a different penalty for each target.
- normalise_decoderbool, default=True
Whether to normalise decoder ouputs.
- Attributes:
- alphastorch.Tensor | np.ndarray
The penalties to use for estimation.
- fit_interceptbool
Whether to fit an intercept.
- normalisebool
Whether to normalise the data
- alpha_per_targetbool
Whether to use a different penalty for each target.
- normalise_decoderbool
Whether to normalise decoder ouputs.
- decoder_mvpy.estimators.RidgeDecoder
The decoder.
- encoder_mvpy.estimators.RidgeDecoder
The encoder.
- scaler_mvpy.estimators.Scaler
The scaler.
- causal_torch.Tensor | np.ndarray
The causal contribution of each feature of shape
(n_features,).- pattern_torch.Tensor | np.ndarray
The decoded patterns of shape
(n_channels, n_features).
See also
mvpy.preprocessing.ScalerIf applied, scalers used in this class.
mvpy.estimators.RidgeDecoderRidge decoders used for the two-step procedure here.
Notes
When penalising per target by setting
alpha_per_targettoTrue, you may want to consider normalising the decoder by also settingnormalise_decodertoTrue. This is because otherwise decoder outputs may live on very different scales, potentially distorting the causal estimates per predictor.Patterns are computed as per [2]. However, these patterns are not disentangled and may, consequently, be less informative than desired, depending on strength of existing correlations.
References
[1]King, J.R., Charton, F., Lopez-Paz, D., & Oquab, M. (2020). Back-to-back regression: Disentangling the influence of correlated factors from multivariate observations. NeuroImage, 220, 117028. 10.1016/j.neuroimage.2020.117028
[2]Haufe, S., Meinecke, F., Görgen, K., Dähne, S., Haynes, J.D., Blankertz, B., & Bießmann, F. (2014). On the interpretation of weight vectors of linear models in multivariate neuroimaging. NeuroImage, 87, 96-110. 10.1016/j.neuroimage.2013.10.067
Examples
>>> import torch >>> from mvpy.estimators import B2B >>> ß = torch.normal(0, 1, (2, 60)) >>> X = torch.normal(0, 1, (100, 2)) >>> y = X @ ß + torch.normal(0, 1, (100, 60)) >>> X, y = y, X >>> y = torch.cat((y, y.mean(1).unsqueeze(-1) + torch.normal(0, 5, (100, 1))), 1) >>> b2b = B2B() >>> b2b.fit(X, y).causal_ tensor([0.4470, 0.4594, 0.0060])