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] Diff of /trunk/gadget/optinfo.h
[mareframe] / trunk / gadget / optinfo.h Repository:
ViewVC logotype

Diff of /trunk/gadget/optinfo.h

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 19, Wed May 25 16:36:33 2016 UTC revision 20, Fri Apr 7 09:20:55 2017 UTC
# Line 5  Line 5 
5  #include "doublematrix.h"  #include "doublematrix.h"
6  #include "doublevector.h"  #include "doublevector.h"
7  #include "intvector.h"  #include "intvector.h"
8    #include "intmatrix.h"
9  #include "seq_optimize_template.h"  #include "seq_optimize_template.h"
10    
11  enum OptType { OPTHOOKE = 1, OPTSIMANN, OPTBFGS };  enum OptType { OPTHOOKE = 1, OPTSIMANN, OPTBFGS, OPTPSO };
12    
13  /**  /**
14   * \class OptInfo   * \class OptInfo
# Line 41  Line 42 
42     * \brief This is the function used to call the optimisation algorithms     * \brief This is the function used to call the optimisation algorithms
43     */     */
44    virtual void OptimiseLikelihood() {};    virtual void OptimiseLikelihood() {};
45    #ifdef _OPENMP
46    /**    /**
47     * \brief This is the function used to call the optimisation algorithms parallelized with OpenMP of the reproducible version     * \brief This is the function used to call the optimisation algorithms parallelized with OpenMP of the reproducible version
48     */     */
49    virtual void OptimiseLikelihoodOMP() {};    virtual void OptimiseLikelihoodOMP() {};
50      virtual void OptimiseLikelihoodREP() {};
51    #endif
52    /**    /**
53     * \brief This function set the seeds used in SA     * \brief This function set the seeds used in SA
54     * \param val array of unsigned int with the seeds     * \param val array of unsigned int with the seeds
# Line 121  Line 125 
125     * \brief This is the function that will calculate the likelihood score using the Hooke & Jeeves optimiser     * \brief This is the function that will calculate the likelihood score using the Hooke & Jeeves optimiser
126     */     */
127    virtual void OptimiseLikelihood();    virtual void OptimiseLikelihood();
128  #ifdef SPECULATIVE  #ifdef _OPENMP
129    /**    /**
130     * \brief This is the function that will calculate the likelihood score using the Hooke & Jeeves optimiser parallelized with the reproducible version implemented OpenMP     * \brief This is the function that will calculate the likelihood score using the Hooke & Jeeves optimiser parallelized with the reproducible version implemented OpenMP
131     */     */
132    
133    virtual void OptimiseLikelihoodOMP();    virtual void OptimiseLikelihoodOMP();
134      virtual void OptimiseLikelihoodREP();
135  #endif  #endif
136  private:  private:
137    /**    /**
# Line 211  Line 217 
217     * \brief This is the function that will calculate the likelihood score using the Simulated Annealing optimiser     * \brief This is the function that will calculate the likelihood score using the Simulated Annealing optimiser
218     */     */
219    virtual void OptimiseLikelihood();    virtual void OptimiseLikelihood();
220  #ifdef SPECULATIVE  #ifdef _OPENMP
221    //#ifdef SPECULATIVE
222    /**    /**
223     * \brief This is the function that will calculate the likelihood score using the Simulated Annealing optimiser parallelized with the reproducible version implemented OpenMP     * \brief This is the function that will calculate the likelihood score using the Simulated Annealing optimiser parallelized with the reproducible version implemented OpenMP
224     */     */
225    virtual void OptimiseLikelihoodOMP();    virtual void OptimiseLikelihoodOMP();
226      virtual void OptimiseLikelihoodREP();
227    //#endif
228  #endif  #endif
229    /**    /**
230     * \brief This function calculate a new valor for the parameter l     * \brief This function calculate a new valor for the parameter l
# Line 315  Line 324 
324     * \brief This is the function that will calculate the likelihood score using the BFGS optimiser     * \brief This is the function that will calculate the likelihood score using the BFGS optimiser
325     */     */
326    virtual void OptimiseLikelihood();    virtual void OptimiseLikelihood();
327  #ifdef SPECULATIVE  #ifdef _OPENMP
328    //#ifdef SPECULATIVE
329    /**    /**
330    * \brief This function call the sequential function. BFGS isn't implemented with OpenMP    * \brief This function call the sequential function. BFGS isn't implemented with OpenMP
331    */    */
332    virtual void OptimiseLikelihoodOMP();    virtual void OptimiseLikelihoodOMP();
333      virtual void OptimiseLikelihoodREP();
334    //#endif
335  #endif  #endif
336  private:  private:
337    /**    /**
# Line 369  Line 381 
381    double gradeps;    double gradeps;
382  };  };
383    
384    /**
385     * \class OptInfoPso
386     * \brief This is the class used for the PSO optimisation
387     *
388     * PSO or Particle Swarm Optimization
389     *
390     * The PSO algorithm used in Gadget is derived from that presented by Kyriakos Kentzoglanakis.
391     */
392    class OptInfoPso : public OptInfo  {
393    public:
394      /**
395       * \brief This is the default OptInfoBFGS constructor
396       */
397      OptInfoPso();
398      /**
399       * \brief This is the default OptInfoBFGS destructor
400       */
401      ~OptInfoPso() {};
402      /**
403       * \brief This is the function used to read in the BFGS parameters
404       * \param infile is the CommentStream to read the optimisation parameters from
405       * \param text is a text string used to compare parameter names
406       */
407      virtual void read(CommentStream& infile, char* text);
408      /**
409       * \brief This function will print information from the optimisation algorithm
410       * \param outfile is the ofstream that the optimisation information gets sent to
411       * \param prec is the precision to use in the output file
412       */
413      virtual void Print(ofstream& outfile, int prec);
414      /**
415       * \brief This is the function that will calculate the likelihood score using the PSO optimiser
416       */
417      virtual void OptimiseLikelihood();
418    #ifdef _OPENMP
419    //#ifdef SPECULATIVE
420      /**
421      * \brief This function call the sequential function. PSO isn't implemented with OpenMP
422      */
423      virtual void OptimiseLikelihoodOMP();
424      virtual void OptimiseLikelihoodREP();
425    //#endif
426    #endif
427    private:
428    
429     /**
430      * \brief CONSTANTS: max swarm size
431      */
432     #define PSO_MAX_SIZE 100
433    
434     /**
435      * \brief CONSTANTS: default value of w (see clerc02)
436      */
437     #define PSO_INERTIA 0.7298
438    
439    
440    
441     /**
442      * \brief NEIGHBORHOOD SCHEMES: global best topology
443      */
444    #define PSO_NHOOD_GLOBAL 0
445    
446     /**
447      * \brief NEIGHBORHOOD SCHEMES: ring topology
448      */
449    #define PSO_NHOOD_RING 1
450    
451     /**
452      * \brief NEIGHBORHOOD SCHEMES: Random neighborhood topology. see http://clerc.maurice.free.fr/pso/random_topology.pdf
453      */
454    #define PSO_NHOOD_RANDOM 2
455    
456    
457    
458     /**
459      * \brief INERTIA WEIGHT UPDATE FUNCTIONS
460      */
461    #define PSO_W_CONST 0
462    #define PSO_W_LIN_DEC 1
463    
464    
465    
466     /**
467      * \brief PSO SOLUTION -- Initialized by the user
468      */
469     typedef struct {
470    
471         double error;
472         double *gbest; // should contain DIM elements!!
473    
474     } pso_result_t;
475    
476     /**
477      * \brief optimization goal (error threshold)
478      */
479     double goal;
480    
481     /**
482      * \brief swarm size (number of particles)
483      */
484     int size;
485    
486     /**
487      * \brief maximum number of iterations
488      */
489     int psoiter;
490    
491     /**
492      * \brief cognitive coefficient
493      */
494     double c1;
495    
496     /**
497      * \brief social coefficient
498      */
499     double c2;
500    
501     /**
502      * \brief max inertia weight value
503      */
504     double w_max;
505    
506     /**
507      * \brief min inertia weight value
508      */
509     double w_min;
510    
511     /**
512      * \brief whether to keep particle position within defined bounds (TRUE) or apply periodic boundary conditions (FALSE)
513      */
514     int clamp_pos;
515    
516     /**
517      * \brief neighborhood strategy (see PSO_NHOOD_*)
518      */
519     int nhood_strategy;
520    
521     /**
522      * \brief neighborhood size
523      */
524     int nhood_size;
525    
526     /**
527      * \brief inertia weight strategy (see PSO_W_*)
528      */
529     int w_strategy;
530    
531    
532     /**
533      * \brief seed for the generator
534      */
535     long seed;
536    
537    
538    
539    
540     /**
541      * \brief return the swarm size based on dimensionality
542      */
543     int pso_calc_swarm_size(int dim);
544    
545     double calc_inertia_const(int step);
546     double calc_inertia_lin_dec(int step);
547     void inform_global(IntMatrix& comm, DoubleMatrix& pos_nb,
548                       DoubleMatrix& pos_b, DoubleVector& fit_b,
549                       DoubleVector& gbest, int improved);
550     void inform_ring(IntMatrix& comm, DoubleMatrix& pos_nb,
551                     DoubleMatrix& pos_b, DoubleVector& fit_b,
552                     DoubleVector& gbest, int improved);
553     void inform_random(IntMatrix& comm, DoubleMatrix& pos_nb,
554                       DoubleMatrix& pos_b, DoubleVector& fit_b,
555                       DoubleVector& gbest,  int improved);
556     void inform(IntMatrix& comm, DoubleMatrix& pos_nb, DoubleMatrix& pos_b, DoubleVector& fit_b, int improved);
557     void init_comm_ring(IntMatrix& comm);
558     void init_comm_random(IntMatrix& comm) ;
559    
560     typedef void (OptInfoPso::*Inform_fun)(IntMatrix&, DoubleMatrix&, DoubleMatrix&, DoubleVector&, DoubleVector&,  int); // neighborhood update function
561     typedef double (OptInfoPso::*Calc_inertia_fun)(int); // inertia weight update function
562    
563    };
564  #endif  #endif

Legend:
Removed from v.19  
changed lines
  Added in v.20

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

Powered By FusionForge