ca.nengo.math.impl
Class NumericallyDifferentiableFunction

java.lang.Object
  extended by ca.nengo.math.impl.NumericallyDifferentiableFunction
All Implemented Interfaces:
DifferentiableFunction, Function, java.io.Serializable, java.lang.Cloneable

public class NumericallyDifferentiableFunction
extends java.lang.Object
implements DifferentiableFunction

A wrapper around any Function that provides a numerical approximation of its derivative, so that it can be used as a DifferentiableFunction. A Function should provide its exact derivative if available, rather than forcing callers to rely on this wrapper. TODO: test

Author:
Bryan Tripp
See Also:
Serialized Form

Nested Class Summary
static class NumericallyDifferentiableFunction.NumericalDerivative
           
 
Constructor Summary
NumericallyDifferentiableFunction()
          Uses dummy parameters to allow setting after construction.
NumericallyDifferentiableFunction(Function function, int derivativeDimension, float delta)
           
 
Method Summary
 Function clone()
           
 float getDelta()
           
 Function getDerivative()
           
 int getDerivativeDimension()
           
 int getDimension()
          Passed through to underlying Function.
 Function getFunction()
           
 float map(float[] from)
          Passed through to underlying Function.
 float[] multiMap(float[][] from)
          Passed through to underlying Function.
 void setFunction(Function function)
           
 
Methods inherited from class java.lang.Object
equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

NumericallyDifferentiableFunction

public NumericallyDifferentiableFunction(Function function,
                                         int derivativeDimension,
                                         float delta)
Parameters:
function - An underlying Function
derivativeDimension - The dimension along which the derivative is to be calculated (note that the gradient of a multi-dimensional Function consists of multiple DifferentiableFunctions)
delta - Derivative approximation of f(x) is [f(x+delta)-f(x-delta)]/[2*delta]

NumericallyDifferentiableFunction

public NumericallyDifferentiableFunction()
Uses dummy parameters to allow setting after construction.

Method Detail

getDerivative

public Function getDerivative()
Specified by:
getDerivative in interface DifferentiableFunction
Returns:
A numerical approximation of the derivative
See Also:
DifferentiableFunction.getDerivative()

getDimension

public int getDimension()
Passed through to underlying Function.

Specified by:
getDimension in interface Function
Returns:
Dimension of the space that the Function maps from
See Also:
Function.getDimension()

getFunction

public Function getFunction()
Returns:
The underlying Function

setFunction

public void setFunction(Function function)
Parameters:
function - A new underlying Function

getDerivativeDimension

public int getDerivativeDimension()
Returns:
The dimension along which the derivative is to be calculated

getDelta

public float getDelta()
Returns:
Delta in derivative approximation [f(x+delta)-f(x-delta)]/[2*delta]

map

public float map(float[] from)
Passed through to underlying Function.

Specified by:
map in interface Function
Parameters:
from - Must have same length as getDimension()
Returns:
result of function operation on arg
See Also:
Function.map(float[])

multiMap

public float[] multiMap(float[][] from)
Passed through to underlying Function.

Specified by:
multiMap in interface Function
Parameters:
from - An array of arguments; each element must have length getDimension().
Returns:
Array of results of function operation on each arg
See Also:
Function.multiMap(float[][])

clone

public Function clone()
               throws java.lang.CloneNotSupportedException
Specified by:
clone in interface Function
Overrides:
clone in class java.lang.Object
Throws:
java.lang.CloneNotSupportedException