aspire.transforms

Contents

aspire.transforms#

Attributes#

Classes#

BaseTransform

Base class for data transforms.

IdentityTransform

Identity transform that does nothing to the data.

CompositeTransform

Base class for data transforms.

FlowTransform

Subclass of CompositeTransform that uses a Flow for transformations.

PeriodicTransform

Base class for data transforms.

BoundedTransform

Base class for bounded transforms.

ProbitTransform

Base class for bounded transforms.

LogitTransform

Base class for bounded transforms.

AffineTransform

Base class for data transforms.

FlowPreconditioningTransform

Base class for data transforms.

Module Contents#

aspire.transforms.logger[source]#
class aspire.transforms.BaseTransform(xp, dtype=None)[source]#

Base class for data transforms.

Parameters:
  • xp (Callable) – The array API namespace to use (e.g., numpy, torch).

  • dtype (Any, optional) – The data type to use for the transform. If not provided, defaults to the default dtype of the array API namespace if available.

xp[source]#
dtype = None[source]#
abstractmethod fit(x)[source]#

Fit the transform to the data.

abstractmethod forward(x)[source]#
abstractmethod inverse(y)[source]#
config_dict()[source]#

Return the configuration of the transform as a dictionary.

save(h5_file, path='data_transform')[source]#

Save config + any fitted state into an HDF5 file.

Parameters:
  • h5_file (h5py.File)

  • path (str)

classmethod load(h5_file, path='data_transform', strict=False)[source]#

Reconstruct transform from file.

Parameters:
  • h5_file (h5py.File) – The HDF5 file to load from.

  • path (str, optional) – The path in the HDF5 file where the transform is stored.

  • strict (bool, optional) – If True, raise an error if the class in the file does not match cls. If False, load the class specified in the file. Default is False.

class aspire.transforms.IdentityTransform(xp, dtype=None)[source]#

Bases: BaseTransform

Identity transform that does nothing to the data.

fit(x)[source]#

Fit the transform to the data.

forward(x)[source]#
inverse(y)[source]#
class aspire.transforms.CompositeTransform(parameters, periodic_parameters=None, prior_bounds=None, bounded_to_unbounded=True, bounded_transform='probit', affine_transform=True, device=None, xp=None, eps=1e-06, dtype=None)[source]#

Bases: BaseTransform

Base class for data transforms.

Parameters:
  • xp (Callable) – The array API namespace to use (e.g., numpy, torch).

  • dtype (Any, optional) – The data type to use for the transform. If not provided, defaults to the default dtype of the array API namespace if available.

  • parameters (list[int])

  • periodic_parameters (list[int])

  • prior_bounds (list[tuple[float, float]])

  • bounded_to_unbounded (bool)

  • bounded_transform (str)

  • affine_transform (bool)

  • eps (float)

parameters[source]#
periodic_parameters = [][source]#
bounded_to_unbounded = True[source]#
bounded_transform = 'probit'[source]#
affine_transform = True[source]#
eps = 1e-06[source]#
device = None[source]#
fit(x)[source]#

Fit the transform to the data.

forward(x)[source]#
inverse(x)[source]#
new_instance(xp=None, dtype=None)[source]#
Parameters:

dtype (Any)

config_dict()[source]#

Return the configuration of the transform as a dictionary.

class aspire.transforms.FlowTransform(parameters, prior_bounds=None, bounded_to_unbounded=True, bounded_transform='probit', affine_transform=True, device=None, xp=None, eps=1e-06, dtype=None)[source]#

Bases: CompositeTransform

Subclass of CompositeTransform that uses a Flow for transformations.

Does not support periodic transforms.

Parameters:
  • parameters (list[int])

  • prior_bounds (list[tuple[float, float]])

  • bounded_to_unbounded (bool)

  • bounded_transform (str)

  • affine_transform (bool)

new_instance(xp=None)[source]#
config_dict()[source]#

Return the configuration of the transform as a dictionary.

class aspire.transforms.PeriodicTransform(lower, upper, xp, dtype=None)[source]#

Bases: BaseTransform

Base class for data transforms.

Parameters:
  • xp (Callable) – The array API namespace to use (e.g., numpy, torch).

  • dtype (Any, optional) – The data type to use for the transform. If not provided, defaults to the default dtype of the array API namespace if available.

name: str = 'periodic'[source]#
requires_prior_bounds: bool = True[source]#
lower[source]#
upper[source]#
fit(x)[source]#

Fit the transform to the data.

forward(x)[source]#
inverse(y)[source]#
config_dict()[source]#

Return the configuration of the transform as a dictionary.

class aspire.transforms.BoundedTransform(lower, upper, xp, dtype=None)[source]#

Bases: BaseTransform

Base class for bounded transforms.

Maps from [lower, upper] to [0, 1] and vice versa using a linear scaling. If the interval [lower, upper] is too small, it will shift by the midpoint.

Must be subclassed to implement specific transforms (e.g., Probit, Logit).

Parameters:
  • lower (Array) – The lower bound of the interval.

  • upper (Array) – The upper bound of the interval.

  • xp (Callable) – The array API namespace to use (e.g., numpy, torch).

  • dtype (Any, optional) – The data type to use for the transform. If not provided, defaults to the default dtype of the array API namespace if available.

name: str = 'bounded'[source]#
requires_prior_bounds: bool = True[source]#
lower[source]#
upper[source]#
to_unit_interval(x)[source]#

Map from [lower, upper] to [0, 1].

Parameters:

x (Array) – The input array to be mapped.

Returns:

A tuple containing the mapped array and the log absolute determinant Jacobian.

Return type:

tuple[Array, Array]

from_unit_interval(y)[source]#

Map from [0, 1] to [lower, upper].

Parameters:

y (Array) – The input array to be mapped.

Returns:

A tuple containing the mapped array and the log absolute determinant Jacobian.

Return type:

tuple[Array, Array]

interval_check(lower, upper)[source]#

Check if the interval [lower, upper] is too small

Parameters:
  • lower (array_api_compat.common._typing.Array)

  • upper (array_api_compat.common._typing.Array)

Return type:

bool

fit(x)[source]#

Fit the transform to the data.

abstractmethod forward(x)[source]#
abstractmethod inverse(y)[source]#
config_dict()[source]#

Return the configuration of the transform as a dictionary.

class aspire.transforms.ProbitTransform(lower, upper, xp, eps=1e-06, dtype=None)[source]#

Bases: BoundedTransform

Base class for bounded transforms.

Maps from [lower, upper] to [0, 1] and vice versa using a linear scaling. If the interval [lower, upper] is too small, it will shift by the midpoint.

Must be subclassed to implement specific transforms (e.g., Probit, Logit).

Parameters:
  • lower (Array) – The lower bound of the interval.

  • upper (Array) – The upper bound of the interval.

  • xp (Callable) – The array API namespace to use (e.g., numpy, torch).

  • dtype (Any, optional) – The data type to use for the transform. If not provided, defaults to the default dtype of the array API namespace if available.

name: str = 'probit'[source]#
requires_prior_bounds: bool = True[source]#
eps = 1e-06[source]#
fit(x)[source]#

Fit the transform to the data.

Parameters:

x (array_api_compat.common._typing.Array)

Return type:

array_api_compat.common._typing.Array

forward(x)[source]#
Parameters:

x (array_api_compat.common._typing.Array)

Return type:

tuple[array_api_compat.common._typing.Array, array_api_compat.common._typing.Array]

inverse(y)[source]#
Parameters:

y (array_api_compat.common._typing.Array)

Return type:

tuple[array_api_compat.common._typing.Array, array_api_compat.common._typing.Array]

config_dict()[source]#

Return the configuration of the transform as a dictionary.

class aspire.transforms.LogitTransform(lower, upper, xp, eps=1e-06, dtype=None)[source]#

Bases: BoundedTransform

Base class for bounded transforms.

Maps from [lower, upper] to [0, 1] and vice versa using a linear scaling. If the interval [lower, upper] is too small, it will shift by the midpoint.

Must be subclassed to implement specific transforms (e.g., Probit, Logit).

Parameters:
  • lower (Array) – The lower bound of the interval.

  • upper (Array) – The upper bound of the interval.

  • xp (Callable) – The array API namespace to use (e.g., numpy, torch).

  • dtype (Any, optional) – The data type to use for the transform. If not provided, defaults to the default dtype of the array API namespace if available.

  • eps (float)

name: str = 'logit'[source]#
requires_prior_bounds: bool = True[source]#
eps = 1e-06[source]#
fit(x)[source]#

Fit the transform to the data.

Parameters:

x (array_api_compat.common._typing.Array)

Return type:

array_api_compat.common._typing.Array

forward(x)[source]#
Parameters:

x (array_api_compat.common._typing.Array)

Return type:

tuple[array_api_compat.common._typing.Array, array_api_compat.common._typing.Array]

inverse(y)[source]#
Parameters:

y (array_api_compat.common._typing.Array)

Return type:

tuple[array_api_compat.common._typing.Array, array_api_compat.common._typing.Array]

config_dict()[source]#

Return the configuration of the transform as a dictionary.

Return type:

dict[str, Any]

class aspire.transforms.AffineTransform(xp, dtype=None)[source]#

Bases: BaseTransform

Base class for data transforms.

Parameters:
  • xp (Callable) – The array API namespace to use (e.g., numpy, torch).

  • dtype (Any, optional) – The data type to use for the transform. If not provided, defaults to the default dtype of the array API namespace if available.

name: str = 'affine'[source]#
requires_prior_bounds: bool = False[source]#
fit(x)[source]#

Fit the transform to the data.

forward(x)[source]#
inverse(y)[source]#
config_dict()[source]#

Return the configuration of the transform as a dictionary.

class aspire.transforms.FlowPreconditioningTransform(parameters, flow_backend='zuko', prior_bounds=None, bounded_to_unbounded=True, bounded_transform='probit', affine_transform=True, periodic_parameters=None, device=None, xp=None, eps=1e-06, dtype=None, flow_matching=False, flow_kwargs=None, fit_kwargs=None)[source]#

Bases: BaseTransform

Base class for data transforms.

Parameters:
  • xp (Callable) – The array API namespace to use (e.g., numpy, torch).

  • dtype (Any, optional) – The data type to use for the transform. If not provided, defaults to the default dtype of the array API namespace if available.

  • parameters (list[int])

  • flow_backend (str)

  • prior_bounds (list[tuple[float, float]])

  • bounded_to_unbounded (bool)

  • bounded_transform (str)

  • affine_transform (bool)

  • periodic_parameters (list[int])

  • flow_matching (bool)

  • flow_kwargs (dict[str, Any])

  • fit_kwargs (dict[str, Any])

parameters[source]#
periodic_parameters = [][source]#
prior_bounds = None[source]#
bounded_to_unbounded = True[source]#
bounded_transform = 'probit'[source]#
affine_transform = True[source]#
eps = 1e-06[source]#
device = 'cpu'[source]#
flow_backend = 'zuko'[source]#
flow_matching = False[source]#
flow_kwargs[source]#
fit_kwargs[source]#
flow = None[source]#
fit(x)[source]#

Fit the transform to the data.

forward(x)[source]#
inverse(y)[source]#
new_instance(xp=None, dtype=None)[source]#
Parameters:

dtype (Any)

abstractmethod save(h5_file, path='data_transform')[source]#

Save config + any fitted state into an HDF5 file.