loss

Loss Function Handling

MuyGPyS includes predefined loss functions and convenience functions for indicating them to optimization.

MuyGPyS.optimize.loss.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 that targets 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.loss.get_loss_func(loss_method)[source]

Select a loss function based upon string key.

Currently supports strings "log" or "cross-entropy" for MuyGPyS.optimize.objective.cross_entropy_fn() and "mse" for MuyGPyS.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.loss.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.