class pyADiff.adjoint.ADTypeA(value, record, dependencies=[], derivative=0.0)

This class overloads the basic numerical type of python. Instead of only an value it also stores a derivative, its dependencies and a record.

This class implements the numerical operators (+, -, .. ) as expected for a numerical type, but additionaly stores the operands (dependencies) and records the operation to the record.

Basic mathematical functions (sin, cos, exp, …) are implemented as member functions and also store the operand in the return ADTypeA and record the operation.

Parameters: value (float or ADType) – The value of the overloaded numerical type. record (ADRecord) – The record of all operations. dependencies (list[tuple(ADTypeA, float or ADType)]) – List of the ADTypeAs this ADTypeA depends on and their partial derivatives. deriative (float or ADType) – The derivative of the overloaded numerical type.

pyADiff.adjoint.ADRecord
Records all operations.
pyADiff.math_functions
Implementation of basic mathematical functions for the ADType.
backpropagate()

Backpropagation.

Calculates and accumulates the partial derivatives of its dependencies.

dependencies

derivative

Derivative of the overloaded numerical type.

value

Value of the overloaded numerical type.

class pyADiff.adjoint.ADRecord

Stores all operations of a computation in a list, preserving their order.

pyADiff.adjoint.ADTypeA
backpropagate()

Backpgropagation.

Backpropagates through all stored computations in reversed order.

record_variable(v)

Adds a variable to the record.

Parameters: v (ADTypeA) – Variable to record.
reset()

Resets the derivatives.

Resets the derivatives of all values to 0.

pyADiff.adjoint.dfdx(f, x_v)

This computes the derivative of f with respect to x at the position x_v. The signature of f is assumed to be:

{scalar, list, array} = f({scalar, list, array})


This function converts the inputs x_v to their respective ADTypeA, runs the function f and simultaneously creates the record of all operations. Then it successively sets the derivtive of the outputs y=f(x) to one and backpropgates through the record. Then the derivative value can be collected from the inputs x.

Only one forward run of f is necessary, no matter the dimension of x. The backpropagation is performed once for each output y.

Parameters: f (function_type) – The function to differentiate. x_v (scalar, list, array) – The value where to evaluate the derivative.

pyADiff.differentiation.derrev()