nr
Class VecFunction

java.lang.Object
  extended by nr.VecFunction

public abstract class VecFunction
extends java.lang.Object

A functionoid designed to implement a vector function of a vector

Author:
Daniel Wachsstock

Constructor Summary
VecFunction()
           
 
Method Summary
 Vec eval(Vec x)
          a vector function of a vector.
abstract  Vec eval(Vec x, Vec y)
          a vector function of a vector.
 Mat jacobian(Vec x)
          Calculates the Jacobian for this function.
 Mat jacobian(Vec x, Mat jac)
          Calculates the Jacobian for this function.
 double jacobianCost()
          The computational cost of evaluating the Jacobian.
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

VecFunction

public VecFunction()
Method Detail

eval

public abstract Vec eval(Vec x,
                         Vec y)
a vector function of a vector.

Parameters:
x - the independent variable
y - the resulting dependent vector. if y == null, a new Vec will be created
Returns:
y

eval

public Vec eval(Vec x)
a vector function of a vector. Should have the same result as eval(Vec,Vec) with y == null. The default implementation just does that.

Parameters:
x - the independent variable
Returns:
the result

jacobianCost

public double jacobianCost()
The computational cost of evaluating the Jacobian. Some algorithms make decisions on how hard a calculation is, so this function should return the ratio of computer time in calling jacobian(nr.Vec, nr.Mat) to eval(nr.Vec, nr.Vec). For the most part this can be ignored. This will usually depend on the size of the input vector, so is unknowable to a generic implementation, so the default implementation throws an Error. If it is needed, it must be implemented (how to get the necessary information is up to you).

For the default jacobian, jacobianCost = 2*x.size() (jacobian calls eval twice for every element of the input vector).

Returns:
the relative cost of evaluating the Jacobian

jacobian

public Mat jacobian(Vec x,
                    Mat jac)
Calculates the Jacobian for this function. Assumes that eval(x) has the same size as x, though that is not imposed by the specification of eval. if f = eval(x) and j = jacobian(x), then j[i][j] = df[i]/dx[j]. In the default implementation, it is calculated by symmetric finite differencing, as in Numerical Recipes eq. 5.7.7. This involves 2*x.size() calls to eval.

Parameters:
x - the independent variable
jac - the the jacobian of eval. If jac == null, a new Mat will be created
Returns:
jac

jacobian

public Mat jacobian(Vec x)
Calculates the Jacobian for this function. Should have the same result as (Vec, Mat) with jac == null. The default implementation does just that.

Parameters:
x - the independent variable
Returns:
the jacobian