MultivariateMuyGPS

class MuyGPyS.gp.multivariate_muygps.MultivariateMuyGPS(*model_args)[source]

Multivariate Local Kriging Gaussian Process.

Performs approximate GP inference by locally approximating an observation’s response using its nearest neighbors with a separate kernel allocated for each response dimension, implemented as individual MuyGPyS.gp.muygps.MuyGPS objects.

This class is similar in interface to MuyGPyS.gp.muygps.MuyGPS, but requires a list of hyperparameter dicts at initialization.

Example

>>> from MuyGPyS.gp import MultivariateMuyGPS as MMuyGPS
>>> k_kwargs1 = {
...     "noise": Parameter(1e-5),
...     "kernel": Matern(
...         smoothness=Parameter(0.67, (0.1, 2.5)),
...         deformation=Isotropy(
...             metric=l2,
...             length_scale=Parameter(0.2),
...         scale=AnalyticScale(),
...     ),
... }
>>> k_kwargs2 = {
...     "noise": Parameter(1e-5),
...     "kernel": Matern(
...         smoothness=Parameter(0.67, (0.1, 2.5)),
...         deformation=Isotropy(
...             metric=l2,
...             length_scale=Parameter(0.2),
...         scale=AnalyticScale(),
...     ),
... }
>>> k_args = [k_kwargs1, k_kwargs2]
>>> mmuygps = MMuyGPS(*k_args)

We can realize kernel tensors for each of the models contained within a MultivariateMuyGPS object by iterating over its models member. Once we have computed pairwise_diffs and crosswise_diffs tensors, it is straightforward to perform each of these realizations.

Example

>>> for model in MuyGPyS.models:
>>>     K = model.kernel(pairwise_diffs)
>>>     Kcross = model.kernel(crosswise_diffs)
>>>     # do something with K and Kcross...
Args
model_args:

Dictionaries defining each internal MuyGPyS.gp.muygps.MuyGPS instance.

fast_coefficients(pairwise_diffs_fast, train_nn_targets_fast)[source]

Produces coefficient matrix for the fast posterior mean given in Equation (8) of [dunton2022fast] for each response dimenion.

Fro each response dimension \(j\), given observation set \(X\) with responses \(Y\), noise prior set \(\varepsilon^{(j)}\), and kernel function \(K_{\theta^{(j)}}(\cdot, \cdot)\), computes the following for each observation element \(\mathbf{x}_i\) with nearest neighbors index set \(N^*_i\), containing i and the indices of the nn_count - 1 nearest neighbors of \(\mathbf{x}_i\):

\[C^{(j)}_i = \left ( K_{\theta^{(j)}}(X_{N_i}, X_{N_i}) + \varepsilon^{(j)}_{N_i} \right )^{-1} Y(X_{N_i})_{:, j}.\]
Parameters:
  • pairwise_diffs – A tensor of shape (train_count, nn_count, nn_count, feature_count) containing the (nn_count, nn_count, feature_count)-shaped pairwise nearest neighbor difference tensors corresponding to each of the batch elements.

  • batch_nn_targets – A tensor of shape (train_count, nn_count, response_count) listing the vector-valued responses for the nearest neighbors of each batch element.

Return type:

ndarray

Returns:

A tensor of shape (batch_count, nn_count, response_count) whose entries comprise the precomputed coefficients for fast posterior mean inference.

fast_posterior_mean(crosswise_diffs, coeffs_tensor)[source]

Performs fast posterior mean inference using provided cross-covariance and precomputed coefficient matrix for each response dimension.

Returns the predicted response across each response dimension in the form of a posterior mean for each element of the batch of observations, as computed in Equation (9) of [dunton2022fast]. For each response dimension \(j\), given the coefficients \(C^{(j)}\) created by fast_coefficients() and Equation (8) of [dunton2022fast], observation set \(X\), noise prior set \(\varepsilon^{(j)}\), and kernel function \(K_{\theta^{(j)}}(\cdot, \cdot)\), computes the following for each test point \(\mathbf{z}\) and index set \(N^*_i\) containing the union of the index \(i\) of the nearest neighbor \(\mathbf{x}_i\) of \(\mathbf{z}\) and the nn_count - 1 nearest neighbors of \(\mathbf{x}_i\):

\[\widehat{Y} \left ( \mathbf{z} \mid X \right )_j = \sigma^2 K_{\theta^{(j)}}(\mathbf{z}, X_{N^*_i}) C^{(j)}_i.\]
Parameters:
  • crosswise_diffs (ndarray) – A matrix of shape (batch_count, nn_count, feature_count) whose rows list the difference between each feature of each batch element element and its nearest neighbors.

  • coeffs_tensor (ndarray) – A tensor of shape (batch_count, nn_count, response_count) providing the precomputed coefficients.

Return type:

ndarray

Returns:

A matrix of shape (batch_count, response_count) whose rows are the predicted response for each of the given indices.

fixed()[source]

Checks whether all kernel and model parameters are fixed for each model, excluding \(\sigma^2\).

Return type:

bool

Returns:

Returns True if all parameters in all models are fixed, and False otherwise.

optimize_scale(pairwise_diffs, nn_targets)[source]

Optimize the value of the \(sigma^2\) scale parameter for each response dimension.

Uses the optimization method specified by the types of the scale parameters to optimize their value.

Parameters:
  • pairwise_diffs (ndarray) – A tensor of shape (batch_count, nn_count, nn_count, feature_count) containing the (nn_count, nn_count, feature_count)-shaped pairwise nearest neighbor difference tensors corresponding to each of the batch elements.

  • nn_targets (ndarray) – Tensor of floats of shape (batch_count, nn_count, response_count) containing the expected response for each nearest neighbor of each batch element.

Returns:

A reference to this model whose global scale parameter (and those of its submodels) has been optimized.

posterior_mean(pairwise_diffs, crosswise_diffs, batch_nn_targets)[source]

Performs simultaneous posterior mean inference on provided difference tensors and the target matrix.

Computes parallelized local solves of systems of linear equations using the kernel realizations, one for each internal model, of the last two dimensions of pairwise_diffs along with crosswise_diffs and batch_nn_targets to predict responses in terms of the posterior mean. Assumes that difference tensors pairwise_diffs and crosswise_diffs are already computed and given as arguments.

Returns the predicted response in the form of a posterior mean for each element of the batch of observations by solving a system of linear equations induced by each kernel functor, one per response dimension, in a generalization of Equation (3.4) of [muyskens2021muygps]. For each response dimension \(j\), given observation set \(X\) with responses \(Y\), noise prior set \(\varepsilon^{(j)}\), and kernel function \(K_{\theta^{(j)}}(\cdot, \cdot)\), computes the following for each prediction element \(\mathbf{z}_i\) with nearest neighbors index set \(N_i\):

\[\widehat{Y} (\mathbf{z}_i \mid X_{N_i})_j = \sigma^2_j K_{\theta^{(j)}} (\mathbf{z}_i, X_{N_i}) \left ( K_{\theta^{(j)}} (X_{N_i}, X_{N_i}) + \varepsilon^{(j)}_{N_i} \right )^{-1} Y(X_{N_i})_{:,j}.\]
Parameters:
  • pairwise_diffs (ndarray) – A tensor of shape (batch_count, nn_count, nn_count, feature_count) containing the (nn_count, nn_count, feature_count)-shaped pairwise nearest neighbor difference tensors corresponding to each of the batch elements.

  • crosswise_diffs (ndarray) – A matrix of shape (batch_count, nn_count, feature_count) whose rows list the difference between each feature of each batch element element and its nearest neighbors.

  • batch_nn_targets (ndarray) – A tensor of shape (batch_count, nn_count, response_count) listing the vector-valued responses for the nearest neighbors of each batch element.

Return type:

ndarray

Returns:

A matrix of shape (batch_count, response_count) whose rows are the predicted response for each of the given indices.

posterior_variance(pairwise_diffs, crosswise_diffs)[source]

Returns the posterior variance from the provided difference tensors.

Return the local posterior variances of each prediction, corresponding to the diagonal elements of a covariance matrix. For each response dimension, given observation set \(X\) with responses \(Y\), noise prior set \(\varepsilon^{(j)}\), and kernel function \(K_{\theta^{(j)}}(\cdot, \cdot)\), computes the following for each prediction element \(\mathbf{z}_i\) with nearest neighbors index set \(N_i\):

\[Var \left ( \widehat{Y} (\mathbf{z}_i \mid X_{N_i}) \right)_j = \sigma_j^2 \left ( K_{\theta^{(j)}} (\mathbf{z}_i, \mathbf{z}_i) - K_{\theta^{(j)}} (\mathbf{z}_i, X_{N_i}) \left ( K_{\theta^{(j)}} (X_{N_i}, X_{N_i} \right ) + \varepsilon^{(j)}_{N_i})^{-1} K_{\theta^{(j)}} (X_{N_i}, \mathbf{z}_i) \right ).\]
Parameters:
  • pairwise_diffs (ndarray) – A tensor of shape (batch_count, nn_count, nn_count, feature_count) containing the (nn_count, nn_count, feature_count)-shaped pairwise nearest neighbor difference tensors corresponding to each of the batch elements.

  • crosswise_diffs (ndarray) – A matrix of shape (batch_count, nn_count, feature_count) whose rows list the difference between each feature of each batch element element and its nearest neighbors.

Return type:

ndarray

Returns:

A vector of shape (batch_count, response_count) consisting of the diagonal elements of the posterior variance for each model.