Overview
Standard Variational Autoencoders are expressive generative models, but they suffer from a fundamental statistical weakness: their latent representations are not identifiable. In practice, many different latent spaces can produce the same data distribution, meaning the model has no way to pin down which latent structure is the “true” one. This ambiguity makes it impossible to reliably recover the underlying factors of variation, which is precisely what causal inference and disentanglement require.
Identifiable VAEs (iVAEs), introduced by Khemakhem et al. (2020), solve this problem by conditioning the latent prior on an observed auxiliary variable \(u\) — for example, a class label, a time index, or an experimental context. This single change is enough to break the symmetry that causes non-identifiability, and the authors prove rigorously that the resulting model can recover the true latent factors up to a simple coordinate-wise transformation (permutation and element-wise rescaling). In effect, iVAEs bridge deep generative modelling with nonlinear Independent Component Analysis (ICA), inheriting the theoretical guarantees of the latter.
For causal inference, identifiability matters because estimating treatment effects requires that the latent representation capture the correct confounding structure — not just a representation that happens to fit the data. iVAEs provide that assurance.
Where iVAE Fits: CEVAE, iVAE, and CausalVAE Compared
These three notebooks collectively cover the main families of deep generative models for causal inference. They share the VAE backbone but make fundamentally different assumptions about the latent space, and each is the right tool in a different setting. The table below places iVAE in that landscape before we dive into its architecture.
| CEVAE |
Independent \(z\); \(x\) are noisy proxies |
Latent confounder recovered from proxy covariates |
Ignorability holds in latent space |
Settings where the true confounders are unobserved but leave a measurable trace in \(x\) |
| iVAE |
Independent \(z\); prior conditioned on \(u\) |
Identifiable latent factors anchored by an auxiliary variable |
Sufficient variation in \(u\); injective decoder |
Settings where an observed context variable (label, time, environment) can anchor the latent space |
| CausalVAE |
DAG over \(z\); \(\varepsilon\) are independent exogenous noises |
Causal graph and structural equations jointly |
DAG is acyclic; weak supervision on graph structure |
Settings where the causal relationships among latent factors need to be modelled and intervened on |
The key conceptual distinction is what each model treats as the source of non-identifiability and how it resolves it:
- CEVAE resolves confounding by inferring a latent common cause from proxy measurements. It does not attempt to make \(z\) identifiable in the ICA sense — it is concerned with removing bias, not with uniquely pinning down the latent axes.
- iVAE resolves rotational non-identifiability by conditioning the prior on \(u\), giving the latent axes fixed reference points. Each component of \(z\) is independently recoverable, but \(z\) carries no explicit causal graph.
- CausalVAE goes further and represents the causal structure among the latent components explicitly as a DAG, enabling do-calculus interventions directly in the latent space. This is the most expressive but also the most demanding in terms of supervision and identifiability requirements.
Reading these three notebooks in sequence — CEVAE → iVAE → CausalVAE — traces a progression from bias removal to identifiable representation to explicit causal structure.
Model Architecture
The iVAE extends the standard VAE by introducing a conditional prior \(p(z \mid u)\) in place of the fixed standard Gaussian prior \(\mathcal{N}(0, I)\). Every component of the model is described below.
Encoder \(q(z \mid x, u)\)
Unlike the standard VAE encoder which sees only \(x\), the iVAE encoder receives both \(x\) and \(u\). It passes them through shared hidden layers and outputs two parameter vectors:
- \(\mu\) — the mean of the approximate posterior.
- \(\log\sigma^2\) — the log-variance of the approximate posterior.
Together, these define the distribution \(q(z \mid x, u) = \mathcal{N}(\mu(x,u),\, \text{diag}(\sigma^2(x,u)))\), a Gaussian whose location and spread depend on the full observed context.
Conditional Prior \(p(z \mid u)\)
This is the architectural innovation that drives identifiability. In a standard VAE the prior \(\mathcal{N}(0,I)\) is completely static — it carries no information about what the data actually is. In the iVAE, a small neural network \(g(u)\) maps the auxiliary variable to a context-specific prior mean:
\[p(z \mid u) = \mathcal{N}(g(u),\, I)\]
Because the prior now shifts as \(u\) changes, different segments of the data are anchored to different regions of the latent space. This is what prevents the latent axes from rotating freely and what ultimately enables identifiability.
In the fully general treatment (Khemakhem et al., 2020) the prior belongs to the exponential family:
\[p(z_i \mid u) = \exp\!\bigl(T_i(z_i) \cdot \lambda_i(u) - \log A(\lambda_i(u))\bigr)\]
where \(T_i(z_i)\) are sufficient statistics and \(\lambda_i(u)\) are natural parameters that vary with \(u\). The Gaussian formulation above is the special case used in most practical implementations, including the one in this notebook.
Reparameterization
To allow gradients to flow through the stochastic sampling step, the model uses the standard reparameterization trick:
\[z = \mu + \sigma \odot \varepsilon, \qquad \varepsilon \sim \mathcal{N}(0, I)\]
This expresses the random sample as a deterministic function of the distributional parameters plus independent noise, making backpropagation through \(z\) straightforward.
Decoder \(p(x \mid z)\)
The decoder maps the latent code \(z\) back to data space to produce a reconstruction \(\hat{x}\). Crucially, the decoder does not see \(u\). All information needed to reconstruct \(x\) must pass through \(z\). This architectural constraint forces the encoder to compress everything about \(x\) that is not already explained by the conditional prior into the latent code.
Loss Function
The iVAE is trained by maximizing the following Evidence Lower Bound (ELBO):
\[\mathcal{L}_{\text{iVAE}} = \mathbb{E}_{q(z \mid x, u)}\!\bigl[\log p(x \mid z)\bigr] - D_{\mathrm{KL}}\!\bigl(q(z \mid x, u) \,\|\, p(z \mid u)\bigr)\]
Comparing this with the standard VAE objective:
\[\mathcal{L}_{\text{VAE}} = \mathbb{E}_{q(z \mid x)}\!\bigl[\log p(x \mid z)\bigr] - D_{\mathrm{KL}}\!\bigl(q(z \mid x) \,\|\, \mathcal{N}(0, I)\bigr)\]
the difference is entirely in the KL term. In the iVAE, the encoder posterior is compared against the context-specific prior \(p(z \mid u)\) rather than a fixed zero-mean Gaussian. This forces latent codes belonging to the same context \(u\) to cluster around the prior mean \(g(u)\), creating distinct, anchored regions in latent space for each value of \(u\).
The reconstruction term is unchanged: it measures how faithfully the decoder recovers \(x\) from \(z\).