bijx.ScalarBijection

class bijx.ScalarBijection[source]

Bases: Bijection

Base class for element-wise one-dimensional bijections.

This abstract class provides the foundation for scalar (element-wise) bijections. It automatically handles log-density updates by summing log-Jacobian contributions over event dimensions, following the change of variables formula for element-wise transformations.

Subclasses must implement:
  • log_jac(): Log absolute determinant of Jacobian \(\log \abs{f'(x)}\)

  • fwd(): Forward transformation \(y = f(x)\)

  • rev(): Reverse transformation \(x = f^{-1}(y)\)

The forward() and reverse() methods are implemented automatically and handle log-density updates by summing scalar log-Jacobians over event axes.

Important

The forward and reverse methods should NOT be overridden.

__init__(*args, **kwargs)

Methods

forward(x, log_density, **kwargs)

Apply forward transformation with log-density update.

fwd(x, **kwargs)

Apply forward transformation.

invert()

Create an inverted version of this bijection.

log_jac(x, y, **kwargs)

Compute log absolute determinant of the Jacobian.

rev(y, **kwargs)

Apply reverse (inverse) transformation.

reverse(y, log_density, **kwargs)

Apply reverse transformation with log-density update.

log_jac(x, y, **kwargs)[source]

Compute log absolute determinant of the Jacobian.

Parameters:
  • x – Input values where Jacobian is computed.

  • y – Output values corresponding to x (i.e., y = fwd(x)).

  • **kwargs – Additional transformation-specific arguments.

Returns:

Log absolute Jacobian determinant \(\log \abs{f'(x)}\) with same shape as x.

fwd(x, **kwargs)[source]

Apply forward transformation.

Parameters:
  • x – Input values to transform.

  • **kwargs – Additional transformation-specific arguments.

Returns:

Transformed values \(y = f(x)\) with same shape as \(x\).

rev(y, **kwargs)[source]

Apply reverse (inverse) transformation.

Parameters:
  • y – Output values to inverse-transform.

  • **kwargs – Additional transformation-specific arguments.

Returns:

Inverse-transformed values \(x = f^{-1}(y)\) with same shape as \(y\).

forward(x, log_density, **kwargs)[source]

Apply forward transformation with log-density update.

Transforms input through the bijection and updates log-density by subtracting the log-Jacobian determinant, summed over event dimensions.

Parameters:
  • x – Input data to transform.

  • log_density – Log density values for the input.

  • **kwargs – Additional arguments passed to fwd() and log_jac().

Returns:

Tuple of (transformed_data, updated_log_density).

reverse(y, log_density, **kwargs)[source]

Apply reverse transformation with log-density update.

Transforms input through the inverse bijection and updates log-density by adding the log-Jacobian determinant, summed over event dimensions.

Parameters:
  • y – Input data to inverse-transform.

  • log_density – Log density values for the input.

  • **kwargs – Additional arguments passed to rev() and log_jac().

Returns:

Tuple of (inverse_transformed_data, updated_log_density).