pysolver_view.differentiation.finite_difference module

pysolver_view.differentiation.finite_difference module#

First derivative primitives with the legacy shape/step conventions.

pysolver_view.differentiation.finite_difference.approx_gradient(function_handle, x, f0=None, abs_step=None, method='central_finite_differences')[source]#

Approximate the derivatives of a given function at a point using various differentiation methods.

Parameters:
function_handlecallable

The function for which derivatives are to be approximated.

xarray_like

The point at which derivatives are to be approximated.

abs_stepfloat or np.ndarray with the same size as x, optional

Step size for finite difference methods. By default uses a suitable value for each method.

methodstr, optional

The method to use for differentiation. Available options are: - ‘forward_finite_differences’ or ‘2-point’: Forward finite differences. - ‘central_finite_differences’ or ‘3-point’: Central finite differences. - ‘complex_step’ or ‘cs’: Complex step method.

Defaults to ‘central_finite_differences’.

Returns:
numpy.ndarray

The approximated derivatives of the function at the given point x.

Raises:
ValueError

If an invalid method is provided.

pysolver_view.differentiation.finite_difference.central_finite_differences(function_handle, x, abs_step=None)[source]#

Gradient approximation by central finite differences.

Parameters:
function_handlecallable

The function for which the derivative is calculated.

xnp.ndarray

The point at which the derivative is calculated.

abs_stepfloat or np.ndarray with the same size as x, optional

The step size for finite differences. Default is cobic root of machine epsilon.

Returns:
np.ndarray

The gradient of the function at point x.

pysolver_view.differentiation.finite_difference.complex_step_derivative(function_handle, x, abs_step=None)[source]#

Gradient approximation using the complex step method.

Parameters:
function_handlecallable

The function for which the derivative is calculated.

xnp.ndarray

The point at which the derivative is calculated.

abs_stepfloat or np.ndarray with the same size as x, optional

The step size for the complex step. Default is machine epsilon.

Returns:
np.ndarray

The gradient of the function at point x.

pysolver_view.differentiation.finite_difference.forward_finite_differences(function_handle, x, abs_step=None, f0=None)[source]#

Gradient approximation by forward finite differences.

Parameters:
function_handlecallable

The function for which the derivative is calculated.

xnp.ndarray

The point at which the derivative is calculated.

abs_stepfloat or np.ndarray with the same size as x, optional

The step size for finite differences. Default is square root of machine epsilon.

Returns:
np.ndarray

The gradient of the function at point x.