25 #ifndef _VFN_REFINABLE_OBJ_H_
26 #define _VFN_REFINABLE_OBJ_H_
35 #include "ObjCryst/CrystVector/CrystVector.h"
36 #include "ObjCryst/ObjCryst/General.h"
37 #include "ObjCryst/RefinableObj/IO.h"
43 template<
class T>
class ObjRegistry;
45 template<
class T>
class RefObjOption;
48 #include "ObjCryst/wxCryst/wxRefinableObj.h"
57 REFPAR_DERIV_STEP_ABSOLUTE,
58 REFPAR_DERIV_STEP_RELATIVE
173 unsigned long mTick0, mTick1;
174 static unsigned long msTick0,msTick1;
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.,
292 void Init(
const string &name,
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.,
346 void Mutate(
const REAL mutateValue);
355 REAL GetSigma()
const;
356 REAL GetHumanSigma()
const;
357 void SetSigma(
const REAL);
370 void SetIsFixed(
const bool);
372 bool IsLimited()
const;
373 void SetIsLimited(
const bool);
380 bool IsPeriodic()
const;
381 void SetIsPeriodic(
const bool,REAL period=1);
435 void SetUseEquation(
const bool useItOrNot,
const REAL c0=0.);
436 void SetUseEquation(
const bool useItOrNot,
const REAL c0,
439 void SetUseEquation(
const bool useItOrNot,
const REAL c0,
442 void SetUseEquation(
const bool useItOrNot,
const REAL c0,
474 void XMLOutput(ostream &os,
const string &name,
int indent=0)
const;
480 void XMLOutput(ostream &os,
int indent=0)
const;
523 static const int mEquationMaxRefPar=10;
525 int mEquationNbRefPar;
527 CrystVector_REAL mEquationCoeff;
542 void WXNotifyDelete();
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;
573 void XMLOutput(ostream &os,
int indent=0)
const;
596 void WXNotifyDelete();
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);
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;
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;
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;
768 void WXNotifyDelete();
804 virtual const string&
GetName()
const;
806 virtual void SetName(
const string &name);
825 void SetParIsUsed(
const string& parName,
const bool use);
898 virtual void Print()
const;
929 const CrystVector_REAL&
GetParamSet(
const unsigned long setId)
const;
934 CrystVector_REAL&
GetParamSet(
const unsigned long setId);
1015 const bool enableRestraints=
false);
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;
1137 virtual std::map<RefinablePar*, CrystVector_REAL> &
GetLSQ_FullDeriv(
const unsigned int,std::set<RefinablePar *> &vPar);
1148 virtual void XMLOutput(ostream &os,
int indent=0)
const;
1201 CrystVector_uint & groupIndex,
1202 unsigned int &firstGroup)
const;
1245 long FindPar(
const string &name)
const;
1247 long FindPar(
const REAL*)
const;
1260 map<unsigned long,pair<CrystVector_REAL,string> >::iterator
FindParamSet(
unsigned long id)
const;
1321 mutable std::map< unsigned int,std::map<RefinablePar*, CrystVector_REAL> >
mLSQ_FullDeriv;
1331 #ifdef __WX__CRYST__
1337 void WXNotifyDelete();
The namespace which includes all objects (crystallographic and algorithmic) in ObjCryst++.
void RefObjRegisterRecursive(T &obj, ObjRegistry< T > ®)
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 > ®, 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 > ®, 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...
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.
RefParType(const string &name)
Create a top parameter type.
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.
const RefParType * mpParent
the parent for this RefParType (we could easily allow several...)
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.
We need to record exactly when refinable objects have been modified for the last time (to avoid re-co...
std::set< RefinableObjClock * > mvParent
List of parent clocks, which will be clicked whenever this one is.
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.
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.
virtual REAL GetLogLikelihood() const
Get -ln(likelihood) for this restraint.
Restraint()
Default constructor, sets RefParType to gpRefParTypeObjCryst.
Generic class for parameters of refinable objects.
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.
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,...
REAL mHumanScale
Scale to be used to display 'human' value.
string GetName() const
Get the parameter's name.
REAL mMin
Hard lower and upper limits.
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...
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,...)
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) ?
REAL * mpValue
Pointer to the refinable value.
REAL mSigma
Calculated sigma on value.
void SetPeriod(const REAL)
Set the period value (if periodic)
bool mIsUsed
Is the parameter currently used ?
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 ?
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.
void SetHumanMax(const REAL)
Get the maximum value allowed (if limited)
REAL mPeriod
Period value (if relevant)
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
int mChoice
Current value.
const string * mpName
(short) Name for this option.
int mNbChoice
Number of different choice possible for this option.
void XMLInput(istream &is, const XMLCrystTag &tag)
XMLInput From stream.
const string * mpChoiceName
Names corresponding to each possible value of this option (Human-understandable).
RefinableObjClock mClock
The clock associated to this option.
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...
void(T::* mfpSetNewValue)(const int)
The pointer to the member function to be used when the choice is changed, to notify immediately the o...
RefObjOption(T *obj)
Constructor for the option.
T * mpObj
The object which uses this option.
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.
RefinableObjClock mListClock
Last time an object was added or removed.
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.
std::list< T * > mvpRegistryList
Another view of the registry of objects - this time as a std::list, which will not be invalidated if ...
bool mAutoUpdateUI
Enable the user interface update.
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.
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.
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.