Spaces:
Running
Running
MilesCranmer
commited on
Commit
•
382662a
1
Parent(s):
6f3a331
Better defaults
Browse files- README.md +5 -0
- eureqa.jl +2 -1
- paralleleureqa.jl +24 -23
README.md
CHANGED
@@ -54,3 +54,8 @@ weights = [8, 1, 1, 1]
|
|
54 |
(for: 1. perturb constant, 2. mutate operator,
|
55 |
3. append a node, 4. delete a subtree).
|
56 |
|
|
|
|
|
|
|
|
|
|
|
|
54 |
(for: 1. perturb constant, 2. mutate operator,
|
55 |
3. append a node, 4. delete a subtree).
|
56 |
|
57 |
+
|
58 |
+
# TODO
|
59 |
+
|
60 |
+
- Record hall of fame
|
61 |
+
- Optionally migrate the hall of fame, rather than current bests
|
eureqa.jl
CHANGED
@@ -322,7 +322,8 @@ function iterate(
|
|
322 |
prev = deepcopy(tree)
|
323 |
|
324 |
mutationChoice = rand()
|
325 |
-
|
|
|
326 |
weights /= sum(weights)
|
327 |
cweights = cumsum(weights)
|
328 |
n = countNodes(tree)
|
|
|
322 |
prev = deepcopy(tree)
|
323 |
|
324 |
mutationChoice = rand()
|
325 |
+
weight_for_constant = min(8, countConstants(tree))
|
326 |
+
weights = [weight_for_constant, 1, 1, 1, 2]
|
327 |
weights /= sum(weights)
|
328 |
cweights = cumsum(weights)
|
329 |
n = countNodes(tree)
|
paralleleureqa.jl
CHANGED
@@ -3,35 +3,36 @@ include("eureqa.jl")
|
|
3 |
println("Lets try to learn (x2^2 + cos(x3)) using regularized evolution from scratch")
|
4 |
const nthreads = Threads.nthreads()
|
5 |
println("Running with $nthreads threads")
|
6 |
-
const npop =
|
7 |
const annealing = true
|
8 |
-
const
|
9 |
-
const ncyclesperiteration = 30000
|
10 |
|
11 |
-
|
12 |
-
|
13 |
-
|
14 |
-
# Repeat this many evolutions; we collect and migrate the best
|
15 |
-
# each time.
|
16 |
-
for k=1:niterations
|
17 |
|
18 |
-
|
19 |
-
|
20 |
-
|
21 |
-
|
22 |
|
23 |
-
|
24 |
-
|
25 |
-
|
26 |
-
|
27 |
-
|
28 |
|
29 |
-
|
30 |
-
|
31 |
-
|
32 |
-
|
33 |
-
|
|
|
34 |
end
|
35 |
end
|
36 |
end
|
37 |
|
|
|
|
3 |
println("Lets try to learn (x2^2 + cos(x3)) using regularized evolution from scratch")
|
4 |
const nthreads = Threads.nthreads()
|
5 |
println("Running with $nthreads threads")
|
6 |
+
const npop = 300
|
7 |
const annealing = true
|
8 |
+
const ncyclesperiteration = 3000
|
|
|
9 |
|
10 |
+
function fullRun(niterations::Integer)
|
11 |
+
# Generate random initial populations
|
12 |
+
allPops = [Population(npop, 3) for j=1:nthreads]
|
13 |
+
# Repeat this many evolutions; we collect and migrate the best
|
14 |
+
# each time.
|
15 |
+
for k=1:niterations
|
16 |
|
17 |
+
# Spawn threads to run indepdent evolutions, then gather them
|
18 |
+
@inbounds Threads.@threads for i=1:nthreads
|
19 |
+
allPops[i] = run(allPops[i], ncyclesperiteration, annealing, verbose=500)
|
20 |
+
end
|
21 |
|
22 |
+
# Get best 10 models from each evolution. Copy because we re-assign later.
|
23 |
+
bestPops = deepcopy(Population([member for pop in allPops for member in bestSubPop(pop).members]))
|
24 |
+
bestCurScoreIdx = argmin([bestPops.members[member].score for member=1:bestPops.n])
|
25 |
+
bestCurScore = bestPops.members[bestCurScoreIdx].score
|
26 |
+
println(bestCurScore, " is the score for ", stringTree(bestPops.members[bestCurScoreIdx].tree))
|
27 |
|
28 |
+
# Migration
|
29 |
+
for j=1:nthreads
|
30 |
+
for k in rand(1:npop, Integer(npop/2))
|
31 |
+
# Copy in case one gets used twice
|
32 |
+
allPops[j].members[k] = deepcopy(bestPops.members[rand(1:size(bestPops.members)[1])])
|
33 |
+
end
|
34 |
end
|
35 |
end
|
36 |
end
|
37 |
|
38 |
+
fullRun(10)
|