Skip to content

Comparison with Finite Differences

finitediff

Finite difference approximation of parametric derivatives.

Warning

Finite difference approximations are typically computationally expensive and inaccurate. They should only be used for comparison in small test cases.

Functions:

Name Description
finite_diff_1_forward

Forward finite difference approximation of a first order derivative

finite_diff_1_backward

Backward finite difference approximation of a first order derivative

finite_diff_1_central

Central finite difference approximation of a first order derivative

finite_diff_2

Implement second order finite differences

compute_fd_jacobian

Compute the Jacobian of the Eikonal equation w.r.t. to parameter with finite differences

eikonax.finitediff.finite_diff_1_forward

finite_diff_1_forward(func: Callable[[jtReal[npt.NDArray, M]], jtReal[npt.NDArray, M]], eval_point: jtReal[npt.NDArray, M], step_width: Real, index: int) -> jtReal[npt.NDArray, N]

Forward finite difference approximation of a first order derivative.

This method expects vector-valued functions \(f: \mathbb{R}^M \to \mathbb{R}^N\), and approximates the first derivative of \(f\) at a given point \(x \in \mathbb{R}^M\) with respect to the \(i\)-th component of \(x\) as

\[ \frac{\partial f(x)}{\partial x_i} \approx \frac{f(x + h e_i) - f(x)}{h} \]

with a step width \(h>0\).

Parameters:

Name Type Description Default
func Callable

Callable to use for FD computation

required
eval_point npt.NDArray

Parameter value at which to approximate the derivative

required
step_width Real

Step width of the finite difference

required
index int

Vector component for which to compute partial derivative

required

Returns:

Type Description
jtReal[npt.NDArray, N]

npt.NDArray: Partial derivative approximation

eikonax.finitediff.finite_diff_1_backward

finite_diff_1_backward(func: Callable[[jtReal[npt.NDArray, M]], jtReal[npt.NDArray, M]], eval_point: jtReal[npt.NDArray, M], step_width: float, index: int) -> jtReal[npt.NDArray, N]

Backward finite difference approximation of a first order derivative.

This method expects vector-valued functions \(f: \mathbb{R}^M \to \mathbb{R}^N\), and approximates the first derivative of \(f\) at a given point \(x \in \mathbb{R}^M\) with respect to the \(i\)-th component of \(x\) as

\[ \frac{\partial f(x)}{\partial x_i} \approx \frac{f(x)- f(x - h e_i)}{h} \]

with a step width \(h>0\).

Parameters:

Name Type Description Default
func Callable

Callable to use for FD computation

required
eval_point npt.NDArray

Parameter value at which to approximate the derivative

required
step_width Real

Step width of the finite difference

required
index int

Vector component for which to compute partial derivative

required

Returns:

Type Description
jtReal[npt.NDArray, N]

npt.NDArray: Partial derivative approximation

eikonax.finitediff.finite_diff_1_central

finite_diff_1_central(func: Callable[[jtReal[npt.NDArray, M]], jtReal[npt.NDArray, M]], eval_point: jtReal[npt.NDArray, M], step_width: float, index: int) -> jtReal[npt.NDArray, N]

Central finite difference approximation of a first order derivative.

This method expects vector-valued functions \(f: \mathbb{R}^M \to \mathbb{R}^N\), and approximates the first derivative of \(f\) at a given point \(x \in \mathbb{R}^M\) with respect to the \(i\)-th component of \(x\) as

\[ \frac{\partial f(x)}{\partial x_i} \approx \frac{f(x + h e_i)- f(x - h e_i)}{2h} \]

with a step width \(h>0\).

Parameters:

Name Type Description Default
func Callable

Callable to use for FD computation

required
eval_point npt.NDArray

Parameter value at which to approximate the derivative

required
step_width Real

Step width of the finite difference

required
index int

Vector component for which to compute partial derivative

required

Returns:

Type Description
jtReal[npt.NDArray, N]

npt.NDArray: Partial derivative approximation

eikonax.finitediff.finite_diff_2

finite_diff_2(func: Callable[[jtReal[npt.NDArray, M]], jtReal[npt.NDArray, M]], eval_point: jtReal[npt.NDArray, M], step_width: float, index_1: int, index_2: int) -> None

Implement second order finite differences.

Not implemented yet

eikonax.finitediff.run_eikonax_with_tensorfield

run_eikonax_with_tensorfield(parameter_vector: jtReal[npt.NDArray, M], eikonax_solver: solver.Solver, tensor_field: tensorfield.TensorField) -> jtReal[npt.NDArray, N]

Wrapper function for Eikonax runs.

Parameters:

Name Type Description Default
parameter_vector npt.NDArray

Parameter vector at which to compute eikonal solution

required
eikonax_solver solver.Solver

Initialized solver object

required
tensor_field tensorfield.TensorField

Initialized tensor field object

required

Returns:

Type Description
jtReal[npt.NDArray, N]

npt.NDArray: Solution of the Eikonal equation

eikonax.finitediff.compute_fd_jacobian

compute_fd_jacobian(eikonax_solver: solver.Solver, tensor_field: tensorfield.TensorField, stencil: Callable, eval_point: jtReal[npt.NDArray | jax.Array, M], step_width: float) -> jtReal[npt.NDArray, 'N M']

Finite Difference Jacobian.

Compute the Jacobian of the discrete Eikonal equation solution \(\mathbf{u}\in\mathbb{R}^N\) w.r.t. to a parameter vector \(\mathbf{m}\in\mathbb{R}^M\) with finite differences.

Warning

This method should only be used for small problems.

Parameters:

Name Type Description Default
eikonax_solver solver.Solver

Initialized solver object

required
tensor_field tensorfield.TensorField

Initialized tensor field object

required
stencil Callable

Finite difference stencil to use for computation

required
eval_point npt.NDArray

Parameter vector at which to approximate derivative

required
step_width float

Step with in FD stencil

required

Returns:

Type Description
jtReal[npt.NDArray, 'N M']

npt.NDArray: (Dense) Jacobian matrix

eikonax.finitediff.compute_fd_hessian

compute_fd_hessian(func: Callable, stencil: Callable, eval_point: jtReal[npt.NDArray | jax.Array, M], step_width: float) -> None

Implement finite difference Hessian computation.

Not implemented yet