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 28 - (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 : ulcessvp 28 nhood_size(5), w_strategy(PSO_W_LIN_DEC), scale(0)
10 : agomez 21 {
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 : ulcessvp 28 // unsigned s1 = 0;
19 :     // unsigned s2 = 0;
20 :     // unsigned s3 = 0;
21 : agomez 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 : ulcessvp 28 // s1 = s;
29 : agomez 21 handle.logMessage(LOGMESSAGE, "Initialising random number generator with", s);
30 : ulcessvp 28 srand(s);
31 : agomez 21 }
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 : ulcessvp 28 } else if (strcasecmp(text, "scale") == 0) {
75 :     infile >> scale;
76 :     count++;
77 :    
78 :     } else {
79 : agomez 21 handle.logMessage(LOGINFO, "Warning in optinfofile - unrecognised option", text);
80 :     infile >> text; //read and ignore the next entry
81 :     }
82 :     infile >> text;
83 :     }
84 :    
85 :     if (count == 0)
86 :     handle.logMessage(LOGINFO, "Warning - no parameters specified for Simulated Annealing optimisation algorithm");
87 :    
88 :     //check the values specified in the optinfo file ...
89 :     if (nhood_strategy!=PSO_NHOOD_GLOBAL &&
90 :     nhood_strategy!=PSO_NHOOD_RING &&
91 :     nhood_strategy!=PSO_NHOOD_RANDOM) {
92 :     handle.logMessage(LOGINFO, "Warning in optinfofile - Invalid nhood_strategy. Setting to default PSO_NHOOD_RANDOM");
93 :     nhood_strategy=PSO_NHOOD_RANDOM;
94 :    
95 :     }
96 :     if (w_strategy!=PSO_W_LIN_DEC &&
97 :     w_strategy!=PSO_W_CONST) {
98 :     handle.logMessage(LOGINFO, "Warning in optinfofile - Invalid w_strategy. Setting to default PSO_W_LIN_DEC");
99 :     w_strategy=PSO_W_LIN_DEC;
100 :     }
101 : ulcessvp 28
102 :     if (scale != 0 && scale != 1) {
103 :     handle.logMessage(LOGINFO, "Warning in optinfofile - value of scale outside bounds", scale);
104 :     scale = 0;
105 :     }
106 : agomez 21 }
107 :    
108 :     void OptInfoPso::Print(ofstream& outfile, int prec) {
109 :     outfile << "; PSO algorithm ran for " << iters
110 :     << " function evaluations\n; and stopped when the likelihood value was "
111 :     << setprecision(prec) << score;
112 :     if (converge == -1)
113 :     outfile << "\n; because an error occured during the optimisation\n";
114 :     else if (converge == 1)
115 :     outfile << "\n; because the convergence criteria were met\n";
116 :     else
117 :     outfile << "\n; because the maximum number of function evaluations was reached\n";
118 :     }

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

Powered By FusionForge