---
title: Conditional Normalizing Flows (CNFs)
url: https://www.emergentmind.com/topics/conditional-normalizing-flows-cnfs
type: topic
---

# Conditional Normalizing Flows (CNFs)

Conditional Normalizing Flows (CNFs) are deep generative models that define families of invertible, flexible maps between simple latent distributions and complex high-dimensional conditional target distributions. By directly parameterizing the change-of-variables between observed variables and a tractable base density, CNFs enable efficient likelihood-based modeling of conditional distributions $p(x|c)$, where $x$ is the target variable and $c$ is a context or conditioning variable. CNFs have become prominent in applications that require calibrated conditional uncertainty quantification, sample efficiency, and the ability to handle highly non-Gaussian or multi-modal posteriors.

## 1. Mathematical Foundations of Conditional Normalizing Flows

Let $x \in \mathcal{X}$ denote the target variable, and $c \in \mathcal{C}$ the conditioning variable. A conditional normalizing flow defines a smooth, invertible mapping
\[
z = f_\theta(x; c)
\]
from $x$ to a latent variable $z$ with a simple, tractable conditional base distribution $p_z(z|c)$. The density $p(x|c)$ is given by the change-of-variables formula:
\[
p(x|c) = p_z(f_\theta(x; c) \mid c) \, \left| \det \left[ \partial_x f_\theta(x; c) \right] \right|
\]
The context $c$ can represent class labels, temporal histories, raw detector readouts, or arbitrary high-dimensional side information.

For Euclidean targets, $p_z(z|c)$ is typically a standard Gaussian; for manifold-valued variables (e.g., directions on the sphere $S^2$), $p_z(z|c)$ may be a uniform or Fisher–von Mises distribution, with the flow parameterized to preserve manifold structure [2309.16380].

Maximum-likelihood training minimizes the expected negative log-likelihood over a dataset $\{(x^{(i)}, c^{(i)})\}$:
\[
L(\theta) = -\mathbb{E}_{(x, c)} \Big[ \log p_z(f_\theta(x; c) \mid c) + \log \left| \det \partial_x f_\theta(x; c) \right| \Big]
\]
Gradient-based optimization and mini-batch training are standard.

## 2. Architectural Variants and Conditioning Mechanisms

CNFs’ expressivity derives from the architecture of the invertible map and the treatment of conditioning:

- **Affine Coupling and Gaussianization Flows:** Typical 1D and low-dimensional flows are constructed by stacking invertible affine-coupling or specialized Gaussianization blocks, with scale/shift parameters produced by conditioning networks [2309.16380].
- **Continuous-Time CNFs:** In high-dimensional or continuous settings, the flow is realized via a Neural ODE whose dynamics are parameterized as $dz/dt = f(z, t; c, \theta)$, with conditioning $c$ injected via, e.g., small neural networks [2106.08462].
- **Graph Neural Network Conditioners:** When context has a non-trivial geometric or relational structure (e.g., IceCube detector modules), graph neural networks process $c$ and emit layerwise flow parameters [2309.16380].
- **Hierarchical/Residual Structures:** For robustness and capacity, multi-resolution CNFs decompose the modeling task into hierarchical scales, factorizing the target as products of conditional flows between coarse and fine information [2106.08462].
- **Mixture/Factorization Methods:** In settings with extremely high-dimensional $c$, hierarchical or soft-gated mixture-of-experts parameterizations are employed to prevent overfitting and promote statistical efficiency [2107.12825].

Table: CNF Conditioning Mechanisms (selected settings)

| Context Structure         | Conditioning Architecture              |
|--------------------------|----------------------------------------|
| Tabular, vectors         | MLP, feature concatenation             |
| Spatial/temporal grids   | CNN/Transformer/State-space model      |
| Graphs                   | GNN-based per-layer parameterization   |
| Survival/covariates      | Softmax-gated vector fields (ODE flows)|

## 3. Training Methodologies and Likelihood Objectives

Across applications, CNFs are trained by exact or approximate maximization of the conditional log-likelihood

Source: https://www.emergentmind.com/topics/conditional-normalizing-flows-cnfs