tensors

Tensor functions

Compute special tensors for the purposes of kernel construction.

MuyGPyS.gp.tensors.batch_features_tensor(features, batch_indices)[source]

Compute a tensor of feature vectors for each batch element.

Parameters:
  • features (ndarray) – The full floating point training or testing data matrix of shape (train_count, feature_count) or (test_count, feature_count).

  • batch_indices (ndarray) – A vector of integers of shape (batch_count,) identifying the training batch of observations to be approximated.

Return type:

ndarray

Returns:

A tensor of shape (batch_count, feature_count) containing the feature vectors for each batch element.

MuyGPyS.gp.tensors.fast_nn_update(train_nn_indices)[source]

Modify the nearest neighbor indices of the training data to include self.

This function is only intended for use in concert with :func:~MuyGPyS.gp.tensors.make_fast_predict_tensors` and MuyGPyS.gp.muygps.MuyGPS.fast_coefficients().

Example

>>> train_nn_indices, _ = nbrs_lookup.get_nns(train_features)
>>> train_nn_indices = fast_nn_update(train_nn_indices)
>>> pairwise_diffs, nn_targets = make_fast_predict_tensors(
...     train_nn_indices,
...     train_features,
...     train_responses,
... )
>>> Kin = muygps_fast.kernel(pairwise_diffs)
>>> precomputed_coefficients_matrix = muygps_fast.fast_coefficients(
...     Kin, nn_targets
... )
>>> # Late on, once test data is encountered
>>> test_indices = np.arange(test_count)
>>> test_nn_indices, _ = nbrs_lookup.get_nns(test_features)
>>> closest_neighbor = test_nn_indices[:, 0]
>>> closest_set = train_nn_indices[closest_neighbor, :]
Parameters:

train_nn_indices (ndarray) – A matrix of integers of shape (train_count, nn_count) listing the nearest neighbor indices for all observations in the batch.

Return type:

ndarray

Returns:

An integral matrix of shape (train_count, nn_count) that is similar to the input, but the most distant neighbor index is removed and the index reference to self has been inserted.

MuyGPyS.gp.tensors.make_fast_predict_tensors(batch_nn_indices, train_features, train_targets)[source]

Create the difference and target tensors for fast posterior mean inference.

Creates pairwise_diffs and batch_nn_targets tensors required by MuyGPyS.gp.muygps.MuyGPS.fast_posterior_mean().

Parameters:
  • batch_nn_indices (ndarray) – A matrix of integers of shape (batch_count, nn_count) listing the nearest neighbor indices for all observations in the batch.

  • train_features (ndarray) – The full floating point training data matrix of shape (train_count, feature_count).

  • train_targets (ndarray) – A matrix of shape (train_count, response_count) whose rows are vector-valued responses for each training element.

Return type:

Tuple[ndarray, ndarray]

Returns:

  • pairwise_diffs – 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.

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

MuyGPyS.gp.tensors.make_heteroscedastic_tensor(measurement_noise, batch_nn_indices)[source]

Create the heteroscedastic noise tensor for nonuniform noise values.

Used to produce the noise tensor needed during batched training and prediction. Creates the noise_tensor tensor required by heteroscedastic MuyGPs models.

Parameters:
  • measurement_noise (ndarray) – A matrix of floats of shape (batch_count,) providing the noise corresponding to the response variable at each input value in the data.

  • batch_nn_indices (ndarray) – A matrix of integers of shape (batch_count, nn_count, nn_count) listing the measurement noise for the nearest neighbors for all observations in the batch.

Return type:

ndarray

Returns:

A matrix of floats of shape (batch_count, nn_count) providing the noise corresponding to the nearest neighbor responses for all observations in the batch.