ObjCryst::LSQNumObj Class Reference

(Quick & dirty) Least-Squares Refinement Object with Numerical derivatives More...

Collaboration diagram for ObjCryst::LSQNumObj:
Collaboration graph
[legend]

List of all members.

Public Member Functions

 LSQNumObj (std::string objName="Unnamed LSQ object")
void SetParIsFixed (const std::string &parName, const bool fix)
 Fix one parameter.
void SetParIsFixed (const RefParType *type, const bool fix)
 Fix one family of parameters.
void UnFixAllPar ()
 UnFix All parameters.
void SetParIsUsed (const std::string &parName, const bool use)
 Set a parameter to be used.
void SetParIsUsed (const RefParType *type, const bool use)
 Set a family of parameters to be used.
void Refine (int nbCycle=1, bool useLevenbergMarquardt=false, const bool silent=false, const bool callBeginEndOptimization=true, const float minChi2var=0.01)
 Do the refinement.
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.
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.
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.
RefinableObjGetCompiledRefinedObj ()
 Access to the RefinableObj which is the compilation of all parameters from the object supplied for optimization and its sub-objects.
const RefinableObjGetCompiledRefinedObj () const
 Access to the RefinableObj which is the compilation of all parameters from the object supplied for optimization and its sub-objects.
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.
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).
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< RefinableObjmRecursiveRefinedObjList
 The recursive list of all refined sub-objects.
RefinableObj mRefParList
 The refinable par list used during refinement.
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.
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.
bool mCopyRefPar
 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.
CrystVector_REAL mLSQObs
 Temporary arrays for LSQ functions evaluation - used when using recursive LSQ function.
CrystVector_REAL mLSQCalc
CrystVector_REAL mLSQWeight
CrystVector_REAL mLSQDeriv

Detailed Description

(Quick & dirty) Least-Squares Refinement Object with Numerical derivatives

This is still highly experimental !

Definition at line 37 of file LSQNumObj.h.


Member Function Documentation

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 655 of file LSQNumObj.cpp.

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 653 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 647 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 642 of file LSQNumObj.cpp.

void ObjCryst::LSQNumObj::PrepareRefParList ( const bool  copy_param = false  ) 

Prepare the full parameter list for the refinement.

Parameters:
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).
Note:
: if copy_param==true, then any modification to the parameters (fixed, limited, used status) only affects the copy and not the original. Also, calling again PrepareRefParList cancels any such modification.
This will be called automatically before starting the refinement only if the parameter list is empty. Otherwise it should be called before refinement.

Definition at line 718 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.

Parameters:
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 90 of file LSQNumObj.cpp.

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 ( const std::string &  parName,
const bool  fix 
)

Fix one parameter.

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 84 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::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)

Parameters:
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 630 of file LSQNumObj.cpp.

void ObjCryst::LSQNumObj::UnFixAllPar (  ) 

UnFix All parameters.

LSQNumObj::PrepareRefParList() must be called first!

Definition at line 73 of file LSQNumObj.cpp.


Member Data Documentation

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 184 of file LSQNumObj.h.

std::map<RefinableObj*,unsigned int> ObjCryst::LSQNumObj::mvRefinedObjMap [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 217 of file LSQNumObj.h.


The documentation for this class was generated from the following files:

Generated on Mon Dec 7 23:06:56 2009 for FOX/ObjCryst++ by  doxygen 1.6.1