nessai.reparameterisations

Functions and objects related to reparametersiations for use in the reparameterisations dictionary.

See the documentation for an in-depth description of how to use these functions and classes.

Module Contents

Classes

Reparameterisation

Base object for reparameterisations.

CombinedReparameterisation

Class to handle multiple reparameterisations

NullReparameterisation

Reparameterisation that does not modify the parameters.

Rescale

Reparameterisation that rescales the parameters by a constant factor

RescaleToBounds

Reparameterisation that maps to the specified interval.

Angle

Reparameterisation for a single angle.

ToCartesian

Convert a parameter to Cartesian coordinates

AnglePair

Reparameterisation for a pair of angles and a radial component.

Functions

get_reparameterisation(reparameterisation, defaults=None)

Function to get a reparameterisation class from a name

Attributes

logger

default_reparameterisations

nessai.reparameterisations.logger
nessai.reparameterisations.get_reparameterisation(reparameterisation, defaults=None)

Function to get a reparameterisation class from a name

Parameters
reparameterisationstr, nessai.reparameterisations.Reparameterisation

Name of the reparameterisations to return or a class that inherits from Reparameterisation

defaultsdict, optional

Dictionary of known reparameterisations that overrides the defaults.

Returns
nessai.reparameteristaions.Reparameterisation

Reparameterisation class.

dict

Keyword arguments for the specific reparameterisation.

class nessai.reparameterisations.Reparameterisation(parameters=None, prior_bounds=None)

Base object for reparameterisations.

Parameters
parametersstr or list

Name of parameters to reparameterise.

prior_boundslist, dict or None

Prior bounds for the parameter(s).

has_prior = False
has_prime_prior = False
requires_prime_prior = False
requires_bounded_prior = False
prior_bounds
prime_prior_bounds
property name(self)

Unique name of the reparameterisations

abstract reparameterise(self, x, x_prime, log_j)

Apply the reparameterisation to convert from x-space to x’-space.

Parameters
xstructured array

Array of inputs

x_primestructured array

Array to be update

log_jarray_like

Log jacobian to be updated

Returns
x, x_primestructured arrays

Update version of the x and x_prime arrays

log_jarray_like

Updated log Jacobian determinant

abstract inverse_reparameterise(self, x, x_prime, log_j)

Apply the reparameterisation to convert from x-space to x’-space

Parameters
xstructured array

Array

x_primestructured array

Array to be update

log_jarray_like

Log jacobian to be updated

Returns
x, x_primestructured arrays

Update version of the x and x_prime arrays

log_jarray_like

Updated log Jacobian determinant

class nessai.reparameterisations.CombinedReparameterisation(reparameterisations=None)

Bases: dict

Class to handle multiple reparameterisations

Parameters
reparameterisationslist, optional

List of reparameterisations to add to the combined reparameterisations. Further reparameterisations can be added using add_reparameterisations.

property has_prime_prior(self)

Boolean to check if prime prior can be enabled

property requires_prime_prior(self)

Boolean to check if any of the priors require the prime space

add_reparameterisation(self, reparameterisation)

Add a reparameterisation

add_reparameterisations(self, reparameterisations)

Add multiple reparameterisations

Parameters
reparameterisationslist of :obj:Reparameterisation

List of reparameterisations to add.

reparameterise(self, x, x_prime, log_j, **kwargs)

Apply the reparameterisation to convert from x-space to x’-space

Parameters
xstructured array

Array

x_primestructured array

Array to be update

log_jarray_like

Log jacobian to be updated

inverse_reparameterise(self, x, x_prime, log_j, **kwargs)

Apply the reparameterisation to convert from x-space to x’-space

Parameters
xstructured array

Array

x_primestructured array

Array to be update

log_jarray_like

Log jacobian to be updated

update_bounds(self, x)

Update the bounds used for the reparameterisation

reset_inversion(self)

Reset edges for boundary inversion

log_prior(self, x)

Compute any additional priors for auxiliary parameters

x_prime_log_prior(self, x_prime)

Compute the prior in the prime space

class nessai.reparameterisations.NullReparameterisation(parameters=None, prior_bounds=None)

Bases: Reparameterisation

Reparameterisation that does not modify the parameters.

Parameters
parameterslist or str

Parameters for which the reparameterisation will be used.

prior_boundslist, dict or None

Prior bounds for parameters. Unused for this reparameterisation.

reparameterise(self, x, x_prime, log_j, **kwargs)

Apply the reparameterisation to convert from x-space to x’-space

Parameters
xstructured array

Array

x_primestructured array

Array to be update

log_jLog jacobian to be updated
inverse_reparameterise(self, x, x_prime, log_j, **kwargs)

Apply the reparameterisation to convert from x-space to x’-space

Parameters
xstructured array

Array

x_primestructured array

Array to be update

log_jLog jacobian to be updated
class nessai.reparameterisations.Rescale(parameters=None, scale=None, prior_bounds=None)

Bases: Reparameterisation

Reparameterisation that rescales the parameters by a constant factor that does not depend on the prior bounds.

Parameters
scalefloat

Scaling constant.

requires_bounded_prior = False
reparameterise(self, x, x_prime, log_j, **kwargs)

Apply the reparameterisation to convert from x-space to x’-space

Parameters
xstructured array

Array

x_primestructured array

Array to be update

log_jLog jacobian to be updated
inverse_reparameterise(self, x, x_prime, log_j, **kwargs)

Apply the reparameterisation to convert from x-space to x’-space

Parameters
xstructured array

Array

x_primestructured array

Array to be update

log_jLog jacobian to be updated
class nessai.reparameterisations.RescaleToBounds(parameters=None, prior_bounds=None, prior=None, rescale_bounds=None, boundary_inversion=None, detect_edges=False, inversion_type='split', detect_edges_kwargs=None, offset=False, update_bounds=True, pre_rescaling=None, post_rescaling=None)

Bases: Reparameterisation

Reparameterisation that maps to the specified interval.

By default the interval is [-1, 1]. Also includes options for boundary inversion.

This reparameterisation can handle multiple parameters.

Parameters
parameterslist of str

List of the names of parameters

prior_boundsdict

Dictionary of prior bounds for each parameter. Does not need to be specified by the user.

rescale_boundslist of tuples, optional

Bounds to rescale to.

update_boundsbool, optional

Enable or disable updating bounds.

prior{‘uniform’, None}

Type of prior used, if uniform prime prior is enabled.

boundary_inversionbool, list, dict, optional

Configuration for boundary inversion. If a list, inversion is only applied to the parameters in the list based on inversion_type. If a dict then each item should be a parameter and a corresponding inversion type {‘split’, ‘inversion’}.

detect_edgesbool, optional

Enable or disable edge detection for inversion.

detect_edges_kwargsdict, optional

Dictionary of kwargs used to configure edge detection.

offsetbool, optional

Enable or disable offset subtraction. If True then the mean value of the prior is subtract of the parameter before the rescaling is applied. This is computed and applied after the ‘pre-rescaling’ if it has been specified.

pre_rescalingtuple of functions

A function that applies a rescaling prior to the main rescaling and its inverse. Each function should return a value and the log-Jacobian determinant.

post_rescalingtuple of functions or {‘logit}

A function that applies a rescaling after to the main rescaling and its inverse. Each function should return a value and the log-Jacobian determinant. For example applying a logit after rescaling to [0, 1].

requires_bounded_prior = True
configure_pre_rescaling(self, pre_rescaling)

Configure the rescaling applied before the standard rescaling.

Used in DistanceReparameterisation.

Parameters
pre_rescalingstr or Tuple[Callable, Callable]

Name of the pre-rescaling of tuple contain the forward and inverse functions that should return the rescaled value and the Jacobian.

configure_post_rescaling(self, post_rescaling)

Configure the rescaling applied after the standard rescaling.

Used to apply the logit/sigmoid transforms after rescaling to [0, 1]

Parameters
post_rescalingstr or Tuple[Callable, Callable]

Name of the post-rescaling of tuple contain the forward and inverse functions that should return the rescaled value and the Jacobian.

pre_rescaling(self, x)

Function applied before rescaling to bounds

pre_rescaling_inv(self, x)

Inverse of function applied before rescaling to bounds

post_rescaling(self, x)

Function applied after rescaling to bounds

post_rescaling_inv(self, x)

Inverse of function applied after rescaling to bounds

reparameterise(self, x, x_prime, log_j, compute_radius=False, **kwargs)

Rescale inputs to the prime space

Parameters
x, x_primearray_like

Arrays of samples in the physical and prime space

log_jarray_like

Array of values of log-Jacobian

compute_radiusbool, optional

If true force duplicate for inversion

kwargs

Parsed to inversion function

inverse_reparameterise(self, x, x_prime, log_j, **kwargs)

Map inputs to the physical space from the prime space

reset_inversion(self)

Reset the edges for inversion

set_bounds(self, prior_bounds)

Set the initial bounds for rescaling

update_bounds(self, x)

Update the bounds used for the reparameterisation

update_prime_prior_bounds(self)

Update the prior bounds used for the prime prior

x_prime_log_prior(self, x_prime)

Compute the prior in the prime space assuming a uniform prior

class nessai.reparameterisations.Angle(parameters=None, prior_bounds=None, scale=1.0, prior=None)

Bases: Reparameterisation

Reparameterisation for a single angle.

This reparameterisations converts an angle to Cartesian coordinates using either a corresponding radial parameter or an auxiliary radial parameter. When using the auxiliary parameter, samples are drawn from a chi-distribution with two degrees of freedom.

Parameters
parametersstr or list

Parameter(s) to use for the reparameterisation. Either just an angle or an angle and corresponding radial parameter

prior_boundsdict

Dictionary of prior bounds. Does not need to be specified when defining reparameterisations.

scalefloat, optional

Value used to rescale the angle before converting to Cartesian coordinates. If None the scale will be set to 2pi / prior_bounds.

prior{‘uniform’, ‘sine’, None}

Type of prior being used for sampling this angle. If specified, the prime prior is enabled. If None then it is disabled.

requires_bounded_prior = True
property angle(self)

The name of the angular parameter

property radial(self)

The name of the radial parameter

property radius(self)

The name of the radial parameter (equivalent to radial)

property x(self)

The name of x coordinate

property y(self)

The name of y coordinate

reparameterise(self, x, x_prime, log_j, **kwargs)

Convert the angle to Cartesian coordinates

inverse_reparameterise(self, x, x_prime, log_j, **kwargs)

Convert from Cartesian to an angle and radial component

log_prior(self, x)

Prior for radial parameter

x_prime_log_prior(self, x_prime)

Compute the prior in the prime space assuming a uniform prior

class nessai.reparameterisations.ToCartesian(mode='split', scale=np.pi, **kwargs)

Bases: Angle

Convert a parameter to Cartesian coordinates

class nessai.reparameterisations.AnglePair(parameters=None, prior_bounds=None, prior=None, convention=None)

Bases: Reparameterisation

Reparameterisation for a pair of angles and a radial component.

Converts to three-dimensional Cartesian coordinates.

If the radial component is not specified, it is sampled from a chi- distribution with three degrees of freedom.

Parameters
parameterslist

List of parameters. Must contain at least the two angles and, optionally, also a radial component.

prior_boundsdict

Dictionary of prior bounds for each parameter

priorstr, {‘isotropic’, None}

Type of prior, used to enable use of the prime prior.

conventionstr, {‘ra-dec’, ‘az-zen’}

Convention used for defining the spherical polar coordinates. If not set, it will be guessed based on either dec or zen. Where it is assumed declination is defined on [-pi/2, pi/2] and zenith on [0, pi].

Notes

The parameters will be reordered such that the first parameter is the angle along the horizon, the second parameter is the vertical angle and the last parameter is the radial parameter.

requires_bounded_prior = True
known_priors = ['isotropic', None]
property angles(self)

Names of the two angles.

Order is: angle along the horizon, vertical angle.

property radial(self)

Name of the radial parameter

property x(self)

Name of the first Cartesian coordinate

property y(self)

Name of the second Cartesian coordinate

property z(self)

Name of the third Cartesian coordinate

reparameterise(self, x, x_prime, log_j, **kwargs)

Convert the spherical polar angles to Cartesian coordinates

inverse_reparameterise(self, x, x_prime, log_j, **kwargs)

Convert from Cartesian to spherical polar angles

log_prior(self, x)

Prior for radial parameter

x_prime_log_prior(self, x_prime)

Log probability of 3d Cartesian coordinates for an isotropic distribution of angles and a radial component drawn from a chi distribution with three degrees of freedom.

nessai.reparameterisations.default_reparameterisations