• R/O
  • HTTP
  • SSH
  • HTTPS

Commit

Tags
Aucun tag

Frequently used words (click to add to your profile)

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

Commit MetaInfo

Révisione97b3200b4e004da7c91a740c5d2560c0ef49297 (tree)
l'heure2014-01-11 21:21:36
AuteurKatsuhiko Nishimra <ktns.87@gmai...>
CommiterKatsuhiko Nishimra

Message de Log

Factor out Optimizer::InitializeState. #32881

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

Change Summary

Modification

--- a/src/optimization/BFGS.cpp
+++ b/src/optimization/BFGS.cpp
@@ -139,10 +139,6 @@ void BFGS::SearchMinimum(boost::shared_ptr<ElectronicStructure> electronicStruct
139139 const double maxNormStep = Parameters::GetInstance()->GetMaxNormStepOptimization();
140140 BFGSState state(molecule);
141141
142- // initialize Hessian with unit matrix
143- const double one = 1;
144- MolDS_wrappers::Blas::GetInstance()->Dcopy(dimension, &one, 0, &state.GetMatrixHessian()[0][0], dimension+1);
145-
146142 // initial calculation
147143 bool requireGuess = true;
148144 this->UpdateElectronicStructure(electronicStructure, molecule, requireGuess, this->CanOutputLogs());
@@ -151,6 +147,8 @@ void BFGS::SearchMinimum(boost::shared_ptr<ElectronicStructure> electronicStruct
151147 requireGuess = false;
152148 state.SetMatrixForce(electronicStructure->GetForce(elecState));
153149
150+ this->InitializeState(state, molecule);
151+
154152 for(int s=0; s<totalSteps; s++){
155153 this->OutputLog(boost::format("%s%d\n\n") % this->messageStartBFGSStep % (s+1));
156154
@@ -228,6 +226,14 @@ void BFGS::SearchMinimum(boost::shared_ptr<ElectronicStructure> electronicStruct
228226 *lineSearchedEnergy = state.GetCurrentEnergy();
229227 }
230228
229+void BFGS::InitializeState(OptimizerState &stateOrig, const Molecule& molecule) const{
230+ const MolDS_wrappers::molds_blas_int dimension = molecule.GetAtomVect().size()*CartesianType_end;
231+ const double one = 1;
232+ BFGSState& state = stateOrig.CastRef<BFGSState>();
233+ // initialize Hessian with unit matrix
234+ MolDS_wrappers::Blas::GetInstance()->Dcopy(dimension, &one, 0, &state.GetMatrixHessian()[0][0], dimension+1);
235+}
236+
231237 void BFGS::CalcRFOStep(double* vectorStep,
232238 double const* const* matrixHessian,
233239 double const* vectorForce,
--- a/src/optimization/BFGS.h
+++ b/src/optimization/BFGS.h
@@ -78,6 +78,7 @@ private:
7878 bool* obainesOptimizedStructure) const;
7979
8080 protected:
81+ void InitializeState(OptimizerState &state, const MolDS_base::Molecule& molecule) const;
8182 void CalcRFOStep(double* vectorStep,
8283 double const* const* matrixHessian,
8384 double const* vectorForce,
--- a/src/optimization/ConjugateGradient.cpp
+++ b/src/optimization/ConjugateGradient.cpp
@@ -96,11 +96,7 @@ void ConjugateGradient::SearchMinimum(boost::shared_ptr<ElectronicStructure> ele
9696 requireGuess = false;
9797 state.SetMatrixForce(electronicStructure->GetForce(elecState));
9898
99- for(int a=0;a<molecule.GetAtomVect().size();a++){
100- for(int i=0; i<CartesianType_end; i++){
101- state.GetMatrixSearchDirection()[a][i] = state.GetMatrixForce()[a][i];
102- }
103- }
99+ this->InitializeState(state, molecule);
104100
105101 // conugate gradient loop
106102 for(int s=0; s<totalSteps; s++){
@@ -127,6 +123,15 @@ void ConjugateGradient::SearchMinimum(boost::shared_ptr<ElectronicStructure> ele
127123 *lineSearchedEnergy = state.GetCurrentEnergy();
128124 }
129125
126+void ConjugateGradient::InitializeState(OptimizerState &stateOrig, const Molecule& molecule) const{
127+ ConjugateGradientState& state = stateOrig.CastRef<ConjugateGradientState>();
128+ for(int a=0;a<molecule.GetAtomVect().size();a++){
129+ for(int i=0; i<CartesianType_end; i++){
130+ state.GetMatrixSearchDirection()[a][i] = state.GetMatrixForce()[a][i];
131+ }
132+ }
133+}
134+
130135 void ConjugateGradient::UpdateSearchDirection(OptimizerState& stateOrig,
131136 boost::shared_ptr<ElectronicStructure> electronicStructure,
132137 const MolDS_base::Molecule& molecule,
--- a/src/optimization/ConjugateGradient.h
+++ b/src/optimization/ConjugateGradient.h
@@ -45,6 +45,7 @@ private:
4545 MolDS_base::Molecule& molecule,
4646 double* lineSearchedEnergy,
4747 bool* obainesOptimizedStructure) const;
48+ void InitializeState(OptimizerState &state, const MolDS_base::Molecule& molecule) const;
4849 void UpdateSearchDirection(OptimizerState& state,
4950 boost::shared_ptr<MolDS_base::ElectronicStructure> electronicStructure,
5051 const MolDS_base::Molecule& molecule,
--- a/src/optimization/Optimizer.h
+++ b/src/optimization/Optimizer.h
@@ -102,6 +102,7 @@ private:
102102 MolDS_base::Molecule& molecule,
103103 double* lineSearchedEnergy,
104104 bool* obainesOptimizedStructure) const = 0;
105+ virtual void InitializeState(OptimizerState &state, const MolDS_base::Molecule& molecule) const = 0;
105106 };
106107
107108 }
--- a/src/optimization/SteepestDescent.h
+++ b/src/optimization/SteepestDescent.h
@@ -33,6 +33,7 @@ private:
3333 MolDS_base::Molecule& molecule,
3434 double* lineSearchedEnergy,
3535 bool* obainesOptimizedStructure) const;
36+ void InitializeState(OptimizerState&, const MolDS_base::Molecule&) const{}
3637 void UpdateSearchDirection(OptimizerState& state,
3738 boost::shared_ptr<MolDS_base::ElectronicStructure> electronicStructure,
3839 const MolDS_base::Molecule& molecule,