biogeme.tools.derivatives module

biogeme.tools.derivatives.checkDerivatives(the_function, x, names=None, logg=False)[source]

Warning

This function is deprecated. Use check_derivatives() instead.

Return type:

tuple[float, ndarray, ndarray, ndarray, ndarray]

Parameters:
  • the_function (Callable[[ndarray], tuple[float, ndarray, ndarray]])

  • x (ndarray)

  • names (list[str] | None)

  • logg (bool | None)

biogeme.tools.derivatives.check_derivatives(the_function, x, names=None, logg=False)[source]

Verifies the analytical derivatives of a function by comparing them with finite difference approximations.

Parameters:
  • the_function (Union[Callable[[ndarray], FunctionOutput], Callable[[ndarray], NamedFunctionOutput]]) –

    A function object that takes a vector as an argument, and returns a tuple:

    • The first element of the tuple is the value of the function \(f\),

    • the second is the gradient of the function,

    • the third is the hessian.

  • x (ndarray) – arguments of the function

  • names (list[str] | None) – the names of the entries of x (for reporting).

  • logg (bool | None) – if True, messages will be displayed.

Return type:

tuple[float, ndarray, ndarray, ndarray, ndarray]

Returns:

tuple f, g, h, gdiff, hdiff where

  • f is the value of the function at x,

  • g is the analytical gradient,

  • h is the analytical hessian,

  • gdiff is the difference between the analytical gradient and the finite difference approximation

  • hdiff is the difference between the analytical hessian and the finite difference approximation

biogeme.tools.derivatives.findiff_H(the_function, x)[source]

Warning

This function is deprecated. Use findiff_h() instead.

Return type:

ndarray

Parameters:
  • the_function (Callable[[ndarray], tuple[float, ndarray, ...]])

  • x (ndarray)

biogeme.tools.derivatives.findiff_g(the_function, x)[source]

Calculates the gradient of a function \(f\) using finite differences

Parameters:
  • the_function (Callable[[ndarray], FunctionOutput]) – A function object that takes a vector as an argument, and returns a tuple. The first element of the tuple is the value of the function \(f\). The other elements are not used.

  • x (ndarray) – argument of the function

Return type:

ndarray

Returns:

numpy vector, same dimension as x, containing the gradient calculated by finite differences.

biogeme.tools.derivatives.findiff_h(the_function, x)[source]

Calculates the hessian of a function \(f\) using finite differences

Parameters:
  • the_function (Union[Callable[[ndarray], FunctionOutput], Callable[[ndarray], NamedFunctionOutput]]) – A function object that takes a vector as an argument, and returns a tuple. The first element of the tuple is the value of the function \(f\), and the second is the gradient of the function. The other elements are not used.

  • x (ndarray) – argument of the function

Return type:

ndarray

Returns:

numpy matrix containing the hessian calculated by finite differences.