org.apache.commons.nabla.algorithmic.forward
Class ForwardAlgorithmicDifferentiator

java.lang.Object
  extended by org.apache.commons.nabla.algorithmic.forward.ForwardAlgorithmicDifferentiator
All Implemented Interfaces:
UnivariateDifferentiator

public class ForwardAlgorithmicDifferentiator
extends Object
implements UnivariateDifferentiator

Automatic differentiator class based on bytecode analysis.

This class is an implementation of the UnivariateDifferentiator interface that computes exact differentials completely automatically and generate java classes and instances that compute the differential of the function as if they were hand-coded and compiled.

The derivative bytecode created the first time an instance of a given class is differentiated is cached and will be reused if other instances of the same class are to be created later. The cache can also be dumped in a jar file for use in an application without bringing the full nabla library and its dependencies.

This differentiator can handle only pure bytecode methods and known methods from math implementation classes like Math or StrictMath. Pure bytecode methods are analyzed and converted. Methods from math implementation classes are only recognized by class and name and replaced by predefined derivative code.

See Also:
FetchDifferentiator

Constructor Summary
ForwardAlgorithmicDifferentiator()
          Simple constructor.
 
Method Summary
 void addMathImplementation(Class<?> mathClass)
          Add an implementation class for mathematical functions.
 UnivariateDerivative differentiate(UnivariateDifferentiable d)
          Create an implementation of a differential for a differentiable function.
 void dumpCache(OutputStream out)
          Dump the cache into a stream.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

ForwardAlgorithmicDifferentiator

public ForwardAlgorithmicDifferentiator()
Simple constructor.

Build a ForwardAlgorithmicDifferentiator instance with an empty cache.

Method Detail

addMathImplementation

public void addMathImplementation(Class<?> mathClass)
Add an implementation class for mathematical functions.

At construction, the differentiator considers only the Math and StrictMath classes are math implementation classes. It may be useful to add other class for example to add some missing functions like inverse hyperbolic cosine that are not provided by the standard java classes as of Java 1.6.

Parameters:
mathClass - implementation class for mathematical functions

dumpCache

public void dumpCache(OutputStream out)
Dump the cache into a stream.

Parameters:
out - output stream where to dump the cache

differentiate

public UnivariateDerivative differentiate(UnivariateDifferentiable d)
                                   throws DifferentiationException
Create an implementation of a differential for a differentiable function.

Specified by:
differentiate in interface UnivariateDifferentiator
Parameters:
d - differentiable function to differentiate
Returns:
derivative function
Throws:
DifferentiationException - if the class cannot be differentiated


Copyright © 2008-2009 The Apache Software Foundation. All Rights Reserved.