Data Fit

class pbparam.DataFit(simulation, data, parameters, variables_to_fit=['Voltage [V]'], cost_function=<pbparam.cost_functions.rmse.RMSE object>, weights=None, solve_options=None)[source]

A class to define an optimisation problem.

Parameters:
  • simulation (pybamm.Simulation) – The simulation to be run to fit to data

  • data (pandas.DataFrame) – The experimental or reference data to be used in optimisation of simulation parameters.

  • parameters (dict) – The parameters to be optimised. They should be provided as a dictionary where the keys are the names of the variables to be optimised and the values are a tuple with the initial guesses and the lower and upper bounds of the optimisation. If a key is a list of strings then all the variables in the list will take the same value.

  • variables_to_fit (str or list of str (optional)) – The variable or variables to optimise in the cost function. The default is “Voltage [V]”. It can be a string or a list of strings.

  • weights (dict (optional)) – The custom weights of individual variables. Default is 1 for all variables. It can be int or list of int that has same length with the data.

  • cost_function (pbparam.BaseCostFunction) – Cost function class to be used in minimisation algorithm. The default is Root-Mean Square Error. It can be selected from pre-defined built-in functions or defined explicitly.

  • solve_options (dict (optional)) – A dictionary of options to pass to the simulation. The default is None.

calculate_solution(parameters=None)[source]

Calculate solution of model.

Parameters:

parameters (array-like (optional)) – Parameters to calcualte the solution for. If not provided, it uses the original parameters.

Returns:

solution – The solution for the given inputs.

Return type:

pybamm.Solution

objective_function(x)[source]

Calculate the cost function given the current values of the parameters

Parameters:

x (array-like) – The current values of the parameters

Returns:

cost – The calculated cost of the simulation with the current parameters

Return type:

float