FOX/ObjCryst++  2022
RefinableObj.h
1 /* ObjCryst++ Object-Oriented Crystallographic Library
2  (c) 2000-2002 Vincent Favre-Nicolin vincefn@users.sourceforge.net
3  2000-2001 University of Geneva (Switzerland)
4 
5  This program is free software; you can redistribute it and/or modify
6  it under the terms of the GNU General Public License as published by
7  the Free Software Foundation; either version 2 of the License, or
8  (at your option) any later version.
9 
10  This program is distributed in the hope that it will be useful,
11  but WITHOUT ANY WARRANTY; without even the implied warranty of
12  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13  GNU General Public License for more details.
14 
15  You should have received a copy of the GNU General Public License
16  along with this program; if not, write to the Free Software
17  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
18 */
19 /*
20 * header file for the RefinablePar and RefinableObj classes
21 *
22 *
23 */
24 
25 #ifndef _VFN_REFINABLE_OBJ_H_
26 #define _VFN_REFINABLE_OBJ_H_
27 
28 #include <string>
29 #include <iostream>
30 #include <vector>
31 #include <list>
32 #include <map>
33 #include <set>
34 
35 #include "ObjCryst/CrystVector/CrystVector.h"
36 #include "ObjCryst/ObjCryst/General.h"
37 #include "ObjCryst/RefinableObj/IO.h"
38 
39 #ifdef __WX__CRYST__
40  class wxWindow;
41 namespace ObjCryst
42 {
43  template<class T> class ObjRegistry;
44  class RefObjOpt;
45  template<class T> class RefObjOption;
46  class RefinableObj;
47 }
48 #include "ObjCryst/wxCryst/wxRefinableObj.h"
49 #endif
50 
51 namespace ObjCryst
52 {
56 {
57  REFPAR_DERIV_STEP_ABSOLUTE,
58  REFPAR_DERIV_STEP_RELATIVE
59 };
60 
80 {
81  public:
84  RefParType(const string &name);
86  RefParType(const RefParType *parent,const string &name);
88  ~RefParType();
90  bool IsDescendantFromOrSameAs(const RefParType *type) const;
92  bool operator==(const RefParType *parent) const;
94  const string& GetName() const;
95  private:
97  void InitId();
101  const string mName;
103  unsigned long mId;
104 };
105 
107 extern const RefParType *gpRefParTypeObjCryst;
109 {
110  public:
112  {
113  if (mCount++ == 0)
114  {
115  gpRefParTypeObjCryst=new RefParType("ObjCryst++");
116  }
117  }
119  {
120  if (--mCount == 0)
121  {
122  delete gpRefParTypeObjCryst;
124  }
125  }
126  private:
127  static long mCount;
128 };
129 static NiftyStaticGlobalObjectsInitializer_RefinableObj NiftyStaticGlobalObjectsInitializer_RefinableObj_counter;
130 
140 {
141  public:
144  bool operator< (const RefinableObjClock &rhs)const;
145  bool operator<=(const RefinableObjClock &rhs)const;
146  bool operator> (const RefinableObjClock &rhs)const;
147  bool operator>=(const RefinableObjClock &rhs)const;
150  void Click();
152  void Reset();
154  void Print()const;
156  void PrintStatic()const;
159  void AddChild(const RefinableObjClock &);
161  void RemoveChild(const RefinableObjClock &);
164  void AddParent(RefinableObjClock &)const;
166  void RemoveParent(RefinableObjClock &)const;
170  void operator=(const RefinableObjClock &rhs);
171  private:
172  bool HasParent(const RefinableObjClock &) const;
173  unsigned long mTick0, mTick1;
174  static unsigned long msTick0,msTick1;
176  std::set<const RefinableObjClock*> mvChild;
180  mutable std::set<RefinableObjClock*> mvParent;
181 };
182 
201 {
202  public:
204  Restraint();
206  Restraint(const RefParType *type);
207  virtual ~Restraint();
208  virtual const RefParType* GetType()const;
209  virtual void SetType(const RefParType *type);
211  virtual REAL GetLogLikelihood()const;
212  private:
213  const RefParType *mpRefParType;
214 };
215 
225 {
226  public:
228 
229 
231  RefinablePar();
254  RefinablePar( const string &name,
255  REAL *refPar,
256  const REAL min,
257  const REAL max,
258  const RefParType *type,
259  RefParDerivStepModel derivMode=REFPAR_DERIV_STEP_RELATIVE,
260  const bool hasLimits=true,
261  const bool isFixed=false,
262  const bool isUsed=true,
263  const bool isPeriodic=false,
264  const REAL humanScale=1.,
265  REAL period=1.);
268  RefinablePar(const RefinablePar &ref);
269  ~RefinablePar();
292  void Init( const string &name,
293  REAL *refPar,
294  const REAL min,
295  const REAL max,
296  const RefParType *type,
297  RefParDerivStepModel derivMode=REFPAR_DERIV_STEP_RELATIVE,
298  const bool hasLimits=true,
299  const bool isFixed=false,
300  const bool isUsed=true,
301  const bool isPeriodic=false,
302  const REAL humanScale=1.,
303  REAL period=1.);
304 
308  void CopyAttributes(const RefinablePar&);
310 
312 
313 
316  REAL GetValue()const;
317 
322  const REAL* GetPointer()const;
323 
327  void SetValue(const REAL value);
328 
332  const REAL& GetHumanValue() const;
333 
337  void SetHumanValue(const REAL&) ;
338 
346  void Mutate(const REAL mutateValue);
353  void MutateTo(const REAL newValue);
354 
355  REAL GetSigma()const;
356  REAL GetHumanSigma()const;
357  void SetSigma(const REAL);
359 
361 
362  string GetName()const;
365  void SetName(const string&);
366 
367  void Print() const;
368 
369  bool IsFixed()const;
370  void SetIsFixed(const bool);
371 
372  bool IsLimited()const;
373  void SetIsLimited(const bool);
374 
376  bool IsUsed()const;
378  void SetIsUsed(const bool);
379 
380  bool IsPeriodic()const;
381  void SetIsPeriodic(const bool,REAL period=1);
382 
384  REAL GetHumanScale()const;
386  void SetHumanScale(const REAL);
388 
389 
391 
392  REAL GetMin()const;
395  void SetMin(const REAL);
396 
398  REAL GetHumanMin()const;
400  void SetHumanMin(const REAL);
401 
403  REAL GetMax()const;
405  void SetMax(const REAL);
406 
408  REAL GetHumanMax()const;
410  void SetHumanMax(const REAL);
411 
413  REAL GetPeriod()const;
415  void SetPeriod(const REAL);
417 
419 
420  REAL GetDerivStep()const;
423  void SetDerivStep(const REAL);
424 
426  REAL GetGlobalOptimStep()const;
428  void SetGlobalOptimStep(const REAL);
430 
431 
432  #if 0
434 
435  void SetUseEquation(const bool useItOrNot,const REAL c0=0.);
436  void SetUseEquation(const bool useItOrNot,const REAL c0,
437  const REAL c1, const RefinablePar &refpar1);
438 
439  void SetUseEquation(const bool useItOrNot,const REAL c0,
440  const REAL c1, const RefinablePar &refpar1,
441  const REAL c2, const RefinablePar &refpar2);
442  void SetUseEquation(const bool useItOrNot,const REAL c0,
443  const REAL c1, const RefinablePar &refpar1,
444  const REAL c2, const RefinablePar &refpar2,
445  const REAL c3, const RefinablePar &refpar3);
447  #endif
449 
450  void AssignClock(RefinableObjClock &clock);
455 
457 
458  void SetLimitsAbsolute(const REAL min, const REAL max);
463  void SetLimitsRelative(const REAL min, const REAL max);
466  void SetLimitsProportional(const REAL min, const REAL max);
468 
474  void XMLOutput(ostream &os,const string &name,int indent=0)const;
480  void XMLOutput(ostream &os,int indent=0)const;
484  void XMLInput(istream &is,const XMLCrystTag &tag);
485  private:
487  void Click();
489  string mName;
491  REAL *mpValue;
493  REAL mMin,mMax;
497  bool mIsFixed;
499  bool mIsUsed;
505  REAL mPeriod;
513  REAL mSigma;
518  #if 0
519  // Parameter defined by equations ? :TODO:
521  bool mUseEquation;
523  static const int mEquationMaxRefPar=10;
525  int mEquationNbRefPar;
527  CrystVector_REAL mEquationCoeff;
529  const RefinablePar *mEquationRefPar[10];
530  #endif
534  RefinableObjClock* mpClock;
535 
536  #ifdef __WX__CRYST__
537  public:
539  WXCrystObjBasic* WXCreate(wxWindow *parent);
540  WXCrystObjBasic* WXGet();
541  void WXDelete();
542  void WXNotifyDelete();
543  private:
544  WXFieldRefPar * mpWXFieldRefPar;
545  #endif
546  friend class RefinableObj;
547 };
552 {
553  public:
557  RefObjOpt();
558  virtual ~RefObjOpt();
559  void Init(const int nbChoice,const string *name,
560  const string *choiceNames);
561  int GetNbChoice()const;
562  int GetChoice()const;
563  virtual void SetChoice(const int choice);
564  void SetChoice(const string &choiceName);
565  const string& GetName()const;
566  const string& GetClassName()const;
567  const string& GetChoiceName(const int i)const;
568  const RefinableObjClock& GetClock()const;
573  void XMLOutput(ostream &os,int indent=0)const;
577  void XMLInput(istream &is,const XMLCrystTag &tag);
578  protected:
582  int mChoice;
585  const string* mpName;
588  const string* mpChoiceName;
591  #ifdef __WX__CRYST__
592  public:
593  WXCrystObjBasic* WXCreate(wxWindow *parent);
594  WXCrystObjBasic* WXGet();
595  void WXDelete();
596  void WXNotifyDelete();
597  private:
598  WXFieldOption * mpWXFieldOption;
599  #endif
600 };
601 
602 
607 template<class T> class RefObjOption:public RefObjOpt
608 {
609  public:
613  RefObjOption(T* obj);
614  ~RefObjOption();
615  void Init(const int nbChoice,const string *name,
616  const string *choiceNames,
617  void (T::*fp)(const int));
618  virtual void SetChoice(const int choice);
619  protected:
620  private:
622  T* mpObj;
626  void (T::*mfpSetNewValue)(const int);
627 };
628 
644 template<class T> class ObjRegistry
645 {
646  public:
647  ObjRegistry();
648  ObjRegistry(const string &name);
649  ~ObjRegistry();
651  void Register(T &obj);
653  void DeRegister(T &obj);
655  void DeRegister(const string &objName);
657  void DeRegisterAll();
659  void DeleteAll();
665  T& GetObj(const unsigned int i);
671  const T& GetObj(const unsigned int i)const;
674  T& GetObj(const string &objName);
677  const T& GetObj(const string &objName)const;
681  T& GetObj(const string &objName, const string& className);
685  const T& GetObj(const string &objName, const string& className)const;
688  long GetNb()const;
689  void Print()const;
690  void SetName(const string &);
691  const string& GetName()const;
694  long Find(const string &objName)const;
700  long Find(const string &objName, const string& className,
701  const bool nothrow=false)const;
704  long Find(const T &obj)const;
707  long Find(const T *pobj)const;
709  const RefinableObjClock& GetRegistryClock()const;
713  void AutoUpdateUI(const bool autoup=true);
718  void UpdateUI();
721  std::size_t size() const;
727  typename vector<T*>::const_iterator begin() const;
733  typename vector<T*>::const_iterator end() const;
739  typename std::list<T*>::const_iterator list_begin() const;
745  typename std::list<T*>::const_iterator list_end() const;
746  private:
748  vector<T*> mvpRegistry;
751  std::list<T*> mvpRegistryList;
753  string mName;
764  #ifdef __WX__CRYST__
765  public:
766  WXRegistry<T>* WXCreate(wxWindow *parent);
767  void WXDelete();
768  void WXNotifyDelete();
769  private:
770  WXRegistry<T> * mpWXRegistry;
771  #endif
772 };
773 
784 {
785  public:
787  RefinableObj();
791  RefinableObj(const bool internalUseOnly);
796  RefinableObj(const RefinableObj &old);
798  virtual ~RefinableObj();
802  virtual const string& GetClassName() const;
804  virtual const string& GetName() const;
806  virtual void SetName(const string &name);
809  void operator=(const RefinableObj &old);
810 
813  void PrepareForRefinement() const;
815  void FixAllPar();
817  void UnFixAllPar();
819  void SetParIsFixed(const long parIndex,const bool fix);
821  void SetParIsFixed(const string& parName,const bool fix);
823  void SetParIsFixed(const RefParType *type,const bool fix);
825  void SetParIsUsed(const string& parName,const bool use);
827  void SetParIsUsed(const RefParType *type,const bool use);
832  long GetNbPar()const;
834  long GetNbParNotFixed()const;
835 
837  RefinablePar& GetPar(const long i);
839  const RefinablePar& GetPar(const long i) const;
840 
842  RefinablePar& GetPar(const string & name);
844  const RefinablePar& GetPar(const string & name) const;
845 
847  RefinablePar& GetPar(const REAL*);
849  const RefinablePar& GetPar(const REAL*) const;
850 
853  RefinablePar& GetParNotFixed(const long i);
856  const RefinablePar& GetParNotFixed(const long i)const;
865  void AddPar(const RefinablePar &newRefPar);
872  void AddPar(RefinablePar *newRefPar);
891  void AddPar(RefinableObj &newRefParList, const bool copyParam=false);
896  vector<RefinablePar *>::iterator RemovePar(RefinablePar *refPar);
897 
898  virtual void Print() const;
899 
908  unsigned long CreateParamSet(const string name="") const;
911  void ClearParamSet(const unsigned long id)const;
916  void SaveParamSet(const unsigned long id)const;
924  void RestoreParamSet(const unsigned long id);
929  const CrystVector_REAL& GetParamSet(const unsigned long setId)const;
934  CrystVector_REAL& GetParamSet(const unsigned long setId);
944  REAL GetParamSet_ParNotFixedHumanValue(const unsigned long setId,const long parNumber)const;
948  const void EraseAllParamSet();
953  const string& GetParamSetName(const unsigned long setId)const;
954 
956  void SetLimitsAbsolute(const string &parName, const REAL min, const REAL max);
958  void SetLimitsAbsolute(const RefParType *type, const REAL min, const REAL max);
962  void SetLimitsRelative(const string &parName, const REAL min, const REAL max);
966  void SetLimitsRelative(const RefParType *type, const REAL min, const REAL max);
969  void SetLimitsProportional(const string &parName, const REAL min, const REAL max);
972  void SetLimitsProportional(const RefParType *type, const REAL min, const REAL max);
974  void SetGlobalOptimStep(const RefParType *type, const REAL step);
975 
980 
983  virtual void RegisterClient(RefinableObj &)const;
985  virtual void DeRegisterClient(RefinableObj &)const;
987  virtual const ObjRegistry<RefinableObj>& GetClientRegistry()const;
990 
992  bool IsBeingRefined()const;
993 
1014  virtual void BeginOptimization(const bool allowApproximations=false,
1015  const bool enableRestraints=false);
1022  virtual void EndOptimization();
1023 
1033  virtual void SetApproximationFlag(const bool allow);
1034 
1038  virtual void RandomizeConfiguration();
1039 
1059  virtual void GlobalOptRandomMove(const REAL mutationAmplitude,
1060  const RefParType *type=gpRefParTypeObjCryst);
1068  void BeginGlobalOptRandomMove();
1069 
1070  // Likelihood
1083  virtual REAL GetLogLikelihood()const;
1084  /* Get log(likelihood) and all its first derivative versus a list of parameters.
1085  *
1086  * \return: a map, with a RefinablePar pointer as key, and as value the corresponding
1087  * derivative. Note that the value of the map for the NULL key is the current value
1088  * for the log(likelihood), which is also returned. The map will include derivatives
1089  * only for parameters which have been supplied in vPar - but if a parameter
1090  * is listed in vPar and has a null derivative, it may be missing in the returned map.
1091  *
1092  * \warning: currently in development, to provide faster, analytic derivatives
1093  *
1094  * \note:ideally, this function should be const - but since numerical derivatives
1095  * may be used before all analytical formulas are entered, a non-const version is
1096  * required.
1097  * \todo
1098  */
1099  //virtual std::map<RefinablePar*, REAL>& GetLogLikelihood_FullDeriv(std::set<RefinablePar *> &vPar);
1100  //LSQ functions
1102  virtual unsigned int GetNbLSQFunction()const;
1103  // Get a Cost function name from its id#.
1104  //virtual const string& GetLSQFunctionName(const unsigned int)const;
1105  // Get the (short) description of a cost function
1106  //virtual const string& GetLSQFunctionDescription(const unsigned int)const;
1108  virtual const CrystVector_REAL& GetLSQCalc(const unsigned int) const;
1110  virtual const CrystVector_REAL& GetLSQObs(const unsigned int) const;
1112  virtual const CrystVector_REAL& GetLSQWeight(const unsigned int) const;
1120  virtual const CrystVector_REAL& GetLSQDeriv(const unsigned int, RefinablePar&);
1137  virtual std::map<RefinablePar*, CrystVector_REAL> & GetLSQ_FullDeriv(const unsigned int,std::set<RefinablePar *> &vPar);
1138 
1142  void ResetParList();
1143 
1148  virtual void XMLOutput(ostream &os,int indent=0)const;
1157  virtual void XMLInput(istream &is,const XMLCrystTag &tag);
1158  //virtual void XMLInputOld(istream &is,const IOCrystTag &tag);
1161  virtual void UpdateDisplay()const;
1162  //Options
1166  unsigned int GetNbOption()const;
1168  RefObjOpt& GetOption(const unsigned int i);
1170  RefObjOpt& GetOption(const string & name);
1172  const RefObjOpt& GetOption(const unsigned int i)const;
1174  const RefObjOpt& GetOption(const string & name)const;
1175  // Genetic
1200  virtual void GetGeneGroup(const RefinableObj &obj,
1201  CrystVector_uint & groupIndex,
1202  unsigned int &firstGroup) const;
1208  void SetDeleteRefParInDestructor(const bool b);
1212  const RefinableObjClock& GetRefParListClock()const;
1213  // Restraints
1222  virtual REAL GetRestraintCost()const;
1227  void AddRestraint(Restraint *pNewRestraint);
1231  vector<Restraint*>::iterator RemoveRestraint(Restraint *pRestraint);
1238  virtual void TagNewBestConfig()const;
1240  const RefinableObjClock& GetClockMaster()const;
1242  size_t int_ptr() const;
1243  protected:
1245  long FindPar(const string &name) const;
1247  long FindPar(const REAL*) const;
1248 
1250  void AddSubRefObj(RefinableObj &);
1252  void RemoveSubRefObj(RefinableObj &);
1253 
1255  void AddOption(RefObjOpt *opt);
1257  virtual void Prepare();
1258 
1260  map<unsigned long,pair<CrystVector_REAL,string> >::iterator FindParamSet(unsigned long id)const;
1261 
1263  string mName;
1264  // Parameters
1266  vector<RefinablePar *> mvpRefPar;
1267  // Restraints
1271  vector<Restraint*> mvpRestraint;
1272 
1273  //Saved sets of parameters
1279  mutable map<unsigned long,pair<CrystVector_REAL,string> > mvpSavedValuesSet;
1280 
1281  // Used during refinements, initialized by PrepareForRefinement()
1283  mutable long mNbRefParNotFixed;
1285  mutable CrystVector_long mRefparNotFixedIndex;
1292 
1298 
1299  // Options for this object
1315  mutable CrystVector_REAL mLSQDeriv;
1321  mutable std::map< unsigned int,std::map<RefinablePar*, CrystVector_REAL> > mLSQ_FullDeriv;
1322  // Temporary map to return the derivative of log(likelihood) versus a list of parameters
1323  //
1324  // \todo In development
1325  //mutable std::map<RefinablePar*, REAL> mLogLikelihood_FullDeriv;
1326 
1327 
1331  #ifdef __WX__CRYST__
1332  public:
1334  virtual WXCrystObjBasic* WXCreate(wxWindow*);
1335  WXCrystObjBasic* WXGet();
1336  void WXDelete();
1337  void WXNotifyDelete();
1338  protected:
1339  WXCrystObjBasic *mpWXCrystObj;
1340  #endif
1341 };
1346 template<class T> void RefObjRegisterRecursive(T &obj,ObjRegistry<T> &reg);
1349 
1356 }//namespace
1357 
1358 #endif// _VFN_REFINABLE_OBJ_H_
The namespace which includes all objects (crystallographic and algorithmic) in ObjCryst++.
Definition: doc-main.h:25
void RefObjRegisterRecursive(T &obj, ObjRegistry< T > &reg)
Register a new object in a registry, and recursively include all included (sub)objects.
const RefParType * gpRefParTypeObjCryst
Top RefParType for the ObjCryst++ library.
void GetSubRefObjListClockRecursive(ObjRegistry< RefinableObj > &reg, RefinableObjClock &clock)
Get the last time any object was added in the recursive list of objects.
ObjRegistry< RefinableObj > gRefinableObjRegistry("Global RefinableObj registry")
Global Registry for all RefinableObj.
void GetRefParListClockRecursive(ObjRegistry< RefinableObj > &reg, RefinableObjClock &clock)
Get the last time any RefinablePar was added in a recursive list of objects.
RefParDerivStepModel
How do we compute steps h for numerical derivative calculation : d=f(x+h)-f(x-h)/h/2 either h is fixe...
Definition: RefinableObj.h:56
ObjRegistry< RefinableObj > gTopRefinableObjRegistry("Global Top RefinableObj registry")
This is a special registry for 'top' object for an optimization.
class to input or output a well-formatted xml beginning or ending tag.
class of refinable parameter types.
Definition: RefinableObj.h:80
RefParType(const string &name)
Create a top parameter type.
~RefParType()
Destructor.
void InitId()
Get a Unique id (RefParType::mId)
bool operator==(const RefParType *parent) const
returns true if the two types are the same.
const string & GetName() const
Get the name for this parameter.
unsigned long mId
The unique number identifying this type.
Definition: RefinableObj.h:103
const RefParType * mpParent
the parent for this RefParType (we could easily allow several...)
Definition: RefinableObj.h:99
bool IsDescendantFromOrSameAs(const RefParType *type) const
Returns true if the parameter is a descendant of 'type'.
const string mName
The name/description for this parameter type.
Definition: RefinableObj.h:101
We need to record exactly when refinable objects have been modified for the last time (to avoid re-co...
Definition: RefinableObj.h:140
std::set< RefinableObjClock * > mvParent
List of parent clocks, which will be clicked whenever this one is.
Definition: RefinableObj.h:180
void Reset()
Reset a Clock to 0, to force an update.
void Print() const
Print clock value. Only for debugging purposes.
std::set< const RefinableObjClock * > mvChild
List of 'child' clocks, which will click this clock whenever they are clicked.
Definition: RefinableObj.h:176
void AddChild(const RefinableObjClock &)
Add a 'child' clock.
void AddParent(RefinableObjClock &) const
Add a 'parent' clock.
void RemoveChild(const RefinableObjClock &)
remove a child clock. This also tells the child clock to remove the parent.
void RemoveParent(RefinableObjClock &) const
remove a parent clock
void operator=(const RefinableObjClock &rhs)
This will (i) set the clock to the same values as the rhs clock, but will not change the list of chil...
void Click()
Record an event for this clock (generally, the 'time' an object has been modified,...
void PrintStatic() const
Print current general clock value. Only for debugging purposes.
Restraint: generic class for a restraint of a given model.
Definition: RefinableObj.h:201
virtual REAL GetLogLikelihood() const
Get -ln(likelihood) for this restraint.
Restraint()
Default constructor, sets RefParType to gpRefParTypeObjCryst.
Generic class for parameters of refinable objects.
Definition: RefinableObj.h:225
void XMLOutput(ostream &os, const string &name, int indent=0) const
XMLOutput to stream in well-formed XML.
void SetHumanScale(const REAL)
Human scale for this parameter : for angles, this is equal to 180/pi.
REAL GetDerivStep() const
Fixed step to use to compute numerical derivative.
REAL mDerivStep
Step to use for numerical derivative calculation.
Definition: RefinableObj.h:509
REAL GetHumanMin() const
Get the minimum value allowed (if limited)
bool mIsPeriodic
Is the parameter periodic ? If this is the case, then when using the RefinablePar::Mutate() function,...
Definition: RefinableObj.h:503
REAL mHumanScale
Scale to be used to display 'human' value.
Definition: RefinableObj.h:517
string GetName() const
Get the parameter's name.
REAL mMin
Hard lower and upper limits.
Definition: RefinableObj.h:493
void SetDerivStep(const REAL)
Fixed step to use to compute numerical derivative.
bool mHasAssignedClock
Is there a clock associated with this parameter ? If yes, then it must Click() it each time it is mod...
Definition: RefinableObj.h:533
void SetMax(const REAL)
Get the maximum value allowed (if limited)
REAL GetMin() const
Minimum value allowed (if limited or periodic)
REAL mGlobalOptimStep
Step to use for global method search (simulated annealing,...)
Definition: RefinableObj.h:507
void Click()
Click the Clock ! to telle the RefinableObj it has been modified.
REAL GetHumanScale() const
Human scale for this parameter : for angles, this is equal to 180/pi.
REAL GetValue() const
of the parameter.
void SetValue(const REAL value)
of the parameter.
void CopyAttributes(const RefinablePar &)
Copy all attributes (limits, flags, etc...) from another RefinablePar object.
void Init(const string &name, REAL *refPar, const REAL min, const REAL max, const RefParType *type, RefParDerivStepModel derivMode=REFPAR_DERIV_STEP_RELATIVE, const bool hasLimits=true, const bool isFixed=false, const bool isUsed=true, const bool isPeriodic=false, const REAL humanScale=1., REAL period=1.)
Constructor.
const REAL * GetPointer() const
Access to a const pointer to the refined value.
void MutateTo(const REAL newValue)
Change the current value to the given one.
void SetHumanValue(const REAL &)
Current value of parameter, scaled if necessary (for angles) to a human-understandable value.
void SetMin(const REAL)
Set the Minimum value allowed (if limited)
bool mHasLimits
Does the refinable parameter need limits (min and max) ?
Definition: RefinableObj.h:495
REAL * mpValue
Pointer to the refinable value.
Definition: RefinableObj.h:491
REAL mSigma
Calculated sigma on value.
Definition: RefinableObj.h:513
void SetPeriod(const REAL)
Set the period value (if periodic)
bool mIsUsed
Is the parameter currently used ?
Definition: RefinableObj.h:499
REAL GetHumanMax() const
Get the maximum value allowed (if limited)
void SetGlobalOptimStep(const REAL)
Maximum step to use during Global Optimization algorithms.
void SetLimitsAbsolute(const REAL min, const REAL max)
Change the limits for this object, giving absolute new limits.
bool IsUsed() const
Is the parameter used (if not, it is simply irrelevant in the model) ?
void AssignClock(RefinableObjClock &clock)
REAL GetMax() const
Get the maximum value allowed (if limited)
const REAL & GetHumanValue() const
Current value of parameter, scaled if necessary (for angles) to a human-understandable value.
void Mutate(const REAL mutateValue)
Add the given amount to the parameter current value.
void SetName(const string &)
Set the name of the parameter. It should be unique in the RefinableObj.
bool mIsFixed
is the parameter currently fixed ?
Definition: RefinableObj.h:497
void SetLimitsRelative(const REAL min, const REAL max)
Change the limits for this object, giving relative new limits (eg giving -.1 and +....
void SetHumanMin(const REAL)
Set the minimum value allowed (if limited)
RefParDerivStepModel mRefParDerivStepModel
Model followed for derivation.
Definition: RefinableObj.h:511
void SetHumanMax(const REAL)
Get the maximum value allowed (if limited)
REAL mPeriod
Period value (if relevant)
Definition: RefinableObj.h:505
RefinablePar()
Default Constructor.
REAL GetGlobalOptimStep() const
Maximum step to use during Global Optimization algorithms.
void SetIsUsed(const bool)
Is the parameter used (if not, it is simply irrelevant in the model) ?
REAL GetPeriod() const
Get the period (if periodic)
void XMLInput(istream &is, const XMLCrystTag &tag)
XMLInput From stream.
void SetLimitsProportional(const REAL min, const REAL max)
Change the limits for this object, proportionnaly to the current value.
string mName
name of the refinable parameter
Definition: RefinableObj.h:489
Base class for options.
Definition: RefinableObj.h:552
int mChoice
Current value.
Definition: RefinableObj.h:582
const string * mpName
(short) Name for this option.
Definition: RefinableObj.h:585
int mNbChoice
Number of different choice possible for this option.
Definition: RefinableObj.h:580
void XMLInput(istream &is, const XMLCrystTag &tag)
XMLInput From stream.
const string * mpChoiceName
Names corresponding to each possible value of this option (Human-understandable).
Definition: RefinableObj.h:588
RefinableObjClock mClock
The clock associated to this option.
Definition: RefinableObj.h:590
RefObjOpt()
Constructor for the option.
void XMLOutput(ostream &os, int indent=0) const
XMLOutput to stream in well-formed XML.
Class for options of RefinableObj, templated so that we can warn the object that something has been c...
Definition: RefinableObj.h:608
void(T::* mfpSetNewValue)(const int)
The pointer to the member function to be used when the choice is changed, to notify immediately the o...
Definition: RefinableObj.h:626
RefObjOption(T *obj)
Constructor for the option.
T * mpObj
The object which uses this option.
Definition: RefinableObj.h:622
Object Registry.
Definition: RefinableObj.h:645
void AutoUpdateUI(const bool autoup=true)
Enable the UI automatic update, so that objects in the registry are automatically added to the UI.
void DeRegisterAll()
De-register all objects from the list.
void DeRegister(T &obj)
De-register an object.
string mName
Name of this registry.
Definition: RefinableObj.h:753
RefinableObjClock mListClock
Last time an object was added or removed.
Definition: RefinableObj.h:755
T & GetObj(const unsigned int i)
Get object #i in the registry.
long GetNb() const
Get the index of an object in the registry, from its name Warning: it can change if an object is remo...
long Find(const string &objName) const
Find the number of an object in the registry from its name (slow !) The search starts at the end of t...
vector< T * >::const_iterator end() const
low-level access to the underlying vector end().
void Register(T &obj)
Register a new object. Already registered objects are skipped.
vector< T * > mvpRegistry
The registry of objects.
Definition: RefinableObj.h:748
std::list< T * > mvpRegistryList
Another view of the registry of objects - this time as a std::list, which will not be invalidated if ...
Definition: RefinableObj.h:751
bool mAutoUpdateUI
Enable the user interface update.
Definition: RefinableObj.h:763
std::size_t size() const
STL access to object size.
std::list< T * >::const_iterator list_end() const
low-level access to the underlying list end().
void UpdateUI()
Manually update the UI, making sure all objects in the registry are displayed This is useful when the...
void DeleteAll()
Delete all objects in the registry.. Use with caution !!
std::list< T * >::const_iterator list_begin() const
low-level access to the underlying list begin().
vector< T * >::const_iterator begin() const
low-level access to the underlying vector begin().
const RefinableObjClock & GetRegistryClock() const
Last time an object was added or removed from the registry.
Generic Refinable Object.
Definition: RefinableObj.h:784
REAL GetParamSet_ParNotFixedHumanValue(const unsigned long setId, const long parNumber) const
Access the (human) value of one refined parameter in a saved set of parameters.
ObjRegistry< RefObjOpt > & GetOptionList()
Access to the options list.
virtual void EndOptimization()
This should be called by any optimization class at the end of an optimization.
void RestoreParamSet(const unsigned long id)
Restore a saved set of values.
virtual ~RefinableObj()
Destructor.
virtual const string & GetClassName() const
Name for this class ("RefinableObj", "Crystal",...).
RefinableObj()
Constructor.
void AddPar(const RefinablePar &newRefPar)
Add a refinable parameter.
void AddRestraint(Restraint *pNewRestraint)
Add a new restraint.
ObjRegistry< RefinableObj > mSubObjRegistry
Registry of RefinableObject needed for this object (owned by this object or not)
bool IsBeingRefined() const
Is the object being refined ? (Can be refined by one algorithm at a time only.)
virtual void SetName(const string &name)
Name of the object.
virtual const CrystVector_REAL & GetLSQDeriv(const unsigned int, RefinablePar &)
Get the first derivative values for the LSQ function, for a given parameter.
virtual void RegisterClient(RefinableObj &) const
Register a new object using this object.
void SetParIsUsed(const string &parName, const bool use)
Set whether a parameter is used.
virtual void XMLOutput(ostream &os, int indent=0) const
Output to stream in well-formed XML.
CrystVector_REAL mLSQDeriv
Temporary array used to return derivative values of the LSQ function for given parameters.
RefinablePar & GetPar(const long i)
Access all parameters in the order they were inputted.
map< unsigned long, pair< CrystVector_REAL, string > > mvpSavedValuesSet
Map of (index,pointers to arrays) used to save sets of values for all parameters.
vector< Restraint * >::iterator RemoveRestraint(Restraint *pRestraint)
Remove a restraint from the list of known restraints.
const string & GetParamSetName(const unsigned long setId) const
Get the name associated to a refpar set.
vector< RefinablePar * >::iterator RemovePar(RefinablePar *refPar)
Remove a refinable parameter.
unsigned int GetNbOption() const
Number of Options for this object.
virtual const string & GetName() const
Name of the object.
void SetLimitsAbsolute(const string &parName, const REAL min, const REAL max)
Change the limits for a given parameter, giving absolute new limits.
void SetDeleteRefParInDestructor(const bool b)
Set this object not to delete its list of parameters when destroyed.
CrystVector_long mRefparNotFixedIndex
Index of not-fixed parameters.
long GetNbPar() const
Total number of refinable parameter in the object.
void ResetParList()
Re-init the list of refinable parameters, removing all parameters.
virtual void XMLInput(istream &is, const XMLCrystTag &tag)
Input From stream.
long FindPar(const string &name) const
Find a refinable parameter with a given name.
void BeginGlobalOptRandomMove()
Raise a flag, to be sure not to make a random change more than once in each RefinableObj.
virtual void SetApproximationFlag(const bool allow)
Enable or disable numerical approximations.
void SaveParamSet(const unsigned long id) const
Save the current set of refined values over a previously-created set of saved values.
virtual void BeginOptimization(const bool allowApproximations=false, const bool enableRestraints=false)
This should be called by any optimization class at the begining of an optimization.
ObjRegistry< RefinableObj > & GetSubObjRegistry()
Access to the registry of RefinableObj used by this object.
virtual unsigned int GetNbLSQFunction() const
Number of LSQ functions.
RefObjOpt & GetOption(const unsigned int i)
Access to the options.
void PrepareForRefinement() const
Find which parameters are used and not fixed, for a refinement /optimization.
size_t int_ptr() const
Access to the integer address of this object, for unique identification from python.
RefinablePar & GetParNotFixed(const long i)
Access all parameters in the order they were inputted, skipping fixed parameters.
const RefinableObjClock & GetRefParListClock() const
What was the last time a RefinablePar was added/removed ?
std::map< unsigned int, std::map< RefinablePar *, CrystVector_REAL > > mLSQ_FullDeriv
Temporary map to return the derivative of the LSQ function versus a list of parameters.
virtual std::map< RefinablePar *, CrystVector_REAL > & GetLSQ_FullDeriv(const unsigned int, std::set< RefinablePar * > &vPar)
Get the first derivative for the LSQ function for each parameter supplied in a list.
ObjRegistry< RefObjOpt > mOptionRegistry
List of options for this object.
RefinableObjClock mRefParListClock
Last time the RefinableParList was modified (a parameter added or removed).
const RefinableObjClock & GetClockMaster() const
This clocks records any change in the object. See refinableObj::mClockMaster.
virtual void TagNewBestConfig() const
During a global optimization, tells the object that the current config is the latest "best" config.
void AddOption(RefObjOpt *opt)
const CrystVector_REAL & GetParamSet(const unsigned long setId) const
Access one save refpar set.
long mNbRefParNotFixed
Total of not-fixed parameters.
bool mDeleteRefParInDestructor
If true (the default), then all RefinablePar will be deleted when the the object is deleted.
int mOptimizationDepth
Is the object being refined or optimized ? if mOptimizationDepth=0, no optimization is taking place.
void ClearParamSet(const unsigned long id) const
Erase the param set with the given id, releasing memory.
virtual const CrystVector_REAL & GetLSQWeight(const unsigned int) const
Get the weight values for the LSQ function.
virtual const CrystVector_REAL & GetLSQObs(const unsigned int) const
Get the observed values for the LSQ function.
void UnFixAllPar()
UnFix All parameters.
void operator=(const RefinableObj &old)
Defined not implemented...
unsigned long CreateParamSet(const string name="") const
Save the current set of refined values in a new set.
virtual void DeRegisterClient(RefinableObj &) const
Deregister an object (which not any more) using this object.
ObjRegistry< RefinableObj > mClientObjRegistry
Registry of RefinableObject using this object.
void FixAllPar()
Fix All parameters.
const void EraseAllParamSet()
Erase all saved refpar sets.
virtual void UpdateDisplay() const
If there is an interface, this should be automatically be called each time there is a 'new,...
void SetLimitsRelative(const string &parName, const REAL min, const REAL max)
Change the limits for a given parameter, giving relative new limits (eg giving -.1 and +....
virtual REAL GetRestraintCost() const
Get the restraint cost (overall penalty of all restraints)
RefinableObjClock mClockMaster
Master clock, which is changed whenever the object has been altered.
virtual REAL GetLogLikelihood() const
Get -log(likelihood) of the current configuration for the object.
virtual void GetGeneGroup(const RefinableObj &obj, CrystVector_uint &groupIndex, unsigned int &firstGroup) const
Get the gene group assigned to each parameter.
vector< Restraint * > mvpRestraint
Vector of pointers to the restraints for this object.
void SetParIsFixed(const long parIndex, const bool fix)
Fix/un-fix one parameter from its #.
string mName
Name for this RefinableObject. Should be unique, at least in the same scope.+.
void SetLimitsProportional(const string &parName, const REAL min, const REAL max)
Change the limits for a given parameter, proportionnaly to the current value.
vector< RefinablePar * > mvpRefPar
Vector of pointers to the refinable parameters.
virtual void RandomizeConfiguration()
Randomize Configuration (before a global optimization).
void AddSubRefObj(RefinableObj &)
void SetGlobalOptimStep(const RefParType *type, const REAL step)
Change the maximum step to use during Global Optimization algorithms.
long GetNbParNotFixed() const
Total number of non-fixed parameters. Is initialized by PrepareForRefinement()
virtual const ObjRegistry< RefinableObj > & GetClientRegistry() const
Get the list of clients.
map< unsigned long, pair< CrystVector_REAL, string > >::iterator FindParamSet(unsigned long id) const
Find a parameter set with a given id (and check if it is there)
virtual const CrystVector_REAL & GetLSQCalc(const unsigned int) const
Get the current calculated value for the LSQ function.
void RemoveSubRefObj(RefinableObj &)
virtual void GlobalOptRandomMove(const REAL mutationAmplitude, const RefParType *type=gpRefParTypeObjCryst)
Make a random move of the current configuration.
Abstract base class for all objects in wxCryst.
Definition: wxCryst.h:128
This displays all components of a ObjCryst++ Registry.
A field for a RefinablePar.
WX representation of a RefObj option. This displays the names of the different choices.