Class SparseGradient
- java.lang.Object
-
- org.hipparchus.analysis.differentiation.SparseGradient
-
- All Implemented Interfaces:
Serializable
,Derivative<SparseGradient>
,Derivative1<SparseGradient>
,DifferentialAlgebra
,CalculusFieldElement<SparseGradient>
,FieldElement<SparseGradient>
public class SparseGradient extends Object implements Derivative1<SparseGradient>, Serializable
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.- See Also:
- Serialized Form
-
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description SparseGradient
abs()
absolute value.SparseGradient
add(SparseGradient a)
Compute this + a.void
addInPlace(SparseGradient a)
Add in place.SparseGradient
atan2(SparseGradient x)
Two arguments arc tangent operation.static SparseGradient
atan2(SparseGradient y, SparseGradient x)
Two arguments arc tangent operation.SparseGradient
compose(double... f)
Compute composition of the instance by a univariate function.SparseGradient
compose(double f0, double f1)
Compute composition of the instance by a univariate function differentiable at order 1.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.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
getAddendum()
Get the addendum to the real value of the number.double
getDerivative(int index)
Get the derivative with respect to a particular index variable.Field<SparseGradient>
getField()
Get theField
to which the instance belongs.int
getFreeParameters()
Get the number of free parameters.double
getPartialDerivative(int... orders)
Get a partial derivative.SparseGradient
getPi()
Get the Archimedes constant π.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 sidesthis
andy
- sqrt(this2 +y2) avoiding intermediate overflow or underflow.static SparseGradient
hypot(SparseGradient x, SparseGradient y)
Returns the hypotenuse of a triangle with sidesx
andy
- 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
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 ofthis
element.SparseGradient
newInstance(double v)
Create an instance corresponding to a constant real value.SparseGradient
pow(double p)
Power operation.static SparseGradient
pow(double a, SparseGradient x)
Compute ax where a is a double and x aSparseGradient
SparseGradient
pow(int n)
Integer power operation.SparseGradient
remainder(double a)
IEEE remainder operator.SparseGradient
remainder(SparseGradient a)
IEEE remainder operator.SparseGradient
scalb(int n)
Multiply the instance by a power of 2.SparseGradient
sqrt()
Square root.SparseGradient
subtract(SparseGradient a)
Compute this - a.double
taylor(double... delta)
Evaluate Taylor expansion of a sparse gradient.SparseGradient
toDegrees()
Convert radians to degrees, with error of less than 0.5 ULPSparseGradient
toRadians()
Convert degrees to radians, with error of less than 0.5 ULPSparseGradient
withValue(double v)
Create a new object with new value (zeroth-order derivative, as passed as input) and same derivatives of order one and above.-
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, toString, wait, wait, wait
-
Methods inherited from interface org.hipparchus.CalculusFieldElement
ceil, floor, isFinite, isInfinite, isNaN, norm, rint, round, sign, ulp
-
Methods inherited from interface org.hipparchus.analysis.differentiation.Derivative
add, getExponent, getReal, pow, subtract
-
Methods inherited from interface org.hipparchus.analysis.differentiation.Derivative1
acos, acosh, asin, asinh, atan, atanh, cbrt, cos, cosh, exp, expm1, getOrder, log, log10, log1p, reciprocal, rootN, sin, sinCos, sinh, sinhCosh, square, tan, tanh
-
Methods inherited from interface org.hipparchus.FieldElement
isZero
-
-
-
-
Method Detail
-
getFreeParameters
public int getFreeParameters()
Get the number of free parameters.- Specified by:
getFreeParameters
in interfaceDifferentialAlgebra
- Returns:
- number of free parameters
-
getPartialDerivative
public double getPartialDerivative(int... orders) throws MathIllegalArgumentException
Get a partial derivative.- Specified by:
getPartialDerivative
in interfaceDerivative<SparseGradient>
- Parameters:
orders
- derivation orders with respect to each variable (if all orders are 0, the value is returned)- Returns:
- partial derivative
- Throws:
MathIllegalArgumentException
- if the numbers of variables does not match the instance- See Also:
Derivative.getValue()
-
newInstance
public SparseGradient newInstance(double v)
Create an instance corresponding to a constant real value.- Specified by:
newInstance
in interfaceCalculusFieldElement<SparseGradient>
- Parameters:
v
- constant real value- Returns:
- instance corresponding to a constant real value
-
withValue
public SparseGradient withValue(double v)
Create a new object with new value (zeroth-order derivative, as passed as input) and same derivatives of order one and above.This default implementation is there so that no API gets broken by the next release, which is not a major one. Custom inheritors should probably overwrite it.
- Specified by:
withValue
in interfaceDerivative<SparseGradient>
- Parameters:
v
- zeroth-order derivative of new represented function- Returns:
- new object with changed value
-
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
-
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
-
getAddendum
public SparseGradient getAddendum()
Get the addendum to the real value of the number.The addendum is considered to be the part that when added back to the
real part
recovers the instance. This means that whene.getReal()
is finite (i.e. neither infinite nor NaN), thene.getAddendum().add(e.getReal())
ise
ande.subtract(e.getReal())
ise.getAddendum()
. Beware that for non-finite numbers, these two equalities may not hold. The first equality (with the addition), always holds even for infinity and NaNs if the real part is independent of the addendum (this is the case for all derivatives types, as well as for complex and Dfp, but it is not the case for Tuple and FieldTuple). The second equality (with the subtraction), generally doesn't hold for non-finite numbers, because the subtraction generates NaNs.- Specified by:
getAddendum
in interfaceCalculusFieldElement<SparseGradient>
- Returns:
- real value
-
getValue
public double getValue()
Get the value of the function.- Specified by:
getValue
in interfaceDerivative<SparseGradient>
- Returns:
- value of the function.
-
add
public SparseGradient add(SparseGradient a)
Compute this + a.- Specified by:
add
in interfaceFieldElement<SparseGradient>
- Parameters:
a
- element to add- Returns:
- a new element representing this + a
-
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
-
subtract
public SparseGradient subtract(SparseGradient a)
Compute this - a.- Specified by:
subtract
in interfaceCalculusFieldElement<SparseGradient>
- Specified by:
subtract
in interfaceFieldElement<SparseGradient>
- Parameters:
a
- element to subtract- Returns:
- a new element representing this - a
-
multiply
public SparseGradient multiply(SparseGradient a)
Compute this × a.- Specified by:
multiply
in interfaceFieldElement<SparseGradient>
- Parameters:
a
- element to multiply- Returns:
- a new element representing this × a
-
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)
'×' operator.- Specified by:
multiply
in interfaceCalculusFieldElement<SparseGradient>
- Parameters:
c
- right hand side parameter of the operator- Returns:
- this×a
-
multiply
public SparseGradient multiply(int n)
Compute n × this. Multiplication by an integer number is defined as the following sum \[ n \times \mathrm{this} = \sum_{i=1}^n \mathrm{this} \]- Specified by:
multiply
in interfaceCalculusFieldElement<SparseGradient>
- Specified by:
multiply
in interfaceFieldElement<SparseGradient>
- Parameters:
n
- Number of timesthis
must be added to itself.- Returns:
- A new element representing n × this.
-
divide
public SparseGradient divide(SparseGradient a)
Compute this ÷ a.- Specified by:
divide
in interfaceCalculusFieldElement<SparseGradient>
- Specified by:
divide
in interfaceFieldElement<SparseGradient>
- Parameters:
a
- element to divide by- Returns:
- a new element representing this ÷ a
-
divide
public SparseGradient divide(double c)
'÷' operator.- Specified by:
divide
in interfaceCalculusFieldElement<SparseGradient>
- Parameters:
c
- right hand side parameter of the operator- Returns:
- this÷a
-
negate
public SparseGradient negate()
Returns the additive inverse ofthis
element.- Specified by:
negate
in interfaceFieldElement<SparseGradient>
- Returns:
- the opposite of
this
.
-
getField
public Field<SparseGradient> getField()
Get theField
to which the instance belongs.- Specified by:
getField
in interfaceFieldElement<SparseGradient>
- Returns:
Field
to which the instance belongs
-
remainder
public SparseGradient remainder(double a)
IEEE remainder operator.- Specified by:
remainder
in interfaceCalculusFieldElement<SparseGradient>
- Specified by:
remainder
in interfaceDerivative<SparseGradient>
- Parameters:
a
- right hand side parameter of the operator- Returns:
- this - n × a where n is the closest integer to this/a
-
remainder
public SparseGradient remainder(SparseGradient a)
IEEE remainder operator.- Specified by:
remainder
in interfaceCalculusFieldElement<SparseGradient>
- Parameters:
a
- right hand side parameter of the operator- Returns:
- this - n × a where n is the closest integer to this/a
-
abs
public SparseGradient abs()
absolute value.- Specified by:
abs
in interfaceCalculusFieldElement<SparseGradient>
- Returns:
- abs(this)
-
copySign
public SparseGradient copySign(SparseGradient sign)
Returns the instance with the sign of the argument. A NaNsign
argument is treated as positive.- Specified by:
copySign
in interfaceCalculusFieldElement<SparseGradient>
- Parameters:
sign
- the sign for the returned value- Returns:
- the instance with the same sign as the
sign
argument
-
copySign
public SparseGradient copySign(double sign)
Returns the instance with the sign of the argument. A NaNsign
argument is treated as positive.- Specified by:
copySign
in interfaceCalculusFieldElement<SparseGradient>
- Parameters:
sign
- the sign for the returned value- Returns:
- the instance with the same sign as the
sign
argument
-
scalb
public SparseGradient scalb(int n)
Multiply the instance by a power of 2.- Specified by:
scalb
in interfaceCalculusFieldElement<SparseGradient>
- Parameters:
n
- power of 2- Returns:
- this × 2n
-
hypot
public SparseGradient hypot(SparseGradient y)
Returns the hypotenuse of a triangle with sidesthis
andy
- 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:
hypot
in interfaceCalculusFieldElement<SparseGradient>
- Parameters:
y
- a value- Returns:
- sqrt(this2 +y2)
-
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)
-
sqrt
public SparseGradient sqrt()
Square root.- Specified by:
sqrt
in interfaceCalculusFieldElement<SparseGradient>
- Specified by:
sqrt
in interfaceDerivative1<SparseGradient>
- Returns:
- square root of the instance
-
pow
public SparseGradient pow(double p)
Power operation.- Specified by:
pow
in interfaceCalculusFieldElement<SparseGradient>
- Parameters:
p
- power to apply- Returns:
- thisp
-
pow
public SparseGradient pow(int n)
Integer power operation.- Specified by:
pow
in interfaceCalculusFieldElement<SparseGradient>
- Parameters:
n
- power to apply- Returns:
- thisn
-
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
-
atan2
public SparseGradient atan2(SparseGradient x)
Two arguments arc tangent operation.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 computesatan2(this, x)
, i.e. the instance represents they
argument and thex
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 languagesatan2
two-arguments arc tangent and putsx
as its first argument.- Specified by:
atan2
in interfaceCalculusFieldElement<SparseGradient>
- Parameters:
x
- second argument of the arc tangent- Returns:
- atan2(this, x)
-
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)
-
toDegrees
public SparseGradient toDegrees()
Convert radians to degrees, with error of less than 0.5 ULP- Specified by:
toDegrees
in interfaceCalculusFieldElement<SparseGradient>
- Returns:
- instance converted into degrees
-
toRadians
public SparseGradient toRadians()
Convert degrees to radians, with error of less than 0.5 ULP- Specified by:
toRadians
in interfaceCalculusFieldElement<SparseGradient>
- 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... f)
Compute composition of the instance by a univariate function.- Specified by:
compose
in interfaceDerivative<SparseGradient>
- Parameters:
f
- array of value and derivatives of the function at the current point (i.e. [f(getValue()
), f'(getValue()
), f''(getValue()
)...]).- Returns:
- f(this)
- Throws:
MathIllegalArgumentException
- if the number of elements in the array is not equal to 2 (i.e. value and first derivative)
-
compose
public SparseGradient compose(double f0, double f1)
Compute composition of the instance by a univariate function differentiable at order 1.- Specified by:
compose
in interfaceDerivative1<SparseGradient>
- Parameters:
f0
- value of functionf1
- first-order derivative- Returns:
- f(this)
-
linearCombination
public SparseGradient linearCombination(SparseGradient[] a, SparseGradient[] b) throws MathIllegalArgumentException
Compute a linear combination.- Specified by:
linearCombination
in interfaceCalculusFieldElement<SparseGradient>
- Parameters:
a
- Factors.b
- Factors.- Returns:
Σi ai bi
.- Throws:
MathIllegalArgumentException
- if arrays dimensions don't match
-
linearCombination
public SparseGradient linearCombination(double[] a, SparseGradient[] b)
Compute a linear combination.- Specified by:
linearCombination
in interfaceCalculusFieldElement<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:
linearCombination
in interfaceCalculusFieldElement<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:
CalculusFieldElement.linearCombination(FieldElement, FieldElement, FieldElement, FieldElement, FieldElement, FieldElement)
,CalculusFieldElement.linearCombination(FieldElement, FieldElement, FieldElement, FieldElement, FieldElement, FieldElement, FieldElement, FieldElement)
-
linearCombination
public SparseGradient linearCombination(double a1, SparseGradient b1, double a2, SparseGradient b2)
Compute a linear combination.- Specified by:
linearCombination
in interfaceCalculusFieldElement<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:
CalculusFieldElement.linearCombination(double, FieldElement, double, FieldElement, double, FieldElement)
,CalculusFieldElement.linearCombination(double, FieldElement, double, FieldElement, double, FieldElement, double, FieldElement)
-
linearCombination
public SparseGradient linearCombination(SparseGradient a1, SparseGradient b1, SparseGradient a2, SparseGradient b2, SparseGradient a3, SparseGradient b3)
Compute a linear combination.- Specified by:
linearCombination
in interfaceCalculusFieldElement<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:
CalculusFieldElement.linearCombination(FieldElement, FieldElement, FieldElement, FieldElement)
,CalculusFieldElement.linearCombination(FieldElement, FieldElement, FieldElement, FieldElement, FieldElement, FieldElement, FieldElement, FieldElement)
-
linearCombination
public SparseGradient linearCombination(double a1, SparseGradient b1, double a2, SparseGradient b2, double a3, SparseGradient b3)
Compute a linear combination.- Specified by:
linearCombination
in interfaceCalculusFieldElement<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:
CalculusFieldElement.linearCombination(double, FieldElement, double, FieldElement)
,CalculusFieldElement.linearCombination(double, FieldElement, double, FieldElement, double, FieldElement, double, FieldElement)
-
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:
linearCombination
in interfaceCalculusFieldElement<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 fourth termb4
- second factor of the fourth term- Returns:
- a1×b1 + a2×b2 + a3×b3 + a4×b4
- See Also:
CalculusFieldElement.linearCombination(FieldElement, FieldElement, FieldElement, FieldElement)
,CalculusFieldElement.linearCombination(FieldElement, FieldElement, FieldElement, FieldElement, FieldElement, FieldElement)
-
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:
linearCombination
in interfaceCalculusFieldElement<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 fourth termb4
- second factor of the fourth term- Returns:
- a1×b1 + a2×b2 + a3×b3 + a4×b4
- See Also:
CalculusFieldElement.linearCombination(double, FieldElement, double, FieldElement)
,CalculusFieldElement.linearCombination(double, FieldElement, double, FieldElement, double, FieldElement)
-
getPi
public SparseGradient getPi()
Get the Archimedes constant π.Archimedes constant is the ratio of a circle's circumference to its diameter.
- Specified by:
getPi
in interfaceCalculusFieldElement<SparseGradient>
- Returns:
- Archimedes constant π
-
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.
-
-