23 #include "ObjCryst/RefinableObj/Simplex.h"
24 #include "ObjCryst/Quirks/VFNStreamFormat.h"
35 VFN_DEBUG_ENTRY(
"SimplexObj::Optimize()",10)
42 CrystVector_long vIndex(n+1);
44 CrystVector_REAL vLLK(n+1);
46 for(
unsigned long i=0;i<n;i++)
55 unsigned long best=0,worst=0,nextworst=0;
56 for(;nbSteps>=0;--nbSteps)
59 if(vLLK(0)>vLLK(1)){worst=0;nextworst=1;}
60 else{worst=1;nextworst=0;}
61 for(
unsigned long i=1;i<=n;i++)
63 if(vLLK(i)<=vLLK(best)) best =i;
64 if(vLLK(i)>vLLK(worst))
69 else if((vLLK(i)>vLLK(nextworst)) && (i!=worst)) nextworst=i;
72 CrystVector_REAL center(n);
74 for(
unsigned long i=0;i<=n;i++)
76 if(i==worst)
continue;
80 CrystVector_REAL worstdiff;
85 if(!silent && (nbSteps%100==0)) cout<<
"Simplex:cycle="<<nbSteps<<
", cost="<<vLLK(best)
86 <<
",best="<<best<<
",worst="<<worst<<
",nextworst="<<nextworst
87 <<
", Worst diff="<<abs(worstdiff.min())+abs(worstdiff.max())<<endl;
88 if((abs(worstdiff.min())+abs(worstdiff.max()))<0.01)
break;
91 cout<<FormatHorizVector<REAL>(vLLK)<<endl;
101 if(llktry<=vLLK(best))
103 else if(llktry>=vLLK(nextworst))
105 const REAL llksave=vLLK(worst);
110 for(
unsigned long i=0;i<=n;i++)
112 if(i==best)
continue;
114 for(
unsigned long j=0;j<n;j++)
115 {(*pi)(j) = 0.5*((*p0)(j) + (*pi)(j));}
125 VFN_DEBUG_EXIT(
"SimplexObj::Optimize()",10)
128 const REAL finalcost,
const REAL maxTime)
130 const long nbStep0=nbSteps;
133 if(!silent) cout <<
"SimplexObj::MultiRunOptimize: Starting Run#"<<abs(
float(nbCycle))<<endl;
135 this->
Optimize(nbSteps,silent,finalcost,maxTime);
136 if(!silent) cout <<
"SimplexObj::MultiRunOptimize: Finished Run#"<<abs(
float(nbCycle))<<endl;
146 CrystVector_long &vIndex,
152 const unsigned long iworst=vIndex(worst);
153 CrystVector_REAL center(n);
155 for(
unsigned long i=0;i<=n;i++)
157 if(i==worst)
continue;
161 for(
unsigned long i=0;i<n;i++)
180 WXOptimizationObj* SimplexObj::WXGet()
184 void SimplexObj::WXDelete(){}
185 void SimplexObj::WXNotifyDelete(){}
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.
void SaveParamSet(const unsigned long id) const
Save the current set of refined values over a previously-created set of saved values.
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.
const CrystVector_REAL & GetParamSet(const unsigned long setId) const
Access one save refpar set.
RefinablePar & GetParNotFixed(const long i)
Access all parameters in the order they were inputted, skipping fixed parameters. ...
long GetNbParNotFixed() const
Total number of non-fixed parameters. Is initialized by PrepareForRefinement()
Abstract base class for all objects in wxCryst.
const void EraseAllParamSet()
Erase all saved refpar sets.
void RestoreParamSet(const unsigned long id)
Restore a saved set of values.
RefinableObj mRefParList
The refinable par list used during refinement.
virtual void XMLOutput(ostream &os, int indent=0) const
Output a description of the object in XML format to a stream.
ObjRegistry< RefinableObj > mRefinedObjList
The refined objects.
void MutateTo(const REAL newValue)
Change the current value to the given one.
Base object for Optimization methods.
The namespace which includes all objects (crystallographic and algorithmic) in ObjCryst++.
REAL GetGlobalOptimStep() const
Maximum step to use during Global Optimization algorithms.
SimplexObj(const string name="Unnamed Simplex Object")
Constructor.
class to input or output a well-formatted xml beginning or ending tag.
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...
unsigned long CreateParamSet(const string name="") const
Save the current set of refined values in a new set.
REAL GenerateNewSimplexConfiguration(CrystVector_REAL &vLLK, CrystVector_long &vIndex, unsigned long worst, REAL f)
Try a new configuration by expanding the worst vertex from the center by a factor f...
virtual REAL GetLogLikelihood() const
The optimized (minimized, actually) function.