Class ScalarFieldFirstOrderDifferentiator
- java.lang.Object
-
- com.opengamma.strata.math.impl.differentiation.ScalarFieldFirstOrderDifferentiator
-
- All Implemented Interfaces:
Differentiator<DoubleArray,Double,DoubleArray>
public class ScalarFieldFirstOrderDifferentiator extends Object implements Differentiator<DoubleArray,Double,DoubleArray>
Differentiates a scalar field (i.e. there is a scalar value for every point in some vector space) with respect to the vector space using finite difference.For a function $y = f(\mathbf{x})$ where $\mathbf{x}$ is a n-dimensional vector and $y$ is a scalar, this class produces a gradient function $\mathbf{g}(\mathbf{x})$, i.e. a function that returns the gradient for each point $\mathbf{x}$, where $\mathbf{g}$ is the n-dimensional vector $\frac{dy}{dx_i}$.
-
-
Constructor Summary
Constructors Constructor Description ScalarFieldFirstOrderDifferentiator()
Creates an instance using the default values of differencing type (central) and eps (10-5).ScalarFieldFirstOrderDifferentiator(FiniteDifferenceType differenceType, double eps)
Creates an instance that approximates the derivative of a scalar function by finite difference.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description Function<DoubleArray,DoubleArray>
differentiate(Function<DoubleArray,Double> function)
Provides a function that performs the differentiation.Function<DoubleArray,DoubleArray>
differentiate(Function<DoubleArray,Double> function, Function<DoubleArray,Boolean> domain)
Provides a function that performs the differentiation.
-
-
-
Constructor Detail
-
ScalarFieldFirstOrderDifferentiator
public ScalarFieldFirstOrderDifferentiator()
Creates an instance using the default values of differencing type (central) and eps (10-5).
-
ScalarFieldFirstOrderDifferentiator
public ScalarFieldFirstOrderDifferentiator(FiniteDifferenceType differenceType, double eps)
Creates an instance that approximates the derivative of a scalar function by finite difference.If the size of the domain is very small or very large, consider re-scaling first. If this value is too small, the result will most likely be dominated by noise. Use around 10-5 times the domain size.
- Parameters:
differenceType
- the type, forward, backward or central. In most situations, central is besteps
- the step size used to approximate the derivative
-
-
Method Detail
-
differentiate
public Function<DoubleArray,DoubleArray> differentiate(Function<DoubleArray,Double> function)
Description copied from interface:Differentiator
Provides a function that performs the differentiation.- Specified by:
differentiate
in interfaceDifferentiator<DoubleArray,Double,DoubleArray>
- Parameters:
function
- a function for which to get the differential function- Returns:
- a function that calculates the differential
-
differentiate
public Function<DoubleArray,DoubleArray> differentiate(Function<DoubleArray,Double> function, Function<DoubleArray,Boolean> domain)
Description copied from interface:Differentiator
Provides a function that performs the differentiation.- Specified by:
differentiate
in interfaceDifferentiator<DoubleArray,Double,DoubleArray>
- Parameters:
function
- a function for which to get the differential functiondomain
- a function that returns false if the requested value is not in the domain, true otherwise- Returns:
- a function that calculates the differential
-
-