Masked Autoregressive Flow for Density Estimation

George Papamakarios, Iain Murray, Theo Pavlakou

Estimating the underlying probability distribution of data—known as density estimation—is a foundational problem in machine learning. A robust density estimator allows systems to perform critical tasks like anomaly detection, data completion, and the generation of new samples. However, researchers historically face a strict "flexibility vs. tractability" trade-off.

Autoregressive models, such as MADE (Masked Autoencoder for Distribution Estimation), excel at decomposing complex distributions into simpler conditional ones, but they can be limited in their representational power. Conversely, normalizing flows transform a simple base distribution (like a standard Gaussian) into a highly complex one using invertible mappings. The catch is that these mappings must have a "tractable Jacobian"—a mathematically feasible way to calculate how the transformation stretches or compresses space.

To solve this, the authors introduce Masked Autoregressive Flow (MAF), a powerful class of normalizing flows that stacks multiple autoregressive models to represent complex probability distributions. MAF provides a flexible, parallelizable framework that outperforms previous methods like Real NVP and MADE.

The Architecture of MAF

The core innovation of MAF lies in treating autoregressive models as normalizing flows and stacking them to build representational power.

  • The Building Block (MADE): MAF uses MADE as its internal layer. MADE applies clever "masks" to a standard neural network's weights, ensuring that each output strictly depends on previous inputs. This satisfies the autoregressive property in a single, highly efficient forward pass.
  • Autoregressive Models as Flows: The authors demonstrate that any autoregressive model with Gaussian conditionals is fundamentally a normalizing flow that transforms random noise into structured data.
  • Stacking for Flexibility: A single autoregressive layer might only capture simple conditional distributions. MAF gains its true power by stacking these layers. Each layer in the stack models the "randomness" used by the layer directly below it.
Complex Density Representation

By composing multiple layers, the model can warp simple distributions into highly complex, multi-modal target densities. To maximize this effect, the authors found it beneficial to reverse or shuffle the ordering of variables between layers in the stack. This ensures that different parts of the model "see" different dependencies in the data, leading to a much better overall fit.

The MAF vs. IAF Duality

The paper highlights a fascinating theoretical duality between MAF and Inverse Autoregressive Flow (IAF). The authors proved that training a MAF via maximum likelihood is mathematically equivalent to performing variational inference with an "implicit" IAF.

Practically, they serve complementary purposes:

  • MAF is optimized for density estimation. It can calculate the exact probability density $p(x)$ for a given datapoint in a single forward pass. However, generating a new sample is slow, requiring $D$ sequential passes for $D$ dimensions.
  • IAF is optimized for sampling. It can generate a new sample in one pass but takes $D$ passes to evaluate the density of an external datapoint.

Empirical Performance

The authors evaluated MAF on a variety of standard benchmarks to prove its general-purpose utility, including classic tabular datasets (POWER, GAS, HEPMASS, MINIBOONE) and image datasets (BSDS300, MNIST, CIFAR-10).

  • State-of-the-Art on Tabular Data: MAF outperformed the popular Real NVP model on all five benchmark datasets. It also consistently beat the base MADE model, proving that stacking layers is vastly superior to simply making a single layer wider or more complex.
  • Massive Gains from Conditioning: On the CIFAR-10 image dataset, MAF was tested on conditional density estimation (where the model is given the image's label, like "cat" or "car"). Its performance nearly doubled with labels, achieving results (2.98 bits/pixel) remarkably close to specialized architectures like PixelCNN++, despite MAF being a general-purpose model without built-in image priors.
  • Training Efficiency: Because it utilizes masking, MAF is significantly faster to train on modern GPUs than recurrent autoregressive models (like LSTMs), which are forced to process dimensions sequentially.

Limitations and Future Directions

While MAF is highly effective, it has notable limitations. The most prominent is the sampling bottleneck: while MAF is lightning-fast at calculating the likelihood of an image, it is painfully slow at generating a new one. For a $32 \times 32$ image, it requires 1,024 sequential passes to generate a single sample.

Additionally, in its vanilla form, MAF lacks spatial priors. It treats an image as a flat vector of numbers and does not inherently understand that neighboring pixels are strongly correlated.

Future work suggests exploring the "automatic discovery" of structure—allowing the model to learn the optimal way to group or order variables dynamically, rather than relying on fixed shuffles, and incorporating convolutional structures to improve efficiency on spatial data.

Summary updated

BibTeX
@inproceedings{papamakarios2017masked,
  author = {George Papamakarios and Iain Murray and Theo Pavlakou},
  title = {{Masked Autoregressive Flow for Density Estimation}},
  booktitle = {Advances in Neural Information Processing Systems},
  year = {2017},
  url = {https://openreview.net/forum?id=rkWLq8-uZH},
}
Figure