DSCompiler

class DSCompiler<T, out A : Algebra<T>>(source)

Class holding "compiled" computation rules for derivative structures.

This class implements the computation rules described in Dan Kalman's paper Doubly Recursive Multivariate Automatic Differentiation, Mathematics Magazine, vol. 75, no. 3, June 2002. However, to avoid performances bottlenecks, the recursive rules are "compiled" once in an unfolded form. This class does this recursion unrolling and stores the computation rules as simple loops with pre-computed indirection arrays.

This class maps all derivative computation into single dimension arrays that hold the value and partial derivatives. The class does not hold these arrays, which remains under the responsibility of the caller. For each combination of number of free parameters and derivation order, only one compiler is necessary, and this compiler will be used to perform computations on all arrays provided to it, which can represent hundreds or thousands of different parameters kept together with all their partial derivatives.

The arrays on which compilers operate contain only the partial derivatives together with the 0th derivative, i.e., the value. The partial derivatives are stored in a compiler-specific order, which can be retrieved using methods getPartialDerivativeIndex and getPartialDerivativeOrders. The value is guaranteed to be stored as the first element (i.e., the getPartialDerivativeIndex method returns 0 when called with 0 for all derivation orders and getPartialDerivativeOrders returns an array filled with 0 when called with 0 as the index).

Note that the ordering changes with number of parameters and derivation order. For example given 2 parameters x and y, df/dy is stored at index 2 when derivation order is set to 1 (in this case the array has three elements: f, df/dx and df/dy). If derivation order is set to 2, then df/dy will be stored at index 3 (in this case the array has six elements: f, df/dx, df/dxdx, df/dy, df/dxdy and df/dydy).

Given this structure, users can perform some simple operations like adding, subtracting or multiplying constants and negating the elements by themselves, knowing if they want to mutate their array or create a new array. These simple operations are not provided by the compiler. The compiler provides only the more complex operations between several arrays.

Derived from Commons Math's DSCompiler.

See also

Functions

Link copied to clipboard
fun getPartialDerivativeIndex(vararg orders: Int): Int

Get the index of a partial derivative in the array.

Link copied to clipboard

Get the derivation orders for a specific index in the array.

Properties

Link copied to clipboard
val algebra: A
Link copied to clipboard

Number of free parameters.

Link copied to clipboard
val order: Int

Derivation order.

Link copied to clipboard
val size: Int

Get the array size required for holding partial derivatives' data.

Link copied to clipboard

Number of partial derivatives (including the single 0 order derivative element).