Class SparseGradient
- All Implemented Interfaces:
Serializable,FieldElement<SparseGradient>,RealFieldElement<SparseGradient>
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 than
DerivativeStructure and use less memory.
- Since:
- 3.3
- See Also:
-
Method Summary
Modifier and TypeMethodDescriptionabs()absolute value.acos()Arc cosine operation.acosh()Inverse hyperbolic cosine operation.add(double c) '+' operator.Compute this + a.voidAdd in place.asin()Arc sine operation.asinh()Inverse hyperbolic sine operation.atan()Arc tangent operation.Two arguments arc tangent operation.static SparseGradientTwo arguments arc tangent operation.atanh()Inverse hyperbolic tangent operation.cbrt()Cubic root.ceil()Get the smallest whole number larger than instance.compose(double f0, double f1) Compute composition of the instance by a univariate function.copySign(double sign) Returns the instance with the sign of the argument.copySign(SparseGradient sign) Returns the instance with the sign of the argument.cos()Cosine operation.cosh()Hyperbolic cosine operation.static SparseGradientcreateConstant(double value) Factory method creating a constant.static SparseGradientcreateVariable(int idx, double value) Factory method creating an independent variable.divide(double c) '÷' operator.Compute this ÷ a.booleanTest for the equality of two sparse gradients.exp()Exponential.expm1()Exponential minus 1.floor()Get the largest whole number smaller than instance.doublegetDerivative(int index) Get the derivative with respect to a particular index variable.getField()Get theFieldto which the instance belongs.doublegetReal()Get the real value of the number.doublegetValue()Get the value of the function.inthashCode()Get a hashCode for the derivative structure.Returns the hypotenuse of a triangle with sidesthisandy- sqrt(this2 +y2) avoiding intermediate overflow or underflow.static SparseGradientReturns the hypotenuse of a triangle with sidesxandy- sqrt(x2 +y2) avoiding intermediate overflow or underflow.linearCombination(double[] a, SparseGradient[] b) Compute a linear combination.linearCombination(double a1, SparseGradient b1, double a2, SparseGradient b2) Compute a linear combination.linearCombination(double a1, SparseGradient b1, double a2, SparseGradient b2, double a3, SparseGradient b3) Compute a linear combination.linearCombination(double a1, SparseGradient b1, double a2, SparseGradient b2, double a3, SparseGradient b3, double a4, SparseGradient b4) Compute a linear combination.linearCombination(SparseGradient[] a, SparseGradient[] b) Compute a linear combination.linearCombination(SparseGradient a1, SparseGradient b1, SparseGradient a2, SparseGradient b2) Compute a linear combination.linearCombination(SparseGradient a1, SparseGradient b1, SparseGradient a2, SparseGradient b2, SparseGradient a3, SparseGradient b3) Compute a linear combination.linearCombination(SparseGradient a1, SparseGradient b1, SparseGradient a2, SparseGradient b2, SparseGradient a3, SparseGradient b3, SparseGradient a4, SparseGradient b4) Compute a linear combination.log()Natural logarithm.log10()Base 10 logarithm.log1p()Shifted natural logarithm.multiply(double c) '×' operator.multiply(int n) Compute n × this.Compute this × a.voidMultiply in place.negate()Returns the additive inverse ofthiselement.intnumVars()Find the number of variables.pow(double p) Power operation.static SparseGradientpow(double a, SparseGradient x) Compute ax where a is a double and x aSparseGradientpow(int n) Integer power operation.Power operation.Returns the multiplicative inverse ofthiselement.remainder(double a) IEEE remainder operator.IEEE remainder operator.rint()Get the whole number that is the nearest to the instance, or the even one if x is exactly half way between two integers.rootN(int n) Nth root.longround()Get the closest long to instance value.scalb(int n) Multiply the instance by a power of 2.signum()Compute the signum of the instance.sin()Sine operation.sinh()Hyperbolic sine operation.sqrt()Square root.subtract(double c) '-' operator.Compute this - a.tan()Tangent operation.tanh()Hyperbolic tangent operation.doubletaylor(double... delta) Evaluate Taylor expansion of a sparse gradient.Convert radians to degrees, with error of less than 0.5 ULPConvert degrees to radians, with error of less than 0.5 ULP
-
Method Details
-
createConstant
Factory method creating a constant.- Parameters:
value- value of the constant- Returns:
- a new instance
-
createVariable
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()Get the real value of the number.- Specified by:
getRealin interfaceRealFieldElement<SparseGradient>- Returns:
- real value
-
add
Compute this + a.- Specified by:
addin interfaceFieldElement<SparseGradient>- Parameters:
a- element to add- Returns:
- a new element representing this + a
-
addInPlace
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
'+' operator.- Specified by:
addin interfaceRealFieldElement<SparseGradient>- Parameters:
c- right hand side parameter of the operator- Returns:
- this+a
-
subtract
Compute this - a.- Specified by:
subtractin interfaceFieldElement<SparseGradient>- Parameters:
a- element to subtract- Returns:
- a new element representing this - a
-
subtract
'-' operator.- Specified by:
subtractin interfaceRealFieldElement<SparseGradient>- Parameters:
c- right hand side parameter of the operator- Returns:
- this-a
-
multiply
Compute this × a.- Specified by:
multiplyin interfaceFieldElement<SparseGradient>- Parameters:
a- element to multiply- Returns:
- a new element representing this × a
-
multiplyInPlace
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
'×' operator.- Specified by:
multiplyin interfaceRealFieldElement<SparseGradient>- Parameters:
c- right hand side parameter of the operator- Returns:
- this×a
-
multiply
Compute n × this. Multiplication by an integer number is defined as the following sumn × this = ∑i=1n this. - Specified by:
multiplyin interfaceFieldElement<SparseGradient>- Parameters:
n- Number of timesthismust be added to itself.- Returns:
- A new element representing n × this.
-
divide
Compute this ÷ a.- Specified by:
dividein interfaceFieldElement<SparseGradient>- Parameters:
a- element to divide by- Returns:
- a new element representing this ÷ a
-
divide
'÷' operator.- Specified by:
dividein interfaceRealFieldElement<SparseGradient>- Parameters:
c- right hand side parameter of the operator- Returns:
- this÷a
-
negate
Returns the additive inverse ofthiselement.- Specified by:
negatein interfaceFieldElement<SparseGradient>- Returns:
- the opposite of
this.
-
getField
Get theFieldto which the instance belongs.- Specified by:
getFieldin interfaceFieldElement<SparseGradient>- Returns:
Fieldto which the instance belongs
-
remainder
IEEE remainder operator.- Specified by:
remainderin interfaceRealFieldElement<SparseGradient>- Parameters:
a- right hand side parameter of the operator- Returns:
- this - n × a where n is the closest integer to this/a (the even integer is chosen for n if this/a is halfway between two integers)
-
remainder
IEEE remainder operator.- Specified by:
remainderin interfaceRealFieldElement<SparseGradient>- Parameters:
a- right hand side parameter of the operator- Returns:
- this - n × a where n is the closest integer to this/a (the even integer is chosen for n if this/a is halfway between two integers)
-
abs
absolute value.- Specified by:
absin interfaceRealFieldElement<SparseGradient>- Returns:
- abs(this)
-
ceil
Get the smallest whole number larger than instance.- Specified by:
ceilin interfaceRealFieldElement<SparseGradient>- Returns:
- ceil(this)
-
floor
Get the largest whole number smaller than instance.- Specified by:
floorin interfaceRealFieldElement<SparseGradient>- Returns:
- floor(this)
-
rint
Get the whole number that is the nearest to the instance, or the even one if x is exactly half way between two integers.- Specified by:
rintin interfaceRealFieldElement<SparseGradient>- Returns:
- a double number r such that r is an integer r - 0.5 ≤ this ≤ r + 0.5
-
round
public long round()Get the closest long to instance value.- Specified by:
roundin interfaceRealFieldElement<SparseGradient>- Returns:
- closest long to
RealFieldElement.getReal()
-
signum
Compute the signum of the instance. The signum is -1 for negative numbers, +1 for positive numbers and 0 otherwise- Specified by:
signumin interfaceRealFieldElement<SparseGradient>- Returns:
- -1.0, -0.0, +0.0, +1.0 or NaN depending on sign of a
-
copySign
Returns the instance with the sign of the argument. A NaNsignargument is treated as positive.- Specified by:
copySignin interfaceRealFieldElement<SparseGradient>- Parameters:
sign- the sign for the returned value- Returns:
- the instance with the same sign as the
signargument
-
copySign
Returns the instance with the sign of the argument. A NaNsignargument is treated as positive.- Specified by:
copySignin interfaceRealFieldElement<SparseGradient>- Parameters:
sign- the sign for the returned value- Returns:
- the instance with the same sign as the
signargument
-
scalb
Multiply the instance by a power of 2.- Specified by:
scalbin interfaceRealFieldElement<SparseGradient>- Parameters:
n- power of 2- Returns:
- this × 2n
-
hypot
Returns the hypotenuse of a triangle with sidesthisandy- sqrt(this2 +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.
- Specified by:
hypotin interfaceRealFieldElement<SparseGradient>- Parameters:
y- a value- Returns:
- sqrt(this2 +y2)
-
hypot
Returns the hypotenuse of a triangle with sidesxandy- 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
Returns the multiplicative inverse ofthiselement.- Specified by:
reciprocalin interfaceFieldElement<SparseGradient>- Specified by:
reciprocalin interfaceRealFieldElement<SparseGradient>- Returns:
- the inverse of
this.
-
sqrt
Square root.- Specified by:
sqrtin interfaceRealFieldElement<SparseGradient>- Returns:
- square root of the instance
-
cbrt
Cubic root.- Specified by:
cbrtin interfaceRealFieldElement<SparseGradient>- Returns:
- cubic root of the instance
-
rootN
Nth root.- Specified by:
rootNin interfaceRealFieldElement<SparseGradient>- Parameters:
n- order of the root- Returns:
- nth root of the instance
-
pow
Power operation.- Specified by:
powin interfaceRealFieldElement<SparseGradient>- Parameters:
p- power to apply- Returns:
- thisp
-
pow
Integer power operation.- Specified by:
powin interfaceRealFieldElement<SparseGradient>- Parameters:
n- power to apply- Returns:
- thisn
-
pow
Power operation.- Specified by:
powin interfaceRealFieldElement<SparseGradient>- Parameters:
e- exponent- Returns:
- thise
-
pow
Compute ax where a is a double and x aSparseGradient- Parameters:
a- number to exponentiatex- power to apply- Returns:
- ax
-
exp
Exponential.- Specified by:
expin interfaceRealFieldElement<SparseGradient>- Returns:
- exponential of the instance
-
expm1
Exponential minus 1.- Specified by:
expm1in interfaceRealFieldElement<SparseGradient>- Returns:
- exponential minus one of the instance
-
log
Natural logarithm.- Specified by:
login interfaceRealFieldElement<SparseGradient>- Returns:
- logarithm of the instance
-
log10
Base 10 logarithm.- Returns:
- base 10 logarithm of the instance
-
log1p
Shifted natural logarithm.- Specified by:
log1pin interfaceRealFieldElement<SparseGradient>- Returns:
- logarithm of one plus the instance
-
cos
Cosine operation.- Specified by:
cosin interfaceRealFieldElement<SparseGradient>- Returns:
- cos(this)
-
sin
Sine operation.- Specified by:
sinin interfaceRealFieldElement<SparseGradient>- Returns:
- sin(this)
-
tan
Tangent operation.- Specified by:
tanin interfaceRealFieldElement<SparseGradient>- Returns:
- tan(this)
-
acos
Arc cosine operation.- Specified by:
acosin interfaceRealFieldElement<SparseGradient>- Returns:
- acos(this)
-
asin
Arc sine operation.- Specified by:
asinin interfaceRealFieldElement<SparseGradient>- Returns:
- asin(this)
-
atan
Arc tangent operation.- Specified by:
atanin interfaceRealFieldElement<SparseGradient>- Returns:
- atan(this)
-
atan2
Two arguments arc tangent operation.- Specified by:
atan2in interfaceRealFieldElement<SparseGradient>- Parameters:
x- second argument of the arc tangent- Returns:
- atan2(this, x)
-
atan2
Two arguments arc tangent operation.- Parameters:
y- first argument of the arc tangentx- second argument of the arc tangent- Returns:
- atan2(y, x)
-
cosh
Hyperbolic cosine operation.- Specified by:
coshin interfaceRealFieldElement<SparseGradient>- Returns:
- cosh(this)
-
sinh
Hyperbolic sine operation.- Specified by:
sinhin interfaceRealFieldElement<SparseGradient>- Returns:
- sinh(this)
-
tanh
Hyperbolic tangent operation.- Specified by:
tanhin interfaceRealFieldElement<SparseGradient>- Returns:
- tanh(this)
-
acosh
Inverse hyperbolic cosine operation.- Specified by:
acoshin interfaceRealFieldElement<SparseGradient>- Returns:
- acosh(this)
-
asinh
Inverse hyperbolic sine operation.- Specified by:
asinhin interfaceRealFieldElement<SparseGradient>- Returns:
- asin(this)
-
atanh
Inverse hyperbolic tangent operation.- Specified by:
atanhin interfaceRealFieldElement<SparseGradient>- Returns:
- atanh(this)
-
toDegrees
Convert radians to degrees, with error of less than 0.5 ULP- Returns:
- instance converted into degrees
-
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
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) throws DimensionMismatchException Compute a linear combination.- Specified by:
linearCombinationin interfaceRealFieldElement<SparseGradient>- Parameters:
a- Factors.b- Factors.- Returns:
Σi ai bi.- Throws:
DimensionMismatchException- if arrays dimensions don't match
-
linearCombination
Compute a linear combination.- Specified by:
linearCombinationin interfaceRealFieldElement<SparseGradient>- Parameters:
a- Factors.b- Factors.- Returns:
Σi ai bi.
-
linearCombination
public SparseGradient linearCombination(SparseGradient a1, SparseGradient b1, SparseGradient a2, SparseGradient b2) Compute a linear combination.- Specified by:
linearCombinationin interfaceRealFieldElement<SparseGradient>- Parameters:
a1- first factor of the first termb1- second factor of the first terma2- first factor of the second termb2- second factor of the second term- Returns:
- a1×b1 + a2×b2
- See Also:
-
linearCombination
Compute a linear combination.- Specified by:
linearCombinationin interfaceRealFieldElement<SparseGradient>- Parameters:
a1- first factor of the first termb1- second factor of the first terma2- first factor of the second termb2- second factor of the second term- Returns:
- a1×b1 + a2×b2
- See Also:
-
linearCombination
public SparseGradient linearCombination(SparseGradient a1, SparseGradient b1, SparseGradient a2, SparseGradient b2, SparseGradient a3, SparseGradient b3) Compute a linear combination.- Specified by:
linearCombinationin interfaceRealFieldElement<SparseGradient>- Parameters:
a1- first factor of the first termb1- second factor of the first terma2- first factor of the second termb2- second factor of the second terma3- first factor of the third termb3- second factor of the third term- Returns:
- a1×b1 + a2×b2 + a3×b3
- See Also:
-
linearCombination
public SparseGradient linearCombination(double a1, SparseGradient b1, double a2, SparseGradient b2, double a3, SparseGradient b3) Compute a linear combination.- Specified by:
linearCombinationin interfaceRealFieldElement<SparseGradient>- Parameters:
a1- first factor of the first termb1- second factor of the first terma2- first factor of the second termb2- second factor of the second terma3- first factor of the third termb3- second factor of the third term- Returns:
- a1×b1 + a2×b2 + a3×b3
- See Also:
-
linearCombination
public SparseGradient linearCombination(SparseGradient a1, SparseGradient b1, SparseGradient a2, SparseGradient b2, SparseGradient a3, SparseGradient b3, SparseGradient a4, SparseGradient b4) Compute a linear combination.- Specified by:
linearCombinationin interfaceRealFieldElement<SparseGradient>- Parameters:
a1- first factor of the first termb1- second factor of the first terma2- first factor of the second termb2- second factor of the second terma3- first factor of the third termb3- second factor of the third terma4- first factor of the third termb4- second factor of the third term- Returns:
- a1×b1 + a2×b2 + a3×b3 + a4×b4
- See Also:
-
linearCombination
public SparseGradient linearCombination(double a1, SparseGradient b1, double a2, SparseGradient b2, double a3, SparseGradient b3, double a4, SparseGradient b4) Compute a linear combination.- Specified by:
linearCombinationin interfaceRealFieldElement<SparseGradient>- Parameters:
a1- first factor of the first termb1- second factor of the first terma2- first factor of the second termb2- second factor of the second terma3- first factor of the third termb3- second factor of the third terma4- first factor of the third termb4- second factor of the third term- Returns:
- a1×b1 + a2×b2 + a3×b3 + a4×b4
- See Also:
-
equals
Test for the equality of two sparse gradients.Sparse gradients are considered equal if they have the same value and the same derivatives.
-
hashCode
public int hashCode()Get a hashCode for the derivative structure.
-