Cost Functions

class ionworkspipeline.costs.Cost(scale='mean', nan_values='mean', objective_weights=None, variable_weights=None)

Base cost function class

Parameters

scalestring or float, optional

How to scale the model and data, for each variable in the cost function. The options are - “mean” (default): uses the mean of the data. - “range”: uses the range of the data. - “sse”: uses the sum of squares of the data. - “mse”: uses the mean of the sum of squares of the data. - “rmse”: uses the root mean square of the sum of squares of the data. - “identity”: uses 1. - float: uses the value of the float.

nan_valuesstring or float, optional

How to deal with any NaN values in the model output. If “mean”, uses the mean of the non-NaN model output values. If “min”, uses the min of the non-NaN model output values. If a float, uses the float value.

objective_weightsdict, optional

Dictionary of {name: weight} pairs for each objective in the cost function. If None, all objectives are weighted equally. If a name is not in the dictionary, it is given a weight of 1.

variable_weightsdict, optional

Dictionary of {name: weight} pairs for each variable in the cost function. If None, all variables are weighted equally. If a name is not in the dictionary, it is given a weight of 1.

__call__(outputs)

Returns the cost function evaluated over all the outputs

Parameters

outputsdict

Dict of outputs for which to compute the cost function. Each value in the dict should be a tuple (model, data) corresponding to one case; having multiple items allows for multi-objective optimization, for example optimizing simultaneously over multiple C-rates. The keys of the dict are the names of the objective optimized. For each (model, data) tuple, both model and data should be a dictionary of {name: value} pairs for variables being optimized over. ‘name’ should be a string and ‘value’ should be a numpy array.

nan_values(model_value, data_value)

How to deal with nan values

objective_weights(name, default=None)

How to weight the output objectives

scalarize(value)

Scalarize the cost function. By default, returns the value unchanged.

scale(model_value, data_value)

How to scale the data for comparison across multiple variables / cases

variable_weights(name, default=None)

How to weight the output variables

class ionworkspipeline.costs.Difference(scale='mean', nan_values='mean', objective_weights=None, variable_weights=None)

Cost function consisting of the difference between the model and the data. If there are multiple outputs, concatenates them together.

Extends: ionworkspipeline.data_fits.costs.costs.Cost

scalarize(value)

See Cost.scalarize()

class ionworkspipeline.costs.RMSE(scale='mean', nan_values='mean', objective_weights=None, variable_weights=None)

Root-mean-square-error cost function

Extends: ionworkspipeline.data_fits.costs.costs.Cost

class ionworkspipeline.costs.Wasserstein(scale='mean', nan_values='mean', objective_weights=None, variable_weights=None)

Wasserstein (or earth mover’s) distance

Extends: ionworkspipeline.data_fits.costs.costs.Difference