Revisión | e97b3200b4e004da7c91a740c5d2560c0ef49297 (tree) |
---|---|
Tiempo | 2014-01-11 21:21:36 |
Autor | Katsuhiko Nishimra <ktns.87@gmai...> |
Commiter | Katsuhiko Nishimra |
Factor out Optimizer::InitializeState. #32881
git-svn-id: https://svn.sourceforge.jp/svnroot/molds/branches/refactor_opt@1641 1136aad2-a195-0410-b898-f5ea1d11b9d8
@@ -139,10 +139,6 @@ void BFGS::SearchMinimum(boost::shared_ptr<ElectronicStructure> electronicStruct | ||
139 | 139 | const double maxNormStep = Parameters::GetInstance()->GetMaxNormStepOptimization(); |
140 | 140 | BFGSState state(molecule); |
141 | 141 | |
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 | - | |
146 | 142 | // initial calculation |
147 | 143 | bool requireGuess = true; |
148 | 144 | this->UpdateElectronicStructure(electronicStructure, molecule, requireGuess, this->CanOutputLogs()); |
@@ -151,6 +147,8 @@ void BFGS::SearchMinimum(boost::shared_ptr<ElectronicStructure> electronicStruct | ||
151 | 147 | requireGuess = false; |
152 | 148 | state.SetMatrixForce(electronicStructure->GetForce(elecState)); |
153 | 149 | |
150 | + this->InitializeState(state, molecule); | |
151 | + | |
154 | 152 | for(int s=0; s<totalSteps; s++){ |
155 | 153 | this->OutputLog(boost::format("%s%d\n\n") % this->messageStartBFGSStep % (s+1)); |
156 | 154 |
@@ -228,6 +226,14 @@ void BFGS::SearchMinimum(boost::shared_ptr<ElectronicStructure> electronicStruct | ||
228 | 226 | *lineSearchedEnergy = state.GetCurrentEnergy(); |
229 | 227 | } |
230 | 228 | |
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 | + | |
231 | 237 | void BFGS::CalcRFOStep(double* vectorStep, |
232 | 238 | double const* const* matrixHessian, |
233 | 239 | double const* vectorForce, |
@@ -78,6 +78,7 @@ private: | ||
78 | 78 | bool* obainesOptimizedStructure) const; |
79 | 79 | |
80 | 80 | protected: |
81 | + void InitializeState(OptimizerState &state, const MolDS_base::Molecule& molecule) const; | |
81 | 82 | void CalcRFOStep(double* vectorStep, |
82 | 83 | double const* const* matrixHessian, |
83 | 84 | double const* vectorForce, |
@@ -96,11 +96,7 @@ void ConjugateGradient::SearchMinimum(boost::shared_ptr<ElectronicStructure> ele | ||
96 | 96 | requireGuess = false; |
97 | 97 | state.SetMatrixForce(electronicStructure->GetForce(elecState)); |
98 | 98 | |
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); | |
104 | 100 | |
105 | 101 | // conugate gradient loop |
106 | 102 | for(int s=0; s<totalSteps; s++){ |
@@ -127,6 +123,15 @@ void ConjugateGradient::SearchMinimum(boost::shared_ptr<ElectronicStructure> ele | ||
127 | 123 | *lineSearchedEnergy = state.GetCurrentEnergy(); |
128 | 124 | } |
129 | 125 | |
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 | + | |
130 | 135 | void ConjugateGradient::UpdateSearchDirection(OptimizerState& stateOrig, |
131 | 136 | boost::shared_ptr<ElectronicStructure> electronicStructure, |
132 | 137 | const MolDS_base::Molecule& molecule, |
@@ -45,6 +45,7 @@ private: | ||
45 | 45 | MolDS_base::Molecule& molecule, |
46 | 46 | double* lineSearchedEnergy, |
47 | 47 | bool* obainesOptimizedStructure) const; |
48 | + void InitializeState(OptimizerState &state, const MolDS_base::Molecule& molecule) const; | |
48 | 49 | void UpdateSearchDirection(OptimizerState& state, |
49 | 50 | boost::shared_ptr<MolDS_base::ElectronicStructure> electronicStructure, |
50 | 51 | const MolDS_base::Molecule& molecule, |
@@ -102,6 +102,7 @@ private: | ||
102 | 102 | MolDS_base::Molecule& molecule, |
103 | 103 | double* lineSearchedEnergy, |
104 | 104 | bool* obainesOptimizedStructure) const = 0; |
105 | + virtual void InitializeState(OptimizerState &state, const MolDS_base::Molecule& molecule) const = 0; | |
105 | 106 | }; |
106 | 107 | |
107 | 108 | } |
@@ -33,6 +33,7 @@ private: | ||
33 | 33 | MolDS_base::Molecule& molecule, |
34 | 34 | double* lineSearchedEnergy, |
35 | 35 | bool* obainesOptimizedStructure) const; |
36 | + void InitializeState(OptimizerState&, const MolDS_base::Molecule&) const{} | |
36 | 37 | void UpdateSearchDirection(OptimizerState& state, |
37 | 38 | boost::shared_ptr<MolDS_base::ElectronicStructure> electronicStructure, |
38 | 39 | const MolDS_base::Molecule& molecule, |