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

View of /trunk/gadget/optinfohooke.cc

Parent Directory Parent Directory | Revision Log Revision Log


Revision 20 - (download) (annotate)
Fri Apr 7 09:20:55 2017 UTC (7 years, 1 month ago) by agomez
File size: 2842 byte(s)
OpenMP integrated in a single model and first version of PSO
#include "optinfo.h"
#include "errorhandler.h"
#include "gadget.h"
#include "global.h"

OptInfoHooke::OptInfoHooke()
  : OptInfo(), hookeiter(1000), rho(0.5), lambda(0.0), hookeeps(1e-4), bndcheck(0.9999) {
  type = OPTHOOKE;
  handle.logMessage(LOGMESSAGE, "Initialising Hooke & Jeeves optimisation algorithm");
}

void OptInfoHooke::read(CommentStream& infile, char* text) {
  handle.logMessage(LOGMESSAGE, "Reading Hooke & Jeeves optimisation parameters");

  int count = 0;
  while (!infile.eof() && strcasecmp(text,"[pso]")  && strcasecmp(text, "[simann]") && strcasecmp(text, "[hooke]") && strcasecmp(text, "[bfgs]")) {
    infile >> ws;
    if (strcasecmp(text, "seed") == 0) {
      int seed = 0;
      infile >> seed >> ws;
      handle.logMessage(LOGMESSAGE, "Initialising random number generator with", seed);
      srand(seed);

    } else if (strcasecmp(text, "rho") == 0) {
      infile >> rho;
      count++;

    } else if (strcasecmp(text, "lambda") == 0) {
      infile >> lambda;
      count++;

    } else if (strcasecmp(text, "hookeeps") == 0) {
      infile >> hookeeps;
      count++;

    } else if (strcasecmp(text, "hookeiter") == 0) {
      infile >> hookeiter;
      count++;

    } else if (strcasecmp(text, "bndcheck") == 0) {
      infile >> bndcheck;
      count++;

    } else {
      handle.logMessage(LOGINFO, "Warning in optinfofile - unrecognised option", text);
      infile >> text;  //read and ignore the next entry
    }
    infile >> text;
  }

  if (count == 0)
    handle.logMessage(LOGINFO, "Warning - no parameters specified for Hooke & Jeeves optimisation algorithm");

  //check the values specified in the optinfo file ...
  if ((rho < rathersmall) || (rho > 1.0)) {
    handle.logMessage(LOGINFO, "Warning in optinfofile - value of rho outside bounds", rho);
    rho = 0.5;
  }
  if ((lambda < 0.0) || (lambda > 1.0)) {
    handle.logMessage(LOGINFO, "Warning in optinfofile - value of lambda outside bounds", lambda);
    lambda = rho;
  }
  if ((bndcheck < 0.5) || (bndcheck > 1.0)) {
    handle.logMessage(LOGINFO, "Warning in optinfofile - value of bndcheck outside bounds", bndcheck);
    bndcheck = 0.9999;
  }
  if (hookeeps < rathersmall) {
    handle.logMessage(LOGINFO, "Warning in optinfofile - value of hookeeps outside bounds", hookeeps);
    hookeeps = 1e-4;
  }
}

void OptInfoHooke::Print(ofstream& outfile, int prec) {
  outfile << "; Hooke & Jeeves algorithm ran for " << iters
    << " function evaluations\n; and stopped when the likelihood value was "
    << setprecision(prec) << score;
  if (converge == -1)
    outfile << "\n; because an error occured during the optimisation\n";
  else if (converge == 1)
    outfile << "\n; because the convergence criteria were met\n";
  else
    outfile << "\n; because the maximum number of function evaluations was reached\n";
}

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

Powered By FusionForge