Adding new Hessians

This section describes how to add further methods to approximate the Hessian within FitBenchmarking

In order to add a new Hessian evaluation method, <hes_method>, you will need to:

  1. Create fitbenchmarking/hessian/<hes_method>_hessian.py, which contains a new subclass of hessian. Then implement the method:

    • abstract Hessian.eval()

      Evaluates Hessian of the model

      Parameters:

      params (list) – The parameter values to find the Hessian at

      Returns:

      Computed Hessian

      Return type:

      3D numpy array

    The method is set sequentially within loop_over_hessians() by using the method attribute of the class.

  2. Enable the new method as an option in Fitting Options, following the instructions in Adding new Options. Specifically:

    • Amend the VALID_FITTING dictionary so that the element associated with the hes_method key contains the new <hes_method>.

  3. Document the available Hessians by:

  • adding to the list of available method options under hes_method in Fitting Options.

  • updating any example files in the examples directory

  1. Create tests for the Hessian evaluation in fitbenchmarking/hessian/tests/test_hessians.py.

The FittingProblem and Jacobian

When adding new Hessian, you will find it helpful to make use of the following members of the FittingProblem and subclasses of Jacobian:

class fitbenchmarking.parsing.fitting_problem.FittingProblem(options)

Definition of a fitting problem, which will be populated by a parser from a problem definition file.

Onces populated, this should include the data, the function and any other additional requirements from the data.

data_e

numpy array The errors or weights

data_x

numpy array The x-data

data_y

numpy array The y-data

eval_model(params, **kwargs)

Function evaluation method

Parameters:

params (list) – parameter value(s)

Returns:

data values evaluated from the function of the problem

Return type:

numpy array

class fitbenchmarking.jacobian.base_jacobian.Jacobian(problem)

Base class for Jacobian.

abstract eval(params, **kwargs)

Evaluates Jacobian of the model, \(\nabla_p f(x,p)\), at the point given by the parameters.

Parameters:

params (list) – The parameter values at which to evaluate the Jacobian

Returns:

Computed Jacobian

Return type:

numpy array