deeprob.flows.models package
Submodules
deeprob.flows.models.base module
- class deeprob.flows.models.base.NormalizingFlow(in_features, dequantize=False, logit=None, in_base=None)[source]
Bases:
ProbabilisticModelInitialize an abstract Normalizing Flow model.
- Parameters
in_features – The input size.
dequantize (bool) – Whether to apply the dequantization transformation.
logit (Optional[float]) – The logit factor to use. Use None to disable the logit transformation.
in_base (Optional[Union[ProbabilisticModel, Distribution]]) – The input base distribution to use. If None, the standard Normal distribution is used.
- Raises
ValueError – If the number of input features is invalid.
ValueError – If the logit value is invalid.
- has_rsample = True
- eval()[source]
Turn off the training mode for both the flows layers and the in_base distribution.
- Returns
Itself.
- preprocess(x)[source]
Preprocess the data batch before feeding it to the probabilistic model (forward mode).
- unpreprocess(x)[source]
Preprocess the data batch before feeding it to the probabilistic model (backward mode).
- rsample(n_samples, y=None)[source]
Sample some values from the modeled distribution by reparametrization. Unlike
NormalizingFlow.sample(), this method allows backpropagation.
deeprob.flows.models.maf module
- class deeprob.flows.models.maf.MAF(in_features, dequantize=False, logit=None, in_base=None, n_flows=5, depth=1, units=128, batch_norm=True, activation='relu', sequential=True, random_state=None)[source]
Bases:
NormalizingFlowInitialize a Masked Autorefressive Flow (MAF) model.
- Parameters
in_features (int) – The number of input features.
dequantize (bool) – Whether to apply the dequantization transformation.
logit (Optional[float]) – The logit factor to use. Use None to disable the logit transformation.
in_base (Optional[Union[ProbabilisticModel, Distribution]]) – The input base distribution to use. If None, the standard Normal distribution is used.
n_flows (int) – The number of sequential autoregressive layers.
depth (int) – The number of hidden layers of flows conditioners.
units (int) – The number of hidden units per layer of flows conditioners.
batch_norm (bool) – Whether to apply batch normalization after each autoregressive layer.
activation (str) – The activation function name to use for the flows conditioners hidden layers.
sequential (bool) – If True build masks degrees sequentially, otherwise randomly.
random_state (Optional[Union[int, RandomState]]) – The random state used to generate the masks degrees. Used only if sequential is False. It can be either a seed integer or a np.random.RandomState instance.
- Raises
ValueError – If a parameter is out of domain.
deeprob.flows.models.realnvp module
- class deeprob.flows.models.realnvp.RealNVP1d(in_features, dequantize=False, logit=None, in_base=None, n_flows=5, depth=1, units=128, batch_norm=True, affine=True)[source]
Bases:
NormalizingFlowReal Non-Volume-Preserving (RealNVP) 1D normalizing flow model.
- Parameters
in_features (int) – The number of input features.
dequantize (bool) – Whether to apply the dequantization transformation.
logit (Optional[float]) – The logit factor to use. Use None to disable the logit transformation.
in_base (Optional[Union[ProbabilisticModel, Distribution]]) – The input base distribution to use. If None, the standard Normal distribution is used.
n_flows (int) – The number of sequential coupling flows.
depth (int) – The number of hidden layers of flows conditioners.
units (int) – The number of hidden units per layer of flows conditioners.
batch_norm (bool) – Whether to apply batch normalization after each coupling layer.
affine (bool) – Whether to use affine transformation. If False then use only translation (as in NICE).
- Raises
ValueError – If a parameter is out of scope.
- class deeprob.flows.models.realnvp.RealNVP2d(in_features, dequantize=False, logit=None, in_base=None, network='resnet', n_flows=1, n_blocks=2, channels=32, affine=True)[source]
Bases:
NormalizingFlowReal Non-Volume-Preserving (RealNVP) 2D normalizing flow model.
- Parameters
in_features (Tuple[int, int, int]) – The input size as a (C, H, W) tuple.
dequantize (bool) – Whether to apply the dequantization transformation.
logit (Optional[float]) – The logit factor to use. Use None to disable the logit transformation.
in_base (Optional[Union[ProbabilisticModel, Distribution]]) – The input base distribution to use. If None, the standard Normal distribution is used.
network (str) – The neural network conditioner to use. It can be either ‘resnet’ or ‘densenet’.
n_flows (int) – The number of sequential multi-scale architectures.
n_blocks (int) – The number of residual blocks or dense blocks.
channels (int) – The number of output channels of each convolutional layer.
affine (bool) – Whether to use affine transformation. If False then use only translation (as in NICE).
- static build_permutation_matrix(channels)[source]
Build the permutation matrix that defines (a non-trivial) variables ordering when downscaling or upscaling as in RealNVP.