Scaler#

class pocomc.scaler.Reparameterize(n_dim: int, bounds: ndarray | list = None, periodic: List[int] = None, reflective: List[int] = None, transform: str = 'probit', scale: bool = True, diagonal: bool = True)#

Class that reparameterises the model using change-of-variables parameter transformations.

Parameters:
  • n_dim (int) – Dimensionality of sampling problem

  • bounds (np.ndarray or list or None) – Parameter bounds

  • periodic (list) – List of indices corresponding to parameters with periodic boundary conditions

  • reflective (list) – List of indices corresponding to parameters with periodic boundary conditions

  • transform (str) – Type of transform to use for bounded parameters. Options are "probit" (default) and "logit".

  • scale (bool) – Rescale parameters to zero mean and unit variance (default is true)

  • diagonal (bool) – Use diagonal transformation (i.e. ignore covariance) (default is true)

Examples

>>> import numpy as np
>>> from pocomc.reparameterize import Reparameterize
>>> bounds = np.array([[0, 1], [0, 1]])
>>> reparam = Reparameterize(2, bounds)
>>> x = np.array([[0.5, 0.5], [0.5, 0.5]])
>>> reparam.forward(x)
array([[0., 0.],
       [0., 0.]])
>>> u = np.array([[0, 0], [0, 0]])
>>> reparam.inverse(u)
(array([[0.5, 0.5],
       [0.5, 0.5]]), array([0., 0.]))
apply_boundary_conditions(x: ndarray)#

Apply boundary conditions (i.e. periodic or reflective) to input. The first kind include phase parameters that might be periodic e.g. on a range [0,2*np.pi]. The latter can arise in cases where parameters are ratios where a/b and b/a are equivalent.

Parameters:

x (np.ndarray) – Input array

Return type:

Transformed input

fit(x: ndarray)#

Learn mean and standard deviation using for rescaling.

Parameters:

x (np.ndarray) – Input data used for training.

forward(x: ndarray)#

Forward transformation (both logit/probit for bounds and affine for all parameters).

Parameters:

x (np.ndarray) – Input data

Returns:

u – Transformed input data

Return type:

np.ndarray

inverse(u: ndarray)#

Inverse transformation (both logit^-1/probit^-1 for bounds and affine for all parameters).

Parameters:

u (np.ndarray) – Input data

Returns:

  • x (np.ndarray) – Transformed input data

  • log_det_J (np.array) – Logarithm of determinant of Jacobian matrix transformation.