FOX/ObjCryst++  1.10.X (development)
1 /* ObjCryst++ Object-Oriented Crystallographic Library
2  (c) 2000-2002 Vincent Favre-Nicolin
3  2000-2001 University of Geneva (Switzerland)
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.
10  This program is distributed in the hope that it will be useful,
11  but WITHOUT ANY WARRANTY; without even the implied warranty of
13  GNU General Public License for more details.
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 */
25 #ifndef _VFN_REFINABLE_OBJ_H_
26 #define _VFN_REFINABLE_OBJ_H_
28 #include <string>
29 #include <iostream>
30 #include <vector>
31 #include <map>
32 #include <set>
34 #include "ObjCryst/CrystVector/CrystVector.h"
35 #include "ObjCryst/ObjCryst/General.h"
36 #include "ObjCryst/RefinableObj/IO.h"
38 #ifdef __WX__CRYST__
39  class wxWindow;
40 namespace ObjCryst
41 {
42  template<class T> class ObjRegistry;
43  class RefObjOpt;
44  template<class T> class RefObjOption;
45  class RefinableObj;
46 }
47 #include "ObjCryst/wxCryst/wxRefinableObj.h"
48 #endif
50 namespace ObjCryst
51 {
55 {
58 };
79 {
80  public:
83  RefParType(const string &name);
85  RefParType(const RefParType *parent,const string &name);
87  ~RefParType();
89  bool IsDescendantFromOrSameAs(const RefParType *type) const;
91  bool operator==(const RefParType *parent) const;
93  const string& GetName() const;
94  private:
96  void InitId();
100  const string mName;
102  unsigned long mId;
103 };
106 extern const RefParType *gpRefParTypeObjCryst;
108 {
109  public:
111  {
112  if (mCount++ == 0)
113  {
114  gpRefParTypeObjCryst=new RefParType("ObjCryst++");
115  }
116  }
118  {
119  if (--mCount == 0)
120  {
121  delete gpRefParTypeObjCryst;
122  gpRefParTypeObjCryst=0;
123  }
124  }
125  private:
126  static long mCount;
127 };
128 static NiftyStaticGlobalObjectsInitializer_RefinableObj NiftyStaticGlobalObjectsInitializer_RefinableObj_counter;
139 {
140  public:
143  bool operator< (const RefinableObjClock &rhs)const;
144  bool operator<=(const RefinableObjClock &rhs)const;
145  bool operator> (const RefinableObjClock &rhs)const;
146  bool operator>=(const RefinableObjClock &rhs)const;
149  void Click();
151  void Reset();
153  void Print()const;
155  void PrintStatic()const;
158  void AddChild(const RefinableObjClock &);
160  void RemoveChild(const RefinableObjClock &);
163  void AddParent(RefinableObjClock &)const;
165  void RemoveParent(RefinableObjClock &)const;
169  void operator=(const RefinableObjClock &rhs);
170  private:
171  bool HasParent(const RefinableObjClock &) const;
172  unsigned long mTick0, mTick1;
173  static unsigned long msTick0,msTick1;
175  std::set<const RefinableObjClock*> mvChild;
179  mutable std::set<RefinableObjClock*> mvParent;
180 };
200 {
201  public:
203  Restraint();
205  Restraint(const RefParType *type);
206  virtual ~Restraint();
207  virtual const RefParType* GetType()const;
208  virtual void SetType(const RefParType *type);
210  virtual REAL GetLogLikelihood()const;
211  private:
212  const RefParType *mpRefParType;
213 };
224 {
225  public:
230  RefinablePar();
253  RefinablePar( const string &name,
254  REAL *refPar,
255  const REAL min,
256  const REAL max,
257  const RefParType *type,
258  RefParDerivStepModel derivMode=REFPAR_DERIV_STEP_RELATIVE,
259  const bool hasLimits=true,
260  const bool isFixed=false,
261  const bool isUsed=true,
262  const bool isPeriodic=false,
263  const REAL humanScale=1.,
264  REAL period=1.);
267  RefinablePar(const RefinablePar &ref);
268  ~RefinablePar();
291  void Init( const string &name,
292  REAL *refPar,
293  const REAL min,
294  const REAL max,
295  const RefParType *type,
296  RefParDerivStepModel derivMode=REFPAR_DERIV_STEP_RELATIVE,
297  const bool hasLimits=true,
298  const bool isFixed=false,
299  const bool isUsed=true,
300  const bool isPeriodic=false,
301  const REAL humanScale=1.,
302  REAL period=1.);
307  void CopyAttributes(const RefinablePar&);
315  REAL GetValue()const;
321  const REAL* GetPointer()const;
326  void SetValue(const REAL value);
331  const REAL& GetHumanValue() const;
336  void SetHumanValue(const REAL&) ;
345  void Mutate(const REAL mutateValue);
352  void MutateTo(const REAL newValue);
354  REAL GetSigma()const;
355  REAL GetHumanSigma()const;
356  void SetSigma(const REAL);
361  string GetName()const;
364  void SetName(const string&);
366  void Print() const;
368  bool IsFixed()const;
369  void SetIsFixed(const bool);
371  bool IsLimited()const;
372  void SetIsLimited(const bool);
375  bool IsUsed()const;
377  void SetIsUsed(const bool);
379  bool IsPeriodic()const;
380  void SetIsPeriodic(const bool,REAL period=1);
383  REAL GetHumanScale()const;
385  void SetHumanScale(const REAL);
391  REAL GetMin()const;
394  void SetMin(const REAL);
397  REAL GetHumanMin()const;
399  void SetHumanMin(const REAL);
402  REAL GetMax()const;
404  void SetMax(const REAL);
407  REAL GetHumanMax()const;
409  void SetHumanMax(const REAL);
412  REAL GetPeriod()const;
414  void SetPeriod(const REAL);
419  REAL GetDerivStep()const;
422  void SetDerivStep(const REAL);
425  REAL GetGlobalOptimStep()const;
427  void SetGlobalOptimStep(const REAL);
431  #if 0
434  void SetUseEquation(const bool useItOrNot,const REAL c0=0.);
435  void SetUseEquation(const bool useItOrNot,const REAL c0,
436  const REAL c1, const RefinablePar &refpar1);
438  void SetUseEquation(const bool useItOrNot,const REAL c0,
439  const REAL c1, const RefinablePar &refpar1,
440  const REAL c2, const RefinablePar &refpar2);
441  void SetUseEquation(const bool useItOrNot,const REAL c0,
442  const REAL c1, const RefinablePar &refpar1,
443  const REAL c2, const RefinablePar &refpar2,
444  const REAL c3, const RefinablePar &refpar3);
446  #endif
449  void AssignClock(RefinableObjClock &clock);
457  void SetLimitsAbsolute(const REAL min, const REAL max);
462  void SetLimitsRelative(const REAL min, const REAL max);
465  void SetLimitsProportional(const REAL min, const REAL max);
473  void XMLOutput(ostream &os,const string &name,int indent=0)const;
479  void XMLOutput(ostream &os,int indent=0)const;
483  void XMLInput(istream &is,const XMLCrystTag &tag);
484  private:
486  void Click();
488  string mName;
490  REAL *mpValue;
492  REAL mMin,mMax;
496  bool mIsFixed;
498  bool mIsUsed;
504  REAL mPeriod;
512  REAL mSigma;
517  #if 0
518  // Parameter defined by equations ? :TODO:
520  bool mUseEquation;
522  static const int mEquationMaxRefPar=10;
524  int mEquationNbRefPar;
526  CrystVector_REAL mEquationCoeff;
528  const RefinablePar *mEquationRefPar[10];
529  #endif
530  bool mHasAssignedClock;
533  RefinableObjClock* mpClock;
535  #ifdef __WX__CRYST__
536  public:
538  WXCrystObjBasic* WXCreate(wxWindow *parent);
539  WXCrystObjBasic* WXGet();
540  void WXDelete();
541  void WXNotifyDelete();
542  private:
543  WXFieldRefPar * mpWXFieldRefPar;
544  #endif
545  friend class RefinableObj;
546 };
551 {
552  public:
556  RefObjOpt();
557  virtual ~RefObjOpt();
558  void Init(const int nbChoice,const string *name,
559  const string *choiceNames);
560  int GetNbChoice()const;
561  int GetChoice()const;
562  virtual void SetChoice(const int choice);
563  void SetChoice(const string &choiceName);
564  const string& GetName()const;
565  const string& GetClassName()const;
566  const string& GetChoiceName(const int i)const;
567  const RefinableObjClock& GetClock()const;
572  void XMLOutput(ostream &os,int indent=0)const;
576  void XMLInput(istream &is,const XMLCrystTag &tag);
577  protected:
581  int mChoice;
584  const string* mpName;
587  const string* mpChoiceName;
590  #ifdef __WX__CRYST__
591  public:
592  WXCrystObjBasic* WXCreate(wxWindow *parent);
593  WXCrystObjBasic* WXGet();
594  void WXDelete();
595  void WXNotifyDelete();
596  private:
597  WXFieldOption * mpWXFieldOption;
598  #endif
599 };
606 template<class T> class RefObjOption:public RefObjOpt
607 {
608  public:
612  RefObjOption(T* obj);
613  ~RefObjOption();
614  void Init(const int nbChoice,const string *name,
615  const string *choiceNames,
616  void (T::*fp)(const int));
617  virtual void SetChoice(const int choice);
618  protected:
619  private:
621  T* mpObj;
625  void (T::*mfpSetNewValue)(const int);
626 };
643 template<class T> class ObjRegistry
644 {
645  public:
646  ObjRegistry();
647  ObjRegistry(const string &name);
648  ~ObjRegistry();
650  void Register(T &obj);
652  void DeRegister(T &obj);
654  void DeRegister(const string &objName);
656  void DeRegisterAll();
658  void DeleteAll();
664  T& GetObj(const unsigned int i);
670  const T& GetObj(const unsigned int i)const;
673  T& GetObj(const string &objName);
676  const T& GetObj(const string &objName)const;
680  T& GetObj(const string &objName, const string& className);
684  const T& GetObj(const string &objName, const string& className)const;
687  long GetNb()const;
688  void Print()const;
689  void SetName(const string &);
690  const string& GetName()const;
693  long Find(const string &objName)const;
699  long Find(const string &objName, const string& className,
700  const bool nothrow=false)const;
703  long Find(const T &obj)const;
706  long Find(const T *pobj)const;
708  const RefinableObjClock& GetRegistryClock()const;
712  void AutoUpdateUI(const bool autoup=true);
717  void UpdateUI();
718  private:
720  vector<T*> mvpRegistry;
722  string mName;
733  #ifdef __WX__CRYST__
734  public:
735  WXRegistry<T>* WXCreate(wxWindow *parent);
736  void WXDelete();
737  void WXNotifyDelete();
738  private:
739  WXRegistry<T> * mpWXRegistry;
740  #endif
741 };
753 {
754  public:
756  RefinableObj();
760  RefinableObj(const bool internalUseOnly);
765  RefinableObj(const RefinableObj &old);
767  virtual ~RefinableObj();
771  virtual const string& GetClassName() const;
773  virtual const string& GetName() const;
775  virtual void SetName(const string &name);
778  void operator=(const RefinableObj &old);
782  void PrepareForRefinement() const;
784  void FixAllPar();
786  void UnFixAllPar();
788  void SetParIsFixed(const long parIndex,const bool fix);
790  void SetParIsFixed(const string& parName,const bool fix);
792  void SetParIsFixed(const RefParType *type,const bool fix);
794  void SetParIsUsed(const string& parName,const bool use);
796  void SetParIsUsed(const RefParType *type,const bool use);
801  long GetNbPar()const;
803  long GetNbParNotFixed()const;
806  RefinablePar& GetPar(const long i);
808  const RefinablePar& GetPar(const long i) const;
811  RefinablePar& GetPar(const string & name);
813  const RefinablePar& GetPar(const string & name) const;
816  RefinablePar& GetPar(const REAL*);
818  const RefinablePar& GetPar(const REAL*) const;
822  RefinablePar& GetParNotFixed(const long i);
825  const RefinablePar& GetParNotFixed(const long i)const;
834  void AddPar(const RefinablePar &newRefPar);
841  void AddPar(RefinablePar *newRefPar);
860  void AddPar(RefinableObj &newRefParList, const bool copyParam=false);
865  vector<RefinablePar *>::iterator RemovePar(RefinablePar *refPar);
867  virtual void Print() const;
877  unsigned long CreateParamSet(const string name="") const;
880  void ClearParamSet(const unsigned long id)const;
885  void SaveParamSet(const unsigned long id)const;
893  void RestoreParamSet(const unsigned long id);
898  const CrystVector_REAL& GetParamSet(const unsigned long setId)const;
903  CrystVector_REAL& GetParamSet(const unsigned long setId);
913  REAL GetParamSet_ParNotFixedHumanValue(const unsigned long setId,const long parNumber)const;
917  const void EraseAllParamSet();
922  const string& GetParamSetName(const unsigned long setId)const;
925  void SetLimitsAbsolute(const string &parName, const REAL min, const REAL max);
927  void SetLimitsAbsolute(const RefParType *type, const REAL min, const REAL max);
931  void SetLimitsRelative(const string &parName, const REAL min, const REAL max);
935  void SetLimitsRelative(const RefParType *type, const REAL min, const REAL max);
938  void SetLimitsProportional(const string &parName, const REAL min, const REAL max);
941  void SetLimitsProportional(const RefParType *type, const REAL min, const REAL max);
943  void SetGlobalOptimStep(const RefParType *type, const REAL step);
952  virtual void RegisterClient(RefinableObj &)const;
954  virtual void DeRegisterClient(RefinableObj &)const;
956  virtual const ObjRegistry<RefinableObj>& GetClientRegistry()const;
961  bool IsBeingRefined()const;
983  virtual void BeginOptimization(const bool allowApproximations=false,
984  const bool enableRestraints=false);
991  virtual void EndOptimization();
1002  virtual void SetApproximationFlag(const bool allow);
1007  virtual void RandomizeConfiguration();
1028  virtual void GlobalOptRandomMove(const REAL mutationAmplitude,
1029  const RefParType *type=gpRefParTypeObjCryst);
1037  void BeginGlobalOptRandomMove();
1039  // Likelihood
1052  virtual REAL GetLogLikelihood()const;
1053  /* Get log(likelihood) and all its first derivative versus a list of parameters.
1054  *
1055  * \return: a map, with a RefinablePar pointer as key, and as value the corresponding
1056  * derivative. Note that the value of the map for the NULL key is the current value
1057  * for the log(likelihood), which is also returned. The map will include derivatives
1058  * only for parameters which have been supplied in vPar - but if a parameter
1059  * is listed in vPar and has a null derivative, it may be missing in the returned map.
1060  *
1061  * \warning: currently in development, to provide faster, analytic derivatives
1062  *
1063  * \note:ideally, this function should be const - but since numerical derivatives
1064  * may be used before all analytical formulas are entered, a non-const version is
1065  * required.
1066  * \todo
1067  */
1068  //virtual std::map<RefinablePar*, REAL>& GetLogLikelihood_FullDeriv(std::set<RefinablePar *> &vPar);
1069  //LSQ functions
1071  virtual unsigned int GetNbLSQFunction()const;
1072  // Get a Cost function name from its id#.
1073  //virtual const string& GetLSQFunctionName(const unsigned int)const;
1074  // Get the (short) description of a cost function
1075  //virtual const string& GetLSQFunctionDescription(const unsigned int)const;
1077  virtual const CrystVector_REAL& GetLSQCalc(const unsigned int) const;
1079  virtual const CrystVector_REAL& GetLSQObs(const unsigned int) const;
1081  virtual const CrystVector_REAL& GetLSQWeight(const unsigned int) const;
1089  virtual const CrystVector_REAL& GetLSQDeriv(const unsigned int, RefinablePar&);
1106  virtual std::map<RefinablePar*, CrystVector_REAL> & GetLSQ_FullDeriv(const unsigned int,std::set<RefinablePar *> &vPar);
1111  void ResetParList();
1117  virtual void XMLOutput(ostream &os,int indent=0)const;
1126  virtual void XMLInput(istream &is,const XMLCrystTag &tag);
1127  //virtual void XMLInputOld(istream &is,const IOCrystTag &tag);
1130  virtual void UpdateDisplay()const;
1131  //Options
1133  unsigned int GetNbOption()const;
1135  RefObjOpt& GetOption(const unsigned int i);
1137  const RefObjOpt& GetOption(const unsigned int i)const;
1138  // Genetic
1163  virtual void GetGeneGroup(const RefinableObj &obj,
1164  CrystVector_uint & groupIndex,
1165  unsigned int &firstGroup) const;
1171  void SetDeleteRefParInDestructor(const bool b);
1175  const RefinableObjClock& GetRefParListClock()const;
1176  // Restraints
1185  virtual REAL GetRestraintCost()const;
1190  void AddRestraint(Restraint *pNewRestraint);
1194  vector<Restraint*>::iterator RemoveRestraint(Restraint *pRestraint);
1201  virtual void TagNewBestConfig()const;
1203  const RefinableObjClock& GetClockMaster()const;
1204  protected:
1206  long FindPar(const string &name) const;
1208  long FindPar(const REAL*) const;
1211  void AddSubRefObj(RefinableObj &);
1213  void RemoveSubRefObj(RefinableObj &);
1216  void AddOption(RefObjOpt *opt);
1218  virtual void Prepare();
1221  map<unsigned long,pair<CrystVector_REAL,string> >::iterator FindParamSet(unsigned long id)const;
1224  string mName;
1225  // Parameters
1227  vector<RefinablePar *> mvpRefPar;
1228  // Restraints
1232  vector<Restraint*> mvpRestraint;
1234  //Saved sets of parameters
1240  mutable map<unsigned long,pair<CrystVector_REAL,string> > mvpSavedValuesSet;
1242  // Used during refinements, initialized by PrepareForRefinement()
1244  mutable long mNbRefParNotFixed;
1246  mutable CrystVector_long mRefparNotFixedIndex;
1260  // Options for this object
1276  mutable CrystVector_REAL mLSQDeriv;
1282  mutable std::map< unsigned int,std::map<RefinablePar*, CrystVector_REAL> > mLSQ_FullDeriv;
1283  // Temporary map to return the derivative of log(likelihood) versus a list of parameters
1284  //
1285  // \todo In development
1286  //mutable std::map<RefinablePar*, REAL> mLogLikelihood_FullDeriv;
1292  #ifdef __WX__CRYST__
1293  public:
1295  virtual WXCrystObjBasic* WXCreate(wxWindow*);
1296  WXCrystObjBasic* WXGet();
1297  void WXDelete();
1298  void WXNotifyDelete();
1299  protected:
1300  WXCrystObjBasic *mpWXCrystObj;
1301  #endif
1302 };
1307 template<class T> void RefObjRegisterRecursive(T &obj,ObjRegistry<T> &reg);
1317 }//namespace
1319 #endif// _VFN_REFINABLE_OBJ_H_
void UpdateUI()
Manually update the UI, making sure all objects in the registry are displayed This is useful when the...
REAL mGlobalOptimStep
Step to use for global method search (simulated annealing,...)
Definition: RefinableObj.h:506
void SetDerivStep(const REAL)
Fixed step to use to compute numerical derivative.
T & GetObj(const unsigned int i)
Get object #i in the registry.
REAL GetHumanMin() const
Get the minimum value allowed (if limited)
void Print() const
Print clock value. Only for debugging purposes.
virtual REAL GetRestraintCost() const
Get the restraint cost (overall penalty of all restraints)
void AddSubRefObj(RefinableObj &)
CrystVector_long mRefparNotFixedIndex
Index of not-fixed parameters.
void AddPar(const RefinablePar &newRefPar)
Add a refinable parameter.
virtual const ObjRegistry< RefinableObj > & GetClientRegistry() const
Get the list of clients.
RefinableObjClock mRefParListClock
Last time the RefinableParList was modified (a parameter added or removed).
virtual void UpdateDisplay() const
If there is an interface, this should be automatically be called each time there is a 'new...
REAL GetMin() const
Minimum value allowed (if limited or periodic)
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 +...
bool mIsFixed
is the parameter currently fixed ?
Definition: RefinableObj.h:496
const RefinableObjClock & GetRegistryClock() const
Last time an object was added or removed from the registry.
void SetParIsUsed(const string &parName, const bool use)
Set whether a parameter is used.
WX representation of a RefObj option. This displays the names of the different choices.
void AutoUpdateUI(const bool autoup=true)
Enable the UI automatic update, so that objects in the registry are automatically added to the UI...
long GetNb() const
Get the index of an object in the registry, from its name Warning: it can change if an object is remo...
string GetName() const
Get the parameter's name.
void Register(T &obj)
Register a new object. Already registered objects are skipped.
We need to record exactly when refinable objects have been modified for the last time (to avoid re-co...
Definition: RefinableObj.h:138
bool IsBeingRefined() const
Is the object being refined ? (Can be refined by one algorithm at a time only.)
virtual void GlobalOptRandomMove(const REAL mutationAmplitude, const RefParType *type=gpRefParTypeObjCryst)
Make a random move of the current configuration.
REAL * mpValue
Pointer to the refinable value.
Definition: RefinableObj.h:490
const REAL * GetPointer() const
Access to a const pointer to the refined value.
void FixAllPar()
Fix All parameters.
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.
const string * mpName
(short) Name for this option.
Definition: RefinableObj.h:584
void SaveParamSet(const unsigned long id) const
Save the current set of refined values over a previously-created set of saved values.
void RemoveParent(RefinableObjClock &) const
remove a parent clock
A field for a RefinablePar.
const string & GetName() const
Get the name for this parameter.
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)
vector< T * > mvpRegistry
The registry of objects.
Definition: RefinableObj.h:720
void SetParIsFixed(const long parIndex, const bool fix)
Fix/un-fix one parameter from its #.
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...
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...
RefParType(const string &name)
Create a top parameter type.
void RefObjRegisterRecursive(T &obj, ObjRegistry< T > &reg)
Register a new object in a registry, and recursively include all included (sub)objects.
void Click()
Record an event for this clock (generally, the 'time' an object has been modified, or some computation has been made)
vector< Restraint * >::iterator RemoveRestraint(Restraint *pRestraint)
Remove a restraint from the list of known restraints.
RefinableObjClock mClock
The clock associated to this option.
Definition: RefinableObj.h:589
void RemoveSubRefObj(RefinableObj &)
long GetNbPar() const
Total number of refinable parameter in the object.
void AddChild(const RefinableObjClock &)
Add a 'child' clock.
long mNbRefParNotFixed
Total of not-fixed parameters.
Class for options of RefinableObj, templated so that we can warn the object that something has been c...
Definition: RefinableObj.h:606
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. ...
void SetLimitsRelative(const REAL min, const REAL max)
Change the limits for this object, giving relative new limits (eg giving -.1 and +.1 will set new limits at the current value + min and current value + max) Thus min should logically be <0 and max >0.
void XMLInput(istream &is, const XMLCrystTag &tag)
XMLInput From stream.
long GetNbParNotFixed() const
Total number of non-fixed parameters. Is initialized by PrepareForRefinement()
RefinablePar & GetPar(const long i)
Access all parameters in the order they were inputted.
std::set< RefinableObjClock * > mvParent
List of parent clocks, which will be clicked whenever this one is.
Definition: RefinableObj.h:179
unsigned long mId
The unique number identifying this type.
Definition: RefinableObj.h:102
void SetIsUsed(const bool)
Is the parameter used (if not, it is simply irrelevant in the model) ?
void PrintStatic() const
Print current general clock value. Only for debugging purposes.
void XMLInput(istream &is, const XMLCrystTag &tag)
XMLInput From stream.
REAL mDerivStep
Step to use for numerical derivative calculation.
Definition: RefinableObj.h:508
void InitId()
Get a Unique id (RefParType::mId)
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:625
void BeginGlobalOptRandomMove()
Raise a flag, to be sure not to make a random change more than once in each RefinableObj.
void Mutate(const REAL mutateValue)
Add the given amount to the parameter current value.
virtual void RegisterClient(RefinableObj &) const
Register a new object using this object.
This displays all components of a ObjCryst++ Registry.
virtual REAL GetLogLikelihood() const
Get -ln(likelihood) for this restraint.
virtual void GetGeneGroup(const RefinableObj &obj, CrystVector_uint &groupIndex, unsigned int &firstGroup) const
Get the gene group assigned to each parameter.
void SetLimitsProportional(const string &parName, const REAL min, const REAL max)
Change the limits for a given parameter, proportionnaly to the current value.
ObjRegistry< RefinableObj > gTopRefinableObjRegistry("Global Top RefinableObj registry")
This is a special registry for 'top' object for an optimization.
RefinableObjClock mClockMaster
Master clock, which is changed whenever the object has been altered.
virtual void SetApproximationFlag(const bool allow)
Enable or disable numerical approximations.
unsigned int GetNbOption() const
Number of Options for this object.
const REAL & GetHumanValue() const
Current value of parameter, scaled if necessary (for angles) to a human-understandable value...
RefObjOpt & GetOption(const unsigned int i)
Access to the options.
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:54
REAL mHumanScale
Scale to be used to display 'human' value.
Definition: RefinableObj.h:516
Generic Refinable Object.
Definition: RefinableObj.h:752
void SetMin(const REAL)
Set the Minimum value allowed (if limited)
REAL mPeriod
Period value (if relevant)
Definition: RefinableObj.h:504
void SetLimitsProportional(const REAL min, const REAL max)
Change the limits for this object, proportionnaly to the current value.
void ResetParList()
Re-init the list of refinable parameters, removing all parameters.
const RefinableObjClock & GetClockMaster() const
This clocks records any change in the object. See refinableObj::mClockMaster.
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< RefinableObj > gRefinableObjRegistry("Global RefinableObj registry")
Global Registry for all RefinableObj.
RefObjOption(T *obj)
Constructor for the option.
Abstract base class for all objects in wxCryst.
Definition: wxCryst.h:127
map< unsigned long, pair< CrystVector_REAL, string > > mvpSavedValuesSet
Map of (index,pointers to arrays) used to save sets of values for all parameters. ...
void GetRefParListClockRecursive(ObjRegistry< RefinableObj > &reg, RefinableObjClock &clock)
Get the last time any RefinablePar was added in a recursive list of objects.
string mName
Name for this RefinableObject. Should be unique, at least in the same scope.+.
void PrepareForRefinement() const
Find which parameters are used and not fixed, for a refinement /optimization.
string mName
Name of this registry.
Definition: RefinableObj.h:722
virtual const CrystVector_REAL & GetLSQDeriv(const unsigned int, RefinablePar &)
Get the first derivative values for the LSQ function, for a given parameter.
bool mHasLimits
Does the refinable parameter need limits (min and max) ?
Definition: RefinableObj.h:494
const void EraseAllParamSet()
Erase all saved refpar sets.
Base class for options.
Definition: RefinableObj.h:550
const string * mpChoiceName
Names corresponding to each possible value of this option (Human-understandable). ...
Definition: RefinableObj.h:587
bool mDeleteRefParInDestructor
If true (the default), then all RefinablePar will be deleted when the the object is deleted...
void RestoreParamSet(const unsigned long id)
Restore a saved set of values.
void AssignClock(RefinableObjClock &clock)
REAL GetMax() const
Get the maximum value allowed (if limited)
vector< Restraint * > mvpRestraint
Vector of pointers to the restraints for this object.
void XMLOutput(ostream &os, int indent=0) const
XMLOutput to stream in well-formed XML.
REAL GetPeriod() const
Get the period (if periodic)
void RemoveChild(const RefinableObjClock &)
remove a child clock. This also tells the child clock to remove the parent.
void operator=(const RefinableObj &old)
Defined not implemented...
RefParDerivStepModel mRefParDerivStepModel
Model followed for derivation.
Definition: RefinableObj.h:510
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.)
Default Constructor.
bool mIsPeriodic
Is the parameter periodic ? If this is the case, then when using the RefinablePar::Mutate() function...
Definition: RefinableObj.h:502
virtual const CrystVector_REAL & GetLSQCalc(const unsigned int) const
Get the current calculated value for the LSQ function.
const string & GetParamSetName(const unsigned long setId) const
Get the name associated to a refpar set.
const RefinableObjClock & GetRefParListClock() const
What was the last time a RefinablePar was added/removed ?
void DeRegister(T &obj)
De-register an object.
void Click()
Click the Clock ! to telle the RefinableObj it has been modified.
void AddParent(RefinableObjClock &) const
Add a 'parent' clock.
ObjRegistry< RefinableObj > & GetSubObjRegistry()
Access to the registry of RefinableObj used by this object.
void CopyAttributes(const RefinablePar &)
Copy all attributes (limits, flags, etc...) from another RefinablePar object.
bool mAutoUpdateUI
Enable the user interface update.
Definition: RefinableObj.h:732
virtual const string & GetClassName() const
Name for this class ("RefinableObj", "Crystal",...).
bool mIsUsed
Is the parameter currently used ?
Definition: RefinableObj.h:498
void DeleteAll()
Delete all objects in the registry.. Use with caution !!
virtual void RandomizeConfiguration()
Randomize Configuration (before a global optimization).
ObjRegistry< RefinableObj > mClientObjRegistry
Registry of RefinableObject using this object.
virtual void XMLOutput(ostream &os, int indent=0) const
Output to stream in well-formed XML.
int mNbChoice
Number of different choice possible for this option.
Definition: RefinableObj.h:579
void SetHumanValue(const REAL &)
Current value of parameter, scaled if necessary (for angles) to a human-understandable value...
Restraint: generic class for a restraint of a given model.
Definition: RefinableObj.h:199
ObjRegistry< RefinableObj > mSubObjRegistry
Registry of RefinableObject needed for this object (owned by this object or not)
CrystVector_REAL mLSQDeriv
Temporary array used to return derivative values of the LSQ function for given parameters.
const string mName
The name/description for this parameter type.
Definition: RefinableObj.h:100
void MutateTo(const REAL newValue)
Change the current value to the given one.
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.
void SetValue(const REAL value)
of the parameter.
REAL GetHumanScale() const
Human scale for this parameter : for angles, this is equal to 180/pi.
bool operator==(const RefParType *parent) const
returns true if the two types are the same.
bool IsDescendantFromOrSameAs(const RefParType *type) const
Returns true if the parameter is a descendant of 'type'.
void Reset()
Reset a Clock to 0, to force an update.
REAL GetHumanMax() const
Get the maximum value allowed (if limited)
RefinableObjClock mListClock
Last time an object was added or removed.
Definition: RefinableObj.h:724
virtual void EndOptimization()
This should be called by any optimization class at the end of an optimization.
long FindPar(const string &name) const
Find a refinable parameter with a given name.
virtual unsigned int GetNbLSQFunction() const
Number of LSQ functions.
The namespace which includes all objects (crystallographic and algorithmic) in ObjCryst++.
Definition: Atom.cpp:47
void SetHumanMin(const REAL)
Set the minimum value allowed (if limited)
void SetMax(const REAL)
Get the maximum value allowed (if limited)
const RefParType * mpParent
the parent for this RefParType (we could easily allow several...)
Definition: RefinableObj.h:98
REAL GetDerivStep() const
Fixed step to use to compute numerical derivative.
virtual REAL GetLogLikelihood() const
Get -log(likelihood) of the current configuration for the object.
Generic class for parameters of refinable objects.
Definition: RefinableObj.h:223
T * mpObj
The object which uses this option.
Definition: RefinableObj.h:621
Constructor for the option.
virtual const string & GetName() const
Name of the object.
REAL GetGlobalOptimStep() const
Maximum step to use during Global Optimization algorithms.
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:532
string mName
name of the refinable parameter
Definition: RefinableObj.h:488
void SetHumanMax(const REAL)
Get the maximum value allowed (if limited)
void GetSubRefObjListClockRecursive(ObjRegistry< RefinableObj > &reg, RefinableObjClock &clock)
Get the last time any object was added in the recursive list of objects.
void AddRestraint(Restraint *pNewRestraint)
Add a new restraint.
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.
REAL GetValue() const
of the parameter.
vector< RefinablePar * >::iterator RemovePar(RefinablePar *refPar)
Remove a refinable parameter.
Default constructor, sets RefParType to gpRefParTypeObjCryst.
virtual const CrystVector_REAL & GetLSQObs(const unsigned int) const
Get the observed values for the LSQ function.
void SetGlobalOptimStep(const RefParType *type, const REAL step)
Change the maximum step to use during Global Optimization algorithms.
void SetLimitsAbsolute(const string &parName, const REAL min, const REAL max)
Change the limits for a given parameter, giving absolute new limits.
vector< RefinablePar * > mvpRefPar
Vector of pointers to the refinable parameters.
class to input or output a well-formatted xml beginning or ending tag.
ObjRegistry< RefObjOpt > mOptionRegistry
List of options for this object.
int mChoice
Current value.
Definition: RefinableObj.h:581
void SetDeleteRefParInDestructor(const bool b)
Set this object not to delete its list of parameters when destroyed.
void SetPeriod(const REAL)
Set the period value (if periodic)
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.
void DeRegisterAll()
De-register all objects from the list.
virtual void TagNewBestConfig() const
During a global optimization, tells the object that the current config is the latest "best" config...
void SetHumanScale(const REAL)
Human scale for this parameter : for angles, this is equal to 180/pi.
bool IsUsed() const
Is the parameter used (if not, it is simply irrelevant in the model) ?
class of refinable parameter types.
Definition: RefinableObj.h:78
virtual ~RefinableObj()
virtual void DeRegisterClient(RefinableObj &) const
Deregister an object (which not any more) using this object.
unsigned long CreateParamSet(const string name="") const
Save the current set of refined values in a new set.
void SetName(const string &)
Set the name of the parameter. It should be unique in the RefinableObj.
std::set< const RefinableObjClock * > mvChild
List of 'child' clocks, which will click this clock whenever they are clicked.
Definition: RefinableObj.h:175
int mOptimizationDepth
Is the object being refined or optimized ? if mOptimizationDepth=0, no optimization is taking place...
void UnFixAllPar()
UnFix All parameters.
const RefParType * gpRefParTypeObjCryst
Top RefParType for the ObjCryst++ library.
Object Registry.
Definition: RefinableObj.h:643
void AddOption(RefObjOpt *opt)
void SetGlobalOptimStep(const REAL)
Maximum step to use during Global Optimization algorithms.
REAL mSigma
Calculated sigma on value.
Definition: RefinableObj.h:512
virtual void SetName(const string &name)
Name of the object.
void SetLimitsAbsolute(const REAL min, const REAL max)
Change the limits for this object, giving absolute new limits.
Hard lower and upper limits.
Definition: RefinableObj.h:492
void XMLOutput(ostream &os, const string &name, int indent=0) const
XMLOutput to stream in well-formed XML.
virtual void XMLInput(istream &is, const XMLCrystTag &tag)
Input From stream.