27 #include <boost/functional/hash.hpp>
29 #include "../exceptions.h"
31 #include "../population.h"
37 namespace pagmo {
namespace problem {
54 noisy::noisy(
const base & p,
unsigned int trials,
const double param_first,
const double param_second,
noise_type distribution,
unsigned int seed):
61 m_original_problem(p.clone()),
63 m_normal_dist(0.0,1.0),
64 m_uniform_dist(0.0,1.0),
65 m_decision_vector_hash(),
66 m_param_first(param_first),
67 m_param_second(param_second),
68 m_noise_type(distribution)
70 if(distribution ==
UNIFORM && param_first > param_second){
71 pagmo_throw(value_error,
"Bounds specified for the uniform noise are not valid.");
79 m_original_problem(prob.m_original_problem->clone()),
80 m_trials(prob.m_trials),
81 m_normal_dist(0.0,1.0),
82 m_uniform_dist(0.0,1.0),
83 m_decision_vector_hash(),
84 m_param_first(prob.m_param_first),
85 m_param_second(prob.m_param_second),
86 m_noise_type(prob.m_noise_type) {}
103 if(m_noise_type ==
UNIFORM && param_first > param_second){
104 pagmo_throw(value_error,
"Bounds specified for the uniform noise are not valid.");
106 m_param_first = param_first;
107 m_param_second = param_second;
116 return m_param_first;
125 return m_param_second;
139 for (
unsigned int j=0; j< m_trials; ++j) {
140 m_original_problem->objfun(tmp, x);
142 for (fitness_vector::size_type i=0; i<f.size();++i) {
143 f[i] = f[i] + tmp[i] / (double)m_trials;
159 for (
unsigned int j=0; j< m_trials; ++j) {
160 m_original_problem->compute_constraints(tmp, x);
162 for (constraint_vector::size_type i=0; i<c.size();++i) {
163 c[i] = c[i] + tmp[i] / (double)m_trials;
172 if(m_noise_type ==
NORMAL){
173 f[i] += m_normal_dist(
m_drng)*m_param_second+m_param_first;
175 else if(m_noise_type ==
UNIFORM){
176 f[i] += m_uniform_dist(
m_drng)*(m_param_second-m_param_first)+m_param_first;
185 if(m_noise_type ==
NORMAL){
186 c[i] += m_normal_dist(
m_drng)*m_param_second+m_param_first;
188 else if(m_noise_type ==
UNIFORM){
189 c[i] += m_uniform_dist(
m_drng)*(m_param_second-m_param_first)+m_param_first;
196 return m_original_problem->get_name() +
" [Noisy]";
205 std::ostringstream oss;
206 oss << m_original_problem->human_readable_extra() << std::endl;
207 oss <<
"\tNoise type: ";
208 if(m_noise_type ==
NORMAL){
209 oss <<
"Normal distribution of ("<<m_param_first<<
","<<m_param_second<<
")";
211 else if(m_noise_type ==
UNIFORM){
212 oss <<
"Uniform distribution over ("<<m_param_first<<
","<<m_param_second<<
")";
215 oss <<
"\n\t Unknown????";
217 oss <<
"\n\ttrials: "<<m_trials;
218 oss <<
"\n\tseed: "<<
m_seed << std::endl;
boost::shared_ptr< base > base_ptr
Alias for shared pointer to base problem.
std::vector< double > decision_vector
Decision vector type.
fitness_vector::size_type f_size_type
Fitness' size type: the same as pagmo::fitness_vector's size type.
rng_double m_drng
Random number generator for double-precision floating point values.
base_ptr clone() const
Clone method.
unsigned int m_seed
Seed of the random number generator.
noise_type
Distribution type of the noise.
std::string human_readable_extra() const
Extra human readable info for the problem.
std::vector< double > fitness_vector
Fitness vector type.
void objfun_impl(fitness_vector &, const decision_vector &) const
std::vector< double > constraint_vector
Constraint vector type.
const decision_vector & get_ub() const
Upper bounds getter.
Base Stochastic Optimization Problem.
constraint_vector::size_type c_size_type
Constraints' size type: the same as pagmo::constraint_vector's size type.
const decision_vector & get_lb() const
Lower bounds getter.
void set_bounds(const decision_vector &, const decision_vector &)
Bounds setter from pagmo::decision_vector.
void compute_constraints_impl(constraint_vector &, const decision_vector &) const
void set_noise_param(double, double)
noisy(const base &=ackley(1), unsigned int trials=1, const double param_first=0.0, const double param_second=0.1, noise_type=NORMAL, unsigned int seed=0u)
double get_param_first() const
double get_param_second() const
std::string get_name() const
Get problem's name.