• R/O
  • HTTP
  • SSH
  • HTTPS

Commit

Tags
No Tags

Frequently used words (click to add to your profile)

javac++androidlinuxc#windowsobjective-ccocoa誰得qtpythonphprubygameguibathyscaphec計画中(planning stage)翻訳omegatframeworktwitterdomtestvb.netdirectxゲームエンジンbtronarduinopreviewer

Commit MetaInfo

Revision79a98bb1a167945549973f6a2124708cac6e45ec (tree)
Time2014-01-11 21:21:41
AuthorKatsuhiko Nishimra <ktns.87@gmai...>
CommiterKatsuhiko Nishimra

Log Message

Factor Out Optimizer::PrepareState. #32881

git-svn-id: https://svn.sourceforge.jp/svnroot/molds/branches/refactor_opt@1643 1136aad2-a195-0410-b898-f5ea1d11b9d8

Change Summary

Incremental Difference

--- a/src/optimization/BFGS.cpp
+++ b/src/optimization/BFGS.cpp
@@ -135,9 +135,9 @@ void BFGS::SearchMinimum(boost::shared_ptr<ElectronicStructure> electronicStruct
135135 double maxGradientThreshold = Parameters::GetInstance()->GetMaxGradientOptimization();
136136 double rmsGradientThreshold = Parameters::GetInstance()->GetRmsGradientOptimization();
137137 const int dimension = molecule.GetAtomVect().size()*CartesianType_end;
138- double trustRadius = Parameters::GetInstance()->GetInitialTrustRadiusOptimization();
139- const double maxNormStep = Parameters::GetInstance()->GetMaxNormStepOptimization();
140138 BFGSState state(molecule);
139+ state.SetTrustRadius(Parameters::GetInstance()->GetInitialTrustRadiusOptimization());
140+ state.SetMaxNormStep(Parameters::GetInstance()->GetMaxNormStepOptimization());
141141
142142 // initial calculation
143143 bool requireGuess = true;
@@ -152,23 +152,7 @@ void BFGS::SearchMinimum(boost::shared_ptr<ElectronicStructure> electronicStruct
152152 for(int s=0; s<totalSteps; s++){
153153 this->OutputOptimizationStepMessage(s);
154154
155- // Store old Force data
156- MolDS_wrappers::Blas::GetInstance()->Dcopy(dimension,
157- static_cast<double const*>(state.GetVectorForce()),
158- state.GetVectorOldForce());
159-
160- this->StoreMolecularGeometry(state.GetMatrixOldCoordinatesRef(), molecule);
161-
162- // Level shift Hessian redundant modes
163- this->ShiftHessianRedundantMode(state.GetMatrixHessian(), molecule);
164-
165- // Limit the trustRadius to maxNormStep
166- trustRadius=min(trustRadius,maxNormStep);
167-
168- //Calculate RFO step
169- this->CalcRFOStep(state.GetVectorStep(), state.GetMatrixHessian(), state.GetVectorForce(), trustRadius, dimension);
170-
171- double approximateChange = this->ApproximateEnergyChange(dimension, state.GetMatrixHessian(), state.GetVectorForce(), state.GetVectorStep());
155+ this->PrepareState(state, molecule, electronicStructure, elecState);
172156
173157 // Take a RFO step
174158 bool doLineSearch = false;
@@ -189,7 +173,7 @@ void BFGS::SearchMinimum(boost::shared_ptr<ElectronicStructure> electronicStruct
189173 }
190174 this->OutputMoleculeElectronicStructure(electronicStructure, molecule, this->CanOutputLogs());
191175
192- this->UpdateTrustRadius(trustRadius, approximateChange, state.GetInitialEnergy(), state.GetCurrentEnergy());
176+ this->UpdateTrustRadius(state.GetTrustRadiusRef(), state.GetApproximateChange(), state.GetInitialEnergy(), state.GetCurrentEnergy());
193177
194178 // check convergence
195179 if(this->SatisfiesConvergenceCriterion(state.GetMatrixForce(),
@@ -234,6 +218,35 @@ void BFGS::InitializeState(OptimizerState &stateOrig, const Molecule& molecule)
234218 MolDS_wrappers::Blas::GetInstance()->Dcopy(dimension, &one, 0, &state.GetMatrixHessian()[0][0], dimension+1);
235219 }
236220
221+void BFGS::PrepareState(OptimizerState& stateOrig,
222+ const MolDS_base::Molecule& molecule,
223+ const boost::shared_ptr<MolDS_base::ElectronicStructure> electronicStructure,
224+ const int elecState) const{
225+ BFGSState& state = stateOrig.CastRef<BFGSState>();
226+ const MolDS_wrappers::molds_blas_int dimension = molecule.GetAtomVect().size()*CartesianType_end;
227+ // Store old Force data
228+ MolDS_wrappers::Blas::GetInstance()->Dcopy(dimension,
229+ static_cast<double const*>(state.GetVectorForce()),
230+ state.GetVectorOldForce());
231+
232+ this->StoreMolecularGeometry(state.GetMatrixOldCoordinatesRef(), molecule);
233+
234+ // Level shift Hessian redundant modes
235+ this->ShiftHessianRedundantMode(state.GetMatrixHessian(), molecule);
236+
237+ // Limit the trustRadius to maxNormStep
238+ state.SetTrustRadius(min(state.GetTrustRadius(),state.GetMaxNormStep()));
239+
240+ //Calculate RFO step
241+ this->CalcRFOStep(state.GetVectorStep(), state.GetMatrixHessian(), state.GetVectorForce(), state.GetTrustRadius(), dimension);
242+
243+ state.SetApproximateChange(this->ApproximateEnergyChange(dimension,
244+ state.GetMatrixHessian(),
245+ state.GetVectorForce(),
246+ state.GetVectorStep())
247+ );
248+}
249+
237250 void BFGS::CalcRFOStep(double* vectorStep,
238251 double const* const* matrixHessian,
239252 double const* vectorForce,
--- a/src/optimization/BFGS.h
+++ b/src/optimization/BFGS.h
@@ -31,6 +31,9 @@ private:
3131 double** matrixOldCoordinates;
3232 double* vectorOldCoordinates;
3333 double** matrixDisplacement;
34+ double approximateChange;
35+ double trustRadius;
36+ double maxNormStep;
3437 size_t numAtoms;
3538 private:
3639 template<class vector>
@@ -48,6 +51,13 @@ private:
4851 double** GetMatrixOldCoordinates() {return this->matrixOldCoordinates;}
4952 double**& GetMatrixOldCoordinatesRef(){return this->matrixOldCoordinates;}
5053 double** GetMatrixDisplacement() {return this->matrixDisplacement;}
54+ double GetApproximateChange() {return this->approximateChange;}
55+ double GetTrustRadius() {return this->trustRadius;}
56+ double& GetTrustRadiusRef() {return this->trustRadius;}
57+ double GetMaxNormStep() {return this->maxNormStep;}
58+ void SetApproximateChange(double approximateChange){this->approximateChange = approximateChange;}
59+ void SetTrustRadius(double trustRadius) {this->trustRadius = trustRadius;}
60+ void SetMaxNormStep(double maxNormStep) {this->maxNormStep = maxNormStep;}
5161 };
5262 public:
5363 BFGS();
@@ -82,6 +92,10 @@ private:
8292
8393 protected:
8494 void InitializeState(OptimizerState &state, const MolDS_base::Molecule& molecule) const;
95+ void PrepareState(OptimizerState& state,
96+ const MolDS_base::Molecule& molecule,
97+ const boost::shared_ptr<MolDS_base::ElectronicStructure> electronicStructure,
98+ const int elecState) const;
8599 void CalcRFOStep(double* vectorStep,
86100 double const* const* matrixHessian,
87101 double const* vectorForce,
--- a/src/optimization/ConjugateGradient.cpp
+++ b/src/optimization/ConjugateGradient.cpp
@@ -101,6 +101,9 @@ void ConjugateGradient::SearchMinimum(boost::shared_ptr<ElectronicStructure> ele
101101 // conugate gradient loop
102102 for(int s=0; s<totalSteps; s++){
103103 this->OutputOptimizationStepMessage(s);
104+
105+ this->PrepareState(state, molecule, electronicStructure, elecState);
106+
104107 state.SetInitialEnergy(state.GetCurrentEnergy());
105108
106109 // do line search
--- a/src/optimization/ConjugateGradient.h
+++ b/src/optimization/ConjugateGradient.h
@@ -49,6 +49,10 @@ private:
4949 double* lineSearchedEnergy,
5050 bool* obainesOptimizedStructure) const;
5151 void InitializeState(OptimizerState &state, const MolDS_base::Molecule& molecule) const;
52+ virtual void PrepareState(OptimizerState& state,
53+ const MolDS_base::Molecule& molecule,
54+ const boost::shared_ptr<MolDS_base::ElectronicStructure> electronicStructure,
55+ const int elecState) const{};
5256 void UpdateSearchDirection(OptimizerState& state,
5357 boost::shared_ptr<MolDS_base::ElectronicStructure> electronicStructure,
5458 const MolDS_base::Molecule& molecule,
--- a/src/optimization/Optimizer.h
+++ b/src/optimization/Optimizer.h
@@ -104,6 +104,10 @@ private:
104104 double* lineSearchedEnergy,
105105 bool* obainesOptimizedStructure) const = 0;
106106 virtual void InitializeState(OptimizerState &state, const MolDS_base::Molecule& molecule) const = 0;
107+ virtual void PrepareState(OptimizerState& state,
108+ const MolDS_base::Molecule& molecule,
109+ const boost::shared_ptr<MolDS_base::ElectronicStructure> electronicStructure,
110+ const int elecState) const = 0;
107111 virtual const std::string& OptimizationStepMessage() const = 0;
108112 };
109113
--- a/src/optimization/SteepestDescent.h
+++ b/src/optimization/SteepestDescent.h
@@ -37,6 +37,10 @@ private:
3737 double* lineSearchedEnergy,
3838 bool* obainesOptimizedStructure) const;
3939 void InitializeState(OptimizerState&, const MolDS_base::Molecule&) const{}
40+ virtual void PrepareState(OptimizerState& state,
41+ const MolDS_base::Molecule& molecule,
42+ const boost::shared_ptr<MolDS_base::ElectronicStructure> electronicStructure,
43+ const int elecState) const{};
4044 void UpdateSearchDirection(OptimizerState& state,
4145 boost::shared_ptr<MolDS_base::ElectronicStructure> electronicStructure,
4246 const MolDS_base::Molecule& molecule,