bilby.core.utils.calculus.derivatives

bilby.core.utils.calculus.derivatives(vals, func, releps=0.001, abseps=None, mineps=1e-09, reltol=0.001, epsscale=0.5, nonfixedidx=None)[source]

Calculate the partial derivatives of a function at a set of values. The derivatives are calculated using the central difference, using an iterative method to check that the values converge as step size decreases.

Parameters:
vals: array_like

A set of values, that are passed to a function, at which to calculate the gradient of that function

func:

A function that takes in an array of values.

releps: float, array_like, 1e-3

The initial relative step size for calculating the derivative.

abseps: float, array_like, None

The initial absolute step size for calculating the derivative. This overrides releps if set. releps is set then that is used.

mineps: float, 1e-9

The minimum relative step size at which to stop iterations if no convergence is achieved.

epsscale: float, 0.5

The factor by which releps if scaled in each iteration.

nonfixedidx: array_like, None

An array of indices in vals that are _not_ fixed values and therefore can have derivatives taken. If None then derivatives of all values are calculated.

Returns:
grads: array_like

An array of gradients for each non-fixed value.