Skip to content

Commit 787ca5b

Browse files
committed
Merge branch 'upstream-objcryst'
* upstream-objcryst: GlobalOptimObj: better access to parameter sets, as well as the current trial and run numbers
2 parents b9794dd + a1f2c6f commit 787ca5b

2 files changed

Lines changed: 53 additions & 2 deletions

File tree

src/ObjCryst/RefinableObj/GlobalOptimObj.cpp

Lines changed: 35 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ ObjRegistry<OptimizationObj> gOptimizationObjRegistry("List of all Optimization
6868

6969
OptimizationObj::OptimizationObj(const string name):
7070
mName(name),mSaveFileName("GlobalOptim.save"),
71-
mNbTrialPerRun(10000000),mNbTrial(0),mBestCost(-1),
71+
mNbTrialPerRun(10000000),mNbTrial(0),mRun(0),mBestCost(-1),
7272
mBestParSavedSetIndex(-1),
7373
mContext(0),
7474
mIsOptimizing(false),mStopAfterCycle(false),
@@ -300,6 +300,10 @@ long& OptimizationObj::NbTrialPerRun() {return mNbTrialPerRun;}
300300

301301
const long& OptimizationObj::NbTrialPerRun() const {return mNbTrialPerRun;}
302302

303+
long OptimizationObj::GetTrial() const {return mNbTrial;}
304+
305+
long OptimizationObj::GetRun() const {return mRun;}
306+
303307
unsigned int OptimizationObj::GetNbOption()const
304308
{
305309
return mOptionRegistry.GetNb();
@@ -353,6 +357,32 @@ const ObjRegistry<RefinableObj>& OptimizationObj::GetRefinedObjList() const
353357
return mRefinedObjList;
354358
}
355359

360+
unsigned int OptimizationObj::GetNbParamSet() const
361+
{
362+
return mvSavedParamSet.size();
363+
}
364+
365+
long OptimizationObj::GetParamSetIndex(const unsigned int i) const
366+
{
367+
if(i>=mvSavedParamSet.size())
368+
throw ObjCrystException("OptimizationObj::GetSavedParamSetIndex(i): i > nb saved param set");
369+
370+
return mvSavedParamSet[i].first;
371+
}
372+
373+
long OptimizationObj::GetParamSetCost(const unsigned int i) const
374+
{
375+
if(i>=mvSavedParamSet.size())
376+
throw ObjCrystException("OptimizationObj::GetSavedParamSetCost(i): i > nb saved param set");
377+
return mvSavedParamSet[i].second;
378+
}
379+
380+
void OptimizationObj::RestoreParamSet(const unsigned int i, const bool update_display)
381+
{
382+
mRefParList.RestoreParamSet(this->GetParamSetIndex(i));
383+
if(update_display) this->UpdateDisplay();
384+
}
385+
356386
void OptimizationObj::PrepareRefParList()
357387
{
358388
VFN_DEBUG_ENTRY("OptimizationObj::PrepareRefParList()",6)
@@ -665,6 +695,7 @@ void MonteCarloObj::MultiRunOptimize(long &nbCycle,long &nbStep,const bool silen
665695
long nbTrialCumul=0;
666696
const long nbCycle0=nbCycle;
667697
Chronometer chrono;
698+
mRun = 0;
668699
while(nbCycle!=0)
669700
{
670701
if(!silent) cout <<"MonteCarloObj::MultiRunOptimize: Starting Run#"<<abs(nbCycle)<<endl;
@@ -747,6 +778,7 @@ void MonteCarloObj::MultiRunOptimize(long &nbCycle,long &nbStep,const bool silen
747778
#ifdef __WX__CRYST__
748779
mMutexStopAfterCycle.Unlock();
749780
#endif
781+
mRun++;
750782
}
751783
mIsOptimizing=false;
752784

@@ -1130,6 +1162,7 @@ void MonteCarloObj::RunRandomLSQMethod(long &nbCycle)
11301162

11311163
const long starting_point=mRefParList.CreateParamSet("MonteCarloObj:Last parameters (RANDOM-LSQ)");
11321164
mRefParList.SaveParamSet(starting_point);
1165+
mRun = 0;
11331166
while(nbCycle!=0) {
11341167
nbCycle--;
11351168
mRefParList.RestoreParamSet(starting_point);
@@ -1181,6 +1214,7 @@ void MonteCarloObj::RunRandomLSQMethod(long &nbCycle)
11811214
#ifdef __WX__CRYST__
11821215
mMutexStopAfterCycle.Unlock();
11831216
#endif
1217+
mRun++;
11841218
}
11851219

11861220
if(bsigma<0 || bdelta<0 || asigma<0 || adelta<0) return;

src/ObjCryst/RefinableObj/GlobalOptimObj.h

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -222,6 +222,10 @@ class OptimizationObj
222222
virtual long& NbTrialPerRun();
223223
/// Number of trial per run
224224
virtual const long& NbTrialPerRun() const;
225+
/// Current trial number (updated during a run)
226+
long GetTrial() const;
227+
/// Current run number (updated during a run)
228+
long GetRun() const;
225229
//Options
226230
/// Access to the options registry
227231
ObjRegistry<RefObjOpt>& GetOptionList();
@@ -240,6 +244,17 @@ class OptimizationObj
240244
/// Update Display (if any display is available), when a new 'relevant' configuration
241245
/// is reached. This calls all RefinableObj::UpdateDisplay()
242246
virtual void UpdateDisplay();
247+
/// Get the number of saved parameters set
248+
unsigned int GetNbParamSet() const;
249+
/// Get the index of a saved parameters set in the compiled RefinableObj.
250+
/// The parameters can then be accessed using GetRefinedObjList().GetParamSet(idx)
251+
long GetParamSetIndex(const unsigned int i) const;
252+
/// Get the cost (log-likelihood) of a saved parameters set
253+
long GetParamSetCost(const unsigned int i) const;
254+
/// Restore a given saved parameter set.
255+
/// This is equivalent to GetRefinedObjList().RestoreParamSet(GetSavedParamSetIndex(i))
256+
/// \param i: the order of the saved parameter set
257+
void RestoreParamSet(const unsigned int i, const bool update_display=true);
243258
protected:
244259
/// \internal Prepare mRefParList for the refinement
245260
void PrepareRefParList();
@@ -265,8 +280,10 @@ class OptimizationObj
265280
//Status of optimization
266281
/// Number of trial per run, to be saved/restored in XML output
267282
long mNbTrialPerRun;
268-
/// Number of trials so far
283+
/// Current trial number
269284
long mNbTrial;
285+
/// Current run number (during multiple runs)
286+
long mRun;
270287
/// Best value of the cost function so far
271288
REAL mBestCost;
272289
/// Index of the 'best' saved parameter set

0 commit comments

Comments
 (0)