Top Description Inners Fields Constructors Methods
org.apache.commons.math3.analysis.differentiation

public Class DerivativeStructure

extends Object
implements RealFieldElement<DerivativeStructure>, Serializable
Class Inheritance
All Implemented Interfaces
java.io.Serializable, org.apache.commons.math3.RealFieldElement, org.apache.commons.math3.FieldElement
Imports
java.io.Serializable, org.apache.commons.math3.Field, .FieldElement, .RealFieldElement, org.apache.commons.math3.exception.DimensionMismatchException, .MathArithmeticException, .NumberIsTooLargeException, org.apache.commons.math3.util.FastMath, .MathArrays, .MathUtils

Class representing both the value and the differentials of a function.

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.

Since
3.1
See Also
DSCompiler

Nested and Inner Type Summary

Modifier and TypeClass and Description
private static class
DerivativeStructure.DataTransferObject

Internal class used only for serialization.

Field Summary

Modifier and TypeField 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.

Constructor Summary

AccessConstructor 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 parameters - 1)
index
,
final double
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 DSCompiler#getPartialDerivativeIndex(int...)
derivatives
)

Build an instance from all its derivatives.

private
DerivativeStructure(final DerivativeStructure
instance to copy
ds
)

Copy constructor.

Method Summary

Modifier and TypeMethod and Description
public DerivativeStructure
public DerivativeStructure
acos()

Implements org.apache.commons.math3.RealFieldElement.acos.

Arc cosine operation.

public DerivativeStructure
acosh()

Implements org.apache.commons.math3.RealFieldElement.acosh.

Inverse hyperbolic cosine operation.

public DerivativeStructure
add(final double
right hand side parameter of the operator
a
)

Implements org.apache.commons.math3.RealFieldElement.add.

'+' operator.

public DerivativeStructure
add(final DerivativeStructure
element to add
a
)

Implements org.apache.commons.math3.FieldElement.add.

Compute this + a.

public DerivativeStructure
asin()

Implements org.apache.commons.math3.RealFieldElement.asin.

Arc sine operation.

public DerivativeStructure
asinh()

Implements org.apache.commons.math3.RealFieldElement.asinh.

Inverse hyperbolic sine operation.

public DerivativeStructure
atan()

Implements org.apache.commons.math3.RealFieldElement.atan.

Arc tangent operation.

public DerivativeStructure
atan2(final DerivativeStructure
second argument of the arc tangent
x
)

Implements org.apache.commons.math3.RealFieldElement.atan2.

Two arguments arc tangent operation.

public static DerivativeStructure

Returns:

atan2(y, x)
atan2
(final DerivativeStructure
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.apache.commons.math3.RealFieldElement.atanh.

Inverse hyperbolic tangent operation.

public DerivativeStructure
public DerivativeStructure
ceil()

Implements org.apache.commons.math3.RealFieldElement.ceil.

Get the smallest whole number larger than instance.

public DerivativeStructure

Returns:

f(this)
compose
(final double...
array of value and derivatives of the function at the current point (i.e. [f(getValue()), f'(getValue()), f''(getValue())...]).
f
)

Compute composition of the instance by a univariate function.

public DerivativeStructure
copySign(final DerivativeStructure
the sign for the returned value
sign
)

Implements org.apache.commons.math3.RealFieldElement.copySign.

Returns the instance with the sign of the argument.

public DerivativeStructure
copySign(final double
the sign for the returned value
sign
)

Implements org.apache.commons.math3.RealFieldElement.copySign, org.apache.commons.math3.RealFieldElement.copySign.

Returns the instance with the sign of the argument.

public DerivativeStructure
cos()

Implements org.apache.commons.math3.RealFieldElement.cos.

Cosine operation.

public DerivativeStructure
cosh()

Implements org.apache.commons.math3.RealFieldElement.cosh.

Hyperbolic cosine operation.

public DerivativeStructure

Returns:

a constant compatible with instance order and number of parameters
createConstant
(final double
value 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.apache.commons.math3.RealFieldElement.divide.

'÷' operator.

public DerivativeStructure
divide(final DerivativeStructure
element to divide by
a
)

Implements org.apache.commons.math3.FieldElement.divide.

Compute this ÷ a.

public boolean

Returns:

true if two derivative structures are equal
equals
(Object
Object to test for equality to this
other
)

Overrides java.lang.Object.equals.

Test for the equality of two derivative structures.

public DerivativeStructure
public DerivativeStructure
expm1()

Implements org.apache.commons.math3.RealFieldElement.expm1.

Exponential minus 1.

public DerivativeStructure
floor()

Implements org.apache.commons.math3.RealFieldElement.floor.

Get the largest whole number smaller than instance.

public double[]

Returns:

a fresh copy of partial derivatives, in an array sorted according to DSCompiler#getPartialDerivativeIndex(int...)
getAllDerivatives
()

Get all partial derivatives.

public int

Returns:

exponent for instance in IEEE754 representation, without bias
getExponent
()

Return the exponent of the instance value, removing the bias.

public Field<DerivativeStructure>
getField()

Implements org.apache.commons.math3.FieldElement.getField.

Get the Field to which the instance belongs.

public int

Returns:

number of free parameters
getFreeParameters
()

Get the number of free parameters.

public int

Returns:

derivation order
getOrder
()

Get the derivation order.

public double

Returns:

partial derivative
getPartialDerivative
(final int...
derivation 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.apache.commons.math3.RealFieldElement.getReal.

Get the real value of the number.

public double

Returns:

value part of the derivative structure
getValue
()

Get the value part of the derivative structure.

public int

Returns:

a hash code value for this object
hashCode
()

Overrides java.lang.Object.hashCode.

Get a hashCode for the derivative structure.

public DerivativeStructure
hypot(final DerivativeStructure
a value
y
)

Implements org.apache.commons.math3.RealFieldElement.hypot.

Returns the hypotenuse of a triangle with sides this and y - sqrt(this2 +y2) avoiding intermediate overflow or underflow.

public static DerivativeStructure

Returns:

sqrt(x2 +y2)
hypot
(final DerivativeStructure
a value
x
,
final DerivativeStructure
a value
y
)

Returns the hypotenuse of a triangle with sides x and y - sqrt(x2 +y2) avoiding intermediate overflow or underflow.

public DerivativeStructure
linearCombination(final DerivativeStructure[]
Factors.
a
,
final DerivativeStructure[]
Factors.
b
)

Implements org.apache.commons.math3.RealFieldElement.linearCombination.

Compute a linear combination.

public DerivativeStructure
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.apache.commons.math3.RealFieldElement.linearCombination.

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.apache.commons.math3.RealFieldElement.linearCombination, org.apache.commons.math3.RealFieldElement.linearCombination.

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.apache.commons.math3.RealFieldElement.linearCombination.

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.apache.commons.math3.RealFieldElement.linearCombination, org.apache.commons.math3.RealFieldElement.linearCombination.

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.apache.commons.math3.RealFieldElement.linearCombination.

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.apache.commons.math3.RealFieldElement.linearCombination, org.apache.commons.math3.RealFieldElement.linearCombination.

Compute a linear combination.

public DerivativeStructure
log()

Implements org.apache.commons.math3.RealFieldElement.log.

Natural logarithm.

public DerivativeStructure

Returns:

base 10 logarithm of the instance
log10
()

Base 10 logarithm.

public DerivativeStructure
log1p()

Implements org.apache.commons.math3.RealFieldElement.log1p.

Shifted natural logarithm.

public DerivativeStructure
multiply(final int
Number of times this must be added to itself.
n
)

Implements org.apache.commons.math3.FieldElement.multiply, org.apache.commons.math3.FieldElement.multiply.

Compute n × this.</center>

public DerivativeStructure
multiply(final double
right hand side parameter of the operator
a
)

Implements org.apache.commons.math3.RealFieldElement.multiply.

'×' operator.

public DerivativeStructure
multiply(final DerivativeStructure
element to multiply
a
)

Implements org.apache.commons.math3.FieldElement.multiply.

Compute this × a.

public DerivativeStructure
negate()

Implements org.apache.commons.math3.FieldElement.negate.

Returns the additive inverse of this element.

public static DerivativeStructure

Returns:

ax
pow
(final double
number to exponentiate
a
,
final DerivativeStructure
power to apply
x
)

Compute ax where a is a double and x a DerivativeStructure

public DerivativeStructure
pow(final double
power to apply
p
)

Implements org.apache.commons.math3.RealFieldElement.pow, org.apache.commons.math3.RealFieldElement.pow.

Power operation.

public DerivativeStructure
pow(final int
power to apply
n
)

Implements org.apache.commons.math3.RealFieldElement.pow, org.apache.commons.math3.RealFieldElement.pow.

Integer power operation.

public DerivativeStructure
pow(final DerivativeStructure
exponent
e
)

Implements org.apache.commons.math3.RealFieldElement.pow.

Power operation.

public DerivativeStructure
reciprocal()

Implements org.apache.commons.math3.RealFieldElement.reciprocal.

Returns the multiplicative inverse of this element.

public DerivativeStructure
remainder(final double
right hand side parameter of the operator
a
)

Implements org.apache.commons.math3.RealFieldElement.remainder, org.apache.commons.math3.RealFieldElement.remainder.

IEEE remainder operator.

public DerivativeStructure
remainder(final DerivativeStructure
right hand side parameter of the operator
a
)

Implements org.apache.commons.math3.RealFieldElement.remainder.

IEEE remainder operator.

public DerivativeStructure
rint()

Implements org.apache.commons.math3.RealFieldElement.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.

public DerivativeStructure
rootN(final int
order of the root
n
)

Implements org.apache.commons.math3.RealFieldElement.rootN.

Nth root.

public long
round()

Implements org.apache.commons.math3.RealFieldElement.round.

Get the closest long to instance value.

public DerivativeStructure
scalb(final int
power of 2
n
)

Implements org.apache.commons.math3.RealFieldElement.scalb.

Multiply the instance by a power of 2.

public DerivativeStructure
signum()

Implements org.apache.commons.math3.RealFieldElement.signum.

Compute the signum of the instance.

public DerivativeStructure
public DerivativeStructure
sinh()

Implements org.apache.commons.math3.RealFieldElement.sinh.

Hyperbolic sine operation.

public DerivativeStructure
public DerivativeStructure
subtract(final double
right hand side parameter of the operator
a
)

Implements org.apache.commons.math3.RealFieldElement.subtract.

'-' operator.

public DerivativeStructure
subtract(final DerivativeStructure
element to subtract
a
)

Implements org.apache.commons.math3.FieldElement.subtract.

Compute this - a.

public DerivativeStructure
tan()

Implements org.apache.commons.math3.RealFieldElement.tan.

Tangent operation.

public DerivativeStructure
tanh()

Implements org.apache.commons.math3.RealFieldElement.tanh.

Hyperbolic tangent operation.

public double

Returns:

value of the Taylor expansion at x + Δx, y + Δy, ...
taylor
(final double...
parameters offsets (Δx, Δy, ...)
delta
)

Evaluate Taylor expansion a derivative structure.

public DerivativeStructure

Returns:

instance converted into degrees
toDegrees
()

Convert radians to degrees, with error of less than 0.5 ULP

public DerivativeStructure

Returns:

instance converted into radians
toRadians
()

Convert degrees to radians, with error of less than 0.5 ULP

private Object

Returns:

data transfer object that will be serialized
writeReplace
()

Replace the instance with a data transfer object for serialization.

Inherited from java.lang.Object:
clonefinalizegetClassnotifynotifyAlltoStringwaitwaitwait