Revisión | 793c1ae342c7c14319749309cb0660aa1bb9fc41 (tree) |
---|---|
Tiempo | 2012-11-27 16:55:06 |
Autor | Katsuhiko Nishimra <ktns.87@gmai...> |
Commiter | Katsuhiko Nishimra |
Set message strings in SetMessages. #28764
git-svn-id: https://svn.sourceforge.jp/svnroot/molds/trunk@1139 1136aad2-a195-0410-b898-f5ea1d11b9d8
@@ -64,7 +64,36 @@ void BFGS::SetMessages(){ | ||
64 | 64 | = "Error in optimization::BFGS::Optimize: Optimization did not met convergence criterion.\n"; |
65 | 65 | this->errorMessageNaNInRFOStep |
66 | 66 | = "Error in optimization::BFGS::Optimize: RFO step has gone NaN. (lambda * s[%d] = %e, lambda = %e, alpha = %e)\n"; |
67 | - this->messageStartBFGSStep = "\n========== START: BFGS step "; | |
67 | + | |
68 | + this->messageStartBFGSStep | |
69 | + = "\n========== START: BFGS step "; | |
70 | + this->messageHillClimbing = | |
71 | + "Detected hill climbing.\n" | |
72 | + "Rolling back molecular geometry.\n"; | |
73 | + this->messageRecalculateRFOStep | |
74 | + = "Recalculating RFO step...\n"; | |
75 | + this->messageRawHessianEigenvalues | |
76 | + = "Eigenvalues of the raw Hessian:"; | |
77 | + this->messageShiftedHessianEigenvalues | |
78 | + = "Eigenvalues of the level shifted hessian:"; | |
79 | + | |
80 | + this->formatEnergyChangeComparison = | |
81 | + "\n" | |
82 | + "actual energy change = %e\n" | |
83 | + "expected energy change = %e\n" | |
84 | + "actual/expected energy change = %f\n"; | |
85 | + this->formatLowestHessianEigenvalue | |
86 | + = "Lowest eigenvalue of the augmented Hessian = %f\n"; | |
87 | + this->format2ndLowestHessianEigenvalue | |
88 | + = "2nd lowest eigenvalue of the augmented Hessian = %f\n"; | |
89 | + this->format3rdLowestHessianEigenvalue | |
90 | + = "3rd lowest eigenvalue of the augmented Hessian = %f\n"; | |
91 | + this->formatRFOStepSize | |
92 | + = "Calculated RFO step size = %f\n"; | |
93 | + this->formatTrustRadiusIs | |
94 | + = "Trust radius is %f\n"; | |
95 | + this->formatIncreaseScalingFactor | |
96 | + = "Scaling factor is increased to %e.\n"; | |
68 | 97 | } |
69 | 98 | |
70 | 99 | void BFGS::SearchMinimum(boost::shared_ptr<ElectronicStructure> electronicStructure, |
@@ -168,16 +197,12 @@ void BFGS::SearchMinimum(boost::shared_ptr<ElectronicStructure> electronicStruct | ||
168 | 197 | |
169 | 198 | // Calculate the correctness of the approximation |
170 | 199 | double r = (lineSearchCurrentEnergy - lineSearchInitialEnergy) |
171 | - / approximateChange; // correctness of the step | |
200 | + / approximateChange; // correctness of the step | |
172 | 201 | bool aproxcheckCanOutputLogs = true; |
173 | 202 | tempCanOutputLogs = molecule.CanOutputLogs(); |
174 | 203 | molecule.SetCanOutputLogs(aproxcheckCanOutputLogs); |
175 | - this->OutputLog(boost::format("\n" | |
176 | - "actual energy change = %e\n" | |
177 | - "expected energy change = %e\n" | |
178 | - "actual/expected energy change = %f\n") | |
179 | - % (lineSearchCurrentEnergy-lineSearchInitialEnergy) | |
180 | - % approximateChange % r); | |
204 | + this->OutputLog(boost::format(this->formatEnergyChangeComparison) | |
205 | + % (lineSearchCurrentEnergy-lineSearchInitialEnergy) % approximateChange % r); | |
181 | 206 | molecule.SetCanOutputLogs(tempCanOutputLogs); |
182 | 207 | |
183 | 208 | // check convergence |
@@ -198,8 +223,7 @@ void BFGS::SearchMinimum(boost::shared_ptr<ElectronicStructure> electronicStruct | ||
198 | 223 | bool tempCanOutputLogs = molecule.CanOutputLogs(); |
199 | 224 | bool rollbackCanOutputLogs = true; |
200 | 225 | molecule.SetCanOutputLogs(rollbackCanOutputLogs); |
201 | - this->OutputLog("Detected hill climbing.\n" | |
202 | - "Rolling back molecular geometry.\n"); | |
226 | + this->OutputLog(this->messageHillClimbing); | |
203 | 227 | for(int i=0;i<molecule.GetNumberAtoms();i++){ |
204 | 228 | const Atom* atom = molecule.GetAtom(i); |
205 | 229 | double* xyz = atom->GetXyz(); |
@@ -317,17 +341,17 @@ void BFGS::CalcRFOStep(double* vectorStep, | ||
317 | 341 | } |
318 | 342 | normStep = sqrt(normStep); |
319 | 343 | |
320 | - this->OutputLog(boost::format("Lowest eigenvalue of the augmented Hessian = %f\n") % vectorEigenValues[0]); | |
321 | - this->OutputLog(boost::format("2nd lowest eigenvalue of the augmented Hessian = %f\n") % vectorEigenValues[1]); | |
322 | - this->OutputLog(boost::format("3rd lowest eigenvalue of the augmented Hessian = %f\n") % vectorEigenValues[2]); | |
323 | - this->OutputLog(boost::format("Calculated RFO step size = %f\n") % normStep); | |
344 | + this->OutputLog(boost::format(this->formatLowestHessianEigenvalue) % vectorEigenValues[0]); | |
345 | + this->OutputLog(boost::format(this->format2ndLowestHessianEigenvalue) % vectorEigenValues[1]); | |
346 | + this->OutputLog(boost::format(this->format3rdLowestHessianEigenvalue) % vectorEigenValues[2]); | |
347 | + this->OutputLog(boost::format(this->formatRFOStepSize) % normStep); | |
348 | + this->OutputLog(boost::format(this->formatTrustRadiusIs) % trustRadius); | |
324 | 349 | |
325 | - this->OutputLog(boost::format("Trust radius is %f\n") % trustRadius); | |
326 | 350 | // Limit the step size to trustRadius |
327 | 351 | if(normStep > trustRadius){ |
328 | 352 | alpha *= normStep / trustRadius * 1.1; // 1.1 is speed up factor |
329 | - this->OutputLog(boost::format("Scaling factor is increased to %e.\n") % alpha); | |
330 | - this->OutputLog("Recalculating RFO step...\n"); | |
353 | + this->OutputLog(boost::format(this->formatTrustRadiusIs) % alpha); | |
354 | + this->OutputLog(this->messageRecalculateRFOStep); | |
331 | 355 | } |
332 | 356 | }while(normStep > trustRadius); |
333 | 357 | } |
@@ -488,7 +512,7 @@ void BFGS::ShiftHessianRedundantMode(double** matrixHessian, | ||
488 | 512 | calcEigenVectors); |
489 | 513 | |
490 | 514 | // Output eigenvalues of the raw Hessianto the log |
491 | - this->OutputLog("Eigenvalues of the raw Hessian:"); | |
515 | + this->OutputLog(this->messageRawHessianEigenvalues); | |
492 | 516 | for(int i=0;i<dimension;i++){ |
493 | 517 | if((i%6) == 0){ |
494 | 518 | this->OutputLog(boost::format("\n%e")%vectorHessianEigenValues[i]); |
@@ -539,7 +563,7 @@ void BFGS::ShiftHessianRedundantMode(double** matrixHessian, | ||
539 | 563 | } |
540 | 564 | |
541 | 565 | // Output eigenvalues of the raw Hessianto the log |
542 | - this->OutputLog("Eigenvalues of the level shifted hessian:"); | |
566 | + this->OutputLog(this->messageShiftedHessianEigenvalues); | |
543 | 567 | for(int i=0;i<dimension;i++){ |
544 | 568 | if((i%6) == 0){ |
545 | 569 | this->OutputLog(boost::format("\n%e")%vectorHessianEigenValues[i]); |
@@ -29,7 +29,21 @@ protected: | ||
29 | 29 | void SetMessages(); |
30 | 30 | private: |
31 | 31 | std::string errorMessageNaNInRFOStep; |
32 | + | |
32 | 33 | std::string messageStartBFGSStep; |
34 | + std::string messageHillClimbing; | |
35 | + std::string messageRecalculateRFOStep; | |
36 | + std::string messageRawHessianEigenvalues; | |
37 | + std::string messageShiftedHessianEigenvalues; | |
38 | + | |
39 | + std::string formatEnergyChangeComparison; | |
40 | + std::string formatLowestHessianEigenvalue; | |
41 | + std::string format2ndLowestHessianEigenvalue; | |
42 | + std::string format3rdLowestHessianEigenvalue; | |
43 | + std::string formatRFOStepSize; | |
44 | + std::string formatTrustRadiusIs; | |
45 | + std::string formatIncreaseScalingFactor; | |
46 | + | |
33 | 47 | virtual void SearchMinimum(boost::shared_ptr<MolDS_base::ElectronicStructure> electronicStructure, |
34 | 48 | MolDS_base::Molecule& molecule, |
35 | 49 | double* lineSearchedEnergy, |