zuko.transforms#

Parameterizable transformations.

Classes#

ComposedTransform

Creates a transformation \(f(x) = f_n \circ \dots \circ f_0(x)\).

IdentityTransform

Creates a transformation \(f(x) = x\).

CosTransform

Creates a transformation \(f(x) = -\cos(x)\).

SinTransform

Creates a transformation \(f(x) = \sin(x)\).

SoftclipTransform

Creates a transformation that maps \(\mathbb{R}\) to the interval \([-B, B]\).

CircularShiftTransform

Creates a transformation that circularly shifts the interval \([-B, B]\).

MonotonicAffineTransform

Creates a transformation \(f(x) = \alpha x + \beta\).

MonotonicRQSTransform

Creates a monotonic rational-quadratic spline (RQS) transformation.

MonotonicTransform

Creates a transformation from a monotonic univariate function \(f_\phi(x)\).

UnconstrainedMonotonicTransform

Creates a monotonic transformation \(f(x)\) by integrating a positive univariate function \(g(x)\).

SOSPolynomialTransform

Creates a sum-of-squares (SOS) polynomial transformation.

FreeFormJacobianTransform

Creates a free-form Jacobian transformation.

AutoregressiveTransform

Transform via an autoregressive scheme.

PermutationTransform

Creates a transformation that permutes the elements.

Descriptions#

class zuko.transforms.ComposedTransform(*transforms, **kwargs)#

Creates a transformation \(f(x) = f_n \circ \dots \circ f_0(x)\).

Parameters

transforms (Transform) – A sequence of transformations \(f_i\).

class zuko.transforms.IdentityTransform(cache_size=0)#

Creates a transformation \(f(x) = x\).

class zuko.transforms.CosTransform(cache_size=0)#

Creates a transformation \(f(x) = -\cos(x)\).

class zuko.transforms.SinTransform(cache_size=0)#

Creates a transformation \(f(x) = \sin(x)\).

class zuko.transforms.SoftclipTransform(bound=5.0, **kwargs)#

Creates a transformation that maps \(\mathbb{R}\) to the interval \([-B, B]\).

\[f(x) = \frac{x}{1 + \left| \frac{x}{B} \right|}\]
Parameters

bound (float) – The codomain bound \(B\).

class zuko.transforms.CircularShiftTransform(bound=5.0, **kwargs)#

Creates a transformation that circularly shifts the interval \([-B, B]\).

\[f(x) = (x \bmod 2B) - B\]

Note

This transformation is only bijective over its domain \([-B, B]\) as \(f(x) = f(x + 2kB)\) for all \(k \in \mathbb{Z}\).

Parameters

bound (float) – The domain bound \(B\).

class zuko.transforms.MonotonicAffineTransform(shift, scale, slope=0.001, **kwargs)#

Creates a transformation \(f(x) = \alpha x + \beta\).

Parameters
  • shift (Tensor) – The shift term \(\beta\), with shape \((*,)\).

  • scale (Tensor) – The unconstrained scale factor \(\alpha\), with shape \((*,)\).

  • slope (float) – The minimum slope of the transformation.

class zuko.transforms.MonotonicRQSTransform(widths, heights, derivatives, bound=5.0, slope=0.001, **kwargs)#

Creates a monotonic rational-quadratic spline (RQS) transformation.

References

Neural Spline Flows (Durkan et al., 2019)
Parameters
  • widths (Tensor) – The unconstrained bin widths, with shape \((*, K)\).

  • heights (Tensor) – The unconstrained bin heights, with shape \((*, K)\).

  • derivatives (Tensor) – The unconstrained knot derivatives, with shape \((*, K - 1)\).

  • bound (float) – The spline’s (co)domain bound \(B\).

  • slope (float) – The minimum slope of the transformation.

class zuko.transforms.MonotonicTransform(f, phi=(), bound=5.0, eps=1e-06, **kwargs)#

Creates a transformation from a monotonic univariate function \(f_\phi(x)\).

The inverse function \(f_\phi^{-1}\) is approximated using the bisection method.

Parameters
  • f (Callable[[Tensor], Tensor]) – A monotonic univariate function \(f_\phi\).

  • phi (Iterable[Tensor]) – The parameters \(\phi\) of \(f_\phi\).

  • bound (float) – The domain bound \(B\).

  • eps (float) – The absolute tolerance for the inverse transformation.

class zuko.transforms.UnconstrainedMonotonicTransform(g, C, n=16, **kwargs)#

Creates a monotonic transformation \(f(x)\) by integrating a positive univariate function \(g(x)\).

\[f(x) = \int_0^x g(u) ~ du + C\]

The definite integral is estimated by a \(n\)-point Gauss-Legendre quadrature.

Parameters
  • g (Callable[[Tensor], Tensor]) – A positive univariate function \(g\).

  • C (Tensor) – The integration constant \(C\).

  • n (int) – The number of points \(n\) for the quadrature.

  • kwargs – Keyword arguments passed to MonotonicTransform.

class zuko.transforms.SOSPolynomialTransform(a, C, **kwargs)#

Creates a sum-of-squares (SOS) polynomial transformation.

The transformation \(f(x)\) is expressed as the primitive integral of the sum of \(K\) squared polynomials of degree \(L\).

\[f(x) = \int_0^x \sum_{i = 1}^K \left( 1 + \sum_{j = 0}^L a_{i,j} ~ u^j \right)^2 ~ du + C\]

References

Sum-of-Squares Polynomial Flow (Jaini et al., 2019)
Parameters
class zuko.transforms.FreeFormJacobianTransform(f, time, phi=(), exact=True, **kwargs)#

Creates a free-form Jacobian transformation.

The transformation is the integration of a system of first-order ordinary differential equations

\[x(T) = \int_0^T f_\phi(t, x(t)) ~ dt .\]

References

FFJORD: Free-form Continuous Dynamics for Scalable Reversible Generative Models (Grathwohl et al., 2018)
Parameters
  • f (Callable[[Tensor, Tensor], Tensor]) – A system of first-order ODEs \(f_\phi\).

  • time (Tensor) – The integration time \(T\).

  • phi (Iterable[Tensor]) – The parameters \(\phi\) of \(f_\phi\).

  • exact (bool) – Whether the exact log-determinant of the Jacobian or an unbiased stochastic estimate thereof is calculated.

class zuko.transforms.AutoregressiveTransform(meta, passes, **kwargs)#

Transform via an autoregressive scheme.

\[y_i = f(x_i; x_{<i})\]
Parameters
  • meta (Callable[[Tensor], Transform]) – A meta function which returns a transformation \(f\).

  • passes (int) – The number of passes for the inverse transformation.

class zuko.transforms.PermutationTransform(order, **kwargs)#

Creates a transformation that permutes the elements.

Parameters

order (LongTensor) – The permutation order, with shape \((*, D)\).