Skip to content

Commit 0dc93aa

Browse files
committed
Fixes
1 parent c2dafd2 commit 0dc93aa

2 files changed

Lines changed: 44 additions & 32 deletions

File tree

src/Genome.cpp

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2527,7 +2527,6 @@ namespace NEAT
25272527

25282528
//t_LinkGenesWeight = a_RNG.RandFloat();
25292529
//Scale(t_LinkGenesWeight, 0.0, 1.0, a_Parameters.MinWeight, a_Parameters.MaxWeight);
2530-
t_LinkGenesWeight = a_RNG.RandFloatSigned() * a_Parameters.WeightReplacementMaxPower;
25312530
}
25322531
else
25332532
{
@@ -2549,9 +2548,6 @@ namespace NEAT
25492548

25502549
did_mutate = true;
25512550
}
2552-
t_LinkGenesWeight = a_RNG.RandFloatSigned() * a_Parameters.WeightReplacementMaxPower;
2553-
2554-
did_mutate = true;
25552551
}
25562552
}
25572553

@@ -2683,7 +2679,7 @@ namespace NEAT
26832679

26842680
m_NeuronGenes[i].m_Bias += t_randnum;
26852681

2686-
Clamp(m_NeuronGenes[i].m_TimeConstant, a_Parameters.MinNeuronBias, a_Parameters.MaxNeuronBias);
2682+
Clamp(m_NeuronGenes[i].m_Bias, a_Parameters.MinNeuronBias, a_Parameters.MaxNeuronBias);
26872683
}
26882684
}
26892685

src/Genome.h

Lines changed: 43 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -86,11 +86,11 @@ namespace NEAT
8686
private:
8787

8888
// ID of genome
89-
unsigned int m_ID;
90-
89+
int m_ID;
90+
9191
// How many inputs/outputs
92-
unsigned int m_NumInputs;
93-
unsigned int m_NumOutputs;
92+
int m_NumInputs;
93+
int m_NumOutputs;
9494

9595
// The genome's fitness score
9696
double m_Fitness;
@@ -99,7 +99,7 @@ namespace NEAT
9999
double m_AdjustedFitness;
100100

101101
// The depth of the network
102-
unsigned int m_Depth;
102+
int m_Depth;
103103

104104
// how many individuals this genome should spawn
105105
double m_OffspringAmount;
@@ -186,19 +186,26 @@ namespace NEAT
186186
Genome(std::ifstream &a_DataFile);
187187

188188
// This creates a CTRNN fully-connected genome
189-
Genome(unsigned int a_ID, unsigned int a_NumInputs, unsigned int a_NumHidden, unsigned int a_NumOutputs,
190-
ActivationFunction a_OutputActType, ActivationFunction a_HiddenActType, const Parameters &a_Parameters);
189+
190+
//Genome(int a_ID, int a_NumInputs, int a_NumHidden, int a_NumOutputs,
191+
// ActivationFunction a_OutputActType, ActivationFunction a_HiddenActType, const Parameters &a_Parameters);
192+
193+
//Genome(unsigned int a_ID, unsigned int a_NumInputs, unsigned int a_NumHidden, unsigned int a_NumOutputs,
194+
// ActivationFunction a_OutputActType, ActivationFunction a_HiddenActType, const Parameters &a_Parameters);
195+
191196

192197
// This creates a standart minimal genome - perceptron-like structure
193-
Genome(unsigned int a_ID,
194-
unsigned int a_NumInputs,
195-
unsigned int a_NumHidden, // ignored for seed_type == 0, specifies number of hidden units if seed_type == 1
196-
unsigned int a_NumOutputs,
197-
bool a_FS_NEAT, ActivationFunction a_OutputActType,
198+
Genome(int a_ID,
199+
int a_NumInputs,
200+
int a_NumHidden, // ignored for seed_type == 0, specifies number of hidden units if seed_type == 1
201+
int a_NumOutputs,
202+
bool a_FS_NEAT,
203+
ActivationFunction a_OutputActType,
198204
ActivationFunction a_HiddenActType,
199-
unsigned int a_SeedType,
205+
int a_SeedType,
200206
const Parameters &a_Parameters,
201-
unsigned int a_NumLayers);
207+
int a_NumLayers,
208+
int a_FS_NEAT_links);
202209

203210
/////////////
204211
// Other possible constructors for different types of networks go here
@@ -256,9 +263,9 @@ namespace NEAT
256263

257264
void SetAdjFitness(double a_af);
258265

259-
unsigned int GetID() const;
260-
261-
void SetID(unsigned int a_id);
266+
int GetID() const;
267+
268+
void SetID(int a_id);
262269

263270
unsigned int GetDepth() const;
264271

@@ -279,6 +286,7 @@ namespace NEAT
279286
return true; // no reason to continue
280287
}
281288

289+
282290
if ((HasLoops() && (a_Parameters.AllowLoops == false)))
283291
{
284292
return true;
@@ -381,7 +389,6 @@ namespace NEAT
381389

382390
return traits;
383391
}
384-
<<<<<<< HEAD
385392

386393
std::map< std::string, Trait> Dict2TraitMap(py::dict d)
387394
{
@@ -402,11 +409,7 @@ namespace NEAT
402409
return ts;
403410
};
404411

405-
406-
407-
=======
408412

409-
>>>>>>> origin/master
410413
py::object GetNeuronTraits()
411414
{
412415
py::list neurons;
@@ -441,7 +444,7 @@ namespace NEAT
441444
return neurons;
442445
}
443446

444-
py::object GetLinkTraits()
447+
py::object GetLinkTraits(bool with_weights=false)
445448
{
446449
py::list links;
447450
for(auto it=m_LinkGenes.begin(); it != m_LinkGenes.end(); it++)
@@ -452,6 +455,10 @@ namespace NEAT
452455
little.append( (*it).FromNeuronID() );
453456
little.append( (*it).ToNeuronID() );
454457
little.append( traits );
458+
if (with_weights)
459+
{
460+
little.append( (*it).m_Weight );
461+
}
455462
links.append( little );
456463
}
457464

@@ -523,13 +530,13 @@ namespace NEAT
523530

524531
// Removes a hidden neuron having only one input and only one output with
525532
// a direct link between them.
526-
bool Mutate_RemoveSimpleNeuron(InnovationDatabase &a_Innovs, RNG &a_RNG);
533+
bool Mutate_RemoveSimpleNeuron(InnovationDatabase &a_Innovs, const Parameters &a_Parameters, RNG &a_RNG);
527534

528535
// Perturbs the weights
529536
bool Mutate_LinkWeights(const Parameters &a_Parameters, RNG &a_RNG);
530537

531538
// Set all link weights to random values between [-R .. R]
532-
void Randomize_LinkWeights(double a_Range, RNG &a_RNG);
539+
void Randomize_LinkWeights(const Parameters &a_Parameters, RNG &a_RNG);
533540

534541
// Set all traits to random values
535542
void Randomize_Traits(const Parameters& a_Parameters, RNG &a_RNG);
@@ -587,11 +594,13 @@ namespace NEAT
587594

588595
void ResetEvaluated();
589596

597+
#if 0 // disabling because of errors I can't fix right now
590598

591599
/////////////////////////////////////////////
592600
// Evolvable Substrate HyperNEAT
593601
////////////////////////////////////////////
594602

603+
595604
// A connection between two points. Stores weight and the coordinates of the points
596605
struct TempConnection
597606
{
@@ -716,7 +725,9 @@ namespace NEAT
716725
coord = coord_in;
717726
};
718727

719-
public void set_children()
728+
public:
729+
730+
void set_children()
720731
{
721732
for(unsigned int ix = 0; ix < 2**coord.size(); ix++){
722733
std::string sum_permute = toBinary(ix, coord.size());
@@ -786,6 +797,7 @@ namespace NEAT
786797

787798
void Clean_Net(std::vector<Connection> &connections, unsigned int input_count,
788799
unsigned int output_count, unsigned int hidden_count);
800+
#endif
789801

790802
#ifdef USE_BOOST_PYTHON
791803

@@ -797,18 +809,22 @@ namespace NEAT
797809
ar & m_ID;
798810
ar & m_NeuronGenes;
799811
ar & m_LinkGenes;
812+
//ar & m_GenomeGene;
800813
ar & m_NumInputs;
801814
ar & m_NumOutputs;
802815
ar & m_Fitness;
803816
ar & m_AdjustedFitness;
804817
ar & m_Depth;
805818
ar & m_OffspringAmount;
806819
ar & m_Evaluated;
820+
821+
ar & m_initial_num_neurons;
822+
ar & m_initial_num_links;
823+
807824
//ar & m_PhenotypeBehavior; // todo: think about how we will handle the behaviors with pickle
808825
}
809826

810827
#endif
811-
812828
};
813829

814830

0 commit comments

Comments
 (0)