Class ScalarFirstOrderDifferentiator

• java.lang.Object
• com.opengamma.strata.math.impl.differentiation.ScalarFirstOrderDifferentiator
• All Implemented Interfaces:
Differentiator<Double,​Double,​Double>

public class ScalarFirstOrderDifferentiator
extends Object
implements Differentiator<Double,​Double,​Double>
Differentiates a scalar function with respect to its argument using finite difference.

For a function $y = f(x)$ where $x$ and $y$ are scalars, this class produces a gradient function $g(x)$, i.e. a function that returns the gradient for each point $x$, where $g$ is the scalar $\frac{dy}{dx}$.

• Constructor Summary

Constructors
Constructor Description
ScalarFirstOrderDifferentiator()
Creates an instance using the default value of eps (10-5) and central differencing type.
ScalarFirstOrderDifferentiator​(FiniteDifferenceType differenceType)
Creates an instance using the default value of eps (10-5).
ScalarFirstOrderDifferentiator​(FiniteDifferenceType differenceType, double eps)
Creates an instance.
• Method Summary

All Methods
Modifier and Type Method Description
Function<Double,​Double> differentiate​(Function<Double,​Double> function)
Provides a function that performs the differentiation.
Function<Double,​Double> differentiate​(Function<Double,​Double> function, Function<Double,​Boolean> domain)
Provides a function that performs the differentiation.
• Methods inherited from class java.lang.Object

clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
• Constructor Detail

• ScalarFirstOrderDifferentiator

public ScalarFirstOrderDifferentiator()
Creates an instance using the default value of eps (10-5) and central differencing type.
• ScalarFirstOrderDifferentiator

public ScalarFirstOrderDifferentiator​(FiniteDifferenceType differenceType)
Creates an instance using the default value of eps (10-5).
Parameters:
differenceType - the differencing type to be used in calculating the gradient function
• ScalarFirstOrderDifferentiator

public ScalarFirstOrderDifferentiator​(FiniteDifferenceType differenceType,
double eps)
Creates an instance.

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 differencing type to be used in calculating the gradient function
eps - the step size used to approximate the derivative
• Method Detail

• differentiate

public Function<Double,​Double> differentiate​(Function<Double,​Double> function)
Description copied from interface: Differentiator
Provides a function that performs the differentiation.
Specified by:
differentiate in interface Differentiator<Double,​Double,​Double>
Parameters:
function - a function for which to get the differential function
Returns:
a function that calculates the differential
• differentiate

public Function<Double,​Double> differentiate​(Function<Double,​Double> function,
Function<Double,​Boolean> domain)
Description copied from interface: Differentiator
Provides a function that performs the differentiation.
Specified by:
differentiate in interface Differentiator<Double,​Double,​Double>
Parameters:
function - a function for which to get the differential function
domain - a function that returns false if the requested value is not in the domain, true otherwise
Returns:
a function that calculates the differential