FOX/ObjCryst++  1.10.X (development)
LSQNumObj.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 /* LSQNumObj.h
20 * header file for Least-Squares refinement witn Numerical derivatives Objects
21 *
22 */
23 #ifndef _LSQOBJNUM_H
24 #define _LSQOBJNUM_H
25 
26 #include "ObjCryst/CrystVector/CrystVector.h"
27 #include "ObjCryst/RefinableObj/RefinableObj.h"
28 #include <string>
29 #include <map>
30 
31 namespace ObjCryst
32 {
37 class LSQNumObj
38 {
39  public:
40  LSQNumObj(std::string objName="Unnamed LSQ object");
41  ~LSQNumObj();
45  void SetParIsFixed(const std::string& parName,const bool fix);
49  void SetParIsFixed(const RefParType *type,const bool fix);
58  void SetParIsFixed(RefinablePar &par,const bool fix);
66  void SetParIsFixed(RefinableObj &obj,const bool fix);
70  void UnFixAllPar();
74  void SetParIsUsed(const std::string& parName,const bool use);
78  void SetParIsUsed(const RefParType *type,const bool use);
95  void Refine (int nbCycle=1,bool useLevenbergMarquardt=false,
96  const bool silent=false, const bool callBeginEndOptimization=true,
97  const float minChi2var=0.01);
98  CrystVector_REAL Sigma()const;
99  CrystMatrix_REAL CorrelMatrix()const;
100  REAL Rfactor()const;
101  REAL RwFactor()const;
102  REAL ChiSquare()const; //uses the weight if specified
115  void SetRefinedObj(RefinableObj &obj, const unsigned int LSQFuncIndex=0, const bool init=true, const bool recursive=false);
116  // Access to the full list of refined objects. The list is initially built
117  // recursively from one object. This function allows to modify the list
118  // of sub-objects before refinement (such as for removing certain types
119  // of objects).
120  //ObjRegistry<RefinableObj> &GetRefinedObjList();
125  const std::map<RefinableObj*,unsigned int>& GetRefinedObjMap() const;
130  std::map<RefinableObj*,unsigned int>& GetRefinedObjMap();
148  const RefinableObj& GetCompiledRefinedObj()const;
149  void SetUseSaveFileOnEachCycle(bool yesOrNo=true);
150  void SetSaveFile(std::string fileName="refine.save");
151  void PrintRefResults()const;
152  void SetDampingFactor(const REAL newDampFact);
153  void PurgeSaveFile();
154  void WriteReportToFile()const;
155 
156  void OptimizeDerivativeSteps();
157  const std::map<pair<const RefinablePar*,const RefinablePar*>,REAL > &GetVarianceCovarianceMap()const;
172  void PrepareRefParList(const bool copy_param=false);
173 
175  const CrystVector_REAL& GetLSQCalc() const;
177  const CrystVector_REAL& GetLSQObs() const;
179  const CrystVector_REAL& GetLSQWeight() const;
181  const CrystVector_REAL& GetLSQDeriv(RefinablePar&par);
182  const std::map<RefinablePar*,CrystVector_REAL>& GetLSQ_FullDeriv();
185  void BeginOptimization(const bool allowApproximations=false, const bool enableRestraints=false);
188  void EndOptimization();
189  protected:
190  private:
191  // Refined object
208  std::string mName;
210  std::string mSaveFileName;
211  REAL mR,mRw,mChiSq;
213  CrystMatrix_REAL mCorrelMatrix;
215  std::map<pair<const RefinablePar*,const RefinablePar*>,REAL > mvVarCovar;
217  CrystVector_REAL mObs;
219  CrystVector_REAL mWeight;
222  int mIndexValuesSetInitial, mIndexValuesSetLast;
225  // The optimized object
226  //RefinableObj *mpRefinedObj;
227  // The index of the LSQ function in the refined object (if there are several...)
228  //unsigned int mLSQFuncIndex;
229 
235  std::map<RefinableObj*,unsigned int> mvRefinedObjMap;
237  mutable std::map<RefinableObj*,unsigned int> mvRefinedObjLSQSize;
238 
245  mutable CrystVector_REAL mLSQObs,mLSQCalc,mLSQWeight,mLSQDeriv;
246  mutable std::map<RefinablePar*,CrystVector_REAL> mLSQ_FullDeriv;
247 #ifdef __WX__CRYST__
248  public:
249  virtual WXCrystObjBasic* WXCreate(wxWindow* parent);
250  WXCrystObjBasic* WXGet();
251  void WXDelete();
252  void WXNotifyDelete();
253  protected:
254  WXCrystObjBasic *mpWXCrystObj;
255 #endif
256 };
257 
258 }//namespace
259 #endif //_LSQOBJNUM_H
RefinableObj & GetCompiledRefinedObj()
Access to the RefinableObj which is the compilation of all parameters from the object supplied for op...
Definition: LSQNumObj.cpp:751
REAL mDampingFactor
Damping factor for the refinement (unused yet...)
Definition: LSQNumObj.h:204
const CrystVector_REAL & GetLSQWeight() const
Get the LSQ weight vector (using either only the top or the hierarchy of object)
Definition: LSQNumObj.cpp:869
void PrepareRefParList(const bool copy_param=false)
Prepare the full parameter list for the refinement.
Definition: LSQNumObj.cpp:816
bool mSaveReportOnEachCycle
Save result to file after each cycle ?
Definition: LSQNumObj.h:206
void SetRefinedObj(RefinableObj &obj, const unsigned int LSQFuncIndex=0, const bool init=true, const bool recursive=false)
Choose the object to refine.
Definition: LSQNumObj.cpp:727
CrystVector_REAL mLSQObs
Temporary arrays for LSQ functions evaluation - used when using recursive LSQ function.
Definition: LSQNumObj.h:245
std::map< pair< const RefinablePar *, const RefinablePar * >, REAL > mvVarCovar
Variance-Covariance matrix, as a std::map.
Definition: LSQNumObj.h:215
const CrystVector_REAL & GetLSQCalc() const
Get the LSQ calc vector (using either only the top or the hierarchy of object)
Definition: LSQNumObj.cpp:830
RefinableObj mRefParList
The refinable par list used during refinement.
Definition: LSQNumObj.h:202
Generic Refinable Object.
Definition: RefinableObj.h:752
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 acco...
Definition: LSQNumObj.cpp:740
CrystVector_REAL mWeight
Weight corresponding to all observed values.
Definition: LSQNumObj.h:219
CrystVector_REAL mObs
Observed values.
Definition: LSQNumObj.h:217
void SetParIsFixed(const std::string &parName, const bool fix)
Fix one parameter.
Abstract base class for all objects in wxCryst.
Definition: wxCryst.h:127
std::map< RefinableObj *, unsigned int > mvRefinedObjMap
Map of the recursive list of the objects to be refined.
Definition: LSQNumObj.h:235
const CrystVector_REAL & GetLSQObs() const
Get the LSQ obs vector (using either only the top or the hierarchy of object)
Definition: LSQNumObj.cpp:849
std::map< RefinableObj *, unsigned int > mvRefinedObjLSQSize
Size of each object LSQ data. This is initialized in LSQNumObj::GetLSQObs()
Definition: LSQNumObj.h:237
std::string mSaveFileName
File name where refinement info is saved.
Definition: LSQNumObj.h:210
ObjRegistry< RefinableObj > mRecursiveRefinedObjList
The recursive list of all refined sub-objects.
Definition: LSQNumObj.h:193
bool mStopAfterCycle
If true, then stop at the end of the cycle. Used in multi-threading environment.
Definition: LSQNumObj.h:224
bool mCopyRefPar
If true, then parameters to be refined will be copied instead of referenced.
Definition: LSQNumObj.h:242
void BeginOptimization(const bool allowApproximations=false, const bool enableRestraints=false)
Tell all refined object that the refinement is beginning.
Definition: LSQNumObj.cpp:943
CrystMatrix_REAL mCorrelMatrix
Correlation matrix between all refined parameters.
Definition: LSQNumObj.h:213
const CrystVector_REAL & GetLSQDeriv(RefinablePar &par)
Get the LSQ deriv vector (using either only the top or the hierarchy of object)
Definition: LSQNumObj.cpp:888
void EndOptimization()
Tell all refined object that the refinement is finished.
Definition: LSQNumObj.cpp:949
std::string mName
Name of the refined object.
Definition: LSQNumObj.h:208
int mIndexValuesSetInitial
Index of the set of saved values for all refinable parameters, before refinement and before the last ...
Definition: LSQNumObj.h:222
The namespace which includes all objects (crystallographic and algorithmic) in ObjCryst++.
Definition: Atom.cpp:47
Generic class for parameters of refinable objects.
Definition: RefinableObj.h:223
void SetParIsUsed(const std::string &parName, const bool use)
Set a parameter to be used.
void UnFixAllPar()
UnFix All parameters.
Definition: LSQNumObj.cpp:87
(Quick & dirty) Least-Squares Refinement Object with Numerical derivatives
Definition: LSQNumObj.h:37
class of refinable parameter types.
Definition: RefinableObj.h:78
Object Registry.
Definition: RefinableObj.h:643
void Refine(int nbCycle=1, bool useLevenbergMarquardt=false, const bool silent=false, const bool callBeginEndOptimization=true, const float minChi2var=0.01)
Do the refinement.
Definition: LSQNumObj.cpp:104