public class SparseGradient extends Object implements RealFieldElement<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 f0,
double f1)
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. |
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. |
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.
|
long |
round()
Get the closest long to instance value.
|
SparseGradient |
scalb(int n)
Multiply the instance by a power of 2.
|
SparseGradient |
signum()
Compute the signum of the instance.
|
SparseGradient |
sin()
Sine operation.
|
SparseGradient |
sinh()
Hyperbolic sine 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
|
public 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 RealFieldElement<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 RealFieldElement<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 RealFieldElement<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 RealFieldElement<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 RealFieldElement<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 RealFieldElement<SparseGradient>
a
- right hand side parameter of the operatorpublic SparseGradient remainder(SparseGradient a)
remainder
in interface RealFieldElement<SparseGradient>
a
- right hand side parameter of the operatorpublic SparseGradient abs()
abs
in interface RealFieldElement<SparseGradient>
public SparseGradient ceil()
ceil
in interface RealFieldElement<SparseGradient>
public SparseGradient floor()
floor
in interface RealFieldElement<SparseGradient>
public SparseGradient rint()
rint
in interface RealFieldElement<SparseGradient>
public long round()
round
in interface RealFieldElement<SparseGradient>
RealFieldElement.getReal()
public SparseGradient signum()
signum
in interface RealFieldElement<SparseGradient>
public SparseGradient copySign(SparseGradient sign)
sign
argument is treated as positive.copySign
in interface RealFieldElement<SparseGradient>
sign
- the sign for the returned valuesign
argumentpublic SparseGradient copySign(double sign)
sign
argument is treated as positive.copySign
in interface RealFieldElement<SparseGradient>
sign
- the sign for the returned valuesign
argumentpublic SparseGradient scalb(int n)
scalb
in interface RealFieldElement<SparseGradient>
n
- power of 2public SparseGradient hypot(SparseGradient y)
this
and y
- sqrt(this2 +y2)
avoiding intermediate overflow or underflow.
hypot
in interface RealFieldElement<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 FieldElement<SparseGradient>
reciprocal
in interface RealFieldElement<SparseGradient>
this
.public SparseGradient sqrt()
sqrt
in interface RealFieldElement<SparseGradient>
public SparseGradient cbrt()
cbrt
in interface RealFieldElement<SparseGradient>
public SparseGradient rootN(int n)
rootN
in interface RealFieldElement<SparseGradient>
n
- order of the rootpublic SparseGradient pow(double p)
pow
in interface RealFieldElement<SparseGradient>
p
- power to applypublic SparseGradient pow(int n)
pow
in interface RealFieldElement<SparseGradient>
n
- power to applypublic SparseGradient pow(SparseGradient e)
pow
in interface RealFieldElement<SparseGradient>
e
- exponentpublic static SparseGradient pow(double a, SparseGradient x)
SparseGradient
a
- number to exponentiatex
- power to applypublic SparseGradient exp()
exp
in interface RealFieldElement<SparseGradient>
public SparseGradient expm1()
expm1
in interface RealFieldElement<SparseGradient>
public SparseGradient log()
log
in interface RealFieldElement<SparseGradient>
public SparseGradient log10()
public SparseGradient log1p()
log1p
in interface RealFieldElement<SparseGradient>
public SparseGradient cos()
cos
in interface RealFieldElement<SparseGradient>
public SparseGradient sin()
sin
in interface RealFieldElement<SparseGradient>
public SparseGradient tan()
tan
in interface RealFieldElement<SparseGradient>
public SparseGradient acos()
acos
in interface RealFieldElement<SparseGradient>
public SparseGradient asin()
asin
in interface RealFieldElement<SparseGradient>
public SparseGradient atan()
atan
in interface RealFieldElement<SparseGradient>
public SparseGradient atan2(SparseGradient x)
atan2
in interface RealFieldElement<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 RealFieldElement<SparseGradient>
public SparseGradient sinh()
sinh
in interface RealFieldElement<SparseGradient>
public SparseGradient tanh()
tanh
in interface RealFieldElement<SparseGradient>
public SparseGradient acosh()
acosh
in interface RealFieldElement<SparseGradient>
public SparseGradient asinh()
asinh
in interface RealFieldElement<SparseGradient>
public SparseGradient atanh()
atanh
in interface RealFieldElement<SparseGradient>
public SparseGradient toDegrees()
public SparseGradient toRadians()
public double taylor(double... delta)
delta
- parameters offsets (Δx, Δy, ...)public SparseGradient compose(double f0, double f1)
f0
- value of the function at (i.e. f(getValue()
))f1
- first derivative of the function at
the current point (i.e. f'(getValue()
))public SparseGradient linearCombination(SparseGradient[] a, SparseGradient[] b) throws DimensionMismatchException
linearCombination
in interface RealFieldElement<SparseGradient>
a
- Factors.b
- Factors.Σi ai bi
.DimensionMismatchException
- if arrays dimensions don't matchpublic SparseGradient linearCombination(double[] a, SparseGradient[] b)
linearCombination
in interface RealFieldElement<SparseGradient>
a
- Factors.b
- Factors.Σi ai bi
.public SparseGradient linearCombination(SparseGradient a1, SparseGradient b1, SparseGradient a2, SparseGradient b2)
linearCombination
in interface RealFieldElement<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 termRealFieldElement.linearCombination(Object, Object, Object, Object, Object, Object)
,
RealFieldElement.linearCombination(Object, Object, Object, Object, Object, Object, Object, Object)
public SparseGradient linearCombination(double a1, SparseGradient b1, double a2, SparseGradient b2)
linearCombination
in interface RealFieldElement<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 termRealFieldElement.linearCombination(double, Object, double, Object, double, Object)
,
RealFieldElement.linearCombination(double, Object, double, Object, double, Object, double, Object)
public SparseGradient linearCombination(SparseGradient a1, SparseGradient b1, SparseGradient a2, SparseGradient b2, SparseGradient a3, SparseGradient b3)
linearCombination
in interface RealFieldElement<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 termRealFieldElement.linearCombination(Object, Object, Object, Object)
,
RealFieldElement.linearCombination(Object, Object, Object, Object, Object, Object, Object, Object)
public SparseGradient linearCombination(double a1, SparseGradient b1, double a2, SparseGradient b2, double a3, SparseGradient b3)
linearCombination
in interface RealFieldElement<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 termRealFieldElement.linearCombination(double, Object, double, Object)
,
RealFieldElement.linearCombination(double, Object, double, Object, double, Object, double, Object)
public SparseGradient linearCombination(SparseGradient a1, SparseGradient b1, SparseGradient a2, SparseGradient b2, SparseGradient a3, SparseGradient b3, SparseGradient a4, SparseGradient b4)
linearCombination
in interface RealFieldElement<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 third termb4
- second factor of the third termRealFieldElement.linearCombination(Object, Object, Object, Object)
,
RealFieldElement.linearCombination(Object, Object, Object, Object, Object, Object)
public SparseGradient linearCombination(double a1, SparseGradient b1, double a2, SparseGradient b2, double a3, SparseGradient b3, double a4, SparseGradient b4)
linearCombination
in interface RealFieldElement<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 third termb4
- second factor of the third termRealFieldElement.linearCombination(double, Object, double, Object)
,
RealFieldElement.linearCombination(double, Object, double, Object, double, Object)
public boolean equals(Object other)
Sparse gradients are considered equal if they have the same value and the same derivatives.
Copyright © 2003–2016 The Apache Software Foundation. All rights reserved.