fitbenchmarking.cost_func.poisson_cost_func module

Implements a Poisson deviance cost function based on Mantid’s: https://docs.mantidproject.org/nightly/fitting/fitcostfunctions/Poisson.html

class fitbenchmarking.cost_func.poisson_cost_func.PoissonCostFunc(problem)

Bases: fitbenchmarking.cost_func.base_cost_func.CostFunc

This defines the Poisson deviance cost-function where, given the set of \(n\) data points \((x_i, y_i)\), and a model function \(f(x,p)\), we find the optimal parameters in the Poisson deviance sense by solving:

\[\min_p \sum_{i=1}^n \left( y_i \left(\log{y_i} - \log{f(x_i, p)} \right) - \left( y_i - f(x_i, p) \right) \right)\]

where \(p\) is a vector of length \(m\), and we start from a given initial guess for the optimal parameters.

This cost function is intended for positive values.

This cost function is not a least squares problem and as such will not work with least squares minimizers. Please use algorithm_type to select general solvers. See options docs (Fitting Options) for information on how to do this.

eval_cost(params, **kwargs)

Evaluate the Poisson deviance cost function

Parameters
  • params (list) – The parameters to calculate residuals for

  • x (np.array (optional)) – The x values to evaluate at. Default is self.problem.data_x

  • y (np.array (optional)) – The y values to evaluate at. Default is self.problem.data_y

Returns

evaluated cost function

Return type

float

hes_cost(params, **kwargs)

Uses the Hessian of the model to evaluate the Hessian of the cost function, \(\nabla_p^2 F(r(x,y,p))\), at the given parameters.

Parameters

params (list) – The parameters at which to calculate Hessians

Returns

evaluated Hessian of the cost function

Return type

2D numpy array

hes_res(params, **kwargs)

Uses the Hessian of the model to evaluate the Hessian of the cost function residual, \(\nabla_p^2 r(x,y,p)\), at the given parameters.

Parameters

params (list) – The parameters at which to calculate Hessians

Returns

evaluated Hessian and Jacobian of the residual at

each x, y pair :rtype: tuple(list of 2D numpy arrays, list of 1D numpy arrays)

jac_cost(params, **kwargs)

Uses the Jacobian of the model to evaluate the Jacobian of the cost function, \(\nabla_p F(r(x,y,p))\), at the given parameters. :param params: The parameters at which to calculate Jacobians :type params: list :return: evaluated Jacobian of the cost function :rtype: 1D numpy array

jac_res(params, **kwargs)

Uses the Jacobian of the model to evaluate the Jacobian of the cost function residual, \(\nabla_p r(x,y,p)\), at the given parameters.

Parameters

params (list) – The parameters at which to calculate Jacobians

Returns

evaluated Jacobian of the residual at each x, y pair

Return type

a list of 1D numpy arrays