aspire.transforms
=================

.. py:module:: aspire.transforms


Attributes
----------

.. autoapisummary::

   aspire.transforms.logger


Classes
-------

.. autoapisummary::

   aspire.transforms.BaseTransform
   aspire.transforms.IdentityTransform
   aspire.transforms.CompositeTransform
   aspire.transforms.FlowTransform
   aspire.transforms.PeriodicTransform
   aspire.transforms.BoundedTransform
   aspire.transforms.ProbitTransform
   aspire.transforms.LogitTransform
   aspire.transforms.AffineTransform
   aspire.transforms.FlowPreconditioningTransform


Module Contents
---------------

.. py:data:: logger

.. py:class:: BaseTransform(xp, dtype=None)

   Base class for data transforms.

   :param xp: The array API namespace to use (e.g., numpy, torch).
   :type xp: :py:class:`Callable`
   :param dtype: The data type to use for the transform. If not provided, defaults to
                 the default dtype of the array API namespace if available.
   :type dtype: :py:class:`Any`, *optional*


   .. py:attribute:: xp


   .. py:attribute:: dtype
      :value: None



   .. py:method:: fit(x)
      :abstractmethod:


      Fit the transform to the data.



   .. py:method:: forward(x)
      :abstractmethod:



   .. py:method:: inverse(y)
      :abstractmethod:



   .. py:method:: config_dict()

      Return the configuration of the transform as a dictionary.



   .. py:method:: save(h5_file, path = 'data_transform')

      Save config + any fitted state into an HDF5 file.



   .. py:method:: load(h5_file, path = 'data_transform', strict = False)
      :classmethod:


      Reconstruct transform from file.

      :param h5_file: The HDF5 file to load from.
      :type h5_file: :py:class:`h5py.File`
      :param path: The path in the HDF5 file where the transform is stored.
      :type path: :py:class:`str`, *optional*
      :param strict: 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.
      :type strict: :py:class:`bool`, *optional*



.. py:class:: IdentityTransform(xp, dtype=None)

   Bases: :py:obj:`BaseTransform`


   Identity transform that does nothing to the data.


   .. py:method:: fit(x)

      Fit the transform to the data.



   .. py:method:: forward(x)


   .. py:method:: inverse(y)


.. py:class:: 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)

   Bases: :py:obj:`BaseTransform`


   Base class for data transforms.

   :param xp: The array API namespace to use (e.g., numpy, torch).
   :type xp: :py:class:`Callable`
   :param dtype: The data type to use for the transform. If not provided, defaults to
                 the default dtype of the array API namespace if available.
   :type dtype: :py:class:`Any`, *optional*


   .. py:attribute:: parameters


   .. py:attribute:: periodic_parameters
      :value: []



   .. py:attribute:: bounded_to_unbounded
      :value: True



   .. py:attribute:: bounded_transform
      :value: 'probit'



   .. py:attribute:: affine_transform
      :value: True



   .. py:attribute:: eps
      :value: 1e-06



   .. py:attribute:: device
      :value: None



   .. py:method:: fit(x)

      Fit the transform to the data.



   .. py:method:: forward(x)


   .. py:method:: inverse(x)


   .. py:method:: new_instance(xp=None, dtype = None)


   .. py:method:: config_dict()

      Return the configuration of the transform as a dictionary.



.. py:class:: FlowTransform(parameters, prior_bounds = None, bounded_to_unbounded = True, bounded_transform = 'probit', affine_transform = True, device=None, xp=None, eps=1e-06, dtype=None)

   Bases: :py:obj:`CompositeTransform`


   Subclass of CompositeTransform that uses a Flow for transformations.

   Does not support periodic transforms.


   .. py:method:: new_instance(xp=None)


   .. py:method:: config_dict()

      Return the configuration of the transform as a dictionary.



.. py:class:: PeriodicTransform(lower, upper, xp, dtype=None)

   Bases: :py:obj:`BaseTransform`


   Base class for data transforms.

   :param xp: The array API namespace to use (e.g., numpy, torch).
   :type xp: :py:class:`Callable`
   :param dtype: The data type to use for the transform. If not provided, defaults to
                 the default dtype of the array API namespace if available.
   :type dtype: :py:class:`Any`, *optional*


   .. py:attribute:: name
      :type:  str
      :value: 'periodic'



   .. py:attribute:: requires_prior_bounds
      :type:  bool
      :value: True



   .. py:attribute:: lower


   .. py:attribute:: upper


   .. py:method:: fit(x)

      Fit the transform to the data.



   .. py:method:: forward(x)


   .. py:method:: inverse(y)


   .. py:method:: config_dict()

      Return the configuration of the transform as a dictionary.



.. py:class:: BoundedTransform(lower, upper, xp, dtype = None)

   Bases: :py:obj:`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).

   :param lower: The lower bound of the interval.
   :type lower: :py:class:`Array`
   :param upper: The upper bound of the interval.
   :type upper: :py:class:`Array`
   :param xp: The array API namespace to use (e.g., numpy, torch).
   :type xp: :py:class:`Callable`
   :param dtype: The data type to use for the transform. If not provided, defaults to
                 the default dtype of the array API namespace if available.
   :type dtype: :py:class:`Any`, *optional*


   .. py:attribute:: name
      :type:  str
      :value: 'bounded'



   .. py:attribute:: requires_prior_bounds
      :type:  bool
      :value: True



   .. py:attribute:: lower


   .. py:attribute:: upper


   .. py:method:: to_unit_interval(x)

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

      :param x: The input array to be mapped.
      :type x: :py:class:`Array`

      :returns: A tuple containing the mapped array and the log absolute determinant Jacobian.
      :rtype: :py:class:`tuple[Array`, :py:class:`Array]`



   .. py:method:: from_unit_interval(y)

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

      :param y: The input array to be mapped.
      :type y: :py:class:`Array`

      :returns: A tuple containing the mapped array and the log absolute determinant Jacobian.
      :rtype: :py:class:`tuple[Array`, :py:class:`Array]`



   .. py:method:: interval_check(lower, upper)

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



   .. py:method:: fit(x)

      Fit the transform to the data.



   .. py:method:: forward(x)
      :abstractmethod:



   .. py:method:: inverse(y)
      :abstractmethod:



   .. py:method:: config_dict()

      Return the configuration of the transform as a dictionary.



.. py:class:: ProbitTransform(lower, upper, xp, eps=1e-06, dtype=None)

   Bases: :py:obj:`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).

   :param lower: The lower bound of the interval.
   :type lower: :py:class:`Array`
   :param upper: The upper bound of the interval.
   :type upper: :py:class:`Array`
   :param xp: The array API namespace to use (e.g., numpy, torch).
   :type xp: :py:class:`Callable`
   :param dtype: The data type to use for the transform. If not provided, defaults to
                 the default dtype of the array API namespace if available.
   :type dtype: :py:class:`Any`, *optional*


   .. py:attribute:: name
      :type:  str
      :value: 'probit'



   .. py:attribute:: requires_prior_bounds
      :type:  bool
      :value: True



   .. py:attribute:: eps
      :value: 1e-06



   .. py:method:: fit(x)

      Fit the transform to the data.



   .. py:method:: forward(x)


   .. py:method:: inverse(y)


   .. py:method:: config_dict()

      Return the configuration of the transform as a dictionary.



.. py:class:: LogitTransform(lower, upper, xp, eps = 1e-06, dtype = None)

   Bases: :py:obj:`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).

   :param lower: The lower bound of the interval.
   :type lower: :py:class:`Array`
   :param upper: The upper bound of the interval.
   :type upper: :py:class:`Array`
   :param xp: The array API namespace to use (e.g., numpy, torch).
   :type xp: :py:class:`Callable`
   :param dtype: The data type to use for the transform. If not provided, defaults to
                 the default dtype of the array API namespace if available.
   :type dtype: :py:class:`Any`, *optional*


   .. py:attribute:: name
      :type:  str
      :value: 'logit'



   .. py:attribute:: requires_prior_bounds
      :type:  bool
      :value: True



   .. py:attribute:: eps
      :value: 1e-06



   .. py:method:: fit(x)

      Fit the transform to the data.



   .. py:method:: forward(x)


   .. py:method:: inverse(y)


   .. py:method:: config_dict()

      Return the configuration of the transform as a dictionary.



.. py:class:: AffineTransform(xp, dtype=None)

   Bases: :py:obj:`BaseTransform`


   Base class for data transforms.

   :param xp: The array API namespace to use (e.g., numpy, torch).
   :type xp: :py:class:`Callable`
   :param dtype: The data type to use for the transform. If not provided, defaults to
                 the default dtype of the array API namespace if available.
   :type dtype: :py:class:`Any`, *optional*


   .. py:attribute:: name
      :type:  str
      :value: 'affine'



   .. py:attribute:: requires_prior_bounds
      :type:  bool
      :value: False



   .. py:method:: fit(x)

      Fit the transform to the data.



   .. py:method:: forward(x)


   .. py:method:: inverse(y)


   .. py:method:: config_dict()

      Return the configuration of the transform as a dictionary.



.. py:class:: 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)

   Bases: :py:obj:`BaseTransform`


   Base class for data transforms.

   :param xp: The array API namespace to use (e.g., numpy, torch).
   :type xp: :py:class:`Callable`
   :param dtype: The data type to use for the transform. If not provided, defaults to
                 the default dtype of the array API namespace if available.
   :type dtype: :py:class:`Any`, *optional*


   .. py:attribute:: parameters


   .. py:attribute:: periodic_parameters
      :value: []



   .. py:attribute:: prior_bounds
      :value: None



   .. py:attribute:: bounded_to_unbounded
      :value: True



   .. py:attribute:: bounded_transform
      :value: 'probit'



   .. py:attribute:: affine_transform
      :value: True



   .. py:attribute:: eps
      :value: 1e-06



   .. py:attribute:: device
      :value: 'cpu'



   .. py:attribute:: flow_backend
      :value: 'zuko'



   .. py:attribute:: flow_matching
      :value: False



   .. py:attribute:: flow_kwargs


   .. py:attribute:: fit_kwargs


   .. py:attribute:: flow
      :value: None



   .. py:method:: fit(x)

      Fit the transform to the data.



   .. py:method:: forward(x)


   .. py:method:: inverse(y)


   .. py:method:: new_instance(xp=None, dtype = None)


   .. py:method:: save(h5_file, path='data_transform')
      :abstractmethod:


      Save config + any fitted state into an HDF5 file.



