Facemorph
Class Powell

java.lang.Object
  extended by Facemorph.Powell
Direct Known Subclasses:
CAAMPowell, GLGroupwiseImageRegistration, GroupwiseImageRegistration, GroupwiseImageRegistrationLinear, MDL2D

public abstract class Powell
extends java.lang.Object

Implements Powells method, classes should subclass this and implement the func and onIteration methods to use


Field Summary
static double TINY
          A very small amount
 
Constructor Summary
Powell()
          Creates a new instance of Powell
 
Method Summary
abstract  double func(double[] params)
          Func should be overrided to calculate the error given the parameters params
 void linmin(double[] p, double[] xi, int n, double[] fret)
          Given an n-dimensional point p[1..n] and an n-dimensional direction xi[1..n], moves and resets p to where the function func(p) takes on a minimum along the direction xi from p, and replaces xi by the actual vector displacement that p was moved.
abstract  void onIteration(double[] params)
          onIteration is called once per complete itrations to show the best current guess.
 void optimiseGA(double[] p, int samples, double mutationRate, boolean keepBest, int maxIts)
          Genetic algorith optimisation
 void powell(double[] p, double[][] xi, int n, double ftol, int[] iter, double[] fret, int maxits)
          Minimization of a function func of n variables.
 double powell(double[] p, double ftol, int[] iter, int maxits)
          Minimization of a function func of n variables.
 void spsa(double[] p, double a, double c, double A, double alpha, double gamma, double ftol, int maxIts)
          Implements basic Simultaneous Perturbation Stochastic Approximation (SPSA) algortihm
 void spsa2(double[] p, double a, double c, double A, double alpha, double gamma, double ftol, int maxIts)
          Implements basic Simultaneous Perturbation Stochastic Approximation (SPSA) algortihm
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

TINY

public static final double TINY
A very small amount

See Also:
Constant Field Values
Constructor Detail

Powell

public Powell()
Creates a new instance of Powell

Method Detail

func

public abstract double func(double[] params)
Func should be overrided to calculate the error given the parameters params

Parameters:
params - the parameters to evaluate
Returns:
returns the error

onIteration

public abstract void onIteration(double[] params)
onIteration is called once per complete itrations to show the best current guess. It can be implemented with an empty body if not needed

Parameters:
params - the current params of the model

optimiseGA

public void optimiseGA(double[] p,
                       int samples,
                       double mutationRate,
                       boolean keepBest,
                       int maxIts)
Genetic algorith optimisation

Parameters:
p - the initial start point (mutated and bred with itself to form the initial population
samples - number of samples in each generation
mutationRate - mutation rate as fraction
keepBest - keep the optimal from each generation, or not
maxIts - maximum number of iterations

powell

public double powell(double[] p,
                     double ftol,
                     int[] iter,
                     int maxits)
              throws PowellException
Minimization of a function func of n variables. Input consists of an initial starting point p[1..n]; an initial matrix xi[1..n][1..n] is generated initial set of directions(the n unit vectors); and ftol, the fractional tolerance in the function value such that failure to decrease by more than this amount on one iteration signals doneness. On output, p is set to the best point found, xi is the then-current direction set, fret is the returned function value at p, and iter is the number of iterations taken. The routine linmin is used.

Parameters:
p - starting point
iter - number of iterations taken
ftol - the fractional tolerance in the function value
maxits - maximum number of iterations permitted
Returns:
the function evaluated at the final point
Throws:
PowellException - if something goes wrong e.g. max iterations exceeded

powell

public void powell(double[] p,
                   double[][] xi,
                   int n,
                   double ftol,
                   int[] iter,
                   double[] fret,
                   int maxits)
            throws PowellException
Minimization of a function func of n variables. Input consists of an initial starting point p[1..n]; an initial matrix xi[1..n][1..n], whose columns contain the initial set of directions(usually the n unit vectors); and ftol, the fractional tolerance in the function value such that failure to decrease by more than this amount on one iteration signals doneness. On output, p is set to the best point found, xi is the then-current direction set, fret is the returned function value at p, and iter is the number of iterations taken. The routine linmin is used.

Parameters:
p - starting point
n - size of vectors
xi - initial direction set
fret - returned function value at final point
iter - number of iterations taken
ftol - the fractional tolerance in the function value
maxits - maximum number of iterations permitted
Throws:
PowellException - if something goes wrong e.g. max iterations exceeded

spsa

public void spsa(double[] p,
                 double a,
                 double c,
                 double A,
                 double alpha,
                 double gamma,
                 double ftol,
                 int maxIts)
Implements basic Simultaneous Perturbation Stochastic Approximation (SPSA) algortihm

Parameters:
p - the initial guess, will also contain the output estimate
a -
c -
A -
alpha -
gamma -
ftol - termination parameter
maxIts - number of iterations to compute (should be replaced with termination condition)

spsa2

public void spsa2(double[] p,
                  double a,
                  double c,
                  double A,
                  double alpha,
                  double gamma,
                  double ftol,
                  int maxIts)
Implements basic Simultaneous Perturbation Stochastic Approximation (SPSA) algortihm

Parameters:
p - the initial guess, will also contain the output estimate
a -
c -
A -
alpha -
gamma -
ftol - related to the termination condition, change in error should be below this
maxIts - number of iterations to compute (should be replaced with termination condition)

linmin

public void linmin(double[] p,
                   double[] xi,
                   int n,
                   double[] fret)
            throws PowellException
Given an n-dimensional point p[1..n] and an n-dimensional direction xi[1..n], moves and resets p to where the function func(p) takes on a minimum along the direction xi from p, and replaces xi by the actual vector displacement that p was moved. Also returns as fret the value of func at the returned location p. This is actually all accomplished by calling the routines mnbrak and brent.

Parameters:
p - an n-dimensional point, used for output
xi - an n-dimensional direction
n - the dimensions of the search space
fret - returns the value of func at the returned location p
Throws:
PowellException - if there is a problem