PaGMO  1.1.5
discrepancy.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_UTIL_DISCREPANCY_H
26 #define PAGMO_UTIL_DISCREPANCY_H
27 
28 #include <iostream>
29 #include <vector>
30 #include <math.h>
31 #include <algorithm>
32 #include <boost/shared_ptr.hpp>
33 
34 #include "../config.h"
35 #include "../exceptions.h"
36 #include "../rng.h"
37 
38 namespace pagmo{ namespace util {
39 
41 
47 namespace discrepancy {
48 
50 double van_der_corput(unsigned int n, unsigned int base);
51 unsigned int prime ( int n );
52 unsigned int prime_ge ( unsigned int n );
53 class __PAGMO_VISIBLE project_2_simplex
54 {
55  public:
56  project_2_simplex(unsigned int dim) : m_dim(dim) {}
57  std::vector<double> operator()(std::vector<double> retval) const;
58  private:
59  unsigned int m_dim;
60 };
62 
63 class base;
65 typedef boost::shared_ptr<base> base_ptr;
66 
67 //---------------------------------------------------------
68 //--------------------BASE CLASS---------------------------
69 //---------------------------------------------------------
70 
72 
78 class __PAGMO_VISIBLE base
79 {
80 public:
82 
86  base(unsigned int dim, unsigned int count = 1) : m_dim(dim), m_count(count) {}
88 
93  virtual std::vector<double> operator()() = 0;
95 
101  virtual std::vector<double> operator()(unsigned int n) = 0;
103  virtual base_ptr clone() const = 0;
105  virtual~base();
106 protected:
108  unsigned int m_dim;
110  unsigned int m_count;
111 };
112 
113 //---------------------------------------------------------
114 //--------------------DERIVED CLASSES----------------------
115 //---------------------------------------------------------
116 
118 
125 class __PAGMO_VISIBLE halton : public base
126 {
127  public:
128  halton(unsigned int dim, unsigned int count = 1);
129  base_ptr clone() const;
130  std::vector<double> operator()();
131  std::vector<double> operator()(unsigned int n);
132  private:
133  std::vector<unsigned int> m_primes;
134 };
135 
137 
145 class __PAGMO_VISIBLE faure : public base
146 {
147  public:
148  faure(unsigned int dim, unsigned int count = 1);
149  base_ptr clone() const;
150  std::vector<double> operator()();
151  std::vector<double> operator()(unsigned int n);
152  private:
153  int *binomial_table ( int qs, int m, int n );
154  void faure_orig ( unsigned int dim_num, unsigned int *seed, double quasi[] );
155  double *faure_generate ( int dim_num, int n, int skip );
156  int i4_log_i4 ( int i4, int j4 );
157  int i4_min ( int i1, int i2 );
158  int i4_power ( int i, int j );
159  private:
160  int *m_coef;
161  int m_hisum_save;
162  int m_qs;
163  int *m_ytemp;
164 
165 };
166 
168 
176 class __PAGMO_VISIBLE simplex : public base
177 {
178 public:
179  simplex(unsigned int dim, unsigned int count);
180  base_ptr clone() const;
181  std::vector<double> operator()();
182  std::vector<double> operator()(unsigned int n);
183 private:
184  halton m_generator;
185  project_2_simplex m_projector;
186 };
187 
188 
190 
198 class __PAGMO_VISIBLE sobol : public base
199 {
200  public:
201  sobol(unsigned int dim, unsigned int count);
202  base_ptr clone() const;
203  std::vector<double> operator()();
204  std::vector<double> operator()(unsigned int n);
205  private:
206  int i8_bit_lo0 ( long long int n );
207  void i8_sobol ( unsigned int dim_num, long long int *seed, double quasi[ ] );
208  private:
209  unsigned int m_dim_num_save;
210  bool m_initialized;
211  long long int m_maxcol;
212  long long int m_seed_save;
213  double recipd;
214  long long int lastq[1111]; //1111 is maximum dimension.
215  long long int poly[1111];
216  long long int v[1111][62]; //2^62 is approx. limit of points requested.
217 };
218 
220 
230 class __PAGMO_VISIBLE lhs : public base
231 {
232  public:
233  lhs(unsigned int dim, unsigned int count);
234  base_ptr clone() const;
235  std::vector<double> operator()();
236  std::vector<double> operator()(unsigned int n);
237  private:
238  std::vector<double> latin_random ( unsigned int dim_num, unsigned int point_num);
239  unsigned int *perm_uniform ( unsigned int n);
240  private:
241  bool m_initialised;
242  std::vector<double> m_set;
243  unsigned int m_next;
244 };
245 
246 }}} //namespace discrepancy
247 
248 #endif
Root PaGMO namespace.
Halton sequence projected on a simplex.
Definition: discrepancy.h:176
boost::shared_ptr< base > base_ptr
Smart pointer to the base discrepancy class.
Definition: discrepancy.h:63
Faure quasi-random point sequence.
Definition: discrepancy.h:145
base(unsigned int dim, unsigned int count=1)
Constructor.
Definition: discrepancy.h:86
unsigned int prime(int n)
Returns a prime number.
Definition: discrepancy.cpp:48
double van_der_corput(unsigned int n, unsigned int base)
Van Der Corput sequence.
Definition: discrepancy.cpp:26
Latin Hypercube Sampling.
Definition: discrepancy.h:230
unsigned int prime_ge(unsigned int n)
Returns the smallest prime greater than or equal to n.
unsigned int m_count
Starting point of the sequence (can be used to skip initial values)
Definition: discrepancy.h:110
Halton quasi-random point sequence.
Definition: discrepancy.h:125
Base low-discrepancy sequence class.
Definition: discrepancy.h:78
Sobol quasi-random point sequence.
Definition: discrepancy.h:198
unsigned int m_dim
Hypercube dimension where sampling with low-discrepancy.
Definition: discrepancy.h:108