DerivativeNumber:
Filter:
DerivativeNumber (extension) | Math

DerivativeNumber
ExtensionExtension

Automatic Differentiation

Description

DerivativeNumber implements forward automatic differentiation.

It 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 derivatives:

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.

derivative

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

.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.

Instance Methods

.real

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

.derivative

Return the derivative 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

.asDerivative

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

.asComplex

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

.asPolar

Returns a Complex with rho (radius) as the receiver and theta as DerivativeNumber(0, 0).

.asPoint

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

Examples

Unit tests

You need the UnitTest class to run these.