Skip to content
This repository was archived by the owner on Dec 11, 2018. It is now read-only.

Commit 8054a08

Browse files
committed
no more parallel
1 parent 87edb34 commit 8054a08

6 files changed

+7
-32
lines changed

config.go

+2-4
Original file line numberDiff line numberDiff line change
@@ -55,8 +55,7 @@ type Config struct {
5555
CoeffUnmatching float64 `json:"coeffUnmatching"` // unmatching genes
5656
CoeffMatching float64 `json:"coeffMatching"` // matching genes
5757

58-
// Miscellaneous settings
59-
Lamarckian bool `json:"lamarckian"` // Lamarckian evolution
58+
// CPPN settings
6059
CPPNActivations []string `json:"cppnActivations"` // additional activations
6160
}
6261

@@ -112,8 +111,7 @@ func (c *Config) Summarize() {
112111
fmt.Fprintf(w, "+ Unmatching connection genes\t%.3f\t\n", c.CoeffUnmatching)
113112
fmt.Fprintf(w, "+ Matching connection genes\t%.3f\t\n\n", c.CoeffMatching)
114113

115-
fmt.Fprintf(w, "Miscellaneous settings\t\n")
116-
fmt.Fprintf(w, "+ Lamarckian evolution\t%t\t\n", c.Lamarckian)
114+
fmt.Fprintf(w, "CPPN settings\t\n")
117115
fmt.Fprintf(w, "+ CPPN Activation functions\t%s\t\n", c.CPPNActivations)
118116

119117
w.Flush()

config_pole_balancing.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
"numInputs": 4,
55
"numOutputs": 2,
66
"fullyConnected": false,
7-
"numGenerations": 50,
7+
"numGenerations": 30,
88
"populationSize": 100,
99
"initFitness": 0.0,
1010
"minimizeFitness": false,

config_template.json

-1
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@
99
"minimizeFitness": false,
1010
"survivalRate": 0.0,
1111
"stagnationLimit": 0,
12-
"hallOfFameSize": 0,
1312
"ratePerturb": 0.0,
1413
"rateAddNode": 0.0,
1514
"rateAddConn": 0.0,

config_xor.json

+1
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
"verbose": true,
44
"numInputs": 3,
55
"numOutputs": 1,
6+
"fullyConnected": true,
67
"numGenerations": 50,
78
"populationSize": 50,
89
"initFitness": 9999.0,

genome.go

+1-15
Original file line numberDiff line numberDiff line change
@@ -193,27 +193,13 @@ func (g *Genome) String() string {
193193
// Evaluate takes an evaluation function and evaluates its fitness. Only perform
194194
// the evaluation if it hasn't yet. If the lamarckian indicator is true, encode
195195
// the phenotype neural network back into the genome.
196-
func (g *Genome) Evaluate(evaluate EvaluationFunc, lamarckian bool) {
196+
func (g *Genome) Evaluate(evaluate EvaluationFunc) {
197197
if g.evaluated {
198198
return
199199
}
200200
nn := NewNeuralNetwork(g)
201201
g.Fitness = evaluate(nn)
202202
g.evaluated = true
203-
204-
// for Lamarckian evolution, any changes to the neural network's weights are
205-
// encoded back to the genome's connection genes.
206-
if lamarckian {
207-
for _, to := range nn.Neurons {
208-
for from, weight := range to.Synapses {
209-
for _, conn := range g.ConnGenes {
210-
if from.ID == conn.From && to.ID == conn.To {
211-
conn.Weight = weight
212-
}
213-
}
214-
}
215-
}
216-
}
217203
}
218204

219205
// ExportJSON exports a JSON file that contains this genome's information. If

neat.go

+2-11
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,6 @@ import (
2222
"math"
2323
"math/rand"
2424
"sort"
25-
"sync"
2625
)
2726

2827
// NEAT is the implementation of NeuroEvolution of Augmenting Topology (NEAT).
@@ -122,17 +121,9 @@ func (n *NEAT) Summarize(gen int) {
122121
// Evaluate evaluates fitness of every genome in the population. After the
123122
// evaluation, their fitness scores are recored in each genome.
124123
func (n *NEAT) Evaluate() {
125-
var wg sync.WaitGroup
126-
127-
for i := range n.Population {
128-
wg.Add(1)
129-
go func(j int) {
130-
defer wg.Done()
131-
n.Population[j].Evaluate(n.Evaluation, n.Config.Lamarckian)
132-
}(i)
124+
for _, genome := range n.Population {
125+
genome.Evaluate(n.Evaluation)
133126
}
134-
135-
wg.Wait()
136127
}
137128

138129
// Speciate performs speciation of each genome. The speciation mechanism is as

0 commit comments

Comments
 (0)