Level 0: Foundation
★☆☆☆☆ Introductory⏱ 5 minGeneral audience. No mathematics required.Predicting an image one pixel at a time
Imagine drawing a digit pixel by pixel, top-left to bottom-right, each time guessing the next pixel from the ones already drawn. Multiply all those guesses together and you get the exact probability of the whole picture. Autoregressive models do exactly this. NADE and MADE are two neural ways to make all the guesses at once during training, while making sure no guess peeks at pixels that come later. The demo shows which inputs each output of a masked network can see.
Autoregressive density models score each new telemetry frame or image patch exactly, and the same masked networks power the normalizing flows used for fast probabilistic surrogates.
- 1. An autoregressive model factorises p(x) by…
- 2. MADE prevents cheating with…
- 3. Sampling from an autoregressive model is…
Level 1: Beginner
★★☆☆☆ Basic⏱ 20 minSecondary-school mathematics: arithmetic and elementary algebra.By hand
- Chain rule: p(x) = Π_d p(x_d | x_before d) holds exactly for any ordering; each conditional is a small classifier (Bernoulli for binary pixels, softmax for 256 intensities).
- FVSBN / logistic autoregression (Frey, 1998): p(x_d = 1 | x_before d) = σ(b_d + Σ_(j< d) W_dj x_j); D(D−1)/2 + D parameters.
- NADE (Larochelle and Murray, 2011): h_d = σ(c + W_(:, < d) x_< d), p(x_d = 1 | …) = σ(b_d + V_d · h_d); W is shared across conditionals, and a_(d+1) = a_d + W_(:, d) x_d makes the whole density O(DH). RNADE (real-valued), DeepNADE and order-agnostic training (Uria et al., 2014–2016) followed.
- MADE (Germain et al., 2015): assign each hidden unit a degree m_k in 1..D−1; connect input j to k only if m_k ≥ j and k to output d only if d > m_k. Then output d depends only on inputs before d; all conditionals come from one autoencoder pass, on a GPU. Order- and connectivity-agnostic training resamples orderings and masks.
- Legacy (2026): MADE blocks are the conditioners of MAF and IAF normalizing flows; the same causal-masking idea is what makes GPT-style transformers autoregressive.
- 1. NADE shares…
- 2. In MADE, hidden unit k connects to output d if…
- 3. MADE blocks reappear in…
Level 2: Intermediate
★★★☆☆ Intermediate⏱ 25 minUndergraduate students and practising engineers.Masks, conditionals and likelihood
Exercise 1.
- Build MADE masks and check the connectivity matrix is strictly lower triangular.
- Compute all NADE conditionals with an exclusive cumulative sum.
- Sum the conditionals into an exact negative log-likelihood.
Practice.
- Implement masks as fixed tensors multiplied into the weights (or with a MaskedLinear layer).
- Verify autoregressiveness numerically: the Jacobian of output d with respect to input j must be zero for j ≥ d.
- Report test NLL in nats per image or bits per dimension.
- Sampling needs D sequential passes; cache activations to make each pass cheap.
- For continuous data, output mixture parameters per dimension (RNADE, MAF).
import torch, torch.nn as nn
class MaskedLinear(nn.Linear):
def __init__(self, d_in, d_out, mask):
super().__init__(d_in, d_out); self.register_buffer("mask", mask)
def forward(self, x): return nn.functional.linear(x, self.weight * self.mask, self.bias)
D, H = 64, 128
m = torch.randint(1, D, (H,)); d = torch.arange(1, D + 1)
net = nn.Sequential(MaskedLinear(D, H, (m[:, None] >= d[None]).float()), nn.ReLU(),
MaskedLinear(H, D, (d[:, None] > m[None]).float()))
loss = nn.functional.binary_cross_entropy_with_logits(net(x), x, reduction="sum") / len(x)- 1. Check autoregressiveness with…
- 2. Sampling D pixels needs…
- 3. Masks are applied by…
Level 3: Advanced
★★★★☆ Advanced⏱ 25 minGraduate level, with full derivations and proofs.Theory
Why the masks work. A path from input j to output d through hidden unit k exists only if m_k ≥ j and d > m_k, which together imply d > j. With several hidden layers, require m^(l)_k ≥ m^(l−1)_k’ for connections. The connectivity matrix M_out M_in counts paths and is strictly lower triangular.
NADE as a mean-field approximation. NADE was derived from an RBM: the conditional p(x_d | x_< d) of an RBM is intractable, and NADE replaces it by one mean-field step with tied weights, which gives h_d = σ(c + W_< d x_< d).
Cost. FVSBN has O(D²) parameters; NADE has O(DH) parameters and O(DH) cost per density evaluation; MADE has O(DH) parameters (per hidden layer) and one pass for all conditionals. All three need D sequential steps to sample.
Ordering. The likelihood is exact for any ordering, but how well a finite network models it depends on the ordering; order-agnostic training averages over orderings and allows ensembles at test time.
| model | parameters (D = 64) | density pass | sampling |
|---|---|---|---|
| FVSBN | 2080 | one | D steps |
| NADE, H = 16 | 2128 | O(DH) | D steps |
| MADE, H = 32 | 4192 | one | D steps |
- 1. A MADE path from j to d implies…
- 2. NADE was derived from…
- 3. Is the chain-rule likelihood exact for any ordering?
Level 4: Expert
★★★★★ Expert⏱ 30 minResearchers: original papers and open problems.How much do autoregressive conditionals gain over independent pixels, and do NADE’s and MADE’s hidden units add to plain logistic autoregression?
History.
- B. Frey, “Graphical models for machine learning and digital communication” (1998): fully visible sigmoid belief networks.
- H. Larochelle and I. Murray, “The neural autoregressive distribution estimator” (2011).
- M. Germain, K. Gregor, I. Murray and H. Larochelle, “MADE: masked autoencoder for distribution estimation” (2015).
- B. Uria et al., “Neural autoregressive distribution estimation” (JMLR 2016); G. Papamakarios et al., “Masked autoregressive flow” (2017).
Exercise 2. 2000 training and 1000 test binarised 8×8 seven-segment digits (width and position vary, 2% flipped pixels).
- Independent: one smoothed Bernoulli per pixel.
- FVSBN: logistic autoregression with a strictly lower-triangular weight matrix.
- NADE: 16 shared hidden units.
- MADE: one ReLU hidden layer of 32 or 128 units with random degrees, plus masked direct input→output connections as in Germain et al.
- Training: 400 Adam steps (lr 0.02, batch 50) for every model.
| model | test NLL (nats/image) | bits/pixel | train NLL |
|---|---|---|---|
| independent | 26.83 | 0.605 | – |
| FVSBN | 12.90 | 0.291 | – |
| NADE, H = 16 | 12.86 | 0.290 | – |
| MADE, H = 32 | 12.38 | 0.279 | 11.34 |
| MADE, H = 128 | 12.30 | 0.277 | 10.69 |
- Conditioning is what matters: logistic autoregression already halved the NLL of independent pixels.
- Hidden units added about 5%: MADE 12.30 vs FVSBN 12.90; NADE with 16 shared units matched FVSBN rather than beating it.
- Overfitting: the train–test gap grew from 1.0 to 1.6 nats as MADE went from 32 to 128 units on 2000 images.
- Samples: 200 ancestral samples from MADE had 14.8 lit pixels on average, against 14.7 in the data.
- Seeds 1 and 2: independent 26.94 and 27.11; FVSBN 12.97 and 12.97; NADE 12.87 and 12.89; MADE-128 12.36 and 12.28.
- Caveat: tiny images and short training; on binarised MNIST published NLLs are about 88 nats (NADE) and 86 nats (MADE ensembles) per 784-pixel image.
NADE and MADE in AI, robotics and aerospace
- Flows: MADE conditioners inside MAF and IAF give fast, exact densities for simulation-based inference of physical parameters.
- Tabular and sensor data: autoregressive density estimators score multichannel telemetry for anomalies.
- Language models: causal masking in transformers is the same idea at scale.
References
- H. Larochelle and I. Murray (2011). “The neural autoregressive distribution estimator.” AISTATS.
- M. Germain, K. Gregor, I. Murray and H. Larochelle (2015). “MADE: masked autoencoder for distribution estimation.” ICML.
- B. Uria, M.-A. Côté, K. Gregor, I. Murray and H. Larochelle (2016). “Neural autoregressive distribution estimation.” JMLR.
- G. Papamakarios, T. Pavlakou and I. Murray (2017). “Masked autoregressive flow for density estimation.” NeurIPS.