Spaces:
Sleeping
Sleeping
Commit
·
a369299
1
Parent(s):
b03c020
Attempting to merge populations
Browse files- README.md +5 -0
- eureqa.jl +6 -0
- paralleleureqa.jl +22 -10
README.md
CHANGED
|
@@ -20,3 +20,8 @@ const y = ((cx,)->cx^2).(X[:, 2]) + cos.(X[:, 3]) .+ 5.0;
|
|
| 20 |
|
| 21 |
The default number of processes is 10; this is set with
|
| 22 |
`addprocs(10)` in `paralleleureqa.jl`.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 20 |
|
| 21 |
The default number of processes is 10; this is set with
|
| 22 |
`addprocs(10)` in `paralleleureqa.jl`.
|
| 23 |
+
|
| 24 |
+
### Hyperparameters
|
| 25 |
+
|
| 26 |
+
Turn on annealing by setting the following in `paralleleureqa.jl`
|
| 27 |
+
`const annealing = true`
|
eureqa.jl
CHANGED
|
@@ -386,6 +386,12 @@ function bestOfSample(pop::Population)::PopMember
|
|
| 386 |
return sample.members[best_idx]
|
| 387 |
end
|
| 388 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 389 |
# Mutate the best sampled member of the population
|
| 390 |
function iterateSample(pop::Population, T::Float64)::PopMember
|
| 391 |
allstar = bestOfSample(pop)
|
|
|
|
| 386 |
return sample.members[best_idx]
|
| 387 |
end
|
| 388 |
|
| 389 |
+
# Return best 10 examples
|
| 390 |
+
function bestSubPop(pop::Population)::Population
|
| 391 |
+
best_idx = sortperm([pop.members[member].score for member=1:pop.n])
|
| 392 |
+
return Population(pop.members[best_idx[1:10]])
|
| 393 |
+
end
|
| 394 |
+
|
| 395 |
# Mutate the best sampled member of the population
|
| 396 |
function iterateSample(pop::Population, T::Float64)::PopMember
|
| 397 |
allstar = bestOfSample(pop)
|
paralleleureqa.jl
CHANGED
|
@@ -1,24 +1,36 @@
|
|
| 1 |
using Distributed
|
| 2 |
-
|
|
|
|
| 3 |
@everywhere include("eureqa.jl")
|
| 4 |
|
| 5 |
println("Lets try to learn (x2^2 + cos(x3) + 5) using regularized evolution from scratch")
|
| 6 |
const npop = 100
|
| 7 |
-
const nthreads = 10
|
| 8 |
const annealing = false
|
|
|
|
| 9 |
bestScore = Inf
|
|
|
|
|
|
|
| 10 |
allPops = [Population(npop, 3) for i=1:nthreads]
|
| 11 |
|
| 12 |
-
|
| 13 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 14 |
|
| 15 |
-
for
|
| 16 |
-
|
| 17 |
-
|
| 18 |
-
|
| 19 |
-
|
| 20 |
-
|
|
|
|
|
|
|
|
|
|
| 21 |
end
|
|
|
|
| 22 |
end
|
| 23 |
|
| 24 |
|
|
|
|
| 1 |
using Distributed
|
| 2 |
+
const nthreads = 10
|
| 3 |
+
addprocs(nthreads)
|
| 4 |
@everywhere include("eureqa.jl")
|
| 5 |
|
| 6 |
println("Lets try to learn (x2^2 + cos(x3) + 5) using regularized evolution from scratch")
|
| 7 |
const npop = 100
|
|
|
|
| 8 |
const annealing = false
|
| 9 |
+
const niterations = 10
|
| 10 |
bestScore = Inf
|
| 11 |
+
|
| 12 |
+
# Generate random initial populations
|
| 13 |
allPops = [Population(npop, 3) for i=1:nthreads]
|
| 14 |
|
| 15 |
+
# Create a mapping for running the algorithm on all processes
|
| 16 |
+
@everywhere f = (pop,)->run(pop, 1000, annealing)
|
| 17 |
+
|
| 18 |
+
# Do niterations cycles
|
| 19 |
+
for i=1:niterations
|
| 20 |
+
# Map it over our workers
|
| 21 |
+
global allPops = deepcopy(pmap(f, allPops))
|
| 22 |
|
| 23 |
+
# Get best 10 models for each processes
|
| 24 |
+
bestPops = Population(vcat(map(((pop,)->bestSubPop(pop).members), allPops)...))
|
| 25 |
+
for pop in bestPops
|
| 26 |
+
bestCurScoreIdx = argmin([pop.members[member].score for member=1:pop.n])
|
| 27 |
+
bestCurScore = pop.members[bestCurScoreIdx].score
|
| 28 |
+
if bestCurScore < bestScore
|
| 29 |
+
global bestScore = bestCurScore
|
| 30 |
+
println(bestScore, " is the score for ", stringTree(pop.members[bestCurScoreIdx].tree))
|
| 31 |
+
end
|
| 32 |
end
|
| 33 |
+
exit()
|
| 34 |
end
|
| 35 |
|
| 36 |
|