objective¶
Objective and Loss Function Handling
MuyGPyS includes predefined loss functions and convenience functions for indicating them to optimization.
- MuyGPyS.optimize.objective.cross_entropy_fn(predictions, targets)[source]¶
Cross entropy function.
Computes the cross entropy loss the predicted versus known response. Transforms
predictions
to be row-stochastic, and ensures thattargets
contains no negative elements.@NOTE[bwp] I don’t remember why we hard-coded eps=1e-6. Might need to revisit.
- Parameters
predictions (
ndarray
) – The predicted response of shape(batch_count, response_count)
.targets (
ndarray
) – The expected response of shape(batch_count, response_count)
.
- Return type
float
- Returns
The cross-entropy loss of the prediction.
- MuyGPyS.optimize.objective.get_loss_func(loss_method)[source]¶
Select a loss function based upon string key.
Currently supports strings
"log"
or"cross-entropy"
forMuyGPyS.optimize.objective.cross_entropy_fn()
and"mse"
forMuyGPyS.optimize.objective.mse_fn()
.- Parameters
predictions – The predicted response of shape
(batch_count, response_count)
.targets – The expected response of shape
(batch_count, response_count)
.
- Return type
Callable
- Returns
The loss function Callable.
- Raises
NotImplementedError – Unrecognized strings will result in an error.
- MuyGPyS.optimize.objective.loo_crossval(x0, objective_fn, kernel_fn, predict_fn, pairwise_dists, crosswise_dists, batch_nn_targets, batch_targets)[source]¶
Leave-one-out cross validation.
Returns leave-one-out cross validation performance for a set
MuyGPS
object. Predicts on all of the training data at once.- Parameters
x0 (
ndarray
) – Current guess for hyperparameter values of shape(opt_count,)
.objective_fn (
Callable
) – The function to be optimized. Can be any function that accepts twonumpy.ndarray
objects indicating the prediction and target values, in that order.kernel_fn (
Callable
) – A function that realizes kernel tensors given a list of the free parameters.predict_fn (
Callable
) – A function that realizes MuyGPs prediction given an epsilon value. The given value is unused if epsilon is fixed.pairwise_dists (
ndarray
) – Distance tensor of floats of shape(batch_count, nn_count, nn_count)
whose second two dimensions give the pairwise distances between the nearest neighbors of each batch element.crosswise_dists (
ndarray
) – Distance matrix of floats of shape(batch_count, nn_count)
whose rows give the distances between each batch element and its nearest neighbors.batch_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.batch_targets (
ndarray
) – Matrix of floats of shape(batch_count, response_count)
whose rows give the expected response for each batch element.
- Return type
float
- Returns
The evaluation of
objective_fn
on the predicted versus expected response.
- MuyGPyS.optimize.objective.mse_fn(predictions, targets)[source]¶
Mean squared error function.
Computes mean squared error loss of the predicted versus known response. Treats multivariate outputs as interchangeable in terms of loss penalty.
- Parameters
predictions (
ndarray
) – The predicted response of shape(batch_count, response_count)
.targets (
ndarray
) – The expected response of shape(batch_count, response_count)
.
- Return type
float
- Returns
The mse loss of the prediction.