Dual:
Filter:
Classes (extension) | Math

Dual
ExtensionExtension

Automatic Differentiation (forward mode)
Location: NOT INSTALLED!

Description

Because automatic differentiation coincides with the algebra of the so called dual numbers (found by William Clifford in 1873), we can make use of this general concept here. Dual numbers in the form a + b\epsilon resemble complex numbers a + bi, but while i^2 = -1, the second component in dual numbers vanishes: \epsilon^2 = 0. This "magically" leads to an algebra of derivatives.

The implementation idea follows Jerzy Karczmarczuk 1998, "Functional differentiation of computer programs".

In order to find the derivative of a function, there are three approaches:

NOTE: This is a reasonably well-tested, but preliminary version. Names (like instance variables or argument names) and functionality may change.

Calling operations on derivatives apply the chain rule and keep track of resulting reals and duals:

This is valid for Arrays:

It is also valid for UGens:

Class Methods

.new

Return a new instance.

Arguments:

real

The real part of the number, which may be any number class or a UGen.

dual

The dual (derivative) part of the number, which may be any number class or a UGen. In algebra, this is called \epsilon (epsilon).

.approximate

Approximate a derivative numerically where no automatic method is implemented yet. Numerical approximation may fail to converge well in some cases, so you can't rely on it.

Inherited class methods

Instance Methods

.real

Return the real part of the number, which carries the result of any past operations.

.dual

Return the dual part of the number, which carries the derivative that follows from all past operations.

<

Returns true if the real part of the receiver is smaller than the real part of the argument.

.differentiationStep

A delta that can be used for approximating a derivative numerically where no automatic method is implemented yet. It can be adjusted to improve this approximation.

Conversions

NOTE: Mixed operations are not yet fully implemented and may therefore not be commutative.

.asDual

Convert receiver to a Dual. In this case, it is already one, so return this. For other classes, it returns Dual(receiver, 0)

.asComplex

Returns a Complex with the real part as the receiver, and the imaginary part as Dual(0, 0).

.asPolar

Returns a Polar with rho (radius) as the receiver and theta as Dual(0, 0).

.asPoint

Returns a Point with the x coordinate as the receiver and the y coordinate as Dual(0, 0).

Inherited instance methods

Examples

Unit tests

You need the UnitTest class to run these.