Main Page | Namespace List | Class Hierarchy | Alphabetical List | Class List | File List | Namespace Members | Class Members | File Members | Related Pages

ObjCryst::OptimizationObj Class Reference

Base object for Optimization methods. More...

Inheritance diagram for ObjCryst::OptimizationObj:

Inheritance graph
[legend]
Collaboration diagram for ObjCryst::OptimizationObj:

Collaboration graph
[legend]
List of all members.

Public Member Functions

 OptimizationObj (const string name="")
 Constructor.

virtual ~OptimizationObj ()
 Destructor.

virtual void RandomizeStartingConfig ()
 Randomize starting configuration. Only affects limited and periodic parameters.

virtual void Optimize (long &nbSteps, const bool silent=false, const REAL finalcost=0, const REAL maxTime=-1)=0
 Launch optimization (a single run) for N steps.

virtual void MultiRunOptimize (long &nbCycle, long &nbSteps, const bool silent=false, const REAL finalcost=0, const REAL maxTime=-1)=0
 Launch optimization for multiple runs of N steps.

void FixAllPar ()
 Fix all parameters.

void SetParIsFixed (const string &parName, const bool fix)
 Fix one parameter.

void SetParIsFixed (const RefParType *type, const bool fix)
 Fix one family of parameters.

void UnFixAllPar ()
 UnFix All parameters.

void SetParIsUsed (const string &parName, const bool use)
 Set a parameter to be used.

void SetParIsUsed (const RefParType *type, const bool use)
 Set a family of parameters to be used.

void SetLimitsRelative (const string &parName, const REAL min, const REAL max)
 Change the relative limits for a parameter from its name.

void SetLimitsRelative (const RefParType *type, const REAL min, const REAL max)
 Change the relative limits for a family of parameter.

void SetLimitsAbsolute (const string &parName, const REAL min, const REAL max)
 Change the absolute limits for a parameter from its name.

void SetLimitsAbsolute (const RefParType *type, const REAL min, const REAL max)
 Change the absolute limits for a family of parameter.

virtual REAL GetLogLikelihood () const
 The optimized (minimized, actually) function.

void StopAfterCycle ()
 Stop after the current cycle. USed for interactive refinement.

virtual void DisplayReport ()
 Show report to the user during refinement. Used for GUI update.

void AddRefinableObj (RefinableObj &)
 Add a refined object. All sub-objects are also added.

RefinableObjGetFullRefinableObj (const bool rebuild=true)
 Get the RefinableObj with all the parameters from all refined objects.

virtual void XMLOutput (ostream &os, int indent=0) const=0
 Output a description of the object in XML format to a stream.

virtual void XMLInput (istream &is, const XMLCrystTag &tag)=0
 Input in XML format from a stream, restoring the set of refined objects and the associated cost functions. Note that the corresponding objects must have been loaded in memory before, else shit happens.

const string & GetName () const
 Get the name for this object.

void SetName (const string &)
 Set the name for this object.

virtual const string GetClassName () const
 Get the name for this class type.

virtual void Print () const
 Print some information about this object.

void RestoreBestConfiguration ()
 Restore the Best configuration.

bool IsOptimizing () const
 Are we busy optimizing ?

void TagNewBestConfig ()
 During a global optimization, tell all objects that the current config is the latest "best" config.

REAL GetLastOptimElapsedTime () const
 Get the elapsed time (in seconds) during the last optimization.

MainTrackerGetMainTracker ()
 Get the MainTracker.

const MainTrackerGetMainTracker () const
 Get the MainTracker.

RefObjOptGetXMLAutoSaveOption ()
const RefObjOptGetXMLAutoSaveOption () const
const REAL & GetBestCost () const
 Access to current best cost.

REAL & GetBestCost ()
 Access to current best cost.


Protected Member Functions

void PrepareRefParList ()
 Prepare mRefParList for the refinement.

virtual void InitOptions ()
 Initialization of options.

virtual void UpdateDisplay ()
 Update Display (if any display is available), when a new 'relevant' configuration is reached.

void BuildRecursiveRefObjList ()
 (Re)build OptimizationObj::mRecursiveRefinedObjList, if an object has been added or modified.


Protected Attributes

RefinableObj mRefParList
 The refinable par list used during refinement.

string mName
 Name of the GlobalOptimization object.

string mSaveFileName
 File name where refinement info is saved (NOT USED so far...).

long mNbTrial
 Number of trials so far.

REAL mBestCost
 Best value of the cost function so far.

long mBestParSavedSetIndex
 Index of the 'best' saved parameter set.

unsigned long mContext
 The current 'context', in the case the optimization is run in different parallel contexts.

map< unsigned long, map< const
RefinableObj *, LogLikelihoodStats > > 
mvContextObjStats
 Statistics for each context (mutable for dynamic update during optimization).

map< const RefinableObj *,
DynamicObjWeight
mvObjWeight
 Weights for each objects in each context (mutable for dynamic update during optimization).

std::vector< pair< long, REAL > > mvSavedParamSet
 List of saved parameter sets.

bool mIsOptimizing
 True if a refinement is being done. For multi-threaded environment.

bool mStopAfterCycle
 If true, then stop at the end of the cycle. Used in multi-threaded environment.

ObjRegistry< RefinableObjmRefinedObjList
 The refined objects.

ObjRegistry< RefinableObjmRecursiveRefinedObjList
 The refined objects, recursively including all sub-objects.

RefObjOpt mXMLAutoSave
 Periodic save of complete environment as an xml file.

REAL mLastOptimTime
 The time elapsed after the last optimization, in seconds.

MainTracker mMainTracker
 MainTracker object to track the evolution of cost functions, likelihood, and individual parameters.


Detailed Description

Base object for Optimization methods.

This is an abstract base class, derived for Monte-Cralo type algorithms (Simulated Annealing & Parallel Tempering), and hopefully soon for Genetic Algorithms.

Remarks:
Instead of keeping a copy of the list of parameters here, maybe it would be better to delegate all parameter handling to the refined objects (they would also have to keep in memory the saved parameter sets, so that could be difficult to administrate...).


Constructor & Destructor Documentation

ObjCryst::OptimizationObj::OptimizationObj const string  name = ""  ) 
 

Constructor.

virtual ObjCryst::OptimizationObj::~OptimizationObj  )  [virtual]
 

Destructor.


Member Function Documentation

void ObjCryst::OptimizationObj::AddRefinableObj RefinableObj  ) 
 

Add a refined object. All sub-objects are also added.

void ObjCryst::OptimizationObj::BuildRecursiveRefObjList  )  [protected]
 

(Re)build OptimizationObj::mRecursiveRefinedObjList, if an object has been added or modified.

If no object has been added and no sub-object has been added/removed, then nothing is done.

virtual void ObjCryst::OptimizationObj::DisplayReport  )  [virtual]
 

Show report to the user during refinement. Used for GUI update.

void ObjCryst::OptimizationObj::FixAllPar  ) 
 

Fix all parameters.

REAL& ObjCryst::OptimizationObj::GetBestCost  ) 
 

Access to current best cost.

const REAL& ObjCryst::OptimizationObj::GetBestCost  )  const
 

Access to current best cost.

virtual const string ObjCryst::OptimizationObj::GetClassName  )  const [virtual]
 

Get the name for this class type.

Reimplemented in ObjCryst::MonteCarloObj.

RefinableObj& ObjCryst::OptimizationObj::GetFullRefinableObj const bool  rebuild = true  ) 
 

Get the RefinableObj with all the parameters from all refined objects.

If rebuild=true, prepare again the list of objects/parameters.

REAL ObjCryst::OptimizationObj::GetLastOptimElapsedTime  )  const
 

Get the elapsed time (in seconds) during the last optimization.

virtual REAL ObjCryst::OptimizationObj::GetLogLikelihood  )  const [virtual]
 

The optimized (minimized, actually) function.

This function is the weighted sum of the chosen Cost Functions for the refined objects.

const MainTracker& ObjCryst::OptimizationObj::GetMainTracker  )  const
 

Get the MainTracker.

MainTracker& ObjCryst::OptimizationObj::GetMainTracker  ) 
 

Get the MainTracker.

const string& ObjCryst::OptimizationObj::GetName  )  const
 

Get the name for this object.

const RefObjOpt& ObjCryst::OptimizationObj::GetXMLAutoSaveOption  )  const
 

RefObjOpt& ObjCryst::OptimizationObj::GetXMLAutoSaveOption  ) 
 

virtual void ObjCryst::OptimizationObj::InitOptions  )  [protected, virtual]
 

Initialization of options.

Reimplemented in ObjCryst::MonteCarloObj.

bool ObjCryst::OptimizationObj::IsOptimizing  )  const
 

Are we busy optimizing ?

virtual void ObjCryst::OptimizationObj::MultiRunOptimize long &  nbCycle,
long &  nbSteps,
const bool  silent = false,
const REAL  finalcost = 0,
const REAL  maxTime = -1
[pure virtual]
 

Launch optimization for multiple runs of N steps.

Parameters:
nbCycle: the number of runs (cycles) to perform. The structure is randomized at the beginning of each cycle. If nbCycle==-1, this will run indefinitely. The nbCycle parameter is decreased after each run.
nbSteps: the number of steps to go. This number is modified (decreases!) as the refinement goes on.
silent : if true, absolutely no message should be printed (except debugging)
finalcost: the optimization will stop if overall cost fallse below this value
maxTime: the optimization will stop after the given number of seconds has been spent optimizing (ignored if <0).

Implemented in ObjCryst::MonteCarloObj, and ObjCryst::SimplexObj.

virtual void ObjCryst::OptimizationObj::Optimize long &  nbSteps,
const bool  silent = false,
const REAL  finalcost = 0,
const REAL  maxTime = -1
[pure virtual]
 

Launch optimization (a single run) for N steps.

Parameters:
nbSteps: the number of steps to go. This number is modified (decreases!) as the refinement goes on.
silent : if true, absolutely no message should be printed (except debugging)
finalcost: the optimization will stop if overall cost fallse below this value
maxTime: the optimization will stop after the given number of seconds has been spent optimizing (ignored if <0).

Implemented in ObjCryst::MonteCarloObj, and ObjCryst::SimplexObj.

void ObjCryst::OptimizationObj::PrepareRefParList  )  [protected]
 

Prepare mRefParList for the refinement.

virtual void ObjCryst::OptimizationObj::Print  )  const [virtual]
 

Print some information about this object.

virtual void ObjCryst::OptimizationObj::RandomizeStartingConfig  )  [virtual]
 

Randomize starting configuration. Only affects limited and periodic parameters.

void ObjCryst::OptimizationObj::RestoreBestConfiguration  ) 
 

Restore the Best configuration.

void ObjCryst::OptimizationObj::SetLimitsAbsolute const RefParType type,
const REAL  min,
const REAL  max
 

Change the absolute limits for a family of parameter.

void ObjCryst::OptimizationObj::SetLimitsAbsolute const string &  parName,
const REAL  min,
const REAL  max
 

Change the absolute limits for a parameter from its name.

void ObjCryst::OptimizationObj::SetLimitsRelative const RefParType type,
const REAL  min,
const REAL  max
 

Change the relative limits for a family of parameter.

void ObjCryst::OptimizationObj::SetLimitsRelative const string &  parName,
const REAL  min,
const REAL  max
 

Change the relative limits for a parameter from its name.

void ObjCryst::OptimizationObj::SetName const string &   ) 
 

Set the name for this object.

void ObjCryst::OptimizationObj::SetParIsFixed const RefParType type,
const bool  fix
 

Fix one family of parameters.

void ObjCryst::OptimizationObj::SetParIsFixed const string &  parName,
const bool  fix
 

Fix one parameter.

void ObjCryst::OptimizationObj::SetParIsUsed const RefParType type,
const bool  use
 

Set a family of parameters to be used.

void ObjCryst::OptimizationObj::SetParIsUsed const string &  parName,
const bool  use
 

Set a parameter to be used.

void ObjCryst::OptimizationObj::StopAfterCycle  ) 
 

Stop after the current cycle. USed for interactive refinement.

void ObjCryst::OptimizationObj::TagNewBestConfig  ) 
 

During a global optimization, tell all objects that the current config is the latest "best" config.

void ObjCryst::OptimizationObj::UnFixAllPar  ) 
 

UnFix All parameters.

virtual void ObjCryst::OptimizationObj::UpdateDisplay  )  [protected, virtual]
 

Update Display (if any display is available), when a new 'relevant' configuration is reached.

This calls all RefinableObj::UpdateDisplay()

virtual void ObjCryst::OptimizationObj::XMLInput istream &  is,
const XMLCrystTag tag
[pure virtual]
 

Input in XML format from a stream, restoring the set of refined objects and the associated cost functions. Note that the corresponding objects must have been loaded in memory before, else shit happens.

Implemented in ObjCryst::MonteCarloObj, and ObjCryst::SimplexObj.

virtual void ObjCryst::OptimizationObj::XMLOutput ostream &  os,
int  indent = 0
const [pure virtual]
 

Output a description of the object in XML format to a stream.

This saves the list of refined object and the cost functions, as well as options for the refinement. The refined objects are not saved, so this must be done somewhere else (they must be reloaded before this object).

Implemented in ObjCryst::MonteCarloObj, and ObjCryst::SimplexObj.


Member Data Documentation

REAL ObjCryst::OptimizationObj::mBestCost [protected]
 

Best value of the cost function so far.

long ObjCryst::OptimizationObj::mBestParSavedSetIndex [protected]
 

Index of the 'best' saved parameter set.

unsigned long ObjCryst::OptimizationObj::mContext [protected]
 

The current 'context', in the case the optimization is run in different parallel contexts.

bool ObjCryst::OptimizationObj::mIsOptimizing [protected]
 

True if a refinement is being done. For multi-threaded environment.

REAL ObjCryst::OptimizationObj::mLastOptimTime [protected]
 

The time elapsed after the last optimization, in seconds.

MainTracker ObjCryst::OptimizationObj::mMainTracker [protected]
 

MainTracker object to track the evolution of cost functions, likelihood, and individual parameters.

string ObjCryst::OptimizationObj::mName [protected]
 

Name of the GlobalOptimization object.

long ObjCryst::OptimizationObj::mNbTrial [protected]
 

Number of trials so far.

ObjRegistry<RefinableObj> ObjCryst::OptimizationObj::mRecursiveRefinedObjList [mutable, protected]
 

The refined objects, recursively including all sub-objects.

This is mutable, since it is a function of mRefinedObjList only.

ObjRegistry<RefinableObj> ObjCryst::OptimizationObj::mRefinedObjList [protected]
 

The refined objects.

RefinableObj ObjCryst::OptimizationObj::mRefParList [mutable, protected]
 

The refinable par list used during refinement.

Only a condensed version of all objects. This is useful to keep an history of modifications, and to restore previous values.

Remarks:
maybe this should be completely delegated to the refined objetcs.

string ObjCryst::OptimizationObj::mSaveFileName [protected]
 

File name where refinement info is saved (NOT USED so far...).

bool ObjCryst::OptimizationObj::mStopAfterCycle [protected]
 

If true, then stop at the end of the cycle. Used in multi-threaded environment.

map<unsigned long, map<const RefinableObj*,LogLikelihoodStats> > ObjCryst::OptimizationObj::mvContextObjStats [mutable, protected]
 

Statistics for each context (mutable for dynamic update during optimization).

map<const RefinableObj*,DynamicObjWeight> ObjCryst::OptimizationObj::mvObjWeight [mutable, protected]
 

Weights for each objects in each context (mutable for dynamic update during optimization).

std::vector<pair<long,REAL> > ObjCryst::OptimizationObj::mvSavedParamSet [protected]
 

List of saved parameter sets.

This is used to save possible solutions during the optimization, so that the user can check them afterwards.

The first member of each pair is the index of the parameter set, and the second is the overall cost for that set.

RefObjOpt ObjCryst::OptimizationObj::mXMLAutoSave [protected]
 

Periodic save of complete environment as an xml file.


The documentation for this class was generated from the following file:
Generated on Tue Nov 14 15:05:42 2006 for ObjCryst++ by doxygen 1.3.6