23 #ifndef _GLOBALOPTIMOBJ_H
24 #define _GLOBALOPTIMOBJ_H
27 #include "ObjCryst/ObjCryst/General.h"
31 class OptimizationObj;
35 #include "ObjCryst/RefinableObj/RefinableObj.h"
36 #include "ObjCryst/RefinableObj/LSQNumObj.h"
37 #include "ObjCryst/RefinableObj/IO.h"
38 #include "ObjCryst/RefinableObj/Tracker.h"
43 #include "ObjCryst/wxCryst/wxGlobalOptimObj.h"
72 ANNEALING_EXPONENTIAL,
84 GLOBAL_OPTIM_SIMULATED_ANNEALING,
85 GLOBAL_OPTIM_PARALLEL_TEMPERING,
86 GLOBAL_OPTIM_RANDOM_LSQ,
87 GLOBAL_OPTIM_SIMULATED_ANNEALING_MULTI,
88 GLOBAL_OPTIM_PARALLEL_TEMPERING_MULTI,
120 virtual void Optimize(
long &nbSteps,
const bool silent=
false,
const REAL finalcost=0,
121 const REAL maxTime=-1)=0;
133 virtual void MultiRunOptimize(
long &nbCycle,
long &nbSteps,
const bool silent=
false,
const REAL finalcost=0,
134 const REAL maxTime=-1)=0;
145 void SetParIsUsed(
const string& parName,
const bool use);
180 virtual void XMLOutput(ostream &os,
int indent=0)
const=0;
195 virtual void Print()
const;
211 const RefObjOpt& GetXMLAutoSaveOption()
const;
218 const bool enableRestraints=
false);
317 virtual void WXDelete()=0;
318 virtual void WXNotifyDelete()=0;
325 wxMutex mMutexStopAfterCycle;
376 const REAL tMax,
const REAL tMin,
378 const REAL mutMax=16.,
const REAL mutMin=.125,
379 const long nbTrialRetry=0,
const REAL minCostRetry=0.);
399 const REAL tMax,
const REAL tMin,
401 const REAL mutMax=16.,
const REAL mutMin=.125);
403 virtual void Optimize(
long &nbSteps,
const bool silent=
false,
const REAL finalcost=0,
404 const REAL maxTime=-1);
405 virtual void MultiRunOptimize(
long &nbCycle,
long &nbSteps,
const bool silent=
false,
const REAL finalcost=0,
406 const REAL maxTime=-1);
412 const REAL maxTime=-1);
417 const REAL maxTime=-1);
419 void RunRandomLSQMethod(
long &nbCycle);
427 virtual void XMLOutput(ostream &os,
int indent=0)
const;
442 virtual void InitLSQ(
const bool useFullPowderPatternProfile=
true);
516 virtual void WXDelete();
517 virtual void WXNotifyDelete();
529 #endif //_GLOBALOPTIMOBJ_H
void SetName(const string &)
Set the name for this object.
void SetLimitsRelative(const string &parName, const REAL min, const REAL max)
Change the relative limits for a parameter from its name.
OptimizationObj(const string name="")
Constructor.
virtual void XMLOutput(ostream &os, int indent=0) const =0
Output a description of the object in XML format to a stream.
RefObjOpt mAutoLSQ
Option to run automatic least-squares refinements.
void RunSimulatedAnnealing(long &nbSteps, const bool silent=false, const REAL finalcost=0, const REAL maxTime=-1)
virtual void RandomizeStartingConfig()
Randomize starting configuration.
virtual void InitLSQ(const bool useFullPowderPatternProfile=true)
Prepare mLSQ for least-squares refinement during the global optimization.
string mName
Name of the GlobalOptimization object.
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.
virtual void Optimize(long &nbSteps, const bool silent=false, const REAL finalcost=0, const REAL maxTime=-1)
Launch optimization (a single run) for N steps.
long mNbTrialRetry
Number of trials before testing if we are below the given minimum cost.
REAL mTemperature
Current temperature for annealing.
void BuildRecursiveRefObjList()
(Re)build OptimizationObj::mRecursiveRefinedObjList, if an object has been added or modified...
REAL mCurrentCost
Current value of the cost function.
void AddRefinableObj(RefinableObj &)
Add a refined object. All sub-objects are also added.
AnnealingSchedule
Annealing schedule type.
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 funct...
string mSaveFileName
File name where refinement info is saved (NOT USED so far...)
REAL mTemperatureMax
Beginning temperature for annealing.
RefObjOpt mGlobalOptimType
Method used for the global optimization.
LSQNumObj & GetLSQObj()
Access to the builtin LSQ optimization object.
ObjRegistry< OptimizationObj > gOptimizationObjRegistry("List of all Optimization objects")
Global Registry for all OptimizationObj.
void SetParIsFixed(const string &parName, const bool fix)
Fix one parameter.
void SetParIsUsed(const string &parName, const bool use)
Set a parameter to be used.
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 DisplayReport()
Show report to the user during refinement. Used for GUI update.
REAL GetLastOptimElapsedTime() const
Get the elapsed time (in seconds) during the last optimization.
void FixAllPar()
Fix all parameters.
GlobalOptimType
Global optimization type.
Generic Refinable Object.
REAL mTotalLogLikelihood
Total Log(Likelihood), to compute the average.
MonteCarloObj(const string name="")
Constructor.
bool mStopAfterCycle
If true, then stop at the end of the cycle. Used in multi-threaded environment.
MainTracker mMainTracker
MainTracker object to track the evolution of cost functions, likelihood, and individual parameters...
REAL mTemperatureMin
Lower temperature.
Abstract base class for all objects in wxCryst.
REAL mMutationAmplitudeGamma
Gamma for the 'gamma' Mutation amplitude schedule.
REAL mMutationAmplitude
Mutation amplitude.
Base object for Monte-Carlo Global Optimization methods.
const string & GetName() const
Get the name for this object.
REAL mBestCost
Best value of the cost function so far.
LSQNumObj mLSQ
Least squares object.
virtual ~OptimizationObj()
Destructor.
long mBestParSavedSetIndex
Index of the 'best' saved parameter set.
virtual void Print() const
Print some information about this object.
virtual void NewConfiguration(const RefParType *type=gpRefParTypeObjCryst)
Make a random change in the configuration.
void TagNewBestConfig()
During a global optimization, tell all objects that the current config is the latest "best" config...
REAL mMutationAmplitudeMin
Mutation amplitude at the end of the optimization.
void SetAlgorithmParallTempering(const AnnealingSchedule scheduleTemp, const REAL tMax, const REAL tMin, const AnnealingSchedule scheduleMutation=ANNEALING_CONSTANT, const REAL mutMax=16., const REAL mutMin=.125)
Set the refinement method to Parallel Tempering.
void SetLimitsAbsolute(const string &parName, const REAL min, const REAL max)
Change the absolute limits for a parameter from its name.
RefObjOpt mAnnealingScheduleTemp
Schedule for the annealing.
unsigned long mContext
The current 'context', in the case the optimization is run in different parallel contexts.
RefinableObj & GetFullRefinableObj(const bool rebuild=true)
Get the RefinableObj with all the parameters from all refined objects.
bool IsOptimizing() const
Are we busy optimizing ?
virtual void MultiRunOptimize(long &nbCycle, long &nbSteps, const bool silent=false, const REAL finalcost=0, const REAL maxTime=-1)
Launch optimization for multiple runs of N steps.
Statistics about each object contributing to the overall Log(likelihood)
long mNbTrialPerRun
Number of trial per run, to be saved/restored in XML output.
RefinableObj mRefParList
The refinable par list used during refinement.
virtual const string GetClassName() const
Get the name for this class type.
RefObjOpt mXMLAutoSave
Periodic save of complete environment as an xml file.
void RunParallelTempering(long &nbSteps, const bool silent=false, const REAL finalcost=0, const REAL maxTime=-1)
A class to hold all trackers.
void RestoreBestConfiguration()
Restore the Best configuration.
virtual ~MonteCarloObj()
Destructor.
ObjRegistry< RefinableObj > mRefinedObjList
The refined objects.
REAL mLastOptimTime
The time elapsed after the last optimization, in seconds.
void UnFixAllPar()
UnFix All parameters.
MainTracker & GetMainTracker()
Get the MainTracker.
map< const RefinableObj *, DynamicObjWeight > mvObjWeight
Weights for each objects in each context (mutable for dynamic update during optimization) ...
Class for Graphical interface to Monte-Carlo objects (Simulated Annealing, Parallel Tempering) ...
REAL mMutationAmplitudeMax
Mutation amplitude at the beginning of the optimization.
Base object for Optimization methods.
ObjRegistry< RefinableObj > mRecursiveRefinedObjList
The refined objects, recursively including all sub-objects.
REAL mMinCostRetry
Cost to reach unless an automatic randomization and retry is done.
void StopAfterCycle()
Stop after the current cycle. USed for interactive refinement.
The namespace which includes all objects (crystallographic and algorithmic) in ObjCryst++.
WX Class for a Global Optimization objects.
RefObjOpt mAnnealingScheduleMutation
Schedule for the annealing.
virtual void EndOptimization()
End optimization for all objects.
virtual const string GetClassName() const
Get the name for this class type.
virtual void XMLInput(istream &is, const XMLCrystTag &tag)
Input in XML format from a stream, restoring the set of refined objects and the associated cost funct...
map< unsigned long, map< const RefinableObj *, LogLikelihoodStats > > mvContextObjStats
Statistics for each context (mutable for dynamic update during optimization)
bool mIsOptimizing
True if a refinement is being done. For multi-threaded environment.
virtual void InitOptions()
Initialization of options.
virtual void XMLOutput(ostream &os, int indent=0) const
Output a description of the object in XML format to a stream.
(Quick & dirty) Least-Squares Refinement Object with Numerical derivatives
virtual void BeginOptimization(const bool allowApproximations=false, const bool enableRestraints=false)
Begin optimization for all objects.
REAL mLastLogLikelihood
Previous log(likelihood)
virtual void UpdateDisplay()
Update Display (if any display is available), when a new 'relevant' configuration is reached...
class to input or output a well-formatted xml beginning or ending tag.
REAL mTemperatureGamma
Gamma for the 'gamma' temperature schedule.
RefObjOpt mSaveTrackedData
Option to save the evolution of tracked data (cost functions, likelihhod, individual parameters...
class of refinable parameter types.
void SetAlgorithmSimulAnnealing(const AnnealingSchedule scheduleTemp, const REAL tMax, const REAL tMin, const AnnealingSchedule scheduleMutation=ANNEALING_CONSTANT, const REAL mutMax=16., const REAL mutMin=.125, const long nbTrialRetry=0, const REAL minCostRetry=0.)
Set the refinement method to simulated Annealing.
long mNbTrial
Number of trials so far.
virtual long & NbTrialPerRun()
Number of trial per run.
std::vector< pair< long, REAL > > mvSavedParamSet
List of saved parameter sets.
const RefParType * gpRefParTypeObjCryst
Top RefParType for the ObjCryst++ library.
virtual REAL GetLogLikelihood() const
The optimized (minimized, actually) function.
const REAL & GetBestCost() const
Access to current best cost.
virtual void InitOptions()
Initialization of options.
REAL mTotalLogLikelihoodDeltaSq
total of (Delta(Log(Likelihood)))^2 between successive trials