leaderbot.models.RaoKupper.loss#

RaoKupper.loss(w=None, return_jac=False, constraint=False)#

Total loss for all data instances.

Parameters:
warray_like, default=None

Parameters. If None, the pre-trained parameters are used, provided is already trained.

return_jacbool, default=False

if True, the Jacobian of loss with respect to the parameters is also returned.

constraintbool, default=False

If True, the constrain on the parameters is also added to the loss.

Returns:
lossfloat

Total loss for all data points.

if return_jac is True:
jacnp.array

An array of the size of the number of parameters, representing the Jacobian of loss.

Raises:
RuntimeWarning

If loss is nan.

RuntimeError

If the model is not trained and the input w is set to None.

See also

train

train model parameters.

fisher

Observed Fisher information matrix.

Examples

>>> from leaderbot.data import load
>>> from leaderbot.models import Davidson

>>> # Create a model
>>> data = load()
>>> model = Davidson(data)

>>> # Generate an array of parameters
>>> import numpy as np
>>> w = np.random.randn(model.n_param)

>>> # Compute loss and its gradient with respect to parameters
>>> loss, jac = model.loss(w, return_jac=True, constraint=False)