nessai.utils.rescaling
Utilities related to rescaling.
Module Contents
Functions
|
Rescale a value to 0 to 1 |
|
Rescale from 0 to 1 to xmin to xmax |
|
Rescale a value to -1 to 1 |
|
Rescale from -1 to 1 to xmin to xmax |
|
Detect edges in input distributions based on the density. |
|
Configure parameters for edge detection |
|
Determine the values of the prior min and max in the rescaled |
|
Logit function that also returns log Jacobian determinant. |
|
Sigmoid function that also returns log Jacobian determinant. |
Attributes
- nessai.utils.rescaling.logger
- nessai.utils.rescaling.rescale_zero_to_one(x, xmin, xmax)
Rescale a value to 0 to 1
- Parameters
- xndarray
Array of values to rescale
- xmin, xmaxfloats
Minimum and maximum values to use for rescaling
- Returns
- ndarray
Array of rescaled values
- ndarray
Array of log determinants of Jacobians for each sample
- nessai.utils.rescaling.inverse_rescale_zero_to_one(x, xmin, xmax)
Rescale from 0 to 1 to xmin to xmax
- Parameters
- xndarray
Array of values to rescale
- xmin, xmaxfloats
Minimum and maximum values to use for rescaling
- Returns
- ndarray
Array of rescaled values
- ndarray
Array of log determinants of Jacobians for each sample
- nessai.utils.rescaling.rescale_minus_one_to_one(x, xmin, xmax)
Rescale a value to -1 to 1
- Parameters
- xndarray
Array of values to rescale
- xmin, xmaxfloats
Minimum and maximum values to use for rescaling
- Returns
- ndarray
Array of rescaled values
- ndarray
Array of log determinants of Jacobians for each sample
- nessai.utils.rescaling.inverse_rescale_minus_one_to_one(x, xmin, xmax)
Rescale from -1 to 1 to xmin to xmax
- Parameters
- xndarray
Array of values to rescale
- xmin, xmaxfloats
Minimum and maximum values to use for rescaling
- Returns
- ndarray
Array of rescaled values
- ndarray
Array of log determinants of Jacobians for each sample
- nessai.utils.rescaling.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_rangearray_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
- nbinsfloat 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_boundslist
List of alloweds bounds.
- teststr 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
- nessai.utils.rescaling.configure_edge_detection(d, detect_edges)
Configure parameters for edge detection
- Parameters
- ddict
Dictionary of kwargs passed to detect_edge.
- detect_edgesbool
If true allows for no inversion to be applied.
- Returns
- dict
Updated kwargs
- nessai.utils.rescaling.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_minfloat
Minimum of the prior.
- prior_maxfloat
Maximum of the prior.
- x_minfloat
New minimum.
- x_maxfloat
New maximum.
- invertFalse or {‘upper’, ‘lower’, ‘both’}, optional
Type of inversion. inversion must also be set to True.
- inversionbool, 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.)
- offsetfloat, optional
Offset to subtract from the values prior to rescaling.
- rescaled_boundslist or tuple
Lower and upper bound which x has been rescaled to. In inversion=True, these values are ignored to match behaviour in the
RescaleToBounds
.
- nessai.utils.rescaling.logit(x, fuzz=1e-12)
Logit function that also returns log Jacobian determinant.
See
nessai.utils.rescaling.sigmoid()
for the inverse.- Parameters
- xfloat or ndarray
Array of values
- fuzzfloat, optional
Fuzz used to avoid nans in logit. Values are rescaled from [0, 1] to [0-fuzz, 1+fuzz].
- Returns
- float or ndarray
Rescaled values.
- float or ndarray
Log Jacobian determinant.
- nessai.utils.rescaling.sigmoid(x, fuzz=1e-12)
Sigmoid function that also returns log Jacobian determinant.
See
nessai.utils.rescaling.logit()
for the inverse.- Parameters
- xfloat or ndarray
Array of values
- fuzzfloat, optional
Fuzz used to avoid nans in logit
- Returns
- float or ndarray
Rescaled values.
- float or ndarray
Log Jacobian determinant.
- nessai.utils.rescaling.rescaling_functions