Monotone maps in functax: inverses and rational-quadratic splines for gauss_flows
Design · functax, gauss_flows and flowjax
1 Dec 2026 · draft for review
Status: open questions decided 1 Dec 2026; issues not yet filed
Updated 1 Dec 2026. Under the gauss_flows layout, the histogram, spline and mixture-CDF bijections and
monotone_inverselive ingauss-flows-maps(Core, tier 1), which may import functax (tier 0). functax’s part of this page is unchanged.
Repositories: functax (monotone interpolants, their inverse, the rational-quadratic scheme), gauss_flows (flowjax shells), flowjax (no longer used for splines)
Companion pages: gauss_flows reparametrisation (its positive maps parameterise the spline slopes here), gauss_flows conditioning and gauss_flows Gaussians (the root-finder move, argminax#110, that the mixture CDFs use).
Related: gauss_flows#162 (
HistogramCDF’s workarounds), gauss_flows#114 (a faster mixture-CDF inverse), functax#115 (gaps the Wave 5 consumers found), gauss_flows#166 (filed as argminax#110) (monotone_inverse)
1Decision¶
Recommended: functax owns monotone one-dimensional maps.
Its 1-D interpolants that are monotone by construction (Linear on increasing data, Pchip, Steffen) gain an exact inverse, and a new RationalQuadratic series scheme gives the spline that neural spline flows use, with a closed-form inverse.
A series interpolant can also be built from given values and slopes, which is how a flow parameterises a spline.
gauss_flows keeps flowjax shells: HistogramCDF inverts its forward interpolant instead of fitting a second one, and its rational-quadratic splines (marginal, coupling and circular) are built on functax instead of flowjax.
The mixture CDFs stay in gauss_flows; their inverse uses monotone_inverse from gauss-flows-maps once gauss_flows#166 (filed as argminax#110) (re-aimed there by the gauss_flows layout) lands, because a mixture CDF is not an interpolant.
What does not change: functax’s forward reads, plans and derivatives; gauss_flows’s public bijection names and their flowjax API.
Alternative: leave splines with flowjax and only fix HistogramCDF’s inverse.
It is smaller, but it keeps two spline families with two conventions for the slopes, the tails and the inverse.
| Map | Owner today | Owner after |
|---|---|---|
| Histogram CDF and its inverse | functax forward, swapped refit | functax forward and inverse |
| Rational-quadratic spline | flowjax | functax |
| Mixture CDF | gauss_flows | gauss-flows-maps, forward and inverse |
| Deep-sigmoid transformer | gauss_flows | gauss_flows |
2Motivation¶
functax’s interpolants have no inverse, so HistogramCDF fits a second one. HistogramCDF builds its forward CDF F as a functax Linear or Pchip interpolant through (x_k, F_k), and its inverse as a second interpolant of the same scheme through (F_k, x_k) (_interpolants in elementwise/histogram.py). For Linear the swapped interpolant is the exact inverse. For Pchip it is not: the inverse of a cubic is not a cubic, and the class docstring says the round trip is approximate (about 1e-5). The swapped fit also needs strictly increasing CDF values, so the class lowers repeated values one ulp at a time (gauss_flows#162 measured that removing the nudge changes 17 of 1000 round-trip rows, all at u > 0.986, by up to 0.017 in x).
The splines come from a second library. RQSplineMarginal, RQSplineCoupling and CircularRationalQuadraticSpline wrap flowjax’s RationalQuadraticSpline (flowjax 19.1.1), with its own conventions: softmax-normalised widths and heights, slopes as softplus plus a 10⁻³ floor, and the identity outside a fixed interval. The circular spline reaches into flowjax’s parameter wrapper to tie its end slopes.
functax already stores the Hermite form these maps need. A functax SeriesInterpolant keeps its coefficients as c = [y; d], the values and the slopes at the knots, and reads a cubic Hermite piece per cell; derivative() reads its slope in closed form (functax#116, closed). Monotone slopes come from pchip_slopes and steffen_slopes. A rational-quadratic piece is the same data with a different read-out, and an inverse is a per-cell solve on data functax already holds.
functax cannot borrow the maps package’s root finder, and does not need to. functax is Core tier 0 and gauss-flows-maps tier 1, so functax may not import monotone_inverse. A monotone interpolant does not need a general root finder: the cell that holds a target value is found by the same search a forward read uses, and inside the cell the equation is linear, quadratic (rational-quadratic) or cubic (Hermite) in one variable on [0, 1].
3User stories¶
As a flow author, I want the inverse of a monotone interpolant to be exact, so that a histogram or spline marginal round-trips to solver precision and its log-determinants cancel.
As a flow author, I want one rational-quadratic spline with the same knots, slopes, tails and derivative read-out as functax’s other schemes, so that a marginal, a coupling and a circular spline share one implementation.
As a user of functax outside flows, I want to invert a monotone interpolant, for example to read the height of a hypsometric curve at a given area or a quantile of an empirical CDF, so that I do not refit the data with its axes swapped.
4Background maths¶
Symbols¶
Knots x_0 < x_1 < … < x_N carry values y_0 < y_1 < … < y_N and slopes d_0, …, d_N, all positive. Cell k is [x_k, x_(k+1)], with width w_k = x_(k+1) − x_k, rise h_k = y_(k+1) − y_k and secant s_k = h_k / w_k. Inside cell k the local coordinate is ξ = (x − x_k) / w_k ∈ [0, 1], and the read-out is y = f(x) = y_k + h_k g_k(ξ) with g_k(0) = 0 and g_k(1) = 1.
The inverse of a monotone piecewise map¶
For a target value v ∈ [y_0, y_N], the inverse finds the cell k with y_k ≤ v ≤ y_(k+1), by the same sorted search a forward read uses on the knots, now on the values. It then solves g_k(ξ) = (v − y_k) / h_k for ξ ∈ [0, 1] and returns x = x_k + w_k ξ. Because the map is increasing, the solution is unique, and its derivative is the reciprocal slope:
The cell equation depends on the scheme:
| Scheme | g_k(ξ) | Inverse in the cell |
|---|---|---|
Linear | ξ | ξ = (v − y_k)/h_k |
RationalQuadratic | rational quadratic | root of a quadratic |
Pchip, Steffen | cubic Hermite | root of a cubic on [0, 1] |
Cubic Hermite. With the Hermite basis h₀₀ = 2ξ³ − 3ξ² + 1, h₁₀ = ξ³ − 2ξ² + ξ, h₀₁ = −2ξ³ + 3ξ² and h₁₁ = ξ³ − ξ², the piece is y = h₀₀ y_k + h₁₀ w_k d_k + h₀₁ y_(k+1) + h₁₁ w_k d_(k+1). The Fritsch–Carlson [1] and Steffen [2] slopes make it increasing on every cell where h_k > 0, so the cubic has one root in [0, 1]. It is found by a fixed number of Newton steps safeguarded by bisection on the bracket [0, 1], which converges quadratically near the root and never leaves the bracket.
The rational-quadratic spline¶
The monotone rational-quadratic spline of Gregory and Delbourgo [3], as used by neural spline flows [4], reads on cell k
with derivative
It is increasing on the cell for any positive d_k and d_(k+1). Its inverse at a value v in the cell is the root in [0, 1] of a ξ² + b ξ + c = 0, with δ = d_(k+1) + d_k − 2 s_k,
taken as ξ = 2c / (−b − √(b² − 4ac)), the form that avoids cancellation [4].
Tails. Outside [x_0, x_N] a flow needs the map to stay a bijection of ℝ. Neural spline flows use linear tails with slope 1 and d_0 = d_N = 1, which make the map the identity outside the interval and C¹ at its ends.
Circular splines. On a circle of period P = x_N − x_0, with y_N − y_0 = P and tied end slopes d_0 = d_N, the spline is C¹ across the wrap point [5]. functax’s periodic Axis already wraps its cells.
Mixture CDFs are not interpolants¶
A mixture CDF F(x) = Σ_m w_m Φ((x − μ_m)/σ_m) has no knots and no per-cell form, so it stays in gauss_flows. Its inverse is a bracketed root find on an increasing function, which is what monotone_inverse in gauss-flows-maps does (gauss_flows#166 (filed as argminax#110), re-aimed).
5Background numerics¶
Precision. The rational-quadratic inverse is closed form and keeps full precision in float64. The cubic inverse runs a fixed number of safeguarded Newton steps (a static count, about 8, to be set by gate M-G1); each step at least halves the bracket, so about 52 steps would reach float64’s spacing on [0, 1] by bisection alone, and Newton reaches it in far fewer near the root.
Gradients. The inverse is defined with jax.custom_jvp: its tangent with respect to v is 1/f′ at the root, and with respect to the knots, values and slopes it follows from differentiating f(f⁻¹(v)) = v. No gradient flows through the Newton iterations.
Flat cells. A Pchip or Steffen cell with h_k = 0 is flat, so its inverse is not unique and 1/f′ is infinite. inverse requires strictly increasing values (decided, GM-O2).
jit and vmap. The cell search and the cell solve are array operations with static loop counts, so inverse is traceable and batches over targets and over a leading batch of fields, as the forward read does.
6What it builds on¶
| Need | Upstream name | State on main |
|---|---|---|
| Hermite coefficients c = [y; d] | functax.interp.SeriesInterpolant | today (functax v0.0.15) |
| Monotone slopes | Pchip, Steffen (pchip_slopes, steffen_slopes) | today (functax v0.0.15) |
| Closed-form derivative read-out | SeriesInterpolant.derivative, Interpolant.derivative | today (functax v0.0.15) |
| Sorted cell search | functax.interp.locate | today (functax v0.0.15) |
| Periodic knots | functax.geometry.Axis (periodic) | today (functax v0.0.15) |
| Positive slopes from raw values | gauss_flows_maps.reparam.Reparametrised("softplus", lower=…) | today; log-value proposed (gauss_flows reparametrisation, R1) |
| Mixture-CDF inverse | gauss_flows_maps.monotone.monotone_inverse | proposed (gauss_flows#166 (filed as argminax#110)) |
| Flow shells | flowjax.bijections.AbstractBijection | today (flowjax) |
7Ownership¶
functax owns monotone 1-D interpolants: their forward read, derivative, inverse, the rational-quadratic scheme, and building a series interpolant from given slopes. It imports nothing from
gauss-flows-maps, flowjax or argminax.gauss-flows-mapsowns the flowjax shells, which are ⓪ structures on the role ladder (gauss_flows layout): how raw network outputs become knots, values and slopes (softmax widths and heights, positive slopes, tails), the log-determinant as the sum of log f′, the fitting ofHistogramCDFfrom data, and the mixture CDFs. It stops importingflowjax.bijections.RationalQuadraticSpline.gauss-flows-mapsalso owns the general bracketed inverse used for mixture CDFs (gauss_flows#166 (filed as argminax#110), re-aimed there).
8API proposal¶
functax.interp¶
class SeriesInterpolant(eqx.Module):
...
def inverse(self, values: Float[Array, "*target"]) -> Float[Array, "*target"]:
"""x with f(x) = v, for a 1-D field whose scheme is monotone and whose data increase."""
class Interpolant(eqx.Module):
...
def inverse(self, values: Float[Array, "*target"]) -> Float[Array, "*target"]:
"""The same, for a 1-D `Linear` field."""
class SeriesScheme(Scheme):
...
def from_slopes(self, axis: Axis, values: Float[Array, "*batch node"],
slopes: Float[Array, "*batch node"], *,
policies: Policies = Policies()) -> SeriesInterpolant:
"""A field with the given slopes, instead of slopes from the scheme's rule."""
class RationalQuadratic(SeriesScheme):
"""Monotone rational-quadratic read-out (Gregory and Delbourgo, 1982).
`fit` takes its slopes from Steffen's rule; `from_slopes` takes any positive slopes.
"""inverse raises ValidationError for a scheme that is not monotone by construction (Cubic, CubicSpline, Akima, BSpline) and for data that do not strictly increase where that can be checked on the host.
Outside [y_0, y_N] it follows the field’s outside policy: "nan", "clamp" and "raise" as for a forward read, and "extrapolate" inverts the end piece’s continuation, which is linear for Linear and for RationalQuadratic with linear tails and is refused for the cubic schemes.
gauss_flows¶
HistogramCDF keeps one functax interpolant per dimension and reads its inverse with inverse; _strictly_increasing and the swapped fit go, and the density reads derivative() instead of jax.grad of the read-out.
A small scalar transformer replaces flowjax’s spline inside the three spline bijections:
class RationalQuadraticTransformer(AbstractBijection):
"""Scalar RQ spline on [−B, B] with identity tails, built on functax.RationalQuadratic."""
raw_widths: Float[Array, " K"]
raw_heights: Float[Array, " K"]
raw_slopes: Float[Array, " K_minus_1"]
bound: float = eqx.field(static=True)
min_slope: float = eqx.field(static=True)
periodic: bool = eqx.field(static=True)
def _interpolant(self) -> SeriesInterpolant:
"""Knots from softmax widths, values from softmax heights, slopes from a positive map."""
def transform_and_log_det(self, x, condition=None):
"""f(x) and log f′(x) from the interpolant; identity outside [−B, B]."""
def inverse_and_log_det(self, y, condition=None):
"""interpolant.inverse(y) and −log f′ at it."""Its array leaves are the raw parameters, so flowjax’s Coupling can still ravel them and have a conditioner predict them. RQSplineMarginal, RQSplineCoupling and CircularRationalQuadraticSpline keep their names and constructors and use it; the circular one sets periodic=True and ties its end slopes.
MixtureGaussianCDF and MixtureLogisticCDF replace gauss_flows’s bisection_inverse helper with monotone_inverse from the same package (see the gauss_flows Gaussians page and gauss_flows#114).
9API usage examples¶
The running example is the marginal of a retrieval residual, an empirical CDF on 64 bins, and an 8-bin spline marginal on [−5, 5]. The markers name the issues under Follow-up issues.
import jax.numpy as jnp
import jax.random as jr
from functax.geometry import Axis
from functax.interp import Pchip, RationalQuadratic
# Shapes: N = 65 knots; K = 8 spline cells; T = 1000 targets
# today (functax)
# F through the empirical CDF knots (x_k, F_k)
# (N,), (N,) → field
cdf = Pchip().fit(Axis(bin_edges), cdf_values)
# proposed (M1)
# x = F⁻¹(u), exact up to the cell solve
# (T,) → (T,)
x_back = cdf.inverse(u)
# proposed (M2)
# a spline with given knots, values and positive slopes; identity slope at the ends
# (K + 1,), (K + 1,), (K + 1,) → field
spline = RationalQuadratic().from_slopes(Axis(knots), values, slopes)
# proposed (M2)
# y = f(x), f′(x) and x = f⁻¹(y), all closed form
# (T,) → (T,)
y = spline(x[:, None])
slope = spline.derivative()(x[:, None])
x_again = spline.inverse(y)bin_edges, cdf_values, u, knots, values, slopes and x are user arrays of the shapes in the header.
10Gates¶
| Gate | Passes when |
|---|---|
| M-G1 round trip | f⁻¹(f(x)) = x to 1e-12 in float64 |
| M-G2 gradients | ∂f⁻¹/∂v = 1/f′; data gradients match differences |
| M-G3 flowjax oracle | equals flowjax’s RQ spline to 1e-6 in float32 |
| M-G4 transforms | eager, jit and vmap agree |
| M-G5 histogram | HistogramCDF round trip to 1e-5 in float32, every row |
| M-G6 cost | inverse within 3× a forward read |
| M-G7 flows | gauss_flows spline tests pass with unchanged tolerances |
M-G1 round trip. For Linear, Pchip, Steffen and RationalQuadratic on hypothesis-generated strictly increasing data (2 to 200 knots, values spanning 10⁻³ to 10³), f⁻¹(f(x)) = x and f(f⁻¹(v)) = v to 1e-12 relative in float64, at targets inside cells and exactly at knots. The fixed Newton count for the cubic schemes is the smallest that passes.
M-G2 gradients. jax.grad of inverse with respect to v equals 1/f′ to 1e-10, and its gradient with respect to the values and slopes matches central differences (functax’s jacrev against differences test).
M-G3 flowjax oracle. With flowjax’s parameterisation (softmax widths and heights, softplus slopes with a 10⁻³ floor, interval [−5, 5]) mapped onto RationalQuadratic.from_slopes, the forward value, the log-derivative and the inverse equal flowjax’s RationalQuadraticSpline to 1e-6 in float32 on 10⁴ points inside and outside the interval.
M-G4 transforms. inverse gives the same result eager, under jit and under vmap over targets and over a batch of fields, as a Python loop.
M-G5 histogram. HistogramCDF(method="monotonic") on the 1000-row fixture of tests/test_transforms_histogram_cdf.py round-trips every row to 1e-5 in float32, including the rows at u > 0.986 that gauss_flows#162 found.
M-G6 cost. At 10⁶ targets on a 1000-knot Pchip field, the jitted inverse takes at most 3 times the jitted forward read, after warm-up (the 3 is an estimate for a few Newton steps per target).
M-G7 flows. gauss_flows’s spline, coupling and circular-spline tests pass on the functax implementation with their tolerances unchanged, and the notebooks that use splines (07_global_flow_sphere.ipynb, 08_conditional_flow_three_ways.ipynb and torus_circular_flow.ipynb) rerun with final negative log-likelihoods within 1% of main’s (an estimate of run-to-run noise).
11Risks¶
The cubic inverse is slow in float32 near flat cells. A nearly flat Pchip cell has a tiny slope, so Newton steps are large and bisection takes over. Fallback: raise the fixed step count for float32, or use the closed-form cubic root for such cells.
flowjax’s spline has behaviour users rely on. Its softmax adjustment and tail conventions shape trained models. Mitigation: gate M-G3 matches it to float32 precision before the switch; trained checkpoints are not portable across the switch, and the changelog says so.
functax’s API rules. functax keeps one parameterisation per module and puts updates behind
with_*methods. Mitigation:from_slopesreturns an ordinarySeriesInterpolant, so no new module type appears; the flow-specific parameterisation (softmax, positive maps) stays in gauss_flows.The slope map’s log-value is not shipped yet. The transformer’s slopes are
Reparametrised("softplus", lower=min_slope), whose forward and inverse argminax has today; the map moves togauss-flows-maps, and itslog_valuewaits for R1 on the gauss_flows reparametrisation page. Fallback: take the log offorwarduntil R1 lands.
12Follow-up issues¶
Filed on 1 Dec 2026: the draft IDs below map to issue numbers in the Filed issues table of the gauss_flows layout page.
Each issue is written to be self-contained when filed. The epic lives in gauss_flows (GM-O4), with M1 and M2 as cross-repo sub-issues.
| ID | Repo | Title |
|---|---|---|
| E | gauss_flows | [EPIC] gauss_flows's elementwise bijections build on functax's monotone maps |
| M1 | functax | feat(interp): inverse of monotone 1-D interpolants (Linear, Pchip, Steffen) |
| M2 | functax | feat(interp): RationalQuadratic, a monotone series scheme with a closed-form inverse, and from_slopes |
| N1 | gauss_flows (maps) | gauss_flows#162: transforms: HistogramCDF inverts its forward interpolant exactly, with no workarounds |
| N2 | gauss_flows (maps) | transforms: rational-quadratic splines on functax instead of flowjax |
| N3 | gauss_flows (maps) | gauss_flows#114: transforms: mixture-CDF inverses through monotone_inverse, from a tight per-dimension bracket |
Order. M1 and M2 run in parallel in functax and ship in one functax release. N1 needs M1, N2 needs M2 (and uses the gauss_flows reparametrisation page’s R1 when it has landed), and N3 needs gauss_flows#166 only. N1 to N3 run in parallel in gauss-flows-maps.
Existing issues. N1 covers both workarounds of gauss_flows#162: the density read moves to derivative() (its blocker functax#116 is closed), and the repeated-knots nudge disappears because no swapped interpolant is fitted. #162 was rewritten in place as N1 on 1 Dec 2026. N3 is gauss_flows#114, rewritten in place the same day to call monotone_inverse instead of writing its own Newton loop. Both are sub-issues of the monotone maps epic gauss_flows#171.
13Open questions¶
All four questions were decided on 1 Dec 2026, as recommended, and the page follows them.
GM-O1. Safeguarded Newton or the closed-form cubic root for the Hermite inverse? Decided: safeguarded Newton with a fixed step count, because Cardano’s formula loses precision in float32 when the cubic is nearly quadratic or nearly linear.
GM-O2. What should
inversedo on a flat cell? Decided: require strictly increasing values and raiseValidationErrorwhere the host can check, since a flow never wants a flat CDF.GM-O3. Should gauss_flows drop flowjax’s spline everywhere? Decided: yes, so that one spline family serves the marginal, coupling and circular bijections.
GM-O4. Where does the epic live? Decided: gauss_flows, with the functax issues as cross-repo sub-issues.
14References¶
Fritsch, F. N. and Carlson, R. E. (1980). Monotone piecewise cubic interpolation. SIAM Journal on Numerical Analysis, 17(2), 238–246.
Steffen, M. (1990). A simple method for monotonic interpolation in one dimension. Astronomy and Astrophysics, 239, 443–450.
Gregory, J. A. and Delbourgo, R. (1982). Piecewise rational quadratic interpolation to monotonic data. IMA Journal of Numerical Analysis, 2(2), 123–130.
Durkan, C., Bekasov, A., Murray, I. and Papamakarios, G. (2019). Neural spline flows. NeurIPS. arXiv:1906.04032.
Rezende, D. J., Papamakarios, G., Racanière, S., Albergo, M. S., Kanwar, G., Shanahan, P. E. and Cranmer, K. (2020). Normalizing flows on tori and spheres. ICML. arXiv:2002.02428.