-
Notifications
You must be signed in to change notification settings - Fork 104
/
cMultiNeat.pxd
463 lines (379 loc) · 13.1 KB
/
cMultiNeat.pxd
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
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
from libcpp.vector cimport vector
from libcpp cimport bool
from libc.stdio cimport FILE
"""
#############################################
Enums
#############################################
"""
cdef extern from "src/Genes.h" namespace "NEAT":
cdef enum NeuronType:
NONE
INPUT
BIAS
HIDDEN
OUTPUT
cdef enum ActivationFunction:
SIGNED_SIGMOID
UNSIGNED_SIGMOID
TANH
TANH_CUBIC
SIGNED_STEP
UNSIGNED_STEP
SIGNED_GAUSS
UNSIGNED_GAUSS
ABS
SIGNED_SINE
UNSIGNED_SINE
#SIGNED_SQUARE
#UNSIGNED_SQUARE
LINEAR
cdef extern from "src/Population.h" namespace "NEAT":
cdef enum SearchMode:
COMPLEXIFYING
SIMPLIFYING
BLENDED
"""
#############################################
RNG class
#############################################
"""
cdef extern from "src/Random.h" namespace "NEAT":
cdef cppclass RNG:
RNG() except +
void Seed(int seed)
void TimeSeed()
int RandPosNeg()
int RandInt(int x, int y)
double RandFloat()
double RandFloatSigned()
double RandGaussSigned()
int Roulette(vector[double]& a_probs)
"""
#############################################
Parameters class
#############################################
"""
cdef extern from "src/Parameters.h" namespace "NEAT":
cdef cppclass Parameters:
unsigned int PopulationSize
bool DynamicCompatibility
unsigned int MinSpecies
unsigned int MaxSpecies
bool InnovationsForever
bool AllowClones
unsigned int YoungAgeTreshold
double YoungAgeFitnessBoost
unsigned int SpeciesMaxStagnation
double StagnationDelta
unsigned int OldAgeTreshold
double OldAgePenalty
bool DetectCompetetiveCoevolutionStagnation
int KillWorstSpeciesEach
int KillWorstAge
double SurvivalRate
double CrossoverRate
double OverallMutationRate
double InterspeciesCrossoverRate
double MultipointCrossoverRate
bool RouletteWheelSelection
bool PhasedSearching
bool DeltaCoding
unsigned int SimplifyingPhaseMPCTreshold
unsigned int SimplifyingPhaseStagnationTreshold
unsigned int ComplexityFloorGenerations
unsigned int NoveltySearch_K
double NoveltySearch_P_min
bool NoveltySearch_Dynamic_Pmin
unsigned int NoveltySearch_No_Archiving_Stagnation_Treshold
double NoveltySearch_Pmin_lowering_multiplier
double NoveltySearch_Pmin_min
unsigned int NoveltySearch_Quick_Archiving_Min_Evaluations
double NoveltySearch_Pmin_raising_multiplier
unsigned int NoveltySearch_Recompute_Sparseness_Each
double MutateAddNeuronProb
bool SplitRecurrent
bool SplitLoopedRecurrent
int NeuronTries
double MutateAddLinkProb
double MutateAddLinkFromBiasProb
double MutateRemLinkProb
double MutateRemSimpleNeuronProb
unsigned int LinkTries
double RecurrentProb
double RecurrentLoopProb
double MutateWeightsProb
double MutateWeightsSevereProb
double WeightMutationRate
double WeightMutationMaxPower
double WeightReplacementMaxPower
double MaxWeight
double MutateActivationAProb
double MutateActivationBProb
double ActivationAMutationMaxPower
double ActivationBMutationMaxPower
double TimeConstantMutationMaxPower
double BiasMutationMaxPower
double MinActivationA
double MaxActivationA
double MinActivationB
double MaxActivationB
double MutateNeuronActivationTypeProb
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
double MutateNeuronTimeConstantsProb
double MutateNeuronBiasesProb
double MinNeuronTimeConstant
double MaxNeuronTimeConstant
double MinNeuronBias
double MaxNeuronBias
bool DontUseBiasNeuron
bool AllowLoops
double DisjointCoeff
double ExcessCoeff
double ActivationADiffCoeff
double ActivationBDiffCoeff
double WeightDiffCoeff
double TimeConstantDiffCoeff
double BiasDiffCoeff
double ActivationFunctionDiffCoeff
double CompatTreshold
double MinCompatTreshold
double CompatTresholdModifier
unsigned int CompatTreshChangeInterval_Generations
unsigned int CompatTreshChangeInterval_Evaluations
# Fraction of individuals to be copied unchanged
double Elitism 'EliteFraction'
Parameters() except +
int Load(const char* filename)
void Save(const char* filename)
void Reset()
##############
# ES HyperNEAT params
##############
double DivisionThreshold
double VarianceThreshold
# Used for Band prunning.
double BandThreshold
# Max and Min Depths of the quadtree
unsigned int InitialDepth
unsigned int MaxDepth
# How many hidden layers before connecting nodes to output. At 0 there is
# one hidden layer. At 1, there are two and so on.
unsigned int IterationLevel
# The Bias value for the CPPN queries.
double CPPN_Bias
# Quadtree Dimensions
# The range of the tree. Typically set to 2,
double Width
double Height
# The (x, y) coordinates of the tree
double Qtree_X
double Qtree_Y
# Use Link Expression output
bool Leo
# Threshold above which a connection is expressed
double LeoThreshold
# Use geometric seeding. Currently only along the X axis. 1
bool LeoSeed
bool GeometrySeed
"""
#############################################
NeuralNetwork class
#############################################
"""
cdef extern from "src/NeuralNetwork.h" namespace "NEAT":
cdef cppclass Connection:
unsigned short int m_source_neuron_idx
unsigned short int m_target_neuron_idx
double m_weight
bool m_recur_flag
cdef cppclass Neuron:
double m_activation
ActivationFunction m_activation_function_type
double m_a
double m_b
double m_timeconst
double m_bias
double m_x
double m_y
double m_z
double m_sx
double m_sy
double m_sz
vector[double] m_substrate_coords
double m_split_y
NeuronType m_type
cdef cppclass NeuralNetwork:
unsigned short m_num_inputs
unsigned short m_num_outputs
vector[Neuron] m_neurons
vector[Connection] m_connections
NeuralNetwork() except +
NeuralNetwork(bool x) except +
void InitRTRLMatrix()
void ActivateFast()
void Activate()
void ActivateUseInternalBias()
void ActivateLeaky(double step)
void RTRL_update_gradients()
void RTRL_update_error(double a_target)
void RTRL_update_weights()
void Adapt(Parameters& a_Parameters)
void Flush()
void FlushCube()
void Input(vector[double]& a_Inputs)
vector[double] Output()
void Clear()
# one-shot save/load
void Save(const char* a_filename)
bool Load(const char* a_filename)
# save/load from already opened files for reading/writing
void Save(FILE* a_file)
void AddNeuron(const Neuron& a_n)
void AddConnection(const Connection& a_c)
Connection GetConnectionByIndex(unsigned int a_idx) const
Neuron GetNeuronByIndex(unsigned int a_idx) const
void SetInputOutputDimentions(const unsigned short a_i, const unsigned short a_o)
unsigned int NumInputs() const
unsigned int NumOutputs() const
cdef extern from "src/Substrate.h" namespace "NEAT":
cdef cppclass Substrate:
vector[vector[double]] m_input_coords
vector[vector[double]] m_hidden_coords
vector[vector[double]] m_output_coords
bool m_leaky
bool m_with_distance
bool m_allow_input_hidden_links
bool m_allow_input_output_links
bool m_allow_hidden_hidden_links
bool m_allow_hidden_output_links
bool m_allow_output_hidden_links
bool m_allow_output_output_links
bool m_allow_looped_hidden_links
bool m_allow_looped_output_links
ActivationFunction m_hidden_nodes_activation
ActivationFunction m_output_nodes_activation
#double m_link_threshold
double m_max_weight_and_bias
double m_min_time_const
double m_max_time_const
Substrate()
Substrate(vector[vector[double]]& a_inputs,
vector[vector[double]]& a_hidden,
vector[vector[double]]& a_outputs)
int GetMinCPPNInputs()
int GetMinCPPNOutputs()
void PrintInfo()
"""
#############################################
Genome class
#############################################
"""
cdef extern from "src/Genome.h" namespace "NEAT":
cdef cppclass Genome:
Genome() except +
Genome(const Genome& a_g) except +
Genome(const char* a_filename)
Genome(unsigned int a_ID,
unsigned int a_NumInputs,
unsigned int a_NumHidden,
unsigned int a_NumOutputs,
bool a_FS_NEAT, ActivationFunction a_OutputActType,
ActivationFunction a_HiddenActType,
unsigned int a_SeedType,
const Parameters& a_Parameters)
unsigned int NumNeurons()
unsigned int NumLinks()
unsigned int NumInputs()
unsigned int NumOutputs()
double GetFitness()
void SetFitness(double a_f)
unsigned int GetID()
void SetID(int a_id)
void CalculateDepth()
unsigned int GetDepth()
void BuildPhenotype(NeuralNetwork& net)
void BuildHyperNEATPhenotype(NeuralNetwork& net, Substrate& subst)
void BuildESHyperNEATPhenotype(NeuralNetwork& a_net, Substrate& subst, Parameters& params)
void Save(const char* a_filename)
# Saves this genome to an already opened file for writing
void Save(FILE* a_fstream);
bool m_Evaluated
bool IsEvaluated()
void SetEvaluated()
void ResetEvaluated()
"""
#############################################
Species class
#############################################
"""
cdef extern from "src/Species.h" namespace "NEAT":
cdef cppclass Species:
Species(const Genome& a_Seed, int a_id) except +
Species& copy 'operator='(const Species& a_g)
double m_BestFitness
Genome m_BestGenome
unsigned int m_GensNoImprovement
int m_R, m_G, m_B
vector[Genome] m_Individuals
# Access
double GetBestFitness()
void SetBestSpecies(bool t)
void SetWorstSpecies(bool t)
void IncreaseAgeGens()
void ResetAgeGens()
void IncreaseGensNoImprovement()
void SetOffspringRqd(double a_ofs)
double GetOffspringRqd()
unsigned int NumIndividuals()
void ClearIndividuals()
int ID()
int GensNoImprovement()
int AgeGens()
Genome GetIndividualByIdx(int a_idx)
bool IsBestSpecies()
bool IsWorstSpecies()
void SetRepresentative(Genome& a_G)
Genome GetLeader()
"""
#############################################
Population class
#############################################
"""
cdef extern from "src/Population.h" namespace "NEAT":
cdef cppclass Population:
Population(const Genome& a_G, const Parameters& a_Parameters, bool a_RandomizeWeights, double a_RandomRange,
int a_RNG_seed)
Population(const char* a_FileName)
RNG m_RNG
Parameters m_Parameters
unsigned int m_Generation
unsigned int m_NumEvaluations
vector[Species] m_Species
SearchMode GetSearchMode()
double GetCurrentMPC()
double GetBaseMPC()
unsigned int NumGenomes()
unsigned int GetGeneration()
double GetBestFitnessEver()
Genome GetBestGenome()
unsigned int GetStagnation()
unsigned int GetMPCStagnation()
unsigned int GetNextGenomeID()
unsigned int GetNextSpeciesID()
void Epoch()
void Save(const char* a_FileName)
Genome* Tick(Genome& a_deleted_genome)