Overview
NICE (Non-linear Independent Components Estimation) is a coupling-based normalizing flow. By default in Zuko, NICE uses affine transformations (making it equivalent to RealNVP), but it can also be configured to use additive transformations as in the original paper.In Zuko, NICE and RealNVP are equivalent by default (both use affine transformations). For the original additive NICE, use custom univariate transformations.
References
NICE: Non-linear Independent Components Estimation (Dinh et al., 2014)https://arxiv.org/abs/1410.8516 Density estimation using Real NVP (Dinh et al., 2016)
https://arxiv.org/abs/1605.08803
Class Definition
Parameters
The number of features in the data. Must be at least 2.
The number of context features for conditional density estimation.
The number of coupling transformations to stack.
Whether random coupling masks are used. If
False, alternating checkered masks are used.Additional keyword arguments passed to
GeneralCouplingTransform:hidden_features: List of hidden layer sizes (default:[64, 64])activation: Activation function (default:ReLU)univariate: Univariate transformation constructor (default:MonotonicAffineTransform)shapes: Parameter shapes for the univariate transformation
Usage Example
Conditional Flow
Original Additive NICE
Training Example
Methods
forward(c=None)
Returns a normalizing flow distribution.
Arguments:
c(Tensor, optional): Context tensor of shape(*, context)
NormalizingFlow: A distribution with:sample(shape): Sample from the distribution (parallel, fast)log_prob(x): Compute log probability (parallel, fast)rsample(shape): Reparameterized sampling
When to Use NICE
Good for:
- Learning baselines and comparisons
- Understanding coupling flows
- Fast bidirectional transformations
- Educational purposes
- For production: Use RealNVP or NSF (more expressive)
- For maximum performance: Use NSF or NAF
- The implementations are equivalent, so prefer RealNVP for clarity
Tips
- Use RealNVP instead: Unless you specifically need additive transformations, RealNVP (which uses affine) is more expressive.
- More layers: Use 5-10 coupling layers since each layer only transforms half the features.
-
Larger networks: Coupling layers need more capacity, use
[256, 256]or larger.
Architecture Details
NICE uses coupling transformations:- Base distribution: Diagonal Gaussian
N(0, I) - Coupling: Binary mask splits features into two groups
- Transformation: Affine by default, or additive in original NICE
Affine NICE (default, equivalent to RealNVP):
Additive NICE (original):
NICE vs RealNVP
| Property | NICE (Additive) | NICE/RealNVP (Affine) |
|---|---|---|
| Jacobian | Volume preserving | Non-volume preserving |
| Parameters | Shift only | Shift and scale |
| Expressivity | Lower | Higher |
| Log-det | Zero (fast) | Non-zero |
| Use case | Historical | Practical |
Advanced Usage
Custom Coupling Patterns
Volume-Preserving Flow
Historical Context
NICE was one of the first successful normalizing flows:- 2014: NICE introduced with additive coupling
- 2016: RealNVP extended to affine coupling (scale + shift)
- Today: Affine coupling is standard, making NICE and RealNVP equivalent in most implementations
Related
- RealNVP - Equivalent implementation with affine transformations
- GeneralCouplingTransform - The underlying coupling transformation
- MAF - Autoregressive alternative
