public class SparseGradient extends Object implements CalculusFieldElement<SparseGradient>, Serializable
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.
Modifier and Type | Method and Description |
---|---|
SparseGradient |
abs()
absolute value.
|
SparseGradient |
acos()
Arc cosine operation.
|
SparseGradient |
acosh()
Inverse hyperbolic cosine operation.
|
SparseGradient |
add(double c)
'+' operator.
|
SparseGradient |
add(SparseGradient a)
Compute this + a.
|
void |
addInPlace(SparseGradient a)
Add in place.
|
SparseGradient |
asin()
Arc sine operation.
|
SparseGradient |
asinh()
Inverse hyperbolic sine operation.
|
SparseGradient |
atan()
Arc tangent operation.
|
SparseGradient |
atan2(SparseGradient x)
Two arguments arc tangent operation.
|
static SparseGradient |
atan2(SparseGradient y,
SparseGradient x)
Two arguments arc tangent operation.
|
SparseGradient |
atanh()
Inverse hyperbolic tangent operation.
|
SparseGradient |
cbrt()
Cubic root.
|
SparseGradient |
ceil()
Get the smallest whole number larger than instance.
|
SparseGradient |
compose(double... f)
Compute composition of the instance by a univariate function.
|
SparseGradient |
copySign(double sign)
Returns the instance with the sign of the argument.
|
SparseGradient |
copySign(SparseGradient sign)
Returns the instance with the sign of the argument.
|
SparseGradient |
cos()
Cosine operation.
|
SparseGradient |
cosh()
Hyperbolic cosine operation.
|
static SparseGradient |
createConstant(double value)
Factory method creating a constant.
|
static SparseGradient |
createVariable(int idx,
double value)
Factory method creating an independent variable.
|
SparseGradient |
divide(double c)
'÷' operator.
|
SparseGradient |
divide(SparseGradient a)
Compute this ÷ a.
|
boolean |
equals(Object other)
Test for the equality of two sparse gradients.
|
SparseGradient |
exp()
Exponential.
|
SparseGradient |
expm1()
Exponential minus 1.
|
SparseGradient |
floor()
Get the largest whole number smaller than instance.
|
double |
getDerivative(int index)
Get the derivative with respect to a particular index variable.
|
Field<SparseGradient> |
getField()
Get the
Field to which the instance belongs. |
SparseGradient |
getPi()
Get the Archimedes constant π.
|
double |
getReal()
Get the real value of the number.
|
double |
getValue()
Get the value of the function.
|
int |
hashCode()
Get a hashCode for the derivative structure.
|
SparseGradient |
hypot(SparseGradient y)
Returns the hypotenuse of a triangle with sides
this and y
- sqrt(this2 +y2)
avoiding intermediate overflow or underflow. |
static SparseGradient |
hypot(SparseGradient x,
SparseGradient y)
Returns the hypotenuse of a triangle with sides
x and y
- sqrt(x2 +y2)
avoiding intermediate overflow or underflow. |
SparseGradient |
linearCombination(double[] a,
SparseGradient[] b)
Compute a linear combination.
|
SparseGradient |
linearCombination(double a1,
SparseGradient b1,
double a2,
SparseGradient b2)
Compute a linear combination.
|
SparseGradient |
linearCombination(double a1,
SparseGradient b1,
double a2,
SparseGradient b2,
double a3,
SparseGradient b3)
Compute a linear combination.
|
SparseGradient |
linearCombination(double a1,
SparseGradient b1,
double a2,
SparseGradient b2,
double a3,
SparseGradient b3,
double a4,
SparseGradient b4)
Compute a linear combination.
|
SparseGradient |
linearCombination(SparseGradient[] a,
SparseGradient[] b)
Compute a linear combination.
|
SparseGradient |
linearCombination(SparseGradient a1,
SparseGradient b1,
SparseGradient a2,
SparseGradient b2)
Compute a linear combination.
|
SparseGradient |
linearCombination(SparseGradient a1,
SparseGradient b1,
SparseGradient a2,
SparseGradient b2,
SparseGradient a3,
SparseGradient b3)
Compute a linear combination.
|
SparseGradient |
linearCombination(SparseGradient a1,
SparseGradient b1,
SparseGradient a2,
SparseGradient b2,
SparseGradient a3,
SparseGradient b3,
SparseGradient a4,
SparseGradient b4)
Compute a linear combination.
|
SparseGradient |
log()
Natural logarithm.
|
SparseGradient |
log10()
Base 10 logarithm.
|
SparseGradient |
log1p()
Shifted natural logarithm.
|
SparseGradient |
multiply(double c)
'×' operator.
|
SparseGradient |
multiply(int n)
Compute n × this.
|
SparseGradient |
multiply(SparseGradient a)
Compute this × a.
|
void |
multiplyInPlace(SparseGradient a)
Multiply in place.
|
SparseGradient |
negate()
Returns the additive inverse of
this element. |
SparseGradient |
newInstance(double v)
Create an instance corresponding to a constant real value.
|
int |
numVars()
Find the number of variables.
|
SparseGradient |
pow(double p)
Power operation.
|
static SparseGradient |
pow(double a,
SparseGradient x)
Compute ax where a is a double and x a
SparseGradient |
SparseGradient |
pow(int n)
Integer power operation.
|
SparseGradient |
pow(SparseGradient e)
Power operation.
|
SparseGradient |
reciprocal()
Returns the multiplicative inverse of
this element. |
SparseGradient |
remainder(double a)
IEEE remainder operator.
|
SparseGradient |
remainder(SparseGradient a)
IEEE remainder operator.
|
SparseGradient |
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.
|
SparseGradient |
rootN(int n)
Nth root.
|
SparseGradient |
scalb(int n)
Multiply the instance by a power of 2.
|
SparseGradient |
sign()
Compute the sign of the instance.
|
SparseGradient |
sin()
Sine operation.
|
FieldSinCos<SparseGradient> |
sinCos()
Combined Sine and Cosine operation.
|
SparseGradient |
sinh()
Hyperbolic sine operation.
|
FieldSinhCosh<SparseGradient> |
sinhCosh()
Combined hyperbolic sine and sosine operation.
|
SparseGradient |
sqrt()
Square root.
|
SparseGradient |
subtract(double c)
'-' operator.
|
SparseGradient |
subtract(SparseGradient a)
Compute this - a.
|
SparseGradient |
tan()
Tangent operation.
|
SparseGradient |
tanh()
Hyperbolic tangent operation.
|
double |
taylor(double... delta)
Evaluate Taylor expansion of a sparse gradient.
|
SparseGradient |
toDegrees()
Convert radians to degrees, with error of less than 0.5 ULP
|
SparseGradient |
toRadians()
Convert degrees to radians, with error of less than 0.5 ULP
|
SparseGradient |
ulp()
Compute least significant bit (Unit in Last Position) for a number.
|
clone, finalize, getClass, notify, notifyAll, toString, wait, wait, wait
getExponent, isFinite, isInfinite, isNaN, norm, round
isZero
public SparseGradient newInstance(double v)
newInstance
in interface CalculusFieldElement<SparseGradient>
v
- constant real valuepublic static SparseGradient createConstant(double value)
value
- value of the constantpublic static SparseGradient createVariable(int idx, double value)
idx
- index of the variablevalue
- value of the variablepublic int numVars()
public double getDerivative(int index)
index
- index to differentiate with.public double getValue()
public double getReal()
getReal
in interface FieldElement<SparseGradient>
public SparseGradient add(SparseGradient a)
add
in interface FieldElement<SparseGradient>
a
- element to addpublic void addInPlace(SparseGradient a)
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.
a
- instance to addpublic SparseGradient add(double c)
add
in interface CalculusFieldElement<SparseGradient>
c
- right hand side parameter of the operatorpublic SparseGradient subtract(SparseGradient a)
subtract
in interface FieldElement<SparseGradient>
a
- element to subtractpublic SparseGradient subtract(double c)
subtract
in interface CalculusFieldElement<SparseGradient>
c
- right hand side parameter of the operatorpublic SparseGradient multiply(SparseGradient a)
multiply
in interface FieldElement<SparseGradient>
a
- element to multiplypublic void multiplyInPlace(SparseGradient a)
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.
a
- instance to multiplypublic SparseGradient multiply(double c)
multiply
in interface CalculusFieldElement<SparseGradient>
c
- right hand side parameter of the operatorpublic SparseGradient multiply(int n)
multiply
in interface FieldElement<SparseGradient>
n
- Number of times this
must be added to itself.public SparseGradient divide(SparseGradient a)
divide
in interface FieldElement<SparseGradient>
a
- element to divide bypublic SparseGradient divide(double c)
divide
in interface CalculusFieldElement<SparseGradient>
c
- right hand side parameter of the operatorpublic SparseGradient negate()
this
element.negate
in interface FieldElement<SparseGradient>
this
.public Field<SparseGradient> getField()
Field
to which the instance belongs.getField
in interface FieldElement<SparseGradient>
Field
to which the instance belongspublic SparseGradient remainder(double a)
remainder
in interface CalculusFieldElement<SparseGradient>
a
- right hand side parameter of the operatorpublic SparseGradient remainder(SparseGradient a)
remainder
in interface CalculusFieldElement<SparseGradient>
a
- right hand side parameter of the operatorpublic SparseGradient abs()
Just another name for CalculusFieldElement.norm()
abs
in interface CalculusFieldElement<SparseGradient>
public SparseGradient ceil()
ceil
in interface CalculusFieldElement<SparseGradient>
public SparseGradient floor()
floor
in interface CalculusFieldElement<SparseGradient>
public SparseGradient rint()
rint
in interface CalculusFieldElement<SparseGradient>
public SparseGradient sign()
sign
in interface CalculusFieldElement<SparseGradient>
public SparseGradient copySign(SparseGradient sign)
sign
argument is treated as positive.copySign
in interface CalculusFieldElement<SparseGradient>
sign
- the sign for the returned valuesign
argumentpublic SparseGradient copySign(double sign)
sign
argument is treated as positive.copySign
in interface CalculusFieldElement<SparseGradient>
sign
- the sign for the returned valuesign
argumentpublic SparseGradient scalb(int n)
scalb
in interface CalculusFieldElement<SparseGradient>
n
- power of 2public SparseGradient ulp()
The ulp
function is a step function, hence all its derivatives are 0.
ulp
in interface CalculusFieldElement<SparseGradient>
public SparseGradient hypot(SparseGradient y)
this
and y
- sqrt(this2 +y2)
avoiding intermediate overflow or underflow.
hypot
in interface CalculusFieldElement<SparseGradient>
y
- a valuepublic static SparseGradient hypot(SparseGradient x, SparseGradient y)
x
and y
- sqrt(x2 +y2)
avoiding intermediate overflow or underflow.
x
- a valuey
- a valuepublic SparseGradient reciprocal()
this
element.reciprocal
in interface CalculusFieldElement<SparseGradient>
reciprocal
in interface FieldElement<SparseGradient>
this
.public SparseGradient sqrt()
sqrt
in interface CalculusFieldElement<SparseGradient>
public SparseGradient cbrt()
cbrt
in interface CalculusFieldElement<SparseGradient>
public SparseGradient rootN(int n)
rootN
in interface CalculusFieldElement<SparseGradient>
n
- order of the rootpublic SparseGradient pow(double p)
pow
in interface CalculusFieldElement<SparseGradient>
p
- power to applypublic SparseGradient pow(int n)
pow
in interface CalculusFieldElement<SparseGradient>
n
- power to applypublic SparseGradient pow(SparseGradient e)
pow
in interface CalculusFieldElement<SparseGradient>
e
- exponentpublic static SparseGradient pow(double a, SparseGradient x)
SparseGradient
a
- number to exponentiatex
- power to applypublic SparseGradient exp()
exp
in interface CalculusFieldElement<SparseGradient>
public SparseGradient expm1()
expm1
in interface CalculusFieldElement<SparseGradient>
public SparseGradient log()
log
in interface CalculusFieldElement<SparseGradient>
public SparseGradient log10()
log10
in interface CalculusFieldElement<SparseGradient>
public SparseGradient log1p()
log1p
in interface CalculusFieldElement<SparseGradient>
public SparseGradient cos()
cos
in interface CalculusFieldElement<SparseGradient>
public SparseGradient sin()
sin
in interface CalculusFieldElement<SparseGradient>
public FieldSinCos<SparseGradient> sinCos()
sinCos
in interface CalculusFieldElement<SparseGradient>
public SparseGradient tan()
tan
in interface CalculusFieldElement<SparseGradient>
public SparseGradient acos()
acos
in interface CalculusFieldElement<SparseGradient>
public SparseGradient asin()
asin
in interface CalculusFieldElement<SparseGradient>
public SparseGradient atan()
atan
in interface CalculusFieldElement<SparseGradient>
public SparseGradient atan2(SparseGradient x)
Beware of the order or arguments! As this is based on a
two-arguments functions, in order to be consistent with
arguments order, the instance is the first argument
and the single provided argument is the second argument.
In order to be consistent with programming languages atan2
,
this method computes atan2(this, x)
, i.e. the instance
represents the y
argument and the x
argument is
the one passed as a single argument. This may seem confusing especially
for users of Wolfram alpha, as this site is not consistent
with programming languages atan2
two-arguments arc tangent
and puts x
as its first argument.
atan2
in interface CalculusFieldElement<SparseGradient>
x
- second argument of the arc tangentpublic static SparseGradient atan2(SparseGradient y, SparseGradient x)
y
- first argument of the arc tangentx
- second argument of the arc tangentpublic SparseGradient cosh()
cosh
in interface CalculusFieldElement<SparseGradient>
public SparseGradient sinh()
sinh
in interface CalculusFieldElement<SparseGradient>
public FieldSinhCosh<SparseGradient> sinhCosh()
sinhCosh
in interface CalculusFieldElement<SparseGradient>
public SparseGradient tanh()
tanh
in interface CalculusFieldElement<SparseGradient>
public SparseGradient acosh()
acosh
in interface CalculusFieldElement<SparseGradient>
public SparseGradient asinh()
asinh
in interface CalculusFieldElement<SparseGradient>
public SparseGradient atanh()
atanh
in interface CalculusFieldElement<SparseGradient>
public SparseGradient toDegrees()
toDegrees
in interface CalculusFieldElement<SparseGradient>
public SparseGradient toRadians()
toRadians
in interface CalculusFieldElement<SparseGradient>
public double taylor(double... delta)
delta
- parameters offsets (Δx, Δy, ...)public SparseGradient compose(double... f)
f
- array of value and derivatives of the function at
the current point (i.e. [f(getValue()
),
f'(getValue()
), f''(getValue()
)...]).MathIllegalArgumentException
- if the number of elements
in the array is not equal to 2 (i.e. value and first derivative)public SparseGradient linearCombination(SparseGradient[] a, SparseGradient[] b) throws MathIllegalArgumentException
linearCombination
in interface CalculusFieldElement<SparseGradient>
a
- Factors.b
- Factors.Σi ai bi
.MathIllegalArgumentException
- if arrays dimensions don't matchpublic SparseGradient linearCombination(double[] a, SparseGradient[] b)
linearCombination
in interface CalculusFieldElement<SparseGradient>
a
- Factors.b
- Factors.Σi ai bi
.public SparseGradient linearCombination(SparseGradient a1, SparseGradient b1, SparseGradient a2, SparseGradient b2)
linearCombination
in interface CalculusFieldElement<SparseGradient>
a1
- first factor of the first termb1
- second factor of the first terma2
- first factor of the second termb2
- second factor of the second termCalculusFieldElement.linearCombination(FieldElement, FieldElement, FieldElement, FieldElement, FieldElement, FieldElement)
,
CalculusFieldElement.linearCombination(FieldElement, FieldElement, FieldElement, FieldElement, FieldElement, FieldElement, FieldElement, FieldElement)
public SparseGradient linearCombination(double a1, SparseGradient b1, double a2, SparseGradient b2)
linearCombination
in interface CalculusFieldElement<SparseGradient>
a1
- first factor of the first termb1
- second factor of the first terma2
- first factor of the second termb2
- second factor of the second termCalculusFieldElement.linearCombination(double, FieldElement, double, FieldElement, double, FieldElement)
,
CalculusFieldElement.linearCombination(double, FieldElement, double, FieldElement, double, FieldElement, double, FieldElement)
public SparseGradient linearCombination(SparseGradient a1, SparseGradient b1, SparseGradient a2, SparseGradient b2, SparseGradient a3, SparseGradient b3)
linearCombination
in interface CalculusFieldElement<SparseGradient>
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 termCalculusFieldElement.linearCombination(FieldElement, FieldElement, FieldElement, FieldElement)
,
CalculusFieldElement.linearCombination(FieldElement, FieldElement, FieldElement, FieldElement, FieldElement, FieldElement, FieldElement, FieldElement)
public SparseGradient linearCombination(double a1, SparseGradient b1, double a2, SparseGradient b2, double a3, SparseGradient b3)
linearCombination
in interface CalculusFieldElement<SparseGradient>
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 termCalculusFieldElement.linearCombination(double, FieldElement, double, FieldElement)
,
CalculusFieldElement.linearCombination(double, FieldElement, double, FieldElement, double, FieldElement, double, FieldElement)
public SparseGradient linearCombination(SparseGradient a1, SparseGradient b1, SparseGradient a2, SparseGradient b2, SparseGradient a3, SparseGradient b3, SparseGradient a4, SparseGradient b4)
linearCombination
in interface CalculusFieldElement<SparseGradient>
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 fourth termb4
- second factor of the fourth termCalculusFieldElement.linearCombination(FieldElement, FieldElement, FieldElement, FieldElement)
,
CalculusFieldElement.linearCombination(FieldElement, FieldElement, FieldElement, FieldElement, FieldElement, FieldElement)
public SparseGradient linearCombination(double a1, SparseGradient b1, double a2, SparseGradient b2, double a3, SparseGradient b3, double a4, SparseGradient b4)
linearCombination
in interface CalculusFieldElement<SparseGradient>
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 fourth termb4
- second factor of the fourth termCalculusFieldElement.linearCombination(double, FieldElement, double, FieldElement)
,
CalculusFieldElement.linearCombination(double, FieldElement, double, FieldElement, double, FieldElement)
public SparseGradient getPi()
Archimedes constant is the ratio of a circle's circumference to its diameter.
getPi
in interface CalculusFieldElement<SparseGradient>
public boolean equals(Object other)
Sparse gradients are considered equal if they have the same value and the same derivatives.
Copyright © 2016-2022 CS GROUP. All rights reserved.