Log In | Get Help   
Home My Page Projects Code Snippets Project Openings Mareframe
Summary Activity Forums Tracker Lists Tasks Docs Surveys News SCM Files
[mareframe] Annotation of /trunk/gadget/optinfobfgs.cc
[mareframe] / trunk / gadget / optinfobfgs.cc Repository:
ViewVC logotype

Annotation of /trunk/gadget/optinfobfgs.cc

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1 - (view) (download)

1 : agomez 1 #include "optinfo.h"
2 :     #include "errorhandler.h"
3 :     #include "gadget.h"
4 :     #include "global.h"
5 :    
6 :     OptInfoBFGS::OptInfoBFGS()
7 :     : OptInfo(), bfgsiter(10000), bfgseps(0.01), beta(0.3), sigma(0.01),
8 :     step(1.0), gradacc(1e-6), gradstep(0.5), gradeps(1e-10) {
9 :     type = OPTBFGS;
10 :     handle.logMessage(LOGMESSAGE, "Initialising BFGS optimisation algorithm");
11 :     }
12 :    
13 :     void OptInfoBFGS::read(CommentStream& infile, char* text) {
14 :     handle.logMessage(LOGMESSAGE, "Reading BFGS optimisation parameters");
15 :    
16 :     int count = 0;
17 :     while (!infile.eof() && strcasecmp(text, "[simann]") && strcasecmp(text, "[hooke]") && strcasecmp(text, "[bfgs]")) {
18 :     infile >> ws;
19 :     if (strcasecmp(text, "seed") == 0) {
20 :     int seed = 0;
21 :     infile >> seed >> ws;
22 :     handle.logMessage(LOGMESSAGE, "Initialising random number generator with", seed);
23 :     srand(seed);
24 :    
25 :     } else if (strcasecmp(text,"beta") == 0) {
26 :     infile >> beta;
27 :     count++;
28 :    
29 :     } else if (strcasecmp(text, "sigma") == 0) {
30 :     infile >> sigma;
31 :     count++;
32 :    
33 :     } else if (strcasecmp(text, "step") == 0) {
34 :     infile >> step;
35 :     count++;
36 :    
37 :     } else if (strcasecmp(text, "gradacc") == 0) {
38 :     infile >> gradacc;
39 :     count++;
40 :    
41 :     } else if (strcasecmp(text, "gradstep") == 0) {
42 :     infile >> gradstep;
43 :     count++;
44 :    
45 :     } else if (strcasecmp(text, "gradeps") == 0) {
46 :     infile >> gradeps;
47 :     count++;
48 :    
49 :     } else if ((strcasecmp(text, "bfgsiter") == 0) || (strcasecmp(text, "maxiter") == 0)) {
50 :     infile >> bfgsiter;
51 :     count++;
52 :    
53 :     } else if (strcasecmp(text, "bfgseps") == 0) {
54 :     infile >> bfgseps;
55 :     count++;
56 :    
57 :     } else {
58 :     handle.logMessage(LOGINFO, "Warning in optinfofile - unrecognised option", text);
59 :     infile >> text; //read and ignore the next entry
60 :     }
61 :     infile >> text;
62 :     }
63 :    
64 :     if (count == 0)
65 :     handle.logMessage(LOGINFO, "Warning - no parameters specified for BFGS optimisation algorithm");
66 :    
67 :     //check the values specified in the optinfo file ...
68 :     if ((beta < rathersmall) || (beta > 1.0)) {
69 :     handle.logMessage(LOGINFO, "Warning in optinfofile - value of beta outside bounds", beta);
70 :     beta = 0.3;
71 :     }
72 :     if ((sigma < rathersmall)|| (sigma > 1.0)) {
73 :     handle.logMessage(LOGINFO, "Warning in optinfofile - value of sigma outside bounds", sigma);
74 :     sigma = 0.01;
75 :     }
76 :     if (step < 1.0) {
77 :     handle.logMessage(LOGINFO, "Warning in optinfofile - value of step outside bounds", step);
78 :     step = 1.0;
79 :     }
80 :     if (bfgseps < rathersmall) {
81 :     handle.logMessage(LOGINFO, "Warning in optinfofile - value of bfgseps outside bounds", bfgseps);
82 :     bfgseps = 0.01;
83 :     }
84 :     if ((gradacc < rathersmall) || (gradacc > 1.0)) {
85 :     handle.logMessage(LOGINFO, "Warning in optinfofile - value of gradacc outside bounds", gradacc);
86 :     gradacc = 1e-6;
87 :     }
88 :     if ((gradstep < rathersmall) || (gradstep > 1.0)) {
89 :     handle.logMessage(LOGINFO, "Warning in optinfofile - value of gradstep outside bounds", gradstep);
90 :     gradstep = 0.5;
91 :     }
92 :     if ((gradeps < verysmall) || (gradeps > gradacc)) {
93 :     handle.logMessage(LOGINFO, "Warning in optinfofile - value of gradeps outside bounds", gradeps);
94 :     gradeps = 1e-10;
95 :     }
96 :     }
97 :    
98 :     void OptInfoBFGS::Print(ofstream& outfile, int prec) {
99 :     outfile << "; BFGS algorithm ran for " << iters
100 :     << " function evaluations\n; and stopped when the likelihood value was "
101 :     << setprecision(prec) << score;
102 :     if (converge == -1)
103 :     outfile << "\n; because an error occured during the optimisation\n";
104 :     else if (converge == 1)
105 :     outfile << "\n; because the convergence criteria were met\n";
106 :     else if (converge == 2)
107 :     outfile << "\n; because the accuracy limit for the gradient calculation was reached\n";
108 :     else
109 :     outfile << "\n; because the maximum number of function evaluations was reached\n";
110 :     }

root@forge.cesga.es
ViewVC Help
Powered by ViewVC 1.0.0  

Powered By FusionForge