aspire.transforms#
Attributes#
Classes#
Base class for data transforms. |
|
Identity transform that does nothing to the data. |
|
Base class for data transforms. |
|
Subclass of CompositeTransform that uses a Flow for transformations. |
|
Base class for data transforms. |
|
Base class for bounded transforms. |
|
Base class for bounded transforms. |
|
Base class for bounded transforms. |
|
Base class for data transforms. |
|
Base class for data transforms. |
Module Contents#
- 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.
- 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:
BaseTransformIdentity transform that does nothing to the data.
- 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:
BaseTransformBase 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)
- 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:
CompositeTransformSubclass 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)
- class aspire.transforms.PeriodicTransform(lower, upper, xp, dtype=None)[source]#
Bases:
BaseTransformBase 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.
- class aspire.transforms.BoundedTransform(lower, upper, xp, dtype=None)[source]#
Bases:
BaseTransformBase 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.
- 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]
- class aspire.transforms.ProbitTransform(lower, upper, xp, eps=1e-06, dtype=None)[source]#
Bases:
BoundedTransformBase 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.
- 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]
- class aspire.transforms.LogitTransform(lower, upper, xp, eps=1e-06, dtype=None)[source]#
Bases:
BoundedTransformBase 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)
- 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]
- class aspire.transforms.AffineTransform(xp, dtype=None)[source]#
Bases:
BaseTransformBase 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.
- 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:
BaseTransformBase 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])