The covariance_functions Module

stat_fem.covariance_functions.calc_r2(x1, x2)

Compute Squared Distance between all pairs of points in two arrays

Wrapper to the Scipy cdist function squared for computing squared distances between pairs of points in two arrays. This returns a 2D array with the first axis of the same length as the first axis of x1, and the second axis of the same length as the first axis of x2. If x1 or x2 are 1D, it broadcasts to 2D assuming that the first axis has length 1.

Parameters:
  • x1 (ndarray) – first set of input coordinates. Must be a 1D or 2D numpy array (if 1D, it assumes the first axis has length 1).
  • x2 (ndarray) – second set of input coordinates. Must be a 1D or 2D numpy array (if 1D, it assumes the first axis has length 1).
Returns:

Squared distance matrix, a numpy array with shape (x1.shape[0], x2.shape[1])

Return type:

ndarray

stat_fem.covariance_functions.sqexp(x1, x2, sigma, l)

Squared Exponential Covariance Function

Returns squared exponential covariance function computed at all pairs of values in coordinate values x1 and x2. This returns a 2D array with the first axis of the same length as the first axis of x1, and the second axis of the same length as the first axis of x2. If x1 or x2 are 1D, it broadcasts to 2D assuming that the first axis has length 1.

Note parameters are assumed to be on log scale. sigma is the overall covariance scale, where exp(sigma) is the standard deviation, and l determines the correlation length, where exp(l) is the length scale.

Parameters:
  • x1 (ndarray) – first set of input coordinates. Must be a 1D or 2D numpy array (if 1D, it assumes the first axis has length 1).
  • x2 (ndarray) – second set of input coordinates. Must be a 1D or 2D numpy array (if 1D, it assumes the first axis has length 1).
  • sigma (float) – Covariance parameter on a logarithmic scale (exp(sigma) gives the standard deviation).
  • l (float) – Correlation length on a logarithmic scale (exp(l) gives the standard deviation).
Returns:

Squared Exponential Covariance Matrix, a numpy array with shape (x1.shape[0], x2.shape[1])

Return type:

ndarray

stat_fem.covariance_functions.sqexp_deriv(x1, x2, sigma, l)

Squared Exponential Covariance Function Derivative

Returns the gradient of the squared exponential covariance function computed at all pairs of values in coordinate values x1 and x2. This returns a 3D array with the first axis of length 2 (representing the two derivative components), the second axis is of the same length as the first axis of x1, and the third axis of the same length as the first axis of x2. If x1 or x2 are 1D, it broadcasts to 2D assuming that the first axis has length 1.

Note parameters are assumed to be on log scale. sigma is the overall covariance scale, where exp(sigma) is the standard deviation, and l determines the correlation length, where exp(l) is the length scale.

Parameters:
  • x1 (ndarray) – first set of input coordinates. Must be a 1D or 2D numpy array (if 1D, it assumes the first axis has length 1).
  • x2 (ndarray) – second set of input coordinates. Must be a 1D or 2D numpy array (if 1D, it assumes the first axis has length 1).
  • sigma (float) – Covariance parameter on a logarithmic scale (exp(sigma) gives the standard deviation).
  • l (float) – Correlation length on a logarithmic scale (exp(l) gives the standard deviation).
Returns:

Squared Exponential Covariance Matrix gradient, a numpy array with shape (2, x1.shape[0], x2.shape[1])

Return type:

ndarray

stat_fem.covariance_functions.sqexp_hessian(x1, x2, sigma, l)

Squared Exponential Covariance Function Hessian

Returns the Hessian of the squared exponential covariance function computed at all pairs of values in coordinate values x1 and x2. This returns a 4D array with the first two axes of length 2 (representing the two derivative components), the third axis is of the same length as the first axis of x1, and the fourth axis of the same length as the first axis of x2. If x1 or x2 are 1D, it broadcasts to 2D assuming that the first axis has length 1.

Note parameters are assumed to be on log scale. sigma is the overall covariance scale, where exp(sigma) is the standard deviation, and l determines the correlation length, where exp(l) is the length scale.

Parameters:
  • x1 (ndarray) – first set of input coordinates. Must be a 1D or 2D numpy array (if 1D, it assumes the first axis has length 1).
  • x2 (ndarray) – second set of input coordinates. Must be a 1D or 2D numpy array (if 1D, it assumes the first axis has length 1).
  • sigma (float) – Covariance parameter on a logarithmic scale (exp(sigma) gives the standard deviation).
  • l (float) – Correlation length on a logarithmic scale (exp(l) gives the standard deviation).
Returns:

Squared Exponential Covariance Matrix Hessian, a numpy array with shape (2, 2, x1.shape[0], x2.shape[1])

Return type:

ndarray