Class CDOptimizeBase

  • Direct Known Subclasses:
    CDOptimizeBFGS, CDOptimizeCG, CDOptimizePS, CDOptimizeSA, CDOptimizeSD

    public abstract class CDOptimizeBase
    extends java.lang.Object
    This is the Java modified version of C++ active appearance model API (AAM_API). It is modified with a subset of required functions for automatic MRI prostate segmentation. AAM-API LICENSE - file: license.txt This software is freely available for non-commercial use such as research and education. Please see the full disclaimer below. All publications describing work using this software should cite the reference given below. Copyright (c) 2000-2003 Mikkel B. Stegmann, mbs@imm.dtu.dk IMM, Informatics & Mathematical Modelling DTU, Technical University of Denmark Richard Petersens Plads, Building 321 DK-2800 Lyngby, Denmark http://www.imm.dtu.dk/~aam/ REFERENCES Please use the reference below, when writing articles, reports etc. where the AAM-API has been used. A draft version the article is available from the homepage. I will be happy to receive pre- or reprints of such articles. /Mikkel ------------- M. B. Stegmann, B. K. Ersboll, R. Larsen, "FAME -- A Flexible Appearance Modelling Environment", IEEE Transactions on Medical Imaging, IEEE, 2003 (to appear) ------------- 3RD PART SOFTWARE The software is partly based on the following libraries: - The Microsoft(tm) Vision Software Developers Kit, VisSDK - LAPACK DISCLAIMER This software is provided 'as-is', without any express or implied warranty. In no event will the author be held liable for any damages arising from the use of this software. Permission is granted to anyone to use this software for any non-commercial purpose, and to alter it, subject to the following restrictions: 1. The origin of this software must not be misrepresented; you must not claim that you wrote the original software. 2. Altered source versions must be plainly marked as such, and must not be misrepresented as being the original software. 3. This notice may not be removed or altered from any source distribution. -- No guarantees of performance accompany this software, nor is any responsibility assumed on the part of the author or IMM. This software is provided by Mikkel B. Stegmann and IMM ``as is'' and any express or implied warranties, including, but not limited to, the implied warranties of merchantability and fitness for a particular purpose are disclaimed. In no event shall IMM or Mikkel B. Stegmann be liable for any direct, indirect, incidental, special, exemplary, or consequential damages (including, but not limited to, procurement of substitute goods or services; loss of use, data, or profits; or business interruption) however caused and on any theory of liability, whether in contract, strict liability, or tort (including negligence or otherwise) arising in any way out of the use of this software, even if advised of the possibility of such damage. $Revision: 1.4 $ $Date: 2003/04/23 14:49:15 $ Optimization base class. This abstract class is the base class for all classes implementing specific optimization procedures. author: Rune Fisker, 26/1-1999
    Author:
    Ruida Cheng
    • Constructor Summary

      Constructors 
      Constructor Description
      CDOptimizeBase()
      Constructor
    • Method Summary

      All Methods Instance Methods Abstract Methods Concrete Methods 
      Modifier and Type Method Description
      double EvalFunction​(CDVector x)
      function and gradient evaluation methods
      void EvalGradient​(CDVector x, CDVector gc, double dFuncVal)
      function and gradient evaluation methods
      int ExactLineSearch​(CDVector xc, double fc, CDVector g, CDVector p, CDVector xplus, double[] fplus, boolean[] maxtaken)
      Perform exact line search Input: xc: parameter fc: function value at xc g: gradient at xc p: search direction Output: xplus: new parameter fplus: function value for new parameter maxtaken: max taken in line search return termination code
      CDOptimizeFuncBase GetFuncEvalBase()
      get point to func eval. base.
      int LineSearch​(CDVector xc, double fc, CDVector g, CDVector p, CDVector xplus, double[] fplus, boolean[] maxtaken)
      Warpper for line search
      int LineSearch​(CDVector xc, double fc, CDVector g, CDVector p, CDVector xplus, double[] fplus, boolean[] maxtaken, boolean fSoft)  
      int MaxFuncEval()
      get the number of evaluations
      int MaxIterations()
      get limit for the number of iterations
      CDVector MethodPar()
      get numerical gradient function
      abstract int Minimize​(CDVector x, CDOptimizeFuncBase pFuncEvalBase)
      the Minimize function using analytic gradient
      int MinimizeNum​(CDVector x, CDOptimizeFuncBase pFuncEvalBase, CDVector vMethodPar)  
      java.lang.String Name()
      name of optimization methode
      void NumGrad​(CDVector x, CDVector gradient, double dFuncVal)
      calculate nummerical gradient function usingdecided gradient calculation method input: x: parameter dFuncVal: function value in x output: gradient: gradient
      int OptMethod()
      name of optimization method
      void SetFuncEvalBase​(CDOptimizeFuncBase pFuncEval)
      set point to func eval. base.
      void SetMachineEps()
      ----------------------------[ MachineEps ]---------------------------- Calculate machine epsilon Algorithm A1.3.1 - p. 303 Dennis and Schnabel, Numerical Methods for Unconstrained Optimization and Nonlinear Equations 1983, Prentice-Hall
      void SetMaxFuncEval​(int nMaxFuncEval)
      set limit for the number of function evaluations
      void SetMaxIterations​(int nMaxIterations)
      set limit for the number of iterations
      void SetMethodPar​(CDVector vMethodPar)
      set numerical gradient function
      int SoftLineSearch​(CDVector xc, double fc, CDVector g, CDVector sn, CDVector xplus, double[] fplus, boolean[] maxtaken)
      Perform line search Given g'p
      int UmStop​(CDVector x, CDVector xplus, double f, double fplus, CDVector g, int retcode, boolean maxtaken)
      Decide wether to terminate minimization Modified version of Algorithm A7.2.1 p. 347 Dennis and Schnabel, Numerical Methods for Unconstrained Optimization and Nonlinear Equations 1983, Prentice-Hall Input: x: parameter xplus: new parameter fplus: function value for new parameter g: gradient at x retcode: return code from line search maxtaken: max taken in line search Output: return termination code
      int UmStop0​(CDVector x0, double functionValue, CDVector gradient)  
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Field Detail

      • ENumGrad

        public int ENumGrad
      • ForwardDifference

        public static int ForwardDifference
      • CentralDifference

        public static int CentralDifference
      • FitLine

        public static int FitLine
      • EOptMethod

        public int EOptMethod
      • eoptUnknown

        public static int eoptUnknown
      • eoptSteepestDescent

        public static int eoptSteepestDescent
      • eoptConjugateGradient

        public static int eoptConjugateGradient
      • eoptBFGS

        public static int eoptBFGS
      • eoptSimulatedAnnealing

        public static int eoptSimulatedAnnealing
      • eoptPatternSearch

        public static int eoptPatternSearch
      • ETermCode

        public int ETermCode
      • etermNoStop

        public static int etermNoStop
      • etermGradTol

        public static int etermGradTol
      • etermStepTol

        public static int etermStepTol
      • etermLineSearch

        public static int etermLineSearch
      • etermConsecMaxStepMax

        public static int etermConsecMaxStepMax
      • etermDeltaFuncVal

        public static int etermDeltaFuncVal
      • etermMaxFuncEval

        public static int etermMaxFuncEval
      • etermMaxIterations

        public static int etermMaxIterations
      • etermUnknown

        public static int etermUnknown
      • m_dMachEps

        public double m_dMachEps
        Machine precision
      • m_dTypF

        public double m_dTypF
        positive scalar estimating the magnitude of f(x) near he minimizer x-star. It is only used in the gradient stopping condition given below. typf should be approximately |f(x*)|
      • m_nFDigits

        public int m_nFDigits
        A positive integer specifying the number of reliable digits returned by the objective function FN. fdigits is used to set the parameter n (eta) that is used in the code to specify the relative noise in f(x); the main use of eta is in calculation finite difference step size. eta is set to macheps if fdigits = -1. If f(x) is suspected to be noisy but the approximate value of fdigits is unknown, it should be estimated be the routine of Hamming[1973] given in Gill, Murray and Wright[1981]
      • m_dMaxStep

        public double m_dMaxStep
        A positive scalar giving the maximum allowable scaled steplength at any iteration. maxstep is used to prevent steps that would cause the optimazation algorithm to overflow or leave the domain of interest, as well as to detect divergence. It should be chosen small enough to prevent the first two of these occurrences but larger than any anticipated reasonable stepsize. The algorithm will halt if it takes steps of length maxstep on m_nConsecMaxStepMax conseccutive iterations
      • m_nConsecMax

        public int m_nConsecMax
        Number of conseccutive past steps whose scaled length was equal to maxstep
      • m_dEta

        public double m_dEta
        machine precision.
      • m_fAnalyticGrad

        public boolean m_fAnalyticGrad
        flag indicating if the gradient is to be calc. analyticaly or nummericaly
      • m_eNumGrad

        public int m_eNumGrad
        methods for estimating the gradient nummericaly
      • m_iStopCriteria

        public int m_iStopCriteria
        holds the stop criteria in use, e.g m_iStopCriteria = etermMaxFuncEval | etermMaxIterations
      • m_dGradTol

        public double m_dGradTol
        A positive scalar giving the tolerance at which the scaled gradient in considered close enough to zero to terminate the algorithm
      • m_dStepTol

        public double m_dStepTol
        A positive scalar giving the tolerance at which the scaled distance between two successive iterated is considered close enough to zero to terminate the algorithm
      • m_nConsecMaxStepMax

        public int m_nConsecMaxStepMax
        max number of conseccutive past steps whose scaled length was equal to maxstep to terminate
      • m_dDeltaFuncVal

        public double m_dDeltaFuncVal
        value for stop criterion: abs(f - fplus)
        • m_nIterations

          public int m_nIterations
          counter to the number of iterations.
        • m_nFuncEval

          public int m_nFuncEval
          counter to the number of function evaluations.
        • m_nGradEval

          public int m_nGradEval
          counter to the number of gradient evaluations.
        • m_fLogFuncValues

          public boolean m_fLogFuncValues
          Logical variable which determines whether function parameters and corresponding return values should be stored for later analysis.
        • m_vFuncVal

          public CDVector m_vFuncVal
        • m_vNFuncEval

          public CDVector m_vNFuncEval
        • m_vvFuncParm

          public java.util.Vector<CDVector> m_vvFuncParm
        • m_pFuncEvalBase

          private CDOptimizeFuncBase m_pFuncEvalBase
          pointer to the function to be minimized.
        • m_vMethodPar

          private CDVector m_vMethodPar
          special parameters used by each optimization method e.g. step size used for calc. nummerical gradient
        • m_nMaxIterations

          private int m_nMaxIterations
          A positive integer specifying the maximum number of iterations that may be performed before the algorithm is halted. Appropriate values depend strongly on the dimension and difficulty of the problem, and the cost of evaluating the nonlinear function.
        • m_nMaxFuncEval

          private int m_nMaxFuncEval
          limit for number of function evaluations.
        • Constructor Detail

          • CDOptimizeBase

            public CDOptimizeBase()
            Constructor
        • Method Detail

          • Minimize

            public abstract int Minimize​(CDVector x,
                                         CDOptimizeFuncBase pFuncEvalBase)
            the Minimize function using analytic gradient
            Parameters:
            x -
            pFuncEvalBase -
            Returns:
          • Name

            public java.lang.String Name()
            name of optimization methode
            Returns:
          • OptMethod

            public int OptMethod()
            name of optimization method
          • EvalFunction

            public double EvalFunction​(CDVector x)
            function and gradient evaluation methods
            Parameters:
            x -
            Returns:
          • EvalGradient

            public void EvalGradient​(CDVector x,
                                     CDVector gc,
                                     double dFuncVal)
            function and gradient evaluation methods
            Parameters:
            x -
            gc -
            dFuncVal -
          • MethodPar

            public CDVector MethodPar()
            get numerical gradient function
            Returns:
          • SetMethodPar

            public void SetMethodPar​(CDVector vMethodPar)
            set numerical gradient function
            Parameters:
            vMethodPar -
          • MaxIterations

            public int MaxIterations()
            get limit for the number of iterations
            Returns:
          • MaxFuncEval

            public int MaxFuncEval()
            get the number of evaluations
            Returns:
          • SetFuncEvalBase

            public void SetFuncEvalBase​(CDOptimizeFuncBase pFuncEval)
            set point to func eval. base.
            Parameters:
            pFuncEval -
          • GetFuncEvalBase

            public CDOptimizeFuncBase GetFuncEvalBase()
            get point to func eval. base.
            Returns:
          • SetMaxIterations

            public void SetMaxIterations​(int nMaxIterations)
            set limit for the number of iterations
            Parameters:
            nMaxIterations - max iterations
          • SetMaxFuncEval

            public void SetMaxFuncEval​(int nMaxFuncEval)
            set limit for the number of function evaluations
            Parameters:
            nMaxFuncEval - max number of evaluations.
          • SetMachineEps

            public void SetMachineEps()
            ----------------------------[ MachineEps ]---------------------------- Calculate machine epsilon Algorithm A1.3.1 - p. 303 Dennis and Schnabel, Numerical Methods for Unconstrained Optimization and Nonlinear Equations 1983, Prentice-Hall
          • UmStop0

            public int UmStop0​(CDVector x0,
                               double functionValue,
                               CDVector gradient)
          • UmStop

            public int UmStop​(CDVector x,
                              CDVector xplus,
                              double f,
                              double fplus,
                              CDVector g,
                              int retcode,
                              boolean maxtaken)
            Decide wether to terminate minimization Modified version of Algorithm A7.2.1 p. 347 Dennis and Schnabel, Numerical Methods for Unconstrained Optimization and Nonlinear Equations 1983, Prentice-Hall Input: x: parameter xplus: new parameter fplus: function value for new parameter g: gradient at x retcode: return code from line search maxtaken: max taken in line search Output: return termination code
          • LineSearch

            public int LineSearch​(CDVector xc,
                                  double fc,
                                  CDVector g,
                                  CDVector p,
                                  CDVector xplus,
                                  double[] fplus,
                                  boolean[] maxtaken)
            Warpper for line search
            Parameters:
            xc - parameter
            fc - function value at xc
            g - gradient at xc
            p - search direction
            xplus - new parameter
            fplus - function value for new parameter
            maxtaken - max taken in line search
            Returns:
            termination code
          • LineSearch

            public int LineSearch​(CDVector xc,
                                  double fc,
                                  CDVector g,
                                  CDVector p,
                                  CDVector xplus,
                                  double[] fplus,
                                  boolean[] maxtaken,
                                  boolean fSoft)
          • ExactLineSearch

            public int ExactLineSearch​(CDVector xc,
                                       double fc,
                                       CDVector g,
                                       CDVector p,
                                       CDVector xplus,
                                       double[] fplus,
                                       boolean[] maxtaken)
            Perform exact line search Input: xc: parameter fc: function value at xc g: gradient at xc p: search direction Output: xplus: new parameter fplus: function value for new parameter maxtaken: max taken in line search return termination code
          • SoftLineSearch

            public int SoftLineSearch​(CDVector xc,
                                      double fc,
                                      CDVector g,
                                      CDVector sn,
                                      CDVector xplus,
                                      double[] fplus,
                                      boolean[] maxtaken)
            Perform line search Given g'p
            • NumGrad

              public void NumGrad​(CDVector x,
                                  CDVector gradient,
                                  double dFuncVal)
              calculate nummerical gradient function usingdecided gradient calculation method input: x: parameter dFuncVal: function value in x output: gradient: gradient