nessai.utils.rescaling
======================

.. py:module:: nessai.utils.rescaling

.. autoapi-nested-parse::

   Utilities related to rescaling.

   ..
       !! processed by numpydoc !!


Functions
---------

.. autoapisummary::

   nessai.utils.rescaling.rescale_zero_to_one
   nessai.utils.rescaling.inverse_rescale_zero_to_one
   nessai.utils.rescaling.rescale_minus_one_to_one
   nessai.utils.rescaling.inverse_rescale_minus_one_to_one
   nessai.utils.rescaling.detect_edge
   nessai.utils.rescaling.configure_edge_detection
   nessai.utils.rescaling.determine_rescaled_bounds
   nessai.utils.rescaling.logit
   nessai.utils.rescaling.sigmoid
   nessai.utils.rescaling.logistic_function
   nessai.utils.rescaling.log_with_log_jacobian
   nessai.utils.rescaling.exp_with_log_jacobian
   nessai.utils.rescaling.gaussian_cdf
   nessai.utils.rescaling.inverse_gaussian_cdf


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

.. py:function:: rescale_zero_to_one(x, xmin, xmax)

   
   Rescale a value to 0 to 1


   :Parameters:

       **x** : ndarray
           Array of values to rescale

       **xmin, xmax** : floats
           Minimum and maximum values to use for rescaling



   :Returns:

       ndarray
           Array of rescaled values

       ndarray
           Array of log determinants of Jacobians for each sample











   ..
       !! processed by numpydoc !!

.. py:function:: inverse_rescale_zero_to_one(x, xmin, xmax)

   
   Rescale from 0 to 1 to xmin to xmax


   :Parameters:

       **x** : ndarray
           Array of values to rescale

       **xmin, xmax** : floats
           Minimum and maximum values to use for rescaling



   :Returns:

       ndarray
           Array of rescaled values

       ndarray
           Array of log determinants of Jacobians for each sample











   ..
       !! processed by numpydoc !!

.. py:function:: rescale_minus_one_to_one(x, xmin, xmax)

   
   Rescale a value to -1 to 1


   :Parameters:

       **x** : ndarray
           Array of values to rescale

       **xmin, xmax** : floats
           Minimum and maximum values to use for rescaling



   :Returns:

       ndarray
           Array of rescaled values

       ndarray
           Array of log determinants of Jacobians for each sample











   ..
       !! processed by numpydoc !!

.. py:function:: inverse_rescale_minus_one_to_one(x, xmin, xmax)

   
   Rescale from -1 to 1 to xmin to xmax


   :Parameters:

       **x** : ndarray
           Array of values to rescale

       **xmin, xmax** : floats
           Minimum and maximum values to use for rescaling



   :Returns:

       ndarray
           Array of rescaled values

       ndarray
           Array of log determinants of Jacobians for each sample











   ..
       !! processed by numpydoc !!

.. py:function:: detect_edge(x, x_range=None, percent=0.1, cutoff=0.5, nbins='auto', allow_both=False, allow_none=False, allowed_bounds=['lower', 'upper'], test=None)

   
   Detect edges in input distributions based on the density.


   :Parameters:

       **x: array_like**
           Samples

       **x_range** : array_like, optional
           Lower and upper bounds used to check inversion, if not specified
           min and max of data are used.

       **percent: float (0.1)**
           Percentage of interval used to check edges

       **cutoff: float (0.1)**
           Minimum fraction of the maximum density contained within the
           percentage of the interval specified

       **nbins** : float or 'auto'
           Number of bins used for histogram.

       **allow_both: bool**
           Allow function to return both instead of force either upper or lower

       **allow_none: bool**
           Allow for neither lower or upper bound to be returned

       **allowed_bounds** : list
           List of alloweds bounds.

       **test** : str or None
           If not None this skips the process and just returns the value of test.
           This is used to verify the inversion in all possible scenarios.



   :Returns:

       str or False, {'lower', 'upper', 'both', False}
           Returns the boundary to apply the inversion or False is no inversion
           is to be applied











   ..
       !! processed by numpydoc !!

.. py:function:: configure_edge_detection(d, detect_edges)

   
   Configure parameters for edge detection


   :Parameters:

       **d** : dict
           Dictionary of kwargs passed to detect_edge.

       **detect_edges** : bool
           If true allows for no inversion to be applied.



   :Returns:

       dict
           Updated kwargs











   ..
       !! processed by numpydoc !!

.. py:function:: determine_rescaled_bounds(prior_min, prior_max, x_min, x_max, invert=None, inversion=False, offset=0, rescale_bounds=[-1, 1])

   
   Determine the values of the prior min and max in the rescaled
   space.


   :Parameters:

       **prior_min** : float
           Minimum of the prior.

       **prior_max** : float
           Maximum of the prior.

       **x_min** : float
           New minimum.

       **x_max** : float
           New maximum.

       **invert** : False or {'upper', 'lower', 'both'}, optional
           Type of inversion. `inversion` must also be set to True.

       **inversion** : bool, optional
           Indicate if the rescaling bounds have been set for inversion. If True
           and invert is None or False, then the rescale bounds are assumed to
           be [-1, 1] rather than [0, 1] (the default for inverted parameters.)

       **offset** : float, optional
           Offset to subtract from the values prior to rescaling.

       **rescaled_bounds** : list or tuple
           Lower and upper bound which x has been rescaled to. In inversion=True,
           these values are ignored to match behaviour in the             :py:class:`~nessai.reparameterisations.RescaleToBounds`.














   ..
       !! processed by numpydoc !!

.. py:function:: logit(x, eps=None)

   
   Logit function that also returns log Jacobian determinant.

   See :py:func:`nessai.utils.rescaling.sigmoid` for the inverse.

   :Parameters:

       **x** : float or ndarray
           Array of values

       **eps** : float, optional
           Epsilon value used to clamp inputs to [eps, 1 - eps]. If None, then
           inputs are not clamped.



   :Returns:

       float or ndarray
           Rescaled values.

       float or ndarray
           Log Jacobian determinant.











   ..
       !! processed by numpydoc !!

.. py:function:: sigmoid(x)

   
   Sigmoid function that also returns log Jacobian determinant.

   See :py:func:`nessai.utils.rescaling.logit` for the inverse.

   :Parameters:

       **x** : float or ndarray
           Array of values



   :Returns:

       float or ndarray
           Rescaled values.

       float or ndarray
           Log Jacobian determinant.











   ..
       !! processed by numpydoc !!

.. py:function:: logistic_function(x, x0=0.0, k=1.0)

   
   Logistic function with configurable midpoint and gradient.


   :Parameters:

       **x** : np.ndarray
           Samples to apply function to

       **x0** : float
           Midpoint

       **k: float**
           Gradient



   :Returns:

       np.ndarrary
           Value of logistic function for each x.











   ..
       !! processed by numpydoc !!

.. py:function:: log_with_log_jacobian(x)

   
   Natural log and log-Jacobian determinant.


   :Parameters:

       **x** : Union[float, np.ndarray]
           Array of values



   :Returns:

       Union[float, numpy.ndarray]
           Rescaled values.

       Union[float, numpy.ndarray]
           Log Jacobian determinant.











   ..
       !! processed by numpydoc !!

.. py:function:: exp_with_log_jacobian(x)

   
   Exponential and log-Jacobian determinant.


   :Parameters:

       **x** : Union[float, np.ndarray]
           Array of values



   :Returns:

       Union[float, numpy.ndarray]
           Rescaled values.

       Union[float, numpy.ndarray]
           Log Jacobian determinant.











   ..
       !! processed by numpydoc !!

.. py:function:: gaussian_cdf(x)

   
   Gaussian CDF with log-Jacobian determinant
















   ..
       !! processed by numpydoc !!

.. py:function:: inverse_gaussian_cdf(x)

   
   Inverse Gaussian CDF with log-Jacobian determinant
















   ..
       !! processed by numpydoc !!

