PaGMO  1.1.5
spheres_q.h
1 /*****************************************************************************
2  * Copyright (C) 2004-2015 The PaGMO development team, *
3  * Advanced Concepts Team (ACT), European Space Agency (ESA) *
4  * *
5  * https://github.com/esa/pagmo *
6  * *
7  * act@esa.int *
8  * *
9  * This program is free software; you can redistribute it and/or modify *
10  * it under the terms of the GNU General Public License as published by *
11  * the Free Software Foundation; either version 2 of the License, or *
12  * (at your option) any later version. *
13  * *
14  * This program is distributed in the hope that it will be useful, *
15  * but WITHOUT ANY WARRANTY; without even the implied warranty of *
16  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
17  * GNU General Public License for more details. *
18  * *
19  * You should have received a copy of the GNU General Public License *
20  * along with this program; if not, write to the *
21  * Free Software Foundation, Inc., *
22  * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
23  *****************************************************************************/
24 
25 #ifndef PAGMO_SPHERES_Q_H
26 #define PAGMO_SPHERES_Q_H
27 
28 #include <string>
29 #include <vector>
30 #include <gsl/gsl_odeiv2.h>
31 
32 #include "../config.h"
33 #include "../serialization.h"
34 #include "../types.h"
35 #include "base_stochastic.h"
36 #include "../rng.h"
37 
38 namespace pagmo { namespace problem {
39 
41 
66 class __PAGMO_VISIBLE spheres_q: public base_stochastic
67 {
68  static int ode_func( double t, const double y[], double f[], void *params );
69  public:
71 
79  spheres_q(int n_evaluations = 10, int n_hidden = 10, double ode_prec = 1E-3, unsigned int seed = 0);
80 
82 
85  spheres_q(const spheres_q &);
86 
88 
91  ~spheres_q();
92 
94 
103  std::vector<std::vector<double> > post_evaluate(const decision_vector &x, int N = 25000, unsigned int seed = 0) const;
104 
106 
114  std::vector<std::vector<double> > simulate(const decision_vector & x, const std::vector<double> &ic, int N) const;
115  base_ptr clone() const;
116 
117 
118  protected:
119  void objfun_impl(fitness_vector &, const decision_vector &) const;
120  private:
121  // Class representing a feed forward neural network
122  class ffnn {
123  friend class spheres;
124  public:
125  ffnn(const unsigned int, const unsigned int,const unsigned int);
126  void eval(double[], const double[]) const;
127  void set_weights(const std::vector<double> &);
128  private:
129  friend class boost::serialization::access;
130  template <class Archive>
131  void serialize(Archive &ar, const unsigned int)
132  {
133  ar & const_cast<unsigned int &>(m_n_inputs);
134  ar & const_cast<unsigned int &>(m_n_hidden);
135  ar & const_cast<unsigned int &>(m_n_outputs);
136  ar & m_weights;
137  ar & m_hidden;
138  }
139  const unsigned int m_n_inputs;
140  const unsigned int m_n_hidden;
141  const unsigned int m_n_outputs;
142  std::vector<double> m_weights;
143  mutable std::vector<double> m_hidden;
144  };
145  double single_fitness( const std::vector<double> &, const ffnn& ) const;
146  friend class boost::serialization::access;
147  template <class Archive>
148  void serialize(Archive &ar, const unsigned int)
149  {
150  ar & boost::serialization::base_object<base_stochastic>(*this);
151  ar & m_ffnn;
152  ar & m_n_evaluations;
153  ar & m_n_hidden_neurons;
154  ar & const_cast<double &>(m_numerical_precision);
155  ar & m_ic;
156  }
157  gsl_odeiv2_driver* m_gsl_drv_pntr;
158  gsl_odeiv2_system m_sys;
159  mutable ffnn m_ffnn;
160  int m_n_evaluations;
161  int m_n_hidden_neurons;
162  const double m_numerical_precision;
163  mutable std::vector<double> m_ic;
164 };
165 
166 }} //namespaces
167 
168 BOOST_CLASS_EXPORT_KEY(pagmo::problem::spheres_q);
169 
170 #endif // PAGMO_SPHERES_Q_H
Root PaGMO namespace.
boost::shared_ptr< base > base_ptr
Alias for shared pointer to base problem.
Definition: problem/base.h:62
std::vector< double > decision_vector
Decision vector type.
Definition: types.h:40
std::vector< double > fitness_vector
Fitness vector type.
Definition: types.h:42
Base Stochastic Optimization Problem.
Evolutionary Neuro-Controller for the MIT Spheres (perception-action defined in the absolute frame) ...
Definition: spheres.h:70
Evolutionary Neuro-Controller for the MIT Spheres (perception-action defined in the body frame) ...
Definition: spheres_q.h:66