FOX/ObjCryst++
1.10.X (development)
|
(Quick & dirty) Least-Squares Refinement Object with Numerical derivatives More...
Public Member Functions | |
LSQNumObj (std::string objName="Unnamed LSQ object") | |
void | SetParIsFixed (const std::string &parName, const bool fix) |
Fix one parameter. More... | |
void | SetParIsFixed (const RefParType *type, const bool fix) |
Fix one family of parameters. More... | |
void | SetParIsFixed (RefinablePar &par, const bool fix) |
Fix one parameter. More... | |
void | SetParIsFixed (RefinableObj &obj, const bool fix) |
Fix all parameters within an object. More... | |
void | UnFixAllPar () |
UnFix All parameters. More... | |
void | SetParIsUsed (const std::string &parName, const bool use) |
Set a parameter to be used. More... | |
void | SetParIsUsed (const RefParType *type, const bool use) |
Set a family of parameters to be used. More... | |
void | Refine (int nbCycle=1, bool useLevenbergMarquardt=false, const bool silent=false, const bool callBeginEndOptimization=true, const float minChi2var=0.01) |
Do the refinement. More... | |
CrystVector_REAL | Sigma () const |
CrystMatrix_REAL | CorrelMatrix () const |
REAL | Rfactor () const |
REAL | RwFactor () const |
REAL | ChiSquare () const |
void | SetRefinedObj (RefinableObj &obj, const unsigned int LSQFuncIndex=0, const bool init=true, const bool recursive=false) |
Choose the object to refine. More... | |
const std::map< RefinableObj *, unsigned int > & | GetRefinedObjMap () const |
Get the map of refined objects - this is a recursive list of all the objects that are taken into account for the refinement. More... | |
std::map< RefinableObj *, unsigned int > & | GetRefinedObjMap () |
Get the map of refined objects - this is a recursive list of all the objects that are taken into account for the refinement. More... | |
RefinableObj & | GetCompiledRefinedObj () |
Access to the RefinableObj which is the compilation of all parameters from the object supplied for optimization and its sub-objects. More... | |
const RefinableObj & | GetCompiledRefinedObj () const |
Access to the RefinableObj which is the compilation of all parameters from the object supplied for optimization and its sub-objects. More... | |
void | SetUseSaveFileOnEachCycle (bool yesOrNo=true) |
void | SetSaveFile (std::string fileName="refine.save") |
void | PrintRefResults () const |
void | SetDampingFactor (const REAL newDampFact) |
void | PurgeSaveFile () |
void | WriteReportToFile () const |
void | OptimizeDerivativeSteps () |
const std::map< pair< const RefinablePar *, const RefinablePar * >, REAL > & | GetVarianceCovarianceMap () const |
void | PrepareRefParList (const bool copy_param=false) |
Prepare the full parameter list for the refinement. More... | |
const CrystVector_REAL & | GetLSQCalc () const |
Get the LSQ calc vector (using either only the top or the hierarchy of object) | |
const CrystVector_REAL & | GetLSQObs () const |
Get the LSQ obs vector (using either only the top or the hierarchy of object) | |
const CrystVector_REAL & | GetLSQWeight () const |
Get the LSQ weight vector (using either only the top or the hierarchy of object) | |
const CrystVector_REAL & | GetLSQDeriv (RefinablePar &par) |
Get the LSQ deriv vector (using either only the top or the hierarchy of object) | |
const std::map< RefinablePar *, CrystVector_REAL > & | GetLSQ_FullDeriv () |
void | BeginOptimization (const bool allowApproximations=false, const bool enableRestraints=false) |
Tell all refined object that the refinement is beginning. | |
void | EndOptimization () |
Tell all refined object that the refinement is finished. | |
Private Attributes | |
ObjRegistry< RefinableObj > | mRecursiveRefinedObjList |
The recursive list of all refined sub-objects. | |
RefinableObj | mRefParList |
The refinable par list used during refinement. More... | |
REAL | mDampingFactor |
Damping factor for the refinement (unused yet...) | |
bool | mSaveReportOnEachCycle |
Save result to file after each cycle ? | |
std::string | mName |
Name of the refined object. | |
std::string | mSaveFileName |
File name where refinement info is saved. | |
REAL | mR |
REAL | mRw |
REAL | mChiSq |
CrystMatrix_REAL | mCorrelMatrix |
Correlation matrix between all refined parameters. | |
std::map< pair< const RefinablePar *, const RefinablePar * >, REAL > | mvVarCovar |
Variance-Covariance matrix, as a std::map. | |
CrystVector_REAL | mObs |
Observed values. | |
CrystVector_REAL | mWeight |
Weight corresponding to all observed values. | |
int | mIndexValuesSetInitial |
Index of the set of saved values for all refinable parameters, before refinement and before the last cycle. More... | |
int | mIndexValuesSetLast |
bool | mStopAfterCycle |
If true, then stop at the end of the cycle. Used in multi-threading environment. | |
std::map< RefinableObj *, unsigned int > | mvRefinedObjMap |
Map of the recursive list of the objects to be refined. More... | |
std::map< RefinableObj *, unsigned int > | mvRefinedObjLSQSize |
Size of each object LSQ data. This is initialized in LSQNumObj::GetLSQObs() | |
bool | mCopyRefPar |
If true, then parameters to be refined will be copied instead of referenced. More... | |
CrystVector_REAL | mLSQObs |
Temporary arrays for LSQ functions evaluation - used when using recursive LSQ function. | |
CrystVector_REAL | mLSQCalc |
CrystVector_REAL | mLSQWeight |
CrystVector_REAL | mLSQDeriv |
std::map< RefinablePar *, CrystVector_REAL > | mLSQ_FullDeriv |
(Quick & dirty) Least-Squares Refinement Object with Numerical derivatives
This is still highly experimental !
Definition at line 37 of file LSQNumObj.h.
RefinableObj & ObjCryst::LSQNumObj::GetCompiledRefinedObj | ( | ) |
Access to the RefinableObj which is the compilation of all parameters from the object supplied for optimization and its sub-objects.
Since this compilation is only updated from the suplied refinableobj and its sub-objects when SetRefinedObj() and PrepareRefParList() are called, it is possible to alter the fixed/limited status of parameters here without affecting the parameters in the refined objects.
Definition at line 751 of file LSQNumObj.cpp.
const RefinableObj & ObjCryst::LSQNumObj::GetCompiledRefinedObj | ( | ) | const |
Access to the RefinableObj which is the compilation of all parameters from the object supplied for optimization and its sub-objects.
Since this compilation is only updated from the suplied refinableobj and its sub-objects when SetRefinedObj() and PrepareRefParList() are called, it is possible to alter the fixed/limited status of parameters here without affecting the parameters in the refined objects.
Definition at line 753 of file LSQNumObj.cpp.
const map< RefinableObj *, unsigned int > & ObjCryst::LSQNumObj::GetRefinedObjMap | ( | ) | const |
Get the map of refined objects - this is a recursive list of all the objects that are taken into account for the refinement.
The key is a pointer to the object and the value is the LSQ function index for that object.
Definition at line 740 of file LSQNumObj.cpp.
map< RefinableObj *, unsigned int > & ObjCryst::LSQNumObj::GetRefinedObjMap | ( | ) |
Get the map of refined objects - this is a recursive list of all the objects that are taken into account for the refinement.
The key is a pointer to the object and the value is the LSQ function index for that object.
Definition at line 745 of file LSQNumObj.cpp.
void ObjCryst::LSQNumObj::PrepareRefParList | ( | const bool | copy_param = false | ) |
Prepare the full parameter list for the refinement.
copy_param | if false (the default), then the lsq algorithm will work directly on the parameters of the refined object and sub-object. So that any modification to the fixed/used/limited status applies permanently to the parameters. if true, then the parameters are copied and therefore only the value of the parameter is changed (and the clocks are ticked). |
Definition at line 816 of file LSQNumObj.cpp.
void ObjCryst::LSQNumObj::Refine | ( | int | nbCycle = 1 , |
bool | useLevenbergMarquardt = false , |
||
const bool | silent = false , |
||
const bool | callBeginEndOptimization = true , |
||
const float | minChi2var = 0.01 |
||
) |
Do the refinement.
nbCycle | number of LSQ cycles - if negative, the algorithm will continue until it reaches (-nbcycle) or until the relative variation in Chi2 is less than minChi2var |
useLevenbergMarquardt | enable Levenberg-Marquardt algorithm to ensure that a decrease of Chi^2 will be obtained (actually a 1% increase is allowed) |
callBeginEndOptimization | if true, will call RefinableObj::BeginOptimization(true,...) and RefinableObj::EndOptimization(). You may not want this if the LSQ is done during another (e.g. monte-carlo) optimization - but then the calling function must ensure that approximations are disabled (using RefinableObj::SetApproximationFlag) for objects where that would render derivative calculations imprecise. |
minChi2var | used for termination of the refinement if the relative variation of Chi2 between two successive cyles is less than minChi2var |
Applying new computed values :TODO: & Check if a limit has been hit
Definition at line 104 of file LSQNumObj.cpp.
void ObjCryst::LSQNumObj::SetParIsFixed | ( | const std::string & | parName, |
const bool | fix | ||
) |
Fix one parameter.
LSQNumObj::PrepareRefParList() must be called first!
void ObjCryst::LSQNumObj::SetParIsFixed | ( | const RefParType * | type, |
const bool | fix | ||
) |
Fix one family of parameters.
LSQNumObj::PrepareRefParList() must be called first!
Definition at line 67 of file LSQNumObj.cpp.
void ObjCryst::LSQNumObj::SetParIsFixed | ( | RefinablePar & | par, |
const bool | fix | ||
) |
Fix one parameter.
Note that this will fix the copied parameter, not the one in the original object. The supplied RefinablePar may be either the copied one or the original.
LSQNumObj::PrepareRefParList() must be called first!
Definition at line 73 of file LSQNumObj.cpp.
void ObjCryst::LSQNumObj::SetParIsFixed | ( | RefinableObj & | obj, |
const bool | fix | ||
) |
Fix all parameters within an object.
Note that this will fix the copied parameters, not the one in the original objects.
LSQNumObj::PrepareRefParList() must be called first!
Definition at line 79 of file LSQNumObj.cpp.
void ObjCryst::LSQNumObj::SetParIsUsed | ( | const std::string & | parName, |
const bool | use | ||
) |
Set a parameter to be used.
LSQNumObj::PrepareRefParList() must be called first!
void ObjCryst::LSQNumObj::SetParIsUsed | ( | const RefParType * | type, |
const bool | use | ||
) |
Set a family of parameters to be used.
LSQNumObj::PrepareRefParList() must be called first!
Definition at line 98 of file LSQNumObj.cpp.
void ObjCryst::LSQNumObj::SetRefinedObj | ( | RefinableObj & | obj, |
const unsigned int | LSQFuncIndex = 0 , |
||
const bool | init = true , |
||
const bool | recursive = false |
||
) |
Choose the object to refine.
The minimization will be done against its LSQ function and its parameters, as well as the LSQ functions and parameters of its sub-objects (if recursive==true)
LSQFuncIndex | one object can have a choice of several LSQ functions to minimize- this allows to choose which one to minimize. |
init | if true, the list of refined objects is first cleared. otherwise the new object (and its sub-objects) is just added to the list. |
recursive | if false, only the supplied object is added, and not its sub-objects |
Definition at line 727 of file LSQNumObj.cpp.
void ObjCryst::LSQNumObj::UnFixAllPar | ( | ) |
UnFix All parameters.
LSQNumObj::PrepareRefParList() must be called first!
Definition at line 87 of file LSQNumObj.cpp.
|
private |
If true, then parameters to be refined will be copied instead of referenced.
Therefore only their values and the parameter's clocks are affected when working on the copy.
Definition at line 242 of file LSQNumObj.h.
|
private |
Index of the set of saved values for all refinable parameters, before refinement and before the last cycle.
Definition at line 222 of file LSQNumObj.h.
|
mutableprivate |
The refinable par list used during refinement.
It is only a compilation of the parameters in RefinableObj and its sub-objects
This list is only updated from the suplied refinableobj and its sub-objects when SetRefinedObj() and PrepareRefParList() are called, so it is possible to alter the fixed/limited status of parameters here without affecting the parameters in the refined objects.
Definition at line 202 of file LSQNumObj.h.
|
private |
Map of the recursive list of the objects to be refined.
The key is the pointer to the object and the value the LSQ function index
Individual LSQ functions can be changed using GetRefinedObjMap().
Definition at line 235 of file LSQNumObj.h.