API reference

Efficient loglikelihood evaluation

tripy.loglikelihood.chol_loglike_1D(y: numpy.ndarray, x: numpy.ndarray, l_corr: Union[int, float], std_model: Union[int, float, numpy.ndarray], std_meas: Optional[Union[int, float, numpy.ndarray]] = None, y_model: Optional[numpy.ndarray] = None) float[source]

Efficient Gaussian loglikelihood for 1D problems with exponential correlation.

Linear time solution for 1D (e.g. timeseries) observations with additive Gaussian noise and exponential model prediction uncertainty. The model prediction uncertainty can be multiplicative or additive.

Parameters
  • y – [N, ] Vector of observations or residuals between measurements

  • predictions. (and model) –

  • x – [N, ] vector of coordinates

  • l_corr – Scalar correlation length

  • std_model – [N, ] vector of model prediction uncertainty coefficient

  • uncertainty (of variation in case of multiplicative model prediction) –

:param : :param or vector of std. devs. for additive in the case of additive model: :param prediction uncertainty.: :param std_meas: [N, ] optional vector of measurement uncertainty std. dev. :param y_model: [N, ] optional vector of model predictions in the case of :param multiplicative model prediction uncertainty.:

Returns

Loglikelihood.

Return type

L

tripy.loglikelihood.chol_loglike_2D(y: numpy.ndarray, Cx: Union[numpy.ndarray, List], Ct: List, std_meas: Union[int, float, numpy.ndarray], y_model: Optional[numpy.ndarray] = None) float[source]

Efficient 2D loglikelihood using block Cholesky decomposition.

Given the uncertainty parameters and vectors of the x and t positions on a lattice, calculates the loglikelihood of the 2D Gaussian process with multiplicative space and time uncertainties and i.i.d. noise. It is intended that this function is general and works with any combination of spatial and temporal covariance, with only the following restrictions:

  • Space and time are separable (Kronecker structure)

  • At least one generalized dimension (space or time) has only one

subdimension and exponential correlation

Notes

  • The tridiagonal inverse of the correlation matrix for exponential

correlation can be obtained using utils.inv_cov_vec_1D. * Having the spatial correlation matrix as an input would result in a full inversion performed for each call to this function which is potentially unecessary. This is solved by specifying the spatial correlation in terms of the inverse.

Warning

  • Directly inverting the correlation matrix to obtain Cx in the general

case is computationally expensive and numerically unstable. To avoid numerical issues it is suggested to add a small value to the diagonal (jitter) before inverting. Values smaller than 1e-6 are typically sufficient.

Parameters
  • y – [Nx, Nt] Array of observations or residuals between measurements

  • predictions. (and model) –

  • Cx – List of diagonal and off diagonal vectors of inverse Exponential

  • matrix. (correlation matrix or full inverse of spatial correlation) –

  • Ct – List of iagonal and off-diagonal of inverse of Exponential temporal correlation matrix.

  • std_meas – Std. dev. of the measurement uncertainty.

  • y_model – [Nx, Nt] optional vector of model predictions in the case of

  • uncertainty. (multiplicative model prediction) –

Returns

Loglikelihood.

Return type

L

tripy.loglikelihood.kron_loglike_2D_tridiag(y: numpy.ndarray, x: numpy.ndarray, t: numpy.ndarray, l_corr_x: Union[int, float], std_x: Union[int, float], l_corr_t: Union[int, float], std_t: Union[int, float], std_meas: Optional[Union[int, float]] = None, check_finite: Optional[bool] = False, jitter: Optional[Union[int, float]] = 1e-06) float[source]

Efficient 2D loglikelihood using Kronecker properties.

Given the uncertainty parameters and vectors of the x and t positions on a lattice, calculates the loglikelihood of the observations for exponential space and time correlation in the additive modeling uncertainty and i.i.d. Gaussian noise.

Warning

  • This is special case of kron_loglike_2D where both space

and time have exponential correlation. * This is superceded by kron_loglike_ND_tridiag and will be removed.

Parameters
  • y – [Nx, Nt] Array of observations or residuals between measurements

  • predictions. (and model) –

  • x – [Nx,] Vector of space coordinates.

  • t – [Nt,] Vector of time coordinates.

  • std_meas – Vector of measurement uncertainty std. dev.

  • l_corr_x – Spatial correlation length.

  • std_x – Std. dev. of model prediction uncertainty in space.

  • l_corr_t – Temporal correlation length.

  • std_t – Std. dev. of model prediction uncertainty in time.

  • check_finite – Optional flag of scipy.linalg.eigh_tridiagonal.

  • jitter – Optional small scalar noise value to ensure numerical

  • 1e-6. (stability in cases with no noise. Default =) –

Returns

Loglikelihood.

Return type

L

tripy.loglikelihood.log_likelihood_linear_normal(y: numpy.ndarray, K: Optional[Union[int, float, numpy.ndarray]], std_meas: Optional[Union[int, float, numpy.ndarray]] = None, y_model: Optional[numpy.ndarray] = None, jitter: Optional[Union[int, float]] = 1e-06) numpy.ndarray[source]

Gaussian log-likelihood function for the following models:

X_model = K1 * f(theta) + E X_model = K2 + E

where
  • K1 ~ MVN(mean=1, covariance=k_cov_mx)

  • K2 ~ MVN(mean)

  • E ~ MVN(mean=0, covariance=e_cov_mx)

  • f is a physical model function parametrized by theta

Notes

  • If K is None, the loglikelihood is calculated as the sum of N

independent normally distributed random variables

Parameters
  • y – [N_1, N_2, … Ni, … N_d] Array of observations or residuals

  • predictions. (between measurements and model) –

  • K – covariance matrix of K, shape [prod(Ni), prod(Ni)].

  • std_meas – [shape(y)] Std. dev. of the measurement uncertainty with

  • y_model – [shape(y)] optional vector of model predictions in the case of

  • uncertainty. (multiplicative model prediction) –

  • jitter – Optional small scalar noise value to ensure numerical

  • 1e-6. (stability in cases with no noise. Default =) –

Returns

value of the log-likelihood evaluated at theta.

Return type

log_like

Sampling from high-dimensional distributions

tripy.sampling.chol_sample_1D(coords: numpy.ndarray, std_noise: Union[numpy.ndarray, float, int], std_model: numpy.ndarray, lcorr: Union[float, int], y_model: Optional[numpy.ndarray] = None, size: Optional[int] = 1) numpy.ndarray[source]

Efficient sampling from Exponentially correlated MVN distribution in 1D.

Utilizes the tridiagonal inverse of the correlation matrix to efficiently sample from large Multivariate Normal distributions using a Cholesky decomposition.

Warning

This function has not been validated against a reference implementation, and should not be trusted.

Parameters
  • coords – [1, N] vector of coordinates.

  • std_noise – [1, N] vector of std. dev. of the measurement uncertainty.

  • std_model – [1, N] vector of std. dev. of the modeling uncertainty.

  • lcorr – Scalar correlation length.

  • y_model – [1, N] vector of model predictions.

  • size – Number of samples.

Returns

[size, N] array of samples.

tripy.sampling.kron_sample_2D(coords_x: numpy.ndarray, coords_t: numpy.ndarray, std_noise: Union[numpy.ndarray, float, int], std_model_x: numpy.ndarray, std_model_t: numpy.ndarray, lcorr_x: Union[float, int], lcorr_t: Union[float, int], y_model: Optional[numpy.ndarray] = None, size: Optional[int] = 1) numpy.ndarray[source]

Efficient sampling from Exponentially correlated MVN distribution in 2D.

Utilizes the tridiagonal inverse of the correlation matrix to efficiently sample from large Multivariate Normal distributions using Kronecker properties.

Warning

This function has not been validated against a reference implementation, and should not be trusted.

Parameters
  • coords_x – [1, Nx] vector of spatial coordinates.

  • coords_t – [1, Nt] vector of temporal coordinates.

  • std_noise – [1, Nx * Nt] Vector std. dev. of the measurement uncertainty.

  • std_model_x – [1, Nx] Vector std. dev. of the modeling uncertainty in space.

  • std_model_t – [1, Nt] Vector std. dev. of the modeling uncertainty in time.

  • lcorr_x – Scalar spatial correlation length.

  • lcorr_t – Scalar temporal correlation length.

  • y_model – [Nx, Nt] Array of model predictions.

  • size – Scalar number of samples.

Returns

[size, Nx * Nt] array of samples.

tripy.sampling.kron_sample_ND(coords: List, std_noise: numpy.ndarray, std_model: List, lcorr: numpy.ndarray, y_model: Optional[numpy.ndarray] = None, size: Optional[int] = 1) numpy.ndarray[source]

Efficient sampling from Exponentially correlated MVN distribution in ND.

Utilizes the tridiagonal inverse of the correlation matrix to efficiently sample from large Multivariate Normal distributions using Kronecker properties.

Warning

This function has not been validated against a reference implementation, and should not be trusted.

Parameters
  • coords – [ND] list of vectors of coordinates per dimension.

  • std_noise – [1, prod(ND)] vector of the std. dev. of the measurement uncertainty.

  • std_model – [ND] list of vectors of the modeling uncertainty std. devs. per dim.

  • lcorr – [ND, 1] vector of correlation lengths per dim.

  • y_model – [N1 x N2 x … x ND] array of model predictions.

  • size – Scalar number of samples.

Returns

[size, prod(ND)] array of samples.