public class Gradient extends Object implements Derivative<Gradient>, CalculusFieldElement<Gradient>, Serializable
This class is a stripped-down version of DerivativeStructure
with derivation order
limited to one.
It should have less overhead than DerivativeStructure
in its domain.
This class is an implementation of Rall's numbers. Rall's numbers are an extension to the real numbers used throughout mathematical expressions; they hold the derivative together with the value of a function.
Gradient
instances can be used directly thanks to
the arithmetic operators to the mathematical functions provided as
methods by this class (+, -, *, /, %, sin, cos ...).
Implementing complex expressions by hand using these classes is a tedious and error-prone task but has the advantage of having no limitation on the derivation order despite not requiring users to compute the derivatives by themselves.
Instances of this class are guaranteed to be immutable.
Constructor and Description |
---|
Gradient(DerivativeStructure ds)
Build an instance from a
DerivativeStructure . |
Gradient(double value,
double... gradient)
Build an instance with values and derivative.
|
Modifier and Type | Method and Description |
---|---|
Gradient |
abs()
absolute value.
|
Gradient |
acos()
Arc cosine operation.
|
Gradient |
acosh()
Inverse hyperbolic cosine operation.
|
Gradient |
add(double a)
'+' operator.
|
Gradient |
add(Gradient a)
Compute this + a.
|
Gradient |
asin()
Arc sine operation.
|
Gradient |
asinh()
Inverse hyperbolic sine operation.
|
Gradient |
atan()
Arc tangent operation.
|
Gradient |
atan2(Gradient x)
Two arguments arc tangent operation.
|
Gradient |
atanh()
Inverse hyperbolic tangent operation.
|
Gradient |
cbrt()
Cubic root.
|
Gradient |
ceil()
Get the smallest whole number larger than instance.
|
Gradient |
compose(double... f)
Compute composition of the instance by a univariate function.
|
static Gradient |
constant(int freeParameters,
double value)
Build an instance corresponding to a constant value.
|
Gradient |
copySign(double sign)
Returns the instance with the sign of the argument.
|
Gradient |
copySign(Gradient sign)
Returns the instance with the sign of the argument.
|
Gradient |
cos()
Cosine operation.
|
Gradient |
cosh()
Hyperbolic cosine operation.
|
Gradient |
divide(double a)
'÷' operator.
|
Gradient |
divide(Gradient a)
Compute this ÷ a.
|
boolean |
equals(Object other)
Test for the equality of two univariate derivatives.
|
Gradient |
exp()
Exponential.
|
Gradient |
expm1()
Exponential minus 1.
|
Gradient |
floor()
Get the largest whole number smaller than instance.
|
int |
getExponent()
Return the exponent of the instance, removing the bias.
|
GradientField |
getField()
Get the
Field to which the instance belongs. |
int |
getFreeParameters()
Get the number of free parameters.
|
double[] |
getGradient()
Get the gradient part of the function.
|
int |
getOrder()
Get the derivation order.
|
double |
getPartialDerivative(int... orders)
Get a partial derivative.
|
double |
getPartialDerivative(int n)
Get the partial derivative with respect to one parameter.
|
Gradient |
getPi()
Get the Archimedes constant π.
|
double |
getReal()
Get the real value of the number.
|
double |
getValue()
Get the value part of the function.
|
int |
hashCode()
Get a hashCode for the univariate derivative.
|
Gradient |
hypot(Gradient y)
Returns the hypotenuse of a triangle with sides
this and y
- sqrt(this2 +y2)
avoiding intermediate overflow or underflow. |
Gradient |
linearCombination(double[] a,
Gradient[] b)
Compute a linear combination.
|
Gradient |
linearCombination(double a1,
Gradient b1,
double a2,
Gradient b2)
Compute a linear combination.
|
Gradient |
linearCombination(double a1,
Gradient b1,
double a2,
Gradient b2,
double a3,
Gradient b3)
Compute a linear combination.
|
Gradient |
linearCombination(double a1,
Gradient b1,
double a2,
Gradient b2,
double a3,
Gradient b3,
double a4,
Gradient b4)
Compute a linear combination.
|
Gradient |
linearCombination(Gradient[] a,
Gradient[] b)
Compute a linear combination.
|
Gradient |
linearCombination(Gradient a1,
Gradient b1,
Gradient a2,
Gradient b2)
Compute a linear combination.
|
Gradient |
linearCombination(Gradient a1,
Gradient b1,
Gradient a2,
Gradient b2,
Gradient a3,
Gradient b3)
Compute a linear combination.
|
Gradient |
linearCombination(Gradient a1,
Gradient b1,
Gradient a2,
Gradient b2,
Gradient a3,
Gradient b3,
Gradient a4,
Gradient b4)
Compute a linear combination.
|
Gradient |
log()
Natural logarithm.
|
Gradient |
log10()
Base 10 logarithm.
|
Gradient |
log1p()
Shifted natural logarithm.
|
Gradient |
multiply(double a)
'×' operator.
|
Gradient |
multiply(Gradient a)
Compute this × a.
|
Gradient |
multiply(int n)
Compute n × this.
|
Gradient |
negate()
Returns the additive inverse of
this element. |
Gradient |
newInstance(double c)
Create an instance corresponding to a constant real value.
|
Gradient |
pow(double p)
Power operation.
|
static Gradient |
pow(double a,
Gradient x)
Compute ax where a is a double and x a
Gradient |
Gradient |
pow(Gradient e)
Power operation.
|
Gradient |
pow(int n)
Integer power operation.
|
Gradient |
reciprocal()
Returns the multiplicative inverse of
this element. |
Gradient |
remainder(double a)
IEEE remainder operator.
|
Gradient |
remainder(Gradient a)
IEEE remainder operator.
|
Gradient |
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.
|
Gradient |
rootN(int n)
Nth root.
|
Gradient |
scalb(int n)
Multiply the instance by a power of 2.
|
Gradient |
sign()
Compute the sign of the instance.
|
Gradient |
sin()
Sine operation.
|
FieldSinCos<Gradient> |
sinCos()
Combined Sine and Cosine operation.
|
Gradient |
sinh()
Hyperbolic sine operation.
|
FieldSinhCosh<Gradient> |
sinhCosh()
Combined hyperbolic sine and sosine operation.
|
Gradient |
sqrt()
Square root.
|
Gradient |
subtract(double a)
'-' operator.
|
Gradient |
subtract(Gradient a)
Compute this - a.
|
Gradient |
tan()
Tangent operation.
|
Gradient |
tanh()
Hyperbolic tangent operation.
|
double |
taylor(double... delta)
Evaluate Taylor expansion a derivative structure.
|
Gradient |
toDegrees()
Convert radians to degrees, with error of less than 0.5 ULP
|
DerivativeStructure |
toDerivativeStructure()
Convert the instance to a
DerivativeStructure . |
Gradient |
toRadians()
Convert degrees to radians, with error of less than 0.5 ULP
|
Gradient |
ulp()
Compute least significant bit (Unit in Last Position) for a number.
|
static Gradient |
variable(int freeParameters,
int index,
double value)
Build a
Gradient representing a variable. |
clone, finalize, getClass, notify, notifyAll, toString, wait, wait, wait
isFinite, isInfinite, isNaN, norm, round
isZero
public Gradient(double value, double... gradient)
value
- value of the functiongradient
- gradient of the functionpublic Gradient(DerivativeStructure ds) throws MathIllegalArgumentException
DerivativeStructure
.ds
- derivative structureMathIllegalArgumentException
- if ds
order
is not 1public static Gradient constant(int freeParameters, double value)
freeParameters
- number of free parameters (i.e. dimension of the gradient)value
- constant value of the functionGradient
with a constant value and all derivatives set to 0.0public static Gradient variable(int freeParameters, int index, double value)
Gradient
representing a variable.
Instances built using this method are considered to be the free variables with respect to which differentials are computed. As such, their differential with respect to themselves is +1.
freeParameters
- number of free parameters (i.e. dimension of the gradient)index
- index of the variable (from 0 to getFreeParameters()
- 1)value
- value of the variableGradient
with a constant value and all derivatives set to 0.0 except the
one at index
which will be set to 1.0public Gradient newInstance(double c)
newInstance
in interface CalculusFieldElement<Gradient>
c
- constant real valuepublic double getReal()
getReal
in interface FieldElement<Gradient>
public double getValue()
getValue
in interface Derivative<Gradient>
public double[] getGradient()
getPartialDerivative(int)
public int getFreeParameters()
getFreeParameters
in interface Derivative<Gradient>
public int getOrder()
getOrder
in interface Derivative<Gradient>
public double getPartialDerivative(int... orders) throws MathIllegalArgumentException
getPartialDerivative
in interface Derivative<Gradient>
orders
- derivation orders with respect to each variable (if all orders are 0,
the value is returned)MathIllegalArgumentException
- if the numbers of variables does not
match the instanceDerivative.getValue()
public double getPartialDerivative(int n) throws MathIllegalArgumentException
n
- index of the parameter (counting from 0)MathIllegalArgumentException
- if n is either negative or larger
or equal to getFreeParameters()
public DerivativeStructure toDerivativeStructure()
DerivativeStructure
.public Gradient add(double a)
add
in interface CalculusFieldElement<Gradient>
a
- right hand side parameter of the operatorpublic Gradient add(Gradient a)
add
in interface FieldElement<Gradient>
a
- element to addpublic Gradient subtract(double a)
subtract
in interface CalculusFieldElement<Gradient>
a
- right hand side parameter of the operatorpublic Gradient subtract(Gradient a)
subtract
in interface FieldElement<Gradient>
a
- element to subtractpublic Gradient multiply(int n)
multiply
in interface FieldElement<Gradient>
n
- Number of times this
must be added to itself.public Gradient multiply(double a)
multiply
in interface CalculusFieldElement<Gradient>
a
- right hand side parameter of the operatorpublic Gradient multiply(Gradient a)
multiply
in interface FieldElement<Gradient>
a
- element to multiplypublic Gradient divide(double a)
divide
in interface CalculusFieldElement<Gradient>
a
- right hand side parameter of the operatorpublic Gradient divide(Gradient a)
divide
in interface FieldElement<Gradient>
a
- element to divide bypublic Gradient remainder(double a)
remainder
in interface CalculusFieldElement<Gradient>
a
- right hand side parameter of the operatorpublic Gradient remainder(Gradient a)
remainder
in interface CalculusFieldElement<Gradient>
a
- right hand side parameter of the operatorpublic Gradient negate()
this
element.negate
in interface FieldElement<Gradient>
this
.public Gradient abs()
Just another name for CalculusFieldElement.norm()
abs
in interface CalculusFieldElement<Gradient>
public Gradient ceil()
ceil
in interface CalculusFieldElement<Gradient>
public Gradient floor()
floor
in interface CalculusFieldElement<Gradient>
public Gradient rint()
rint
in interface CalculusFieldElement<Gradient>
public Gradient sign()
sign
in interface CalculusFieldElement<Gradient>
public Gradient copySign(Gradient sign)
sign
argument is treated as positive.copySign
in interface CalculusFieldElement<Gradient>
sign
- the sign for the returned valuesign
argumentpublic Gradient copySign(double sign)
sign
argument is treated as positive.copySign
in interface CalculusFieldElement<Gradient>
sign
- the sign for the returned valuesign
argumentpublic int getExponent()
For double numbers of the form 2x, the unbiased exponent is exactly x.
getExponent
in interface CalculusFieldElement<Gradient>
public Gradient scalb(int n)
scalb
in interface CalculusFieldElement<Gradient>
n
- power of 2public Gradient ulp()
The ulp
function is a step function, hence all its derivatives are 0.
ulp
in interface CalculusFieldElement<Gradient>
public Gradient hypot(Gradient y)
this
and y
- sqrt(this2 +y2)
avoiding intermediate overflow or underflow.
hypot
in interface CalculusFieldElement<Gradient>
y
- a valuepublic Gradient reciprocal()
this
element.reciprocal
in interface CalculusFieldElement<Gradient>
reciprocal
in interface FieldElement<Gradient>
this
.public Gradient compose(double... f)
compose
in interface Derivative<Gradient>
f
- array of value and derivatives of the function at
the current point (i.e. [f(Derivative.getValue()
),
f'(Derivative.getValue()
), f''(Derivative.getValue()
)...]).public Gradient sqrt()
sqrt
in interface CalculusFieldElement<Gradient>
public Gradient cbrt()
cbrt
in interface CalculusFieldElement<Gradient>
public Gradient rootN(int n)
rootN
in interface CalculusFieldElement<Gradient>
n
- order of the rootpublic GradientField getField()
Field
to which the instance belongs.getField
in interface FieldElement<Gradient>
Field
to which the instance belongspublic static Gradient pow(double a, Gradient x)
Gradient
a
- number to exponentiatex
- power to applypublic Gradient pow(double p)
pow
in interface CalculusFieldElement<Gradient>
p
- power to applypublic Gradient pow(int n)
pow
in interface CalculusFieldElement<Gradient>
n
- power to applypublic Gradient pow(Gradient e)
pow
in interface CalculusFieldElement<Gradient>
e
- exponentpublic Gradient exp()
exp
in interface CalculusFieldElement<Gradient>
public Gradient expm1()
expm1
in interface CalculusFieldElement<Gradient>
public Gradient log()
log
in interface CalculusFieldElement<Gradient>
public Gradient log1p()
log1p
in interface CalculusFieldElement<Gradient>
public Gradient log10()
log10
in interface CalculusFieldElement<Gradient>
public Gradient cos()
cos
in interface CalculusFieldElement<Gradient>
public Gradient sin()
sin
in interface CalculusFieldElement<Gradient>
public FieldSinCos<Gradient> sinCos()
sinCos
in interface CalculusFieldElement<Gradient>
public Gradient tan()
tan
in interface CalculusFieldElement<Gradient>
public Gradient acos()
acos
in interface CalculusFieldElement<Gradient>
public Gradient asin()
asin
in interface CalculusFieldElement<Gradient>
public Gradient atan()
atan
in interface CalculusFieldElement<Gradient>
public Gradient atan2(Gradient 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<Gradient>
x
- second argument of the arc tangentpublic Gradient cosh()
cosh
in interface CalculusFieldElement<Gradient>
public Gradient sinh()
sinh
in interface CalculusFieldElement<Gradient>
public FieldSinhCosh<Gradient> sinhCosh()
sinhCosh
in interface CalculusFieldElement<Gradient>
public Gradient tanh()
tanh
in interface CalculusFieldElement<Gradient>
public Gradient acosh()
acosh
in interface CalculusFieldElement<Gradient>
public Gradient asinh()
asinh
in interface CalculusFieldElement<Gradient>
public Gradient atanh()
atanh
in interface CalculusFieldElement<Gradient>
public Gradient toDegrees()
toDegrees
in interface CalculusFieldElement<Gradient>
public Gradient toRadians()
toRadians
in interface CalculusFieldElement<Gradient>
public double taylor(double... delta)
delta
- parameters offsets (Δx, Δy, ...)public Gradient linearCombination(Gradient[] a, Gradient[] b)
linearCombination
in interface CalculusFieldElement<Gradient>
a
- Factors.b
- Factors.Σi ai bi
.public Gradient linearCombination(double[] a, Gradient[] b)
linearCombination
in interface CalculusFieldElement<Gradient>
a
- Factors.b
- Factors.Σi ai bi
.public Gradient linearCombination(Gradient a1, Gradient b1, Gradient a2, Gradient b2)
linearCombination
in interface CalculusFieldElement<Gradient>
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 Gradient linearCombination(double a1, Gradient b1, double a2, Gradient b2)
linearCombination
in interface CalculusFieldElement<Gradient>
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 Gradient linearCombination(Gradient a1, Gradient b1, Gradient a2, Gradient b2, Gradient a3, Gradient b3)
linearCombination
in interface CalculusFieldElement<Gradient>
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 Gradient linearCombination(double a1, Gradient b1, double a2, Gradient b2, double a3, Gradient b3)
linearCombination
in interface CalculusFieldElement<Gradient>
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 Gradient linearCombination(Gradient a1, Gradient b1, Gradient a2, Gradient b2, Gradient a3, Gradient b3, Gradient a4, Gradient b4)
linearCombination
in interface CalculusFieldElement<Gradient>
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 Gradient linearCombination(double a1, Gradient b1, double a2, Gradient b2, double a3, Gradient b3, double a4, Gradient b4)
linearCombination
in interface CalculusFieldElement<Gradient>
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 Gradient getPi()
Archimedes constant is the ratio of a circle's circumference to its diameter.
getPi
in interface CalculusFieldElement<Gradient>
public boolean equals(Object other)
univariate derivatives are considered equal if they have the same derivatives.
Copyright © 2016-2021 CS GROUP. All rights reserved.