# API Reference

`gauss_flows` is a [JAX](https://docs.jax.dev/) / [FlowJax](https://github.com/danielward27/flowjax)
toolkit for **Gaussianization flows** — normalizing flows that iteratively map data to a
standard normal by alternating marginal CDF transforms with learned rotations (the RBIG
pattern), together with the [SurVAE](https://arxiv.org/abs/2007.02731) hierarchy of
bijections, surjections, and stochastic transforms, and the information-theoretic measures
those flows unlock. It ships as two packages of one uv workspace: `gauss-flows-maps` (import `gauss_flows_maps`), the invertible and conditioned maps, and `gauss-flows-models` (import `gauss_flows_models`), the flows, filters, distributions and measures built on them. The reference is organised by theme rather than dumped as one flat page,
and the [capability index](capabilities.md) lists every public name on one page, with a
one-line summary each, followed by the public API of the libraries gauss_flows builds on:

| Section | What's inside |
|---------|---------------|
| [Bijections](bijections.md) | `gauss_flows_maps.bijections` and `.conditioning`: exactly-invertible transforms — coupling, marginal CDFs, linear/rotation, normalisation, periodic and classic residual layers — and the conditioner; FFJORD is in `gauss_flows_models.flows` |
| [Conditioners](conditioning.md) | `gauss_flows_maps.conditioning`: the conditioners `c(h, z) -> y` shared by conditional flows and conditioned neural fields: `ConcatConditioner`, `AffineModulation` (FiLM) and `HyperLinear` |
| [Surjections & Stochastic](surjections.md) | `gauss_flows_maps.surjections`: deterministic surjections (abs, sort, max-pool, augment/slice) and stochastic transforms (VAE, permutation) with lower-bound likelihoods |
| [Monotone inverses](monotone.md) | `gauss_flows_maps.monotone`: `monotone_inverse`, the bracketed inverse of an elementwise increasing function (a mixture-CDF quantile, a flow transformer), and the `Chandrupatla` root finder it uses by default |
| [Reparametrisations](reparam.md) | `gauss_flows_maps.reparam`: constrained parameters x = g(u) (exp, softplus and sigmoid with bounds, compositions, Cholesky factors, simplex weights) and their `paramax.Parameterize` leaves |
| [Base Distributions](distributions.md) | `gauss_flows_models.distributions`: latent distributions for the flow base — Gaussian mixtures, low-rank PCA Gaussian, conditional/class-conditional diagonals, and manifold (sphere) distributions |
| [Flows & RBIG](flows.md) | `gauss_flows_models.flows` and `.filters`: flow containers (`SurVAEFlow`) and one-call factories — `gaussianization_flow`, `coupling_gaussianization_flow`, `iterative_rbig`, plus the `fit_rbig` warm-start |
| [Training](inference.md) | `gauss_flows_models.inference`: the `negative_log_likelihood` loss and the `fit_gaussianization_flow` loop (the NumPyro bridges live in pyrox-flows) |
| [Information Theory](info_theory.md) | `gauss_flows_models.info_theory`: entropy, total correlation, mutual information, KL, negentropy — Monte-Carlo (flow-based), analytical Gaussian closed forms, and RBIG-way reductions |

## Conventions

A few patterns hold across the whole package:

- **Built on FlowJax.** Every bijection subclasses
  [`flowjax.bijections.AbstractBijection`](https://danielward27.github.io/flowjax/);
  base distributions subclass `flowjax`/`equinox` modules. Compose transforms with
  FlowJax [`Chain`](https://danielward27.github.io/flowjax/) / `Scan` and wrap them with
  [`Transformed`](https://danielward27.github.io/flowjax/) — or use the package's
  `SurVAEFlow` container when a chain mixes surjections and stochastic steps.

- **Single-event, not batched.** Transform methods
  (`transform_and_log_det` / `inverse_and_log_det` / `forward_and_log_det`) assume
  `x.shape == self.shape` and return a **scalar** `log_det`. Vectorise over a batch with
  [`jax.vmap`](https://docs.jax.dev/en/latest/_autosummary/jax.vmap.html) /
  `eqx.filter_vmap`; the `SurVAEFlow` container already vmaps `log_prob` / `sample` over
  any leading `sample_shape`. This matches the FlowJax convention, which runtime-enforces
  `x.shape == bijection.shape`.

    ```python
    import jax, jax.numpy as jnp, jax.random as jr
    from gauss_flows_maps.bijections import MixtureGaussianCDF

    t = MixtureGaussianCDF(n_components=8, shape=(4,))
    x = jr.normal(jr.key(0), (4,))          # one event, shape == t.shape
    y, log_det = t.transform_and_log_det(x)  # y: (4,), log_det: scalar

    xs = jr.normal(jr.key(1), (32, 4))       # a batch
    ys, log_dets = jax.vmap(t.transform_and_log_det)(xs)  # (32, 4), (32,)
    ```

- **Immutable Equinox modules.** Transforms and distributions are
  [`equinox.Module`](https://docs.kidger.site/equinox/) pytrees — immutable, JIT/grad/vmap
  friendly. Trainable parameters are array leaves; filter them with
  `eqx.filter(model, eqx.is_inexact_array)` when building an optimiser. Constructors that
  draw random weights take a `key` (`jax.random.PRNGKey`/`jax.random.key`).

- **Unicode math in docstrings.** Docstrings use mathematical Unicode freely
  (`−`, `×`, `σ`, `ℝ`, `∑`) — `RUF002` is ignored project-wide for this reason. Public
  transforms and distributions document a **Shape:** section (per-method input/output
  shapes, single-event convention) and a runnable **Example:** block.

Every public name is reached through its module (`gauss_flows_maps.bijections.AffineCoupling`, `gauss_flows_models.flows.gaussianization_flow`); never import from the internal `_src/` paths.

## Package overview

::: gauss_flows_maps
    options:
      members: false
      show_root_heading: false
      show_source: false

::: gauss_flows_models
    options:
      members: false
      show_root_heading: false
      show_source: false
