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/optinfopso.cc
[mareframe] / trunk / gadget / optinfopso.cc Repository:
ViewVC logotype

Annotation of /trunk/gadget/optinfopso.cc

Parent Directory Parent Directory | Revision Log Revision Log


Revision 21 - (view) (download)

1 : agomez 21 #include "optinfo.h"
2 :     #include "errorhandler.h"
3 :     #include "gadget.h"
4 :     #include "global.h"
5 :    
6 :     OptInfoPso::OptInfoPso()
7 :     : OptInfo(), goal(1e-5), psoiter(100000), c1(1.496), c2(1.496),
8 :     w_max(PSO_INERTIA), w_min(0.3), clamp_pos(1), nhood_strategy(PSO_NHOOD_RING),
9 :     nhood_size(5), w_strategy(PSO_W_LIN_DEC)
10 :     {
11 :     type = OPTPSO;
12 :     handle.logMessage(LOGMESSAGE, "Initialising PSO optimisation algorithm");
13 :     }
14 :    
15 :     void OptInfoPso::read(CommentStream& infile, char* text) {
16 :     handle.logMessage(LOGMESSAGE, "Reading PSO optimisation parameters");
17 :    
18 :     unsigned s1 = 0;
19 :     unsigned s2 = 0;
20 :     unsigned s3 = 0;
21 :    
22 :     int count = 0;
23 :     while (!infile.eof() && strcasecmp(text, "[PSO]") && strcasecmp(text, "[simann]") && strcasecmp(text, "[hooke]") && strcasecmp(text, "[bfgs]")) {
24 :     infile >> ws;
25 :     if (strcasecmp(text, "seed") == 0) {
26 :     int s = 0;
27 :     infile >> s >> ws;
28 :     s1 = s;
29 :     handle.logMessage(LOGMESSAGE, "Initialising random number generator with", s);
30 :     srand(s1);
31 :     }
32 :     else if (strcasecmp(text, "psoiter") == 0) {
33 :     infile >> psoiter;
34 :     count++;
35 :    
36 :     } else if (strcasecmp(text, "goal") == 0) {
37 :     infile >> goal;
38 :     count++;
39 :    
40 :     } else if (strcasecmp(text, "c1") == 0) {
41 :     infile >> c1;
42 :     count++;
43 :    
44 :     } else if (strcasecmp(text, "c2") == 0) {
45 :     infile >> c2;
46 :     count++;
47 :    
48 :     } else if (strcasecmp(text, "w_max") == 0) {
49 :     infile >> w_max;
50 :     count++;
51 :    
52 :     } else if (strcasecmp(text, "w_min") == 0) {
53 :     infile >> w_min;
54 :     count++;
55 :    
56 :     } else if (strcasecmp(text, "clamp_pos") == 0) {
57 :     infile >> clamp_pos;
58 :     count++;
59 :     } else if (strcasecmp(text, "nhood_strategy") == 0) {
60 :     infile >> nhood_strategy;
61 :     count++;
62 :    
63 :     } else if (strcasecmp(text, "nhood_size") == 0) {
64 :     infile >> nhood_size;
65 :     count++;
66 :    
67 :     } else if (strcasecmp(text, "w_strategy") == 0) {
68 :     infile >> w_strategy;
69 :     count++;
70 :     } else if (strcasecmp(text, "size") == 0) {
71 :     infile >> size;
72 :     count++;
73 :    
74 :     } else {
75 :     handle.logMessage(LOGINFO, "Warning in optinfofile - unrecognised option", text);
76 :     infile >> text; //read and ignore the next entry
77 :     }
78 :     infile >> text;
79 :     }
80 :    
81 :     if (count == 0)
82 :     handle.logMessage(LOGINFO, "Warning - no parameters specified for Simulated Annealing optimisation algorithm");
83 :    
84 :     //check the values specified in the optinfo file ...
85 :     if (nhood_strategy!=PSO_NHOOD_GLOBAL &&
86 :     nhood_strategy!=PSO_NHOOD_RING &&
87 :     nhood_strategy!=PSO_NHOOD_RANDOM) {
88 :     handle.logMessage(LOGINFO, "Warning in optinfofile - Invalid nhood_strategy. Setting to default PSO_NHOOD_RANDOM");
89 :     nhood_strategy=PSO_NHOOD_RANDOM;
90 :    
91 :     }
92 :     if (w_strategy!=PSO_W_LIN_DEC &&
93 :     w_strategy!=PSO_W_CONST) {
94 :     handle.logMessage(LOGINFO, "Warning in optinfofile - Invalid w_strategy. Setting to default PSO_W_LIN_DEC");
95 :     w_strategy=PSO_W_LIN_DEC;
96 :     }
97 :     }
98 :    
99 :     void OptInfoPso::Print(ofstream& outfile, int prec) {
100 :     outfile << "; PSO algorithm ran for " << iters
101 :     << " function evaluations\n; and stopped when the likelihood value was "
102 :     << setprecision(prec) << score;
103 :     if (converge == -1)
104 :     outfile << "\n; because an error occured during the optimisation\n";
105 :     else if (converge == 1)
106 :     outfile << "\n; because the convergence criteria were met\n";
107 :     else
108 :     outfile << "\n; because the maximum number of function evaluations was reached\n";
109 :     }

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

Powered By FusionForge