causalflows.flows¶
Wrappers for causal normalizing flows using standard architectures.
Classes¶
Creates a lazy causal normalizing flow (initialized after passing the context). |
|
Creates a causal flow using a masked autoregressive flow (MAF) as base model. |
|
Creates a causal flow using a neural autoregressive flow (NAF) as base model. |
|
Creates a causal flow using a neural circular spline flow (NCSF) as base model. |
|
Creates a causal flow using a neural spline flow (NSF) as the base model. |
|
Creates a causal flow using an unconstrained neural autoregressive flow (UNAF) as base model. |
Descriptions¶
- class causalflows.flows.CausalFlow(transform, base)¶
Creates a lazy causal normalizing flow (initialized after passing the context).
See also
zuko.flows.core.Flow- Flow base class from Zuko.causalflows.distributions.CausalNormalizingFlow- Class returned after the forward pass.
- Parameters:
transform (Union[LazyTransform, Sequence[LazyTransform]]) – A lazy transformation or sequence of lazy transformations.
base (LazyDistribution) – A lazy distribution.
- class causalflows.flows.CausalMAF(features, context=0, *args, order=None, adjacency=None, **kwargs)¶
Creates a causal flow using a masked autoregressive flow (MAF) as base model.
- Parameters:
features (int) – The number of features.
context (int) – The number of context features.
order (LongTensor | None) – The causal order to follow by the flow. If used, then
adjacencymust beNone.adjacency (BoolTensor | None) – The causal graph to pass to the flow. If used, then
ordermust beNone.kwargs – Keyword arguments passed to
MaskedAutoregressiveTransform.
See also
MAFThe equivalent non-causal counterpart from Zuko.
Example
>>> flow = CausalMAF(3, 4, order=torch.arange(3)) >>> flow CausalMAF( (transform): MaskedAutoregressiveTransform( (base): MonotonicAffineTransform() (order): [0, 1, 2] (hyper): MaskedMLP( (0): MaskedLinear(in_features=7, out_features=64, bias=True) (1): ReLU() (2): MaskedLinear(in_features=64, out_features=64, bias=True) (3): ReLU() (4): MaskedLinear(in_features=64, out_features=6, bias=True) ) ) (base): UnconditionalDistribution(DiagNormal(loc: torch.Size([3]), scale: torch.Size([3]))) ) >>> c = torch.randn(4) >>> x = flow(c).sample() >>> x tensor([-1.9301, -0.1411, -0.7982]) >>> flow(c).log_prob(x) tensor(-5.1800, grad_fn=<AddBackward0>)
References
Masked Autoregressive Flow for Density Estimation (Papamakarios et al., 2017)
- class causalflows.flows.CausalNAF(features, context=0, signal=16, *args, order=None, adjacency=None, network=None, **kwargs)¶
Creates a causal flow using a neural autoregressive flow (NAF) as base model.
- Parameters:
features (int) – The number of features.
context (int) – The number of context features.
signal (int) – The number of signal features of the monotonic network.
order (LongTensor | None) – The causal order to follow by the flow. If used, then
adjacencymust beNone.adjacency (BoolTensor | None) – The causal graph to follow by the flow. If used, then
ordermust beNone.network (Dict[str, Any] | None) – Keyword arguments passed to
MNN.kwargs – Keyword arguments passed to
MaskedAutoregressiveTransform.
See also
NAFThe equivalent non-causal counterpart from Zuko.
Warning
Invertibility is only guaranteed for features within the interval \([-10, 10]\). It is recommended to standardize features (zero mean, unit variance) before training.
References
Neural Autoregressive Flows (Huang et al., 2018)
- class causalflows.flows.CausalNCSF(features, context=0, bins=8, **kwargs)¶
Creates a causal flow using a neural circular spline flow (NCSF) as base model.
Circular spline transformations are obtained by composing circular domain shifts with regular spline transformations. Features are assumed to lie in the half-open interval \([-\pi, \pi)\).
- Parameters:
See also
NCSFThe equivalent non-causal counterpart from Zuko.
References
Normalizing Flows on Tori and Spheres (Rezende et al., 2020)
- class causalflows.flows.CausalNSF(features, context=0, bins=8, **kwargs)¶
Creates a causal flow using a neural spline flow (NSF) as the base model.
- Parameters:
See also
NSFThe equivalent non-causal counterpart from Zuko.
Warning
Spline transformations are defined over the domain \([-5, 5]\). Any feature outside of this domain is not transformed. It is recommended to standardize features (zero mean, unit variance) before training.
References
Neural Spline Flows (Durkan et al., 2019)
- class causalflows.flows.CausalUNAF(features, context=0, signal=16, *args, order=None, adjacency=None, network=None, **kwargs)¶
Creates a causal flow using an unconstrained neural autoregressive flow (UNAF) as base model.
- Parameters:
features (int) – The number of features.
context (int) – The number of context features.
signal (int) – The number of signal features of the monotonic network.
order (LongTensor | None) – The causal order to follow by the flow. If used, then
adjacencymust beNone.adjacency (BoolTensor | None) – The causal graph to follow by the flow. If used, then
ordermust beNone.network (Dict[str, Any]) – Keyword arguments passed to
UMNN.kwargs – Keyword arguments passed to
MaskedAutoregressiveTransform.
See also
UNAFThe equivalent non-causal counterpart from Zuko.
Warning
Invertibility is only guaranteed for features within the interval \([-10, 10]\). It is recommended to standardize features (zero mean, unit variance) before training.
References
Unconstrained Monotonic Neural Networks (Wehenkel et al., 2019)