Revisión | 58acae003a8d93744ca20ebc970a7c63396810b0 (tree) |
---|---|
Tiempo | 2013-08-08 19:43:39 |
Autor | Katsuhiko Nishimra <ktns.87@gmai...> |
Commiter | Katsuhiko Nishimra |
Factor out BFGS::UpdateTrustRadius. #31856
git-svn-id: https://svn.sourceforge.jp/svnroot/molds/trunk@1466 1136aad2-a195-0410-b898-f5ea1d11b9d8
@@ -186,15 +186,7 @@ void BFGS::SearchMinimum(boost::shared_ptr<ElectronicStructure> electronicStruct | ||
186 | 186 | } |
187 | 187 | this->OutputMoleculeElectronicStructure(electronicStructure, molecule, this->CanOutputLogs()); |
188 | 188 | |
189 | - // Calculate the correctness of the approximation | |
190 | - double r = (lineSearchCurrentEnergy - lineSearchInitialEnergy) | |
191 | - / approximateChange; // correctness of the step | |
192 | - bool aproxcheckCanOutputLogs = true; | |
193 | - tempCanOutputLogs = molecule.CanOutputLogs(); | |
194 | - molecule.SetCanOutputLogs(aproxcheckCanOutputLogs); | |
195 | - this->OutputLog(boost::format(this->formatEnergyChangeComparison) | |
196 | - % (lineSearchCurrentEnergy-lineSearchInitialEnergy) % approximateChange % r); | |
197 | - molecule.SetCanOutputLogs(tempCanOutputLogs); | |
189 | + this->UpdateTrustRadius(trustRadius, approximateChange, lineSearchInitialEnergy, lineSearchCurrentEnergy); | |
198 | 190 | |
199 | 191 | // check convergence |
200 | 192 | if(this->SatisfiesConvergenceCriterion(matrixForce, |
@@ -207,9 +199,7 @@ void BFGS::SearchMinimum(boost::shared_ptr<ElectronicStructure> electronicStruct | ||
207 | 199 | break; |
208 | 200 | } |
209 | 201 | |
210 | - // Update the trust radius | |
211 | - if(r < 0) | |
212 | - { | |
202 | + if(lineSearchCurrentEnergy > lineSearchInitialEnergy){ | |
213 | 203 | // Rollback molecular geometry |
214 | 204 | bool tempCanOutputLogs = molecule.CanOutputLogs(); |
215 | 205 | bool rollbackCanOutputLogs = true; |
@@ -224,23 +214,8 @@ void BFGS::SearchMinimum(boost::shared_ptr<ElectronicStructure> electronicStruct | ||
224 | 214 | } |
225 | 215 | lineSearchCurrentEnergy = lineSearchInitialEnergy; |
226 | 216 | molecule.SetCanOutputLogs(tempCanOutputLogs); |
227 | - // and rerun with smaller trust radius | |
228 | - // without updating Hessian | |
229 | - trustRadius /= 4; | |
230 | - continue; | |
231 | - } | |
232 | - else if(r<0.25){ | |
233 | - trustRadius /= 4; | |
234 | - } | |
235 | - else if(r<0.75){ | |
236 | - // keep trust radius | |
237 | - } | |
238 | - else if(r<2){ | |
239 | - trustRadius *= 2; | |
240 | - } | |
241 | - else{ | |
242 | - trustRadius /= 2; | |
243 | 217 | } |
218 | + | |
244 | 219 | //Calculate displacement (K_k at Eq. (15) in [SJTO_1983]) |
245 | 220 | MallocerFreer::GetInstance()->Malloc(&matrixDisplacement, molecule.GetNumberAtoms(), CartesianType_end); |
246 | 221 | for(int i=0;i<molecule.GetNumberAtoms();i++){ |
@@ -555,8 +530,37 @@ double BFGS::ApproximateEnergyChange(int dimension, | ||
555 | 530 | approximateChangeDenominator += vectorStep[i] * vectorStep[i]; |
556 | 531 | for(int j=0;j<dimension;j++){ |
557 | 532 | approximateChangeNumerator += vectorStep[i] * matrixHessian[i][j] * vectorStep[j] / 2; |
558 | - } | |
559 | 533 | } |
560 | - return approximateChangeNumerator / approximateChangeDenominator; | |
561 | 534 | } |
535 | + return approximateChangeNumerator / approximateChangeDenominator; | |
536 | +} | |
537 | + | |
538 | +void BFGS::UpdateTrustRadius(double &trustRadius, | |
539 | + double approximateEnergyChange, | |
540 | + double initialEnergy, | |
541 | + double currentEnergy)const{ | |
542 | + // Calculate the correctness of the approximation | |
543 | + double r = (currentEnergy - initialEnergy) | |
544 | + / approximateEnergyChange; | |
545 | + | |
546 | + this->OutputLog(boost::format(this->formatEnergyChangeComparison) | |
547 | + % (currentEnergy-initialEnergy) % approximateEnergyChange % r); | |
548 | + | |
549 | + if(r < 0) | |
550 | + { | |
551 | + trustRadius /= 4; | |
552 | + } | |
553 | + else if(r<0.25){ | |
554 | + trustRadius /= 4; | |
555 | + } | |
556 | + else if(r<0.75){ | |
557 | + // keep trust radius | |
558 | + } | |
559 | + else if(r<2){ | |
560 | + trustRadius *= 2; | |
561 | + } | |
562 | + else{ | |
563 | + trustRadius /= 2; | |
564 | + } | |
565 | +} | |
562 | 566 | } |
@@ -67,6 +67,10 @@ protected: | ||
67 | 67 | double const* const* matrixHessian, |
68 | 68 | double const* vectorForce, |
69 | 69 | double const* vectorStep) const; |
70 | + void UpdateTrustRadius(double &trustRadius, | |
71 | + double approximateEnergyChange, | |
72 | + double currentEnergy, | |
73 | + double initialEnergy)const; | |
70 | 74 | }; |
71 | 75 | |
72 | 76 | } |