1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415
|
/**************************************************************************/
/* Copyright 2012 Tim Day */
/* */
/* This file is part of Evolvotron */
/* */
/* Evolvotron is free software: you can redistribute it and/or modify */
/* it under the terms of the GNU General Public License as published by */
/* the Free Software Foundation, either version 3 of the License, or */
/* (at your option) any later version. */
/* */
/* Evolvotron is distributed in the hope that it will be useful, */
/* but WITHOUT ANY WARRANTY; without even the implied warranty of */
/* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the */
/* GNU General Public License for more details. */
/* */
/* You should have received a copy of the GNU General Public License */
/* along with Evolvotron. If not, see <http://www.gnu.org/licenses/>. */
/**************************************************************************/
/*! \file
\brief Interface for class MutationParameters.
*/
#ifndef _mutation_parameters_h_
#define _mutation_parameters_h_
#include "random.h"
class FunctionNode;
class FunctionRegistration;
class FunctionRegistry;
//! Class encapsulating mutation parameters.
/*! For example, magnitude of variations, probability of leaves being dropped.
Also provides a random number generator.
*/
class MutationParameters
{
private:
const std::auto_ptr<FunctionRegistry> _function_registry;
protected:
//! A random number generator.
/*! Declared mutable so we can pass const MutationParameters& around and still do useful work with it.
*/
mutable Random01 _r01;
//! Negative-exponential generator might be useful too.
mutable RandomNegExp _r_negexp;
//! Specifies the base magnitude of random changes the function parameters.
real _base_magnitude_parameter_variation;
//! Specifies the base probability of a the parameter set being completely reset.
real _base_probability_parameter_reset;
//! Specifies the base probability of a child being dropped and replaced with a new random stub.
real _base_probability_glitch;
//! Specifies the base probability of all child nodes being reordered.
real _base_probability_shuffle;
//! Specifies the base probability of a random stub being inserted before a child.
real _base_probability_insert;
//! Specifies the base probability of a node being replaced with an alternate type.
real _base_probability_substitute;
//! Specifies the proportion of basic node types.
real _proportion_basic;
//! Specifies the proportion of Constant nodes vs Position type nodes.
real _proportion_constant;
//! Specifies the probability of a using a FunctionNodePositionTransformed instead of FunctionNodePosition
real _identity_supression;
//! The maximum number of iterations an iterative function node can have initially.
uint _max_initial_iterations;
//! The base probability of the number of iterations changing by plus or minus 1.
real _base_probability_iterations_change_step;
//! The base probability of the number of iterations changing by times or divide 2.
real _base_probability_iterations_change_jump;
//! Individual weighting modifiers for each function type
/*! Will only be applied to random functions we're asked for.
The bulk of nodes are created by FunctionNode and are boring to keep the branching ratio down.
\todo Implement a branching ratio query method.
*/
std::map<const FunctionRegistration*,real> _function_weighting;
//! Total of function weights, for normalisation.
real _function_weighting_total;
//! Map from [0,1] to a function registration, taking weights into account.
std::map<real,const FunctionRegistration*> _function_pick;
//! What state a reset should return autocool to.
const bool _autocool_reset_state;
//! Whether autocooling is being applied.
bool _autocool_enable;
//! Number of generations at which parameters will be half cooled.
uint _autocool_halflife;
//! Count of number of generations for decay cooling.
uint _autocool_generations;
//! Just use SingleChannelNoise for almost all functions (useful for debugging).
const bool _debug_mode;
void recalculate_function_stuff();
public:
//! Trivial constructor.
MutationParameters(uint seed,bool ac,bool debug_mode);
//! Trivial destructor.
virtual ~MutationParameters();
//! Accessor.
const FunctionRegistry& function_registry() const
{
return *_function_registry;
}
//! Reset to initial values.
void reset();
//! Multiply most parameters by the given factor
void general_cool(real f);
//! Returns a reference to the random number generator.
/*! Need this for e.g RandomXYZInSphere constructor.
*/
Random01& rng01() const
{
return _r01;
}
//! Return a number in the range [0,1)
real r01() const
{
return _r01();
}
real rnegexp() const
{
return _r_negexp();
}
//! Accessor, with decay.
real effective_magnitude_parameter_variation() const
{
return base_magnitude_parameter_variation()*decay_factor();
}
//! Accessor.
real base_magnitude_parameter_variation() const
{
return _base_magnitude_parameter_variation;
}
//! Accessor.
void base_magnitude_parameter_variation(real v)
{
_base_magnitude_parameter_variation=v;
report_change();
}
//! Accessor, with decay.
real effective_probability_parameter_reset() const
{
return base_probability_parameter_reset()*decay_factor();
}
//! Accessor.
real base_probability_parameter_reset() const
{
return _base_probability_parameter_reset;
}
//! Accessor.
void base_probability_parameter_reset(real v)
{
_base_probability_parameter_reset=v;
report_change();
}
//! Accessor, with decay.
real effective_probability_glitch() const
{
return base_probability_glitch()*decay_factor();
}
//! Accessor.
real base_probability_glitch() const
{
return _base_probability_glitch;
}
//! Accessor.
void base_probability_glitch(real v)
{
_base_probability_glitch=v;
report_change();
}
//! Accessor, with decay.
real effective_probability_shuffle() const
{
return base_probability_shuffle()*decay_factor();
}
//! Accessor.
real base_probability_shuffle() const
{
return _base_probability_shuffle;
}
//! Accessor.
void base_probability_shuffle(real v)
{
_base_probability_shuffle=v;
report_change();
}
//! Accessor, with decay.
real effective_probability_insert() const
{
return base_probability_insert()*decay_factor();
}
//! Accessor.
real base_probability_insert() const
{
return _base_probability_insert;
}
//! Accessor.
void base_probability_insert(real v)
{
_base_probability_insert=v;
report_change();
}
//! Accessor.
real effective_probability_substitute() const
{
return base_probability_substitute()*decay_factor();
}
//! Accessor.
real base_probability_substitute() const
{
return _base_probability_substitute;
}
//! Accessor.
void base_probability_substitute(real v)
{
_base_probability_substitute=v;
report_change();
}
//! Accessor.
real proportion_constant() const
{
return _proportion_constant;
}
//! Accessor.
void proportion_constant(real v)
{
_proportion_constant=v;
report_change();
}
//! Accessor.
real identity_supression() const
{
return _identity_supression;
}
//! Accessor.
void identity_supression(real v)
{
_identity_supression=v;
report_change();
}
//! Accessor.
uint max_initial_iterations() const
{
return _max_initial_iterations;
}
//! Accessor.
void max_initial_iterations(uint v)
{
_max_initial_iterations=v;
report_change();
}
//! Accessor, with decay.
real effective_probability_iterations_change_step() const
{
return base_probability_iterations_change_step()*decay_factor();
}
//! Accessor.
real base_probability_iterations_change_step() const
{
return _base_probability_iterations_change_step;
}
//! Accessor.
void base_probability_iterations_change_step(real v)
{
_base_probability_iterations_change_step=v;
report_change();
}
//! Accessor, with decay.
real effective_probability_iterations_change_jump() const
{
return base_probability_iterations_change_jump()*decay_factor();
}
//! Accessor.
real base_probability_iterations_change_jump() const
{
return _base_probability_iterations_change_jump;
}
//! Accessor.
void base_probability_iterations_change_jump(real v)
{
_base_probability_iterations_change_jump=v;
report_change();
}
//! Accessor.
real proportion_basic() const
{
return _proportion_basic;
}
//! Accessor.
void proportion_basic(real p)
{
_proportion_basic=p;
report_change();
}
//! Accessor.
bool autocool_enable() const
{
return _autocool_enable;
}
//! Accessor.
void autocool_enable(bool v)
{
_autocool_enable=v;
std::clog << "Autocooling " << (autocool_enable() ? "ON" : "OFF") << "\n";
report_change();
}
//! Accessor.
int autocool_halflife() const
{
return _autocool_halflife;
}
//! Accessor.
void autocool_halflife(int v)
{
_autocool_halflife=v;
report_change();
}
//! Accessor
int autocool_generations() const
{
return _autocool_generations;
}
//! Accessor.
void autocool_generations(int v)
{
_autocool_generations=v;
report_change();
}
//! Accessor.
void autocool_generations_increment()
{
_autocool_generations++;
report_change();
}
//! Calculate branching ratio for above calls
/* Call user should be checking this and diluting with boring nodes to keep it under control
*/
real random_function_branching_ratio() const;
//! This returns a new random bit of tree.
/*! Setting the "exciting" flag avoids the most basic node types, but only at the top level of the stub tree.
*/
std::auto_ptr<FunctionNode> random_function_stub(bool exciting) const;
void change_function_weighting(const FunctionRegistration* fn,real w);
void randomize_function_weightings_for_classifications(uint classification_mask);
real get_weighting(const FunctionRegistration* fn);
protected:
//! Compute current decay factor
real decay_factor() const;
//! Return a random function appropriately biased by current settings
std::auto_ptr<FunctionNode> random_function() const;
//! Return a random function registration, appropriately biased by current settings
const FunctionRegistration* random_weighted_function_registration() const;
//! Intended for Qt-world subclass to override to emit signal.
virtual void report_change();
};
#endif
|