This class is the workhorse of the differentiation package.
This class is an implementation of the extension to Rall's numbers described in Dan Kalman's paper Doubly Recursive Multivariate Automatic Differentiation, Mathematics Magazine, vol. 75, no. 3, June 2002. 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. Dan Kalman's derivative structures hold all partial derivatives up to any specified order, with respect to any number of free parameters. Rall's numbers therefore can be seen as derivative structures for order one derivative and one free parameter, and real numbers can be seen as derivative structures with zero order derivative and no free parameters.
DerivativeStructure 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 no requiring users to compute the derivatives by
themselves. Implementing complex expression can also be done by developing computation
code using standard primitive double values and to use differentiators to create the DerivativeStructure-based instances. This method is simpler but may be limited in
the accuracy and derivation orders and may be computationally intensive (this is
typically the case for finite differences
differentiator.
Instances of this class are guaranteed to be immutable.
DSCompiler
| Modifier and Type | Class and Description |
|---|---|
| private static class | DerivativeStructure.
Internal class used only for serialization. |
| Modifier and Type | Field and Description |
|---|---|
| private transient DSCompiler | compiler
Compiler for the current dimensions. |
| private final double[] | data
Combined array holding all values. |
| private static final long | serialVersionUID
Serializable UID. |
| Access | Constructor and Description |
|---|---|
| private | DerivativeStructure(final DSCompiler
compiler to use for computation compiler)Build an instance with all values and derivatives set to 0. |
| public | DerivativeStructure(final int
number of free parameters parameters, final int derivation order order)Build an instance with all values and derivatives set to 0. |
| public | DerivativeStructure(final int
number of free parameters parameters, final int derivation order order, final double value of the constant value)Build an instance representing a constant value. |
| public | DerivativeStructure(final int
number of free parameters parameters, final int derivation order order, final int index of the variable (from 0 to index, final double parameters - 1)value of the variable value)Build an instance representing a variable. |
| public | DerivativeStructure(final double
first scale factor a1, final DerivativeStructure first base (unscaled) derivative structure ds1, final double second scale factor a2, final DerivativeStructure second base (unscaled) derivative structure ds2)Linear combination constructor. |
| public | DerivativeStructure(final double
first scale factor a1, final DerivativeStructure first base (unscaled) derivative structure ds1, final double second scale factor a2, final DerivativeStructure second base (unscaled) derivative structure ds2, final double third scale factor a3, final DerivativeStructure third base (unscaled) derivative structure ds3)Linear combination constructor. |
| public | DerivativeStructure(final double
first scale factor a1, final DerivativeStructure first base (unscaled) derivative structure ds1, final double second scale factor a2, final DerivativeStructure second base (unscaled) derivative structure ds2, final double third scale factor a3, final DerivativeStructure third base (unscaled) derivative structure ds3, final double fourth scale factor a4, final DerivativeStructure fourth base (unscaled) derivative structure ds4)Linear combination constructor. |
| public | DerivativeStructure(final int
number of free parameters parameters, final int derivation order order, final double... derivatives sorted according to
derivatives)DSCompiler#getPartialDerivativeIndex(int.Build an instance from all its derivatives. |
| private |
| Modifier and Type | Method and Description |
|---|---|
| public DerivativeStructure | |
| public DerivativeStructure | |
| public DerivativeStructure | acosh()
Implements org. Inverse hyperbolic cosine operation. |
| public DerivativeStructure | add(final double
right hand side parameter of the operator a)Implements org. '+' operator. |
| public DerivativeStructure | add(final DerivativeStructure
element to add a)Implements org. Compute this + a. |
| public DerivativeStructure | |
| public DerivativeStructure | asinh()
Implements org. Inverse hyperbolic sine operation. |
| public DerivativeStructure | |
| public DerivativeStructure | atan2(final DerivativeStructure
second argument of the arc tangent x)Implements org. Two arguments arc tangent operation. |
| public static DerivativeStructure | Returns: atan2(y, x)first argument of the arc tangent y, final DerivativeStructure second argument of the arc tangent x)Two arguments arc tangent operation. |
| public DerivativeStructure | atanh()
Implements org. Inverse hyperbolic tangent operation. |
| public DerivativeStructure | |
| public DerivativeStructure | ceil()
Implements org. Get the smallest whole number larger than instance. |
| public DerivativeStructure | Returns: f(this)array of value and derivatives of the function at
the current point (i.e. [f( f)getValue()),
f'(getValue()), f''(getValue())...]).Compute composition of the instance by a univariate function. |
| public DerivativeStructure | copySign(final DerivativeStructure
the sign for the returned value sign)Implements org. Returns the instance with the sign of the argument. |
| public DerivativeStructure | copySign(final double
the sign for the returned value sign)Implements org. Returns the instance with the sign of the argument. |
| public DerivativeStructure | |
| public DerivativeStructure | |
| public DerivativeStructure | Returns: a constant compatible with instance order and number of parametersvalue of the constant c)Create a constant compatible with instance order and number of parameters. |
| public DerivativeStructure | divide(final double
right hand side parameter of the operator a)Implements org. '÷' operator. |
| public DerivativeStructure | divide(final DerivativeStructure
element to divide by a)Implements org. Compute this ÷ a. |
| public boolean | Returns: true if two derivative structures are equalObject to test for equality to this other)Overrides java. Test for the equality of two derivative structures. |
| public DerivativeStructure | |
| public DerivativeStructure | |
| public DerivativeStructure | floor()
Implements org. Get the largest whole number smaller than instance. |
| public double[] | Returns: a fresh copy of partial derivatives, in an array sorted according toDSCompiler#getPartialDerivativeIndex(int.Get all partial derivatives. |
| public int | Returns: exponent for instance in IEEE754 representation, without biasReturn the exponent of the instance value, removing the bias. |
| public Field | getField()
Implements org. Get the |
| public int | |
| public int | |
| public double | Returns: partial derivativederivation orders with respect to each variable (if all orders are 0,
the value is returned) orders)Get a partial derivative. |
| public double | getReal()
Implements org. Get the real value of the number. |
| public double | Returns: value part of the derivative structureGet the value part of the derivative structure. |
| public int | Returns: a hash code value for this objectOverrides java. Get a hashCode for the derivative structure. |
| public DerivativeStructure | hypot(final DerivativeStructure
a value y)Implements org. Returns the hypotenuse of a triangle with sides |
| public static DerivativeStructure | Returns: sqrt(x2 +y2)a value x, final DerivativeStructure a value y)Returns the hypotenuse of a triangle with sides |
| public DerivativeStructure | linearCombination(final DerivativeStructure[]
Factors. a, final DerivativeStructure[] Factors. b)Implements org. Compute a linear combination. |
| public DerivativeStructure | linearCombination(final double[]
Factors. a, final DerivativeStructure[] Factors. b)Implements org. Compute a linear combination. |
| public DerivativeStructure | linearCombination(final DerivativeStructure
first factor of the first term a1, final DerivativeStructure second factor of the first term b1, final DerivativeStructure first factor of the second term a2, final DerivativeStructure second factor of the second term b2)Implements org. Compute a linear combination. |
| public DerivativeStructure | linearCombination(final double
first factor of the first term a1, final DerivativeStructure second factor of the first term b1, final double first factor of the second term a2, final DerivativeStructure second factor of the second term b2)Implements org. Compute a linear combination. |
| public DerivativeStructure | linearCombination(final DerivativeStructure
first factor of the first term a1, final DerivativeStructure second factor of the first term b1, final DerivativeStructure first factor of the second term a2, final DerivativeStructure second factor of the second term b2, final DerivativeStructure first factor of the third term a3, final DerivativeStructure second factor of the third term b3)Implements org. Compute a linear combination. |
| public DerivativeStructure | linearCombination(final double
first factor of the first term a1, final DerivativeStructure second factor of the first term b1, final double first factor of the second term a2, final DerivativeStructure second factor of the second term b2, final double first factor of the third term a3, final DerivativeStructure second factor of the third term b3)Implements org. Compute a linear combination. |
| public DerivativeStructure | linearCombination(final DerivativeStructure
first factor of the first term a1, final DerivativeStructure second factor of the first term b1, final DerivativeStructure first factor of the second term a2, final DerivativeStructure second factor of the second term b2, final DerivativeStructure first factor of the third term a3, final DerivativeStructure second factor of the third term b3, final DerivativeStructure first factor of the third term a4, final DerivativeStructure second factor of the third term b4)Implements org. Compute a linear combination. |
| public DerivativeStructure | linearCombination(final double
first factor of the first term a1, final DerivativeStructure second factor of the first term b1, final double first factor of the second term a2, final DerivativeStructure second factor of the second term b2, final double first factor of the third term a3, final DerivativeStructure second factor of the third term b3, final double first factor of the third term a4, final DerivativeStructure second factor of the third term b4)Implements org. Compute a linear combination. |
| public DerivativeStructure | |
| public DerivativeStructure | |
| public DerivativeStructure | |
| public DerivativeStructure | multiply(final int
Number of times n)this must be added to itself.Implements org. Compute n × this.</center> |
| public DerivativeStructure | multiply(final double
right hand side parameter of the operator a)Implements org. '×' operator. |
| public DerivativeStructure | multiply(final DerivativeStructure
element to multiply a)Implements org. Compute this × a. |
| public DerivativeStructure | negate()
Implements org. Returns the additive inverse of |
| public static DerivativeStructure | Returns: axnumber to exponentiate a, final DerivativeStructure power to apply x)Compute ax where a is a double and x a |
| public DerivativeStructure | pow(final double
power to apply p)Implements org. Power operation. |
| public DerivativeStructure | pow(final int
power to apply n)Implements org. Integer power operation. |
| public DerivativeStructure | pow(final DerivativeStructure
exponent e)Implements org. Power operation. |
| public DerivativeStructure | reciprocal()
Implements org. Returns the multiplicative inverse of |
| public DerivativeStructure | remainder(final double
right hand side parameter of the operator a)Implements org. IEEE remainder operator. |
| public DerivativeStructure | remainder(final DerivativeStructure
right hand side parameter of the operator a)Implements org. IEEE remainder operator. |
| public DerivativeStructure | rint()
Implements org. Get the whole number that is the nearest to the instance, or the even one if x is exactly half way between two integers. |
| public DerivativeStructure | rootN(final int
order of the root n)Implements org. Nth root. |
| public long | round()
Implements org. Get the closest long to instance value. |
| public DerivativeStructure | scalb(final int
power of 2 n)Implements org. Multiply the instance by a power of 2. |
| public DerivativeStructure | signum()
Implements org. Compute the signum of the instance. |
| public DerivativeStructure | |
| public DerivativeStructure | |
| public DerivativeStructure | |
| public DerivativeStructure | subtract(final double
right hand side parameter of the operator a)Implements org. '-' operator. |
| public DerivativeStructure | subtract(final DerivativeStructure
element to subtract a)Implements org. Compute this - a. |
| public DerivativeStructure | |
| public DerivativeStructure | |
| public double | Returns: value of the Taylor expansion at x + Δx, y + Δy, ...parameters offsets (Δx, Δy, ...) delta)Evaluate Taylor expansion a derivative structure. |
| public DerivativeStructure | Returns: instance converted into degreesConvert radians to degrees, with error of less than 0.5 ULP |
| public DerivativeStructure | Returns: instance converted into radiansConvert degrees to radians, with error of less than 0.5 ULP |
| private Object | Returns: data transfer object that will be serializedReplace the instance with a data transfer object for serialization. |