Class SparseGradient
- java.lang.Object
-
- org.apache.commons.math4.legacy.analysis.differentiation.SparseGradient
-
- All Implemented Interfaces:
FieldElement<SparseGradient>
,RealFieldElement<SparseGradient>
public final class SparseGradient extends Object implements RealFieldElement<SparseGradient>
First derivative computation with large number of variables.This class plays a similar role to
DerivativeStructure
, with a focus on efficiency when dealing with large number of independent variables and most computation depend only on a few of them, and when only first derivative is desired. When these conditions are met, this class should be much faster thanDerivativeStructure
and use less memory.- Since:
- 3.3
-
-
Method Summary
-
-
-
Method Detail
-
createConstant
public static SparseGradient createConstant(double value)
Factory method creating a constant.- Parameters:
value
- value of the constant- Returns:
- a new instance
-
createVariable
public static SparseGradient createVariable(int idx, double value)
Factory method creating an independent variable.- Parameters:
idx
- index of the variablevalue
- value of the variable- Returns:
- a new instance
-
numVars
public int numVars()
Find the number of variables.- Returns:
- number of variables
-
getDerivative
public double getDerivative(int index)
Get the derivative with respect to a particular index variable.- Parameters:
index
- index to differentiate with.- Returns:
- derivative with respect to a particular index variable
-
getValue
public double getValue()
Get the value of the function.- Returns:
- value of the function.
-
getReal
public double getReal()
- Specified by:
getReal
in interfaceRealFieldElement<SparseGradient>
-
add
public SparseGradient add(SparseGradient a)
- Specified by:
add
in interfaceFieldElement<SparseGradient>
-
addInPlace
public void addInPlace(SparseGradient a)
Add in place.This method is designed to be faster when used multiple times in a loop.
The instance is changed here, in order to not change the instance the
add(SparseGradient)
method should be used.- Parameters:
a
- instance to add
-
add
public SparseGradient add(double c)
- Specified by:
add
in interfaceRealFieldElement<SparseGradient>
-
subtract
public SparseGradient subtract(SparseGradient a)
- Specified by:
subtract
in interfaceFieldElement<SparseGradient>
-
subtract
public SparseGradient subtract(double c)
- Specified by:
subtract
in interfaceRealFieldElement<SparseGradient>
-
multiply
public SparseGradient multiply(SparseGradient a)
- Specified by:
multiply
in interfaceFieldElement<SparseGradient>
-
multiplyInPlace
public void multiplyInPlace(SparseGradient a)
Multiply in place.This method is designed to be faster when used multiple times in a loop.
The instance is changed here, in order to not change the instance the
add(SparseGradient)
method should be used.- Parameters:
a
- instance to multiply
-
multiply
public SparseGradient multiply(double c)
- Specified by:
multiply
in interfaceRealFieldElement<SparseGradient>
-
multiply
public SparseGradient multiply(int n)
- Specified by:
multiply
in interfaceFieldElement<SparseGradient>
-
divide
public SparseGradient divide(SparseGradient a)
- Specified by:
divide
in interfaceFieldElement<SparseGradient>
-
divide
public SparseGradient divide(double c)
- Specified by:
divide
in interfaceRealFieldElement<SparseGradient>
-
negate
public SparseGradient negate()
- Specified by:
negate
in interfaceFieldElement<SparseGradient>
-
getField
public Field<SparseGradient> getField()
- Specified by:
getField
in interfaceFieldElement<SparseGradient>
-
remainder
public SparseGradient remainder(double a)
- Specified by:
remainder
in interfaceRealFieldElement<SparseGradient>
-
remainder
public SparseGradient remainder(SparseGradient a)
- Specified by:
remainder
in interfaceRealFieldElement<SparseGradient>
-
abs
public SparseGradient abs()
- Specified by:
abs
in interfaceRealFieldElement<SparseGradient>
-
ceil
public SparseGradient ceil()
- Specified by:
ceil
in interfaceRealFieldElement<SparseGradient>
-
floor
public SparseGradient floor()
- Specified by:
floor
in interfaceRealFieldElement<SparseGradient>
-
rint
public SparseGradient rint()
- Specified by:
rint
in interfaceRealFieldElement<SparseGradient>
-
round
public long round()
- Specified by:
round
in interfaceRealFieldElement<SparseGradient>
-
signum
public SparseGradient signum()
- Specified by:
signum
in interfaceRealFieldElement<SparseGradient>
-
copySign
public SparseGradient copySign(SparseGradient sign)
- Specified by:
copySign
in interfaceRealFieldElement<SparseGradient>
-
copySign
public SparseGradient copySign(double sign)
- Specified by:
copySign
in interfaceRealFieldElement<SparseGradient>
-
scalb
public SparseGradient scalb(int n)
- Specified by:
scalb
in interfaceRealFieldElement<SparseGradient>
-
hypot
public SparseGradient hypot(SparseGradient y)
- Specified by:
hypot
in interfaceRealFieldElement<SparseGradient>
-
hypot
public static SparseGradient hypot(SparseGradient x, SparseGradient y)
Returns the hypotenuse of a triangle with sidesx
andy
- sqrt(x2 +y2) avoiding intermediate overflow or underflow.- If either argument is infinite, then the result is positive infinity.
- else, if either argument is NaN then the result is NaN.
- Parameters:
x
- a valuey
- a value- Returns:
- sqrt(x2 +y2)
-
reciprocal
public SparseGradient reciprocal()
- Specified by:
reciprocal
in interfaceFieldElement<SparseGradient>
- Specified by:
reciprocal
in interfaceRealFieldElement<SparseGradient>
-
sqrt
public SparseGradient sqrt()
- Specified by:
sqrt
in interfaceRealFieldElement<SparseGradient>
-
cbrt
public SparseGradient cbrt()
- Specified by:
cbrt
in interfaceRealFieldElement<SparseGradient>
-
rootN
public SparseGradient rootN(int n)
- Specified by:
rootN
in interfaceRealFieldElement<SparseGradient>
-
pow
public SparseGradient pow(double p)
- Specified by:
pow
in interfaceRealFieldElement<SparseGradient>
-
pow
public SparseGradient pow(int n)
- Specified by:
pow
in interfaceRealFieldElement<SparseGradient>
-
pow
public SparseGradient pow(SparseGradient e)
- Specified by:
pow
in interfaceRealFieldElement<SparseGradient>
-
pow
public static SparseGradient pow(double a, SparseGradient x)
Compute ax where a is a double and x aSparseGradient
.- Parameters:
a
- number to exponentiatex
- power to apply- Returns:
- ax
-
exp
public SparseGradient exp()
- Specified by:
exp
in interfaceRealFieldElement<SparseGradient>
-
expm1
public SparseGradient expm1()
- Specified by:
expm1
in interfaceRealFieldElement<SparseGradient>
-
log
public SparseGradient log()
- Specified by:
log
in interfaceRealFieldElement<SparseGradient>
-
log10
public SparseGradient log10()
Base 10 logarithm.- Specified by:
log10
in interfaceRealFieldElement<SparseGradient>
- Returns:
- base 10 logarithm of the instance
-
log1p
public SparseGradient log1p()
- Specified by:
log1p
in interfaceRealFieldElement<SparseGradient>
-
cos
public SparseGradient cos()
- Specified by:
cos
in interfaceRealFieldElement<SparseGradient>
-
sin
public SparseGradient sin()
- Specified by:
sin
in interfaceRealFieldElement<SparseGradient>
-
tan
public SparseGradient tan()
- Specified by:
tan
in interfaceRealFieldElement<SparseGradient>
-
acos
public SparseGradient acos()
- Specified by:
acos
in interfaceRealFieldElement<SparseGradient>
-
asin
public SparseGradient asin()
- Specified by:
asin
in interfaceRealFieldElement<SparseGradient>
-
atan
public SparseGradient atan()
- Specified by:
atan
in interfaceRealFieldElement<SparseGradient>
-
atan2
public SparseGradient atan2(SparseGradient x)
- Specified by:
atan2
in interfaceRealFieldElement<SparseGradient>
-
atan2
public static SparseGradient atan2(SparseGradient y, SparseGradient x)
Two arguments arc tangent operation.- Parameters:
y
- first argument of the arc tangentx
- second argument of the arc tangent- Returns:
- atan2(y, x)
-
cosh
public SparseGradient cosh()
- Specified by:
cosh
in interfaceRealFieldElement<SparseGradient>
-
sinh
public SparseGradient sinh()
- Specified by:
sinh
in interfaceRealFieldElement<SparseGradient>
-
tanh
public SparseGradient tanh()
- Specified by:
tanh
in interfaceRealFieldElement<SparseGradient>
-
acosh
public SparseGradient acosh()
- Specified by:
acosh
in interfaceRealFieldElement<SparseGradient>
-
asinh
public SparseGradient asinh()
- Specified by:
asinh
in interfaceRealFieldElement<SparseGradient>
-
atanh
public SparseGradient atanh()
- Specified by:
atanh
in interfaceRealFieldElement<SparseGradient>
-
toDegrees
public SparseGradient toDegrees()
Convert radians to degrees, with error of less than 0.5 ULP.- Returns:
- instance converted into degrees
-
toRadians
public SparseGradient toRadians()
Convert degrees to radians, with error of less than 0.5 ULP.- Returns:
- instance converted into radians
-
taylor
public double taylor(double... delta)
Evaluate Taylor expansion of a sparse gradient.- Parameters:
delta
- parameters offsets (Δx, Δy, ...)- Returns:
- value of the Taylor expansion at x + Δx, y + Δy, ...
-
compose
public SparseGradient compose(double f0, double f1)
Compute composition of the instance by a univariate function.- Parameters:
f0
- value of the function at (i.e. f(getValue()
))f1
- first derivative of the function at the current point (i.e. f'(getValue()
))- Returns:
- f(this)
-
linearCombination
public SparseGradient linearCombination(SparseGradient[] a, SparseGradient[] b)
- Specified by:
linearCombination
in interfaceRealFieldElement<SparseGradient>
-
linearCombination
public SparseGradient linearCombination(double[] a, SparseGradient[] b)
- Specified by:
linearCombination
in interfaceRealFieldElement<SparseGradient>
-
linearCombination
public SparseGradient linearCombination(SparseGradient a1, SparseGradient b1, SparseGradient a2, SparseGradient b2)
- Specified by:
linearCombination
in interfaceRealFieldElement<SparseGradient>
-
linearCombination
public SparseGradient linearCombination(double a1, SparseGradient b1, double a2, SparseGradient b2)
- Specified by:
linearCombination
in interfaceRealFieldElement<SparseGradient>
-
linearCombination
public SparseGradient linearCombination(SparseGradient a1, SparseGradient b1, SparseGradient a2, SparseGradient b2, SparseGradient a3, SparseGradient b3)
- Specified by:
linearCombination
in interfaceRealFieldElement<SparseGradient>
-
linearCombination
public SparseGradient linearCombination(double a1, SparseGradient b1, double a2, SparseGradient b2, double a3, SparseGradient b3)
- Specified by:
linearCombination
in interfaceRealFieldElement<SparseGradient>
-
linearCombination
public SparseGradient linearCombination(SparseGradient a1, SparseGradient b1, SparseGradient a2, SparseGradient b2, SparseGradient a3, SparseGradient b3, SparseGradient a4, SparseGradient b4)
- Specified by:
linearCombination
in interfaceRealFieldElement<SparseGradient>
-
linearCombination
public SparseGradient linearCombination(double a1, SparseGradient b1, double a2, SparseGradient b2, double a3, SparseGradient b3, double a4, SparseGradient b4)
- Specified by:
linearCombination
in interfaceRealFieldElement<SparseGradient>
-
equals
public boolean equals(Object other)
Test for the equality of two sparse gradients.Sparse gradients are considered equal if they have the same value and the same derivatives.
-
-