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.- 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, muygps, optim_params, 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.muygps (
MuyGPS
) – The MuyGPS object.optim_params (
Dict
) – Dictionary of references of unfixed hyperparameters belonging to the MuyGPS object. Keys should be strings, and values should be objects of typeMuyGPyS.gp.kernels.Hyperparameter
. Must have anopt_count
number of key-value pairs, matching the shape ofx0
.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.