#ifndef NUMOPTSIMMANNCONTINUOUS_HH #define NUMOPTSIMMANNCONTINUOUS_HH //////////////////////////////////////////////////////////////////////////// //! lib=NumOptimise //! docentry="Optimisation;Numerical Methods.Optimisation" //! file="amma/PatternRec/Optimise/NumOptSimmAnnContinuous.hh" //! userlevel=Default //! rcsid="$Id: NumOptSimmAnnContinuous.hh,v 1.2 2000/07/06 08:11:30 eevsspsoft Exp $" #include "amma/Num/NumOptimiseB.hh" class SimplexC; // -------------------------------------------------------------------------- // ********** NumOptSimmAnnContinuousBC *********************************** // -------------------------------------------------------------------------- //: Simulated Annealing for continuous optimisation implementation class. // // This is the implementation class of the Simulated Annealing optimiser for continuous spaces. Please refer to Section 10.9 of Numerical Recipes in C for description. class NumOptSimmAnnContinuousBC: public NumOptimiseBC { UIntT _iterations; RealT Tau; RealT minTemp; RealT ftol; int idum; public: NumOptSimmAnnContinuousBC (UIntT iterations, RealT Tau, RealT minTemp, RealT ftol); //: Constructor //!param: iterations - maximum number of iterations to be used at each temperature //!param: Tau - constant //!param: minTemp - the minimum temperature to be used during the annealing schedule //!param: ftol - the accepted tolerance for early exit NumOptSimmAnnContinuousBC (istream &in); //: Constructs from stream NumOptSimmAnnContinuousBC (const NumOptSimmAnnContinuousBC &oth); //: Copy constructor virtual BodyRefCounterVC & Copy () const; //: Makes a deep copy and is virtual protected: VectorC GetRandomX(const VectorC & X, const VectorC & minX, const VectorC & maxX) const; //: return a random vector VectorC MinimalX (const NumCostC &domain); //: Determines Xmin=arg min_{X} |f(X)-Yd| virtual const StringC GetInfo () const; //: Prints information about the optimiser virtual BooleanT Save (ostream &out) const; //: Writes object to stream, can be loaded using constructor friend class NumOptSimmAnnContinuousC; //: Handle class private: RealT ExtrapolateAndReplace (RealT fac, const NumCostC &domain, SimplexC & simplex, RealT tt, VectorC & pbest, RealT & ybest); // Extrapolates by a factor 'fac' through the face of the simplex across from the high point; replace the high point if the new point is better. void MultiContractAndReplace (const NumCostC &domain, SimplexC & simplex) const; // Contract around the best point; update the simplex void SetInitialValues (const NumCostC &domain, SimplexC & simplex) const; // Calculate and set the cost of each vertex in the simplex. void RandomizeSimplex (SimplexC & simplex, RealT temp); // Add a thermal random fluctuation to the values in the simplex }; //////////////////////////////////////////////////////////////////////////// //! lib=NumOptimise //! docentry="Optimisation;Numerical Methods.Optimisation" #include "amma/Num/NumOptimise.hh" //: Metropolis optimiser implementation class. // // This is the implementation class of the Metropolis optimiser. This is a stochastic algorithm in which uphill moves a sometimes permitted in order to help prevent the solution from settling in a local minimum. class NumOptSimmAnnContinuousC: public NumOptimiseC { public: NumOptSimmAnnContinuousC (UIntT iterations, RealT Tau, RealT minTemp, RealT ftol) :NumOptimiseC(*(new NumOptSimmAnnContinuousBC (iterations, Tau, minTemp, ftol))) {} //: Constructor //!param: iterations - maximum number of iterations to use //!param: Tau - constant //!param: minTemp - the minimum temperature to be used during the annealing schedule //!param: ftol - the accepted tolerance for early exit NumOptSimmAnnContinuousC (const NumOptSimmAnnContinuousC &oth) :NumOptimiseC (oth){}; //: Copy constructor NumOptSimmAnnContinuousC (NumOptSimmAnnContinuousBC &oth) :NumOptimiseC(oth){}; //: Constructs from body class NumOptSimmAnnContinuousC & operator=(const NumOptSimmAnnContinuousC & cost) { cout.flush(); NumOptimiseC::operator= (cost); return *this; } //: Assigment of cost object. inline NumOptSimmAnnContinuousC Copy () const {return NumOptSimmAnnContinuousC(static_cast (Body().Copy()));} //: Makes a deep copy VectorC GetRandomX(const VectorC & X, const VectorC & minX, const VectorC & maxX) const {return Body().GetRandomX(X, minX, maxX);} //: return a random vector protected: NumOptSimmAnnContinuousBC &Body() { return static_cast(NumOptimiseC::Body()); } //: Access Body const NumOptSimmAnnContinuousBC &Body() const { return static_cast(NumOptimiseC::Body()); } //: Access Body }; #endif