Class AlgorithmConstPowellOptBase
- java.lang.Object
-
- java.lang.Thread
-
- gov.nih.mipav.model.algorithms.AlgorithmBase
-
- gov.nih.mipav.model.algorithms.AlgorithmConstPowellOptBase
-
- All Implemented Interfaces:
de.jtem.numericalMethods.calculus.function.RealFunctionOfSeveralVariables
,java.awt.event.ActionListener
,java.awt.event.WindowListener
,java.lang.Runnable
,java.util.EventListener
- Direct Known Subclasses:
AlgorithmConstPowellOpt3D
public abstract class AlgorithmConstPowellOptBase extends AlgorithmBase implements de.jtem.numericalMethods.calculus.function.RealFunctionOfSeveralVariables
Powell's Method
Runs Powell's method. Powell's method is a way to find minimums without finding derivatives. Basically, it starts at some point P in N-dimensional space, proceeds in a direction, and minimizes along that line using a 1-dimensional minimization method. It continues like this until the point has moved by less than the tolerance. It starts with the initial point defined in the constructor and initial directions of (1 0 ... 0) (0 1 0 ... ) ..., the basis vectors. At the end, "point" is the best point found and functionAtBest is the value at "point".
This is an abstract class which contains many of the basic functions needed to run Powell's method. 2D and 3D versions extend this version.
This optimization technique is based on FLIRT. FLIRT stands for FMRIB's Linear Image Registration Tool. For more information on FLIRT, visit their homepage at http://www.fmrib.ox.ac.uk/fsl/flirt/. Their main paper is:
Jenkinson, M. and Smith, S. (2001a).
A global optimisation method for robust affine registration of brain images.
Medical Image Analysis, 5(2):143-156.
- Version:
- 0.1 Oct 1, 2001
- Author:
- Neva Cherniavsky
-
-
Field Summary
Fields Modifier and Type Field Description protected int
bracketBound
The initial bracket size for first iteration of Powell.protected AlgorithmOptimizeFunctionBase
costFunction
Cost function called to measure cost - 1D.protected double[]
finalPoint
Final point when optimization is complete.protected TransMatrixd
fromOrigin
The transformation matrix from the origin of the input image.protected double
functionAtBest
The cost of the function at the best minimum.protected int
maxIterations
The maximum number of iterations the optimization allows.protected ViewJProgressBar
myProgressBar
Progress bar that may be set for long optimization runs.protected int
nDims
Degress of freedom.protected AlgorithmBase
parent
Parent algorithm that called this optimization.protected double[]
point
Point that is currently being optimized.protected int
progressBegin
Where progress is when sent in.protected int
progressMax
The max the progress can go to.protected double[]
start
Point that was initially passed into function.protected boolean
success
Indicates whether the Powell algorithm succeeded in finding a minimum.protected double[]
tolerance
Array of tolerances for each dimension.protected TransMatrixd
toOrigin
The transformation matrix to the origin of the input image.protected float[][]
trLimits
Array of translation and rotation limits for each dimension.-
Fields inherited from class gov.nih.mipav.model.algorithms.AlgorithmBase
destFlag, destImage, image25D, mask, maxProgressValue, minProgressValue, multiThreadingEnabled, nthreads, progress, progressModulus, progressStep, runningInSeparateThread, separable, srcImage, threadStopped
-
-
Constructor Summary
Constructors Constructor Description AlgorithmConstPowellOptBase(AlgorithmBase parentAlgo, int degreeOfFreedom, AlgorithmOptimizeFunctionBase costFunc, double[] initial, double[] tols, int maxIter, int coords, int bracket)
Constructs a new algorithm with the given centers of mass (needed for setting the transformations), the given cost function (which was constructed with the proper images), the initial point we're looking at, and some tolerance within that point to look for the minimum.
-
Method Summary
All Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description abstract TransMatrixd
convertToMatrix(double[] vector)
Helper method that converts a vector with certain values set to a matrix.protected void
debugPoint(double[] point, java.lang.String message)
Method to display current point values.boolean
didSucceed()
Returns whether or not a minimum was found.void
disposeLocal()
Sets everything to null and prepares this class for destruction.double
eval(double[] x)
double
getCost()
Returns the cost of the best transformation.abstract double[]
getFinal()
Returns the final point with translations, rotations, scales, and skews representing the best Transformation.abstract double[]
getFinal(double[] point)
Returns the final point with translations, rotations, scales, and skews representing the best Transformation.abstract TransMatrixd
getMatrix()
Returns the matrix representing the best transformation.abstract TransMatrixd
getMatrix(double sample)
Returns the matrix representing the best transformation.int
getNumberOfVariables()
double[]
getPoint()
Returns the optimized point, with length == degrees of freedom.abstract void
measureCost()
Calls cost function with inputed point and saves result in functionAtBest.abstract void
setInitialPoint(double[] initial)
Sets the initial point to the value passed in.abstract void
setLimits(float[][] limits)
Sets the limits on rotation and translation.void
setMaxIterations(int max)
Sets the maximum number of iterations.-
Methods inherited from class gov.nih.mipav.model.algorithms.AlgorithmBase
actionPerformed, addListener, addProgressChangeListener, calculateImageSize, calculatePrincipleAxis, computeElapsedTime, computeElapsedTime, convertIntoFloat, delinkProgressToAlgorithm, delinkProgressToAlgorithmMulti, displayError, errorCleanUp, finalize, fireProgressStateChanged, fireProgressStateChanged, fireProgressStateChanged, fireProgressStateChanged, fireProgressStateChanged, generateProgressValues, getDestImage, getElapsedTime, getMask, getMaxProgressValue, getMinProgressValue, getNumberOfThreads, getProgress, getProgressChangeListener, getProgressChangeListeners, getProgressModulus, getProgressStep, getProgressValues, getSrcImage, isCompleted, isImage25D, isMultiThreadingEnabled, isRunningInSeparateThread, isThreadStopped, linkProgressToAlgorithm, linkProgressToAlgorithm, makeProgress, notifyListeners, removeListener, removeProgressChangeListener, run, runAlgorithm, setCompleted, setImage25D, setMask, setMaxProgressValue, setMinProgressValue, setMultiThreadingEnabled, setNumberOfThreads, setProgress, setProgressModulus, setProgressStep, setProgressValues, setProgressValues, setRunningInSeparateThread, setSrcImage, setStartTime, setThreadStopped, startMethod, windowActivated, windowClosed, windowClosing, windowDeactivated, windowDeiconified, windowIconified, windowOpened
-
Methods inherited from class java.lang.Thread
activeCount, checkAccess, clone, countStackFrames, currentThread, dumpStack, enumerate, getAllStackTraces, getContextClassLoader, getDefaultUncaughtExceptionHandler, getId, getName, getPriority, getStackTrace, getState, getThreadGroup, getUncaughtExceptionHandler, holdsLock, interrupt, interrupted, isAlive, isDaemon, isInterrupted, join, join, join, onSpinWait, resume, setContextClassLoader, setDaemon, setDefaultUncaughtExceptionHandler, setName, setPriority, setUncaughtExceptionHandler, sleep, sleep, start, stop, suspend, toString, yield
-
-
-
-
Field Detail
-
bracketBound
protected int bracketBound
The initial bracket size for first iteration of Powell.
-
costFunction
protected AlgorithmOptimizeFunctionBase costFunction
Cost function called to measure cost - 1D.
-
finalPoint
protected double[] finalPoint
Final point when optimization is complete.
-
fromOrigin
protected TransMatrixd fromOrigin
The transformation matrix from the origin of the input image.
-
functionAtBest
protected double functionAtBest
The cost of the function at the best minimum.
-
maxIterations
protected int maxIterations
The maximum number of iterations the optimization allows.
-
myProgressBar
protected ViewJProgressBar myProgressBar
Progress bar that may be set for long optimization runs.
-
nDims
protected int nDims
Degress of freedom.
-
parent
protected AlgorithmBase parent
Parent algorithm that called this optimization.
-
point
protected double[] point
Point that is currently being optimized.
-
progressBegin
protected int progressBegin
Where progress is when sent in.
-
progressMax
protected int progressMax
The max the progress can go to.
-
start
protected double[] start
Point that was initially passed into function.
-
success
protected boolean success
Indicates whether the Powell algorithm succeeded in finding a minimum.
-
tolerance
protected double[] tolerance
Array of tolerances for each dimension.
-
toOrigin
protected TransMatrixd toOrigin
The transformation matrix to the origin of the input image.
-
trLimits
protected float[][] trLimits
Array of translation and rotation limits for each dimension.
-
-
Constructor Detail
-
AlgorithmConstPowellOptBase
public AlgorithmConstPowellOptBase(AlgorithmBase parentAlgo, int degreeOfFreedom, AlgorithmOptimizeFunctionBase costFunc, double[] initial, double[] tols, int maxIter, int coords, int bracket)
Constructs a new algorithm with the given centers of mass (needed for setting the transformations), the given cost function (which was constructed with the proper images), the initial point we're looking at, and some tolerance within that point to look for the minimum. The initial point contains rotations, translations, scales, and skews.- Parameters:
parentAlgo
- DOCUMENT ME!degreeOfFreedom
- Degree of freedom for transformation (must be 3, 4, 6, 7, 9, or 12).costFunc
- Cost function to use.initial
- Initial point to start from, length of 12.tols
- Tolerance for each dimension (tols.length == degreeOfFreedom).maxIter
- The maximum iterations.coords
- 2 or 3 for 2D or 3Dbracket
- the bracket bound for the first iteration of powell
-
-
Method Detail
-
convertToMatrix
public abstract TransMatrixd convertToMatrix(double[] vector)
Helper method that converts a vector with certain values set to a matrix. For values not set, uses those in start variable.- Parameters:
vector
- Point with possible rotations, translations, etc. set.- Returns:
- Matrix representation of that point.
-
getFinal
public abstract double[] getFinal()
Returns the final point with translations, rotations, scales, and skews representing the best Transformation.- Returns:
- A vector representing the best transformation in terms of translations, rotations, scales, and skews.
-
getFinal
public abstract double[] getFinal(double[] point)
Returns the final point with translations, rotations, scales, and skews representing the best Transformation.- Returns:
- A vector representing the best transformation in terms of translations, rotations, scales, and skews.
-
getMatrix
public abstract TransMatrixd getMatrix()
Returns the matrix representing the best transformation.- Returns:
- A matrix representing the best transformation.
-
getMatrix
public abstract TransMatrixd getMatrix(double sample)
Returns the matrix representing the best transformation. The passed in parameter represents the resolution (same in all directions and for both input and reference images, since resampled isotropically). Since the optimization was done in pixel space, not millimeter space, the translation parameters need to be scaled by the sample value.- Parameters:
sample
- Sample size.- Returns:
- A matrix representing the best transformation.
-
measureCost
public abstract void measureCost()
Calls cost function with inputed point and saves result in functionAtBest.
-
setInitialPoint
public abstract void setInitialPoint(double[] initial)
Sets the initial point to the value passed in.- Parameters:
initial
- Initial point.
-
setLimits
public abstract void setLimits(float[][] limits)
Sets the limits on rotation and translation.- Parameters:
limits
- limits
-
didSucceed
public boolean didSucceed()
Returns whether or not a minimum was found.- Returns:
- whether or not a minimum was found.
-
disposeLocal
public void disposeLocal()
Sets everything to null and prepares this class for destruction.
-
getCost
public double getCost()
Returns the cost of the best transformation.- Returns:
- The cost of the best transformation.
-
getPoint
public double[] getPoint()
Returns the optimized point, with length == degrees of freedom.- Returns:
- The optimized point.
-
setMaxIterations
public void setMaxIterations(int max)
Sets the maximum number of iterations.- Parameters:
max
- The max number of iterations.
-
debugPoint
protected void debugPoint(double[] point, java.lang.String message)
Method to display current point values.- Parameters:
point
- DOCUMENT ME!message
- DOCUMENT ME!
-
eval
public double eval(double[] x)
- Specified by:
eval
in interfacede.jtem.numericalMethods.calculus.function.RealFunctionOfSeveralVariables
-
getNumberOfVariables
public int getNumberOfVariables()
- Specified by:
getNumberOfVariables
in interfacede.jtem.numericalMethods.calculus.function.RealFunctionOfSeveralVariables
-
-