API reference

Efficient loglikelihood evaluation

tripy.loglikelihood.chol_loglike_1D(coord_x: numpy.ndarray, x_model: numpy.ndarray, x_meas: numpy.ndarray, l_corr: Union[int, float], std_model: numpy.ndarray, std_meas: numpy.ndarray) float[source]

Efficient Gaussian loglikelihood for 1D problems with multiplicative exponential covariance.

Linear time solution for 1D (e.g. timeseries) observations with gaussian i.i.d. white noise and multiplicative modeling uncertainty with exponential correlation.

Parameters
  • coord_x – [N, ] vector of coordinates

  • x_model – [N, ] vector of model predictions

  • x_meas – [N, ] vector of measurements

  • l_corr – Scalar correlation length

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

  • variation (of) –

  • std_meas – [N, ] vector of measurement uncertainty std. dev.

Returns:

tripy.loglikelihood.chol_loglike_2D(y_res, y_model, Cx, Ct, std_meas)[source]

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.

TODO :
  • Find a way to replace DPOTRF with DPTTRF in the Cholesky decomposition

    to take advantage of tridiagonality

  • Add some basic input checks

  • 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)

    • Correlation in time is exponential

    If possible, this function should be unaware of the types of kernels passed and call methods of the kernel class (e.g. kernel.inv, kernel.chol…) and the rest will be handled by the kernel. This would allow for taking advantage of kernel-specific optimizations without overcomplicating this function.

  • Implement the following methods for the kernels (when more efficient than

the general case):
  • inv

  • inv_chol (with option of adding a diagonal vector)

  • inv_eig

INPUT:

y_res: [Nx, Nt] Array of residuals y_model: [Nx, Nt] Array of model output x, t: [1, Nx], [1, Nt] Space and time point vectors lcorr: Space and time correlation lengthscale std: Standard deviation chol: Callable

OPTIONAL:

check_finite: Optional flag of scipy.linalg.eigh_tridiagonal. False improves performance

Returns

Loglikelihood assuming exponential covariance and multiplicative modeling uncertainty

Return type

L

tripy.loglikelihood.kron_loglike_temporal(y, std_meas, cov_mx_x, t, l_corr_t, std_t, check_finite=False)[source]

Efficient loglikelihood evaluation for Kronecker covariance matrices with Markovian temporal covariance.

Any combination of a single dimension with Markovian covariance and N nonseparable dimensions with non-Markovian covariance can be evaluated using this function.

INPUT:

y: [Nx, Nt] Array of observations t: [1, Nt] Time point vector lcorr: Time correlation lengthscale std: Standard deviation

OPTIONAL:

check_finite: Optional flag of scipy.linalg.eigh_tridiagonal. False improves performance

Returns

Loglikelihood assuming exponential covariance and additive modeling uncertainty

Return type

L

tripy.loglikelihood.kron_loglike_2D_tridiag(y, x, t, std_meas, l_corr_x, std_x, l_corr_t, std_t, check_finite=False)[source]

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 superceded by kron_loglike_ND_tridiag and will be removed.

INPUT:

y: [Nx, Nt] Array of observations x, t: [1, Nx], [1, Nt] Space and time point vectors lcorr: Space and time correlation lengthscale std: Standard deviation

OPTIONAL:

check_finite: Optional flag of scipy.linalg.eigh_tridiagonal. False improves performance

Returns

Loglikelihood assuming exponential covariance and additive modeling uncertainty

Return type

L

tripy.loglikelihood.kron_loglike_ND_tridiag(y: Union[List, numpy.ndarray], x: List, std_meas: Union[int, float], std_model: Union[List, numpy.ndarray, int, float], lcorr_d: Union[int, float, numpy.ndarray], check_finite=False) float[source]
Parameters
  • y

  • x

  • std_meas

  • std_model

  • lcorr_d

  • check_finite

Returns:

References

[1] Efficient inference in matrix-variate Gaussian models with i.i.d. observation noise. Stegle et al. (2011)

[2] E Gilboa, Y Saatçi, JP Cunningham - Scaling Multidimensional Inference for Structured Gaussian Processes, Pattern Analysis and Machine Intelligence, IEEE, 2015

tripy.loglikelihood.log_likelihood_linear_normal(theta: numpy.ndarray, x_meas: numpy.ndarray, physical_model: Callable[[numpy.ndarray], numpy.ndarray], k_cov_mx: Optional[numpy.ndarray] = None, e_cov_mx: Optional[numpy.ndarray] = None) numpy.ndarray[source]

Log-likelihood function for the following model:

X_model = K*physical_model_fun(theta) + E

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

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

  • MVN() multivariate normal distribution

physical_model_fun() has no additional uncertainty, e.g. surrogate model uncertainty.

Parameters
  • theta – value of the parameter(s) to be estimated in the Bayesian inference, `shape [1, K].

  • x_meas – measurements in a [T, S] shape. T corresponds to the time space and S to the physical and quantity space.

  • physical_model – function that takes as input theta and gives out x_model.

  • k_cov_mx – covariance matrix of K, shape [T*S, T*S].

  • e_cov_mx – covariance matrix of elastic_mod, shape [T*S, T*S].

Returns

value of the log-likelihood evaluated at theta.

Return type

log_like

Sampling from high-dimensional distributions

tripy.sampling.chol_sample_1D(coords, std_noise, std_model, lcorr, y_model=None, size=1)[source]
Parameters
  • coords

  • std_noise

  • std_model

  • lcorr

  • y_model

  • size

Returns:

tripy.sampling.kron_sample_2D(coords_x, coords_t, std_noise, std_model_x, std_model_t, lcorr_x, lcorr_t, y_model=None, size=1)[source]
tripy.sampling.kron_sample_ND(coords, std_noise, std_model, lcorr, y_model=None, size=1)[source]
Parameters
  • coords

  • std_noise

  • std_model

  • lcorr

  • y_model

  • size

Returns