FOX/ObjCryst++  2022
ObjCryst::OptimizationObj Class Referenceabstract

Base object for Optimization methods. More...

+ Inheritance diagram for ObjCryst::OptimizationObj:
+ Collaboration diagram for ObjCryst::OptimizationObj:

Classes

struct  DynamicObjWeight
 
struct  LogLikelihoodStats
 Statistics about each object contributing to the overall Log(likelihood) More...
 

Public Member Functions

 OptimizationObj ()
 Default constructor.
 
 OptimizationObj (const string name)
 Constructor.
 
 OptimizationObj (const OptimizationObj &old)
 Copy constructor.
 
virtual ~OptimizationObj ()
 Destructor.
 
virtual void RandomizeStartingConfig ()
 Randomize starting configuration. More...
 
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. More...
 
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. More...
 
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. More...
 
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. More...
 
virtual void XMLOutput (ostream &os, int indent=0) const =0
 Output a description of the object in XML format to a stream. More...
 
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. More...
 
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.
 
virtual void BeginOptimization (const bool allowApproximations=false, const bool enableRestraints=false)
 Begin optimization for all objects.
 
virtual void EndOptimization ()
 End optimization for all objects.
 
virtual long & NbTrialPerRun ()
 Number of trial per run.
 
virtual const long & NbTrialPerRun () const
 Number of trial per run.
 
long GetTrial () const
 Current trial number (updated during a run)
 
long GetRun () const
 Current run number (updated during a run)
 
ObjRegistry< RefObjOpt > & GetOptionList ()
 Access to the options registry.
 
unsigned int GetNbOption () const
 Number of Options for this object.
 
RefObjOptGetOption (const unsigned int i)
 Access to the options.
 
RefObjOptGetOption (const string &name)
 Access to the options by name.
 
const RefObjOptGetOption (const unsigned int i) const
 const access to the options
 
const RefObjOptGetOption (const string &name) const
 const access to the options by name
 
const ObjRegistry< RefinableObj > & GetRefinedObjList () const
 Access the list of refined object.
 
virtual void UpdateDisplay () const
 Update Display (if any display is available), when a new 'relevant' configuration is reached. More...
 
unsigned int GetNbParamSet () const
 Get the number of saved parameters set.
 
long GetParamSetIndex (const unsigned int i) const
 Get the index of a saved parameters set in the compiled RefinableObj. More...
 
long GetParamSetCost (const unsigned int i) const
 Get the cost (log-likelihood) of a saved parameters set.
 
void RestoreParamSet (const unsigned int i, const bool update_display=true)
 Restore a given saved parameter set. More...
 

Protected Member Functions

void PrepareRefParList ()
 
virtual void InitOptions ()
 Initialization of options.
 
void BuildRecursiveRefObjList ()
 (Re)build OptimizationObj::mRecursiveRefinedObjList, if an object has been added or modified. More...
 
void AddOption (RefObjOpt *opt)
 

Protected Attributes

RefinableObj mRefParList
 The refinable par list used during refinement. More...
 
string mName
 Name of the GlobalOptimization object.
 
string mSaveFileName
 File name where refinement info is saved (NOT USED so far...)
 
long mNbTrialPerRun
 Number of trial per run, to be saved/restored in XML output.
 
long mNbTrial
 Current trial number.
 
long mRun
 Current run number (during multiple runs)
 
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 *, DynamicObjWeightmvObjWeight
 Weights for each objects in each context (mutable for dynamic update during optimization)
 
std::vector< pair< long, REAL > > mvSavedParamSet
 List of saved parameter sets. More...
 
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. More...
 
ObjRegistry< RefinableObjmRecursiveRefinedObjList
 The refined objects, recursively including all sub-objects. More...
 
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.
 
ObjRegistry< RefObjOptmOptionRegistry
 List of options for this object. More...
 

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...).

Definition at line 102 of file GlobalOptimObj.h.

Member Function Documentation

◆ AddOption()

void ObjCryst::OptimizationObj::AddOption ( RefObjOpt opt)
protected

Add an option for this parameter

Definition at line 549 of file GlobalOptimObj.cpp.

◆ BuildRecursiveRefObjList()

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.

Definition at line 533 of file GlobalOptimObj.cpp.

◆ GetFullRefinableObj()

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.

Definition at line 296 of file GlobalOptimObj.cpp.

◆ GetLogLikelihood()

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.

Definition at line 246 of file GlobalOptimObj.cpp.

◆ GetParamSetIndex()

long ObjCryst::OptimizationObj::GetParamSetIndex ( const unsigned int  i) const

Get the index of a saved parameters set in the compiled RefinableObj.

The parameters can then be accessed using GetRefinedObjList().GetParamSet(idx)

Definition at line 420 of file GlobalOptimObj.cpp.

◆ MultiRunOptimize()

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
nbCyclethe 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.
nbStepsthe 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)
finalcostthe optimization will stop if overall cost fallse below this value
maxTimethe optimization will stop after the given number of seconds has been spent optimizing (ignored if <0).

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

◆ Optimize()

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
nbStepsthe 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)
finalcostthe optimization will stop if overall cost fallse below this value
maxTimethe optimization will stop after the given number of seconds has been spent optimizing (ignored if <0).

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

◆ PrepareRefParList()

void ObjCryst::OptimizationObj::PrepareRefParList ( )
protected

Prepare mRefParList for the refinement

Definition at line 441 of file GlobalOptimObj.cpp.

◆ RandomizeStartingConfig()

void ObjCryst::OptimizationObj::RandomizeStartingConfig ( )
virtual

Randomize starting configuration.

Only affects limited and periodic parameters.

Definition at line 157 of file GlobalOptimObj.cpp.

◆ RestoreParamSet()

void ObjCryst::OptimizationObj::RestoreParamSet ( const unsigned int  i,
const bool  update_display = true 
)

Restore a given saved parameter set.

This is equivalent to GetRefinedObjList().RestoreParamSet(GetSavedParamSetIndex(i))

Parameters
ithe order of the saved parameter set

Definition at line 435 of file GlobalOptimObj.cpp.

◆ UpdateDisplay()

void ObjCryst::OptimizationObj::UpdateDisplay ( ) const
virtual

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

This calls all RefinableObj::UpdateDisplay()

Reimplemented in ObjCryst::MonteCarloObj.

Definition at line 525 of file GlobalOptimObj.cpp.

◆ XMLInput()

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::SimplexObj, and ObjCryst::MonteCarloObj.

◆ XMLOutput()

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::SimplexObj, and ObjCryst::MonteCarloObj.

Member Data Documentation

◆ mOptionRegistry

ObjRegistry<RefObjOpt> ObjCryst::OptimizationObj::mOptionRegistry
protected

List of options for this object.

Note that these are just references, to options allocated by the object, to have a simple global access to all options

Definition at line 354 of file GlobalOptimObj.h.

◆ mRecursiveRefinedObjList

ObjRegistry<RefinableObj> ObjCryst::OptimizationObj::mRecursiveRefinedObjList
mutableprotected

The refined objects, recursively including all sub-objects.

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

Definition at line 341 of file GlobalOptimObj.h.

◆ mRefinedObjList

ObjRegistry<RefinableObj> ObjCryst::OptimizationObj::mRefinedObjList
mutableprotected

The refined objects.

This is mutable to allow a copy constructor for the OptimizationObj, and because the objects are not owned but rather referenced here.

Definition at line 338 of file GlobalOptimObj.h.

◆ mRefParList

RefinableObj ObjCryst::OptimizationObj::mRefParList
mutableprotected

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.

Definition at line 278 of file GlobalOptimObj.h.

◆ mvSavedParamSet

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.

Definition at line 327 of file GlobalOptimObj.h.


The documentation for this class was generated from the following files: