/
Parameters.h
377 lines (269 loc) · 12.2 KB
/
Parameters.h
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
#ifndef _PARAMETERS_H
#define _PARAMETERS_H
///////////////////////////////////////////////////////////////////////////////////////////
// MultiNEAT - Python/C++ NeuroEvolution of Augmenting Topologies Library
//
// Copyright (C) 2012 Peter Chervenski
//
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU Lesser General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// This program 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 Lesser General Public License
// along with this program. If not, see < http://www.gnu.org/licenses/ >.
//
// Contact info:
//
// Peter Chervenski < spookey@abv.bg >
// Shane Ryan < shane.mcdonald.ryan@gmail.com >
///////////////////////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////////
// File: Parameters.h
// Description: Definition for the parameters class.
///////////////////////////////////////////////////////////////////////////////
namespace NEAT
{
//////////////////////////////////////////////
// The NEAT Parameters class
//////////////////////////////////////////////
class Parameters
{
public:
/////////////////////
// Members
/////////////////////
////////////////////
// Basic parameters
////////////////////
// Size of population
unsigned int PopulationSize;
// If true, this enables dynamic compatibility thresholding
// It will keep the number of species between MinSpecies and MaxSpecies
bool DynamicCompatibility;
// Minimum number of species
unsigned int MinSpecies;
// Maximum number of species
unsigned int MaxSpecies;
// Don't wipe the innovation database each generation?
bool InnovationsForever;
// Allow clones or nearly identical genomes to exist simultaneously in the population.
// This is useful for non-deterministic environments,
// as the same individual will get more than one chance to prove himself, also
// there will be more chances the same individual to mutate in different ways.
// The drawback is greatly increased time for reproduction. If you want to
// search quickly, yet less efficient, leave this to true.
bool AllowClones;
////////////////////////////////
// GA Parameters
////////////////////////////////
// Age treshold, meaning if a species is below it, it is considered young
unsigned int YoungAgeTreshold;
// Fitness boost multiplier for young species (1.0 means no boost)
// Make sure it is >= 1.0 to avoid confusion
double YoungAgeFitnessBoost;
// Number of generations without improvement (stagnation) allowed for a species
unsigned int SpeciesMaxStagnation;
// Minimum jump in fitness necessary to be considered as improvement.
// Setting this value to 0.0 makes the system to behave like regular NEAT.
double StagnationDelta;
// Age threshold, meaning if a species if above it, it is considered old
unsigned int OldAgeTreshold;
// Multiplier that penalizes old species.
// Make sure it is < 1.0 to avoid confusion.
double OldAgePenalty;
// Detect competetive coevolution stagnation
// This kills the worst species of age >N (each X generations)
bool DetectCompetetiveCoevolutionStagnation;
// Each X generation..
int KillWorstSpeciesEach;
// Of age above..
int KillWorstAge;
// Percent of best individuals that are allowed to reproduce. 1.0 = 100%
double SurvivalRate;
// Probability for a baby to result from sexual reproduction (crossover/mating). 1.0 = 100%
double CrossoverRate;
// If a baby results from sexual reproduction, this probability determines if mutation will
// be performed after crossover. 1.0 = 100% (always mutate after crossover)
double OverallMutationRate;
// Probability for a baby to result from inter-species mating.
double InterspeciesCrossoverRate;
// Probability for a baby to result from Multipoint Crossover when mating. 1.0 = 100%
// The default if the Average mating.
double MultipointCrossoverRate;
// Performing roulette wheel selection or not?
bool RouletteWheelSelection;
///////////////////////////////////
// Phased Search parameters //
///////////////////////////////////
// Using phased search or not
bool PhasedSearching;
// Using delta coding or not
bool DeltaCoding;
// What is the MPC + base MPC needed to begin simplifying phase
unsigned int SimplifyingPhaseMPCTreshold;
// How many generations of global stagnation should have passed to enter simplifying phase
unsigned int SimplifyingPhaseStagnationTreshold;
// How many generations of MPC stagnation are needed to turn back on complexifying
unsigned int ComplexityFloorGenerations;
/////////////////////////////////////
// Novelty Search parameters //
/////////////////////////////////////
// the K constant
unsigned int NoveltySearch_K;
// Sparseness treshold. Add to the archive if above
double NoveltySearch_P_min;
// Dynamic Pmin?
bool NoveltySearch_Dynamic_Pmin;
// How many evaluations should pass without adding to the archive
// in order to lower Pmin
unsigned int NoveltySearch_No_Archiving_Stagnation_Treshold;
// How should it be multiplied (make it less than 1.0)
double NoveltySearch_Pmin_lowering_multiplier;
// Not lower than this value
double NoveltySearch_Pmin_min;
// How many one-after-another additions to the archive should
// pass in order to raise Pmin
unsigned int NoveltySearch_Quick_Archiving_Min_Evaluations;
// How should it be multiplied (make it more than 1.0)
double NoveltySearch_Pmin_raising_multiplier;
// Per how many evaluations to recompute the sparseness
unsigned int NoveltySearch_Recompute_Sparseness_Each;
///////////////////////////////////
// Mutation parameters
///////////////////////////////////
// Probability for a baby to be mutated with the Add-Neuron mutation.
double MutateAddNeuronProb;
// Allow splitting of any recurrent links
bool SplitRecurrent;
// Allow splitting of looped recurrent links
bool SplitLoopedRecurrent;
// Maximum number of tries to find a link to split
int NeuronTries;
// Probability for a baby to be mutated with the Add-Link mutation
double MutateAddLinkProb;
// Probability for a new incoming link to be from the bias neuron;
double MutateAddLinkFromBiasProb;
// Probability for a baby to be mutated with the Remove-Link mutation
double MutateRemLinkProb;
// Probability for a baby that a simple neuron will be replaced with a link
double MutateRemSimpleNeuronProb;
// Maximum number of tries to find 2 neurons to add/remove a link
unsigned int LinkTries;
// Probability that a link mutation will be made recurrent
double RecurrentProb;
// Probability that a recurrent link mutation will be looped
double RecurrentLoopProb;
// Probability for a baby's weights to be mutated
double MutateWeightsProb;
// Probability for a severe (shaking) weight mutation
double MutateWeightsSevereProb;
// Probability for a particular gene to be mutated. 1.0 = 100%
double WeightMutationRate;
// Maximum perturbation for a weight mutation
double WeightMutationMaxPower;
// Maximum magnitude of a replaced weight
double WeightReplacementMaxPower;
// Maximum absolute magnitude of a weight
double MaxWeight;
// Probability for a baby's A activation function parameters to be perturbed
double MutateActivationAProb;
// Probability for a baby's B activation function parameters to be perturbed
double MutateActivationBProb;
// Maximum magnitude for the A parameter perturbation
double ActivationAMutationMaxPower;
// Maximum magnitude for the B parameter perturbation
double ActivationBMutationMaxPower;
// Maximum magnitude for time costants perturbation
double TimeConstantMutationMaxPower;
// Maximum magnitude for biases perturbation
double BiasMutationMaxPower;
// Activation parameter A min/max
double MinActivationA;
double MaxActivationA;
// Activation parameter B min/max
double MinActivationB;
double MaxActivationB;
// Probability for a baby that an activation function type will be changed for a single neuron
// considered a structural mutation because of the large impact on fitness
double MutateNeuronActivationTypeProb;
// Probabilities for a particular activation function appearance
double ActivationFunction_SignedSigmoid_Prob;
double ActivationFunction_UnsignedSigmoid_Prob;
double ActivationFunction_Tanh_Prob;
double ActivationFunction_TanhCubic_Prob;
double ActivationFunction_SignedStep_Prob;
double ActivationFunction_UnsignedStep_Prob;
double ActivationFunction_SignedGauss_Prob;
double ActivationFunction_UnsignedGauss_Prob;
double ActivationFunction_Abs_Prob;
double ActivationFunction_SignedSine_Prob;
double ActivationFunction_UnsignedSine_Prob;
double ActivationFunction_SignedSquare_Prob;
double ActivationFunction_UnsignedSquare_Prob;
double ActivationFunction_Linear_Prob;
// Probability for a baby's neuron time constant values to be mutated
double MutateNeuronTimeConstantsProb;
// Probability for a baby's neuron bias values to be mutated
double MutateNeuronBiasesProb;
// Time constant range
double MinNeuronTimeConstant;
double MaxNeuronTimeConstant;
// Bias range
double MinNeuronBias;
double MaxNeuronBias;
/////////////////////////////////////
// Speciation parameters
/////////////////////////////////////
// Percent of disjoint genes importance
double DisjointCoeff;
// Percent of excess genes importance
double ExcessCoeff;
// Node-specific activation parameter A difference importance
double ActivationADiffCoeff;
// Node-specific activation parameter B difference importance
double ActivationBDiffCoeff;
// Average weight difference importance
double WeightDiffCoeff;
// Average time constant difference importance
double TimeConstantDiffCoeff;
// Average bias difference importance
double BiasDiffCoeff;
// Activation function type difference importance
double ActivationFunctionDiffCoeff;
// Compatibility treshold
double CompatTreshold;
// Minumal value of the compatibility treshold
double MinCompatTreshold;
// Modifier per generation for keeping the species stable
double CompatTresholdModifier;
// Per how many generations to change the treshold
unsigned int CompatTreshChangeInterval_Generations;
// Per how many evaluations to change the treshold
unsigned int CompatTreshChangeInterval_Evaluations;
/////////////////////////////////////
// Constructors
/////////////////////////////////////
// Load defaults
Parameters();
////////////////////////////////////
// Methods
////////////////////////////////////
// Load the parameters from a file
// returns 0 on success
int Load(const char* filename);
// Load the parameters from an already opened file for reading
int Load(std::ifstream& a_DataFile);
void Save(const char* filename);
// Saves the parameters to an already opened file for writing
void Save(FILE* a_fstream);
// resets the parameters to built-in defaults
void Reset();
};
} // namespace NEAT
#endif