MilesCranmer commited on
Commit
5dffe92
1 Parent(s): 2a2a517

Remove extra code

Browse files
Files changed (2) hide show
  1. eureqa.jl +0 -2
  2. paralleleureqa.jl +3 -117
eureqa.jl CHANGED
@@ -16,12 +16,10 @@ const y = ((cx,)->cx^2).(X[:, 2]) + cos.(X[:, 3]) .+ 5.0;
16
  const parsimony = 0.01
17
  # How much to scale temperature by (T between 0 and 1)
18
  const alpha = 10.0
19
-
20
  const maxsize = 20
21
 
22
 
23
 
24
-
25
  id = (x,) -> x
26
  const nuna = size(unaops)[1]
27
  const nbin = size(binops)[1]
 
16
  const parsimony = 0.01
17
  # How much to scale temperature by (T between 0 and 1)
18
  const alpha = 10.0
 
19
  const maxsize = 20
20
 
21
 
22
 
 
23
  id = (x,) -> x
24
  const nuna = size(unaops)[1]
25
  const nbin = size(binops)[1]
paralleleureqa.jl CHANGED
@@ -13,15 +13,14 @@ allPops = [Population(npop, 3) for j=1:nthreads]
13
  bestScore = Inf
14
  # Repeat this many evolutions; we collect and migrate the best
15
  # each time.
16
- for k=1:4
17
- # Spawn independent evolutions
18
 
19
- # Gather them
20
  @inbounds Threads.@threads for i=1:nthreads
21
  allPops[i] = run(allPops[i], ncyclesperiteration, annealing)
22
  end
23
 
24
- # Get best 10 models for each processes. Copy because we re-assign later.
25
  bestPops = deepcopy(Population([member for pop in allPops for member in bestSubPop(pop).members]))
26
  bestCurScoreIdx = argmin([bestPops.members[member].score for member=1:bestPops.n])
27
  bestCurScore = bestPops.members[bestCurScoreIdx].score
@@ -36,116 +35,3 @@ for k=1:4
36
  end
37
  end
38
 
39
- ## Possibly calls once for every thread? But works.
40
-
41
- # using Distributed
42
- # addprocs(8)
43
- # @everywhere const nthreads = 8
44
-
45
- # @everywhere include("eureqa.jl")
46
-
47
- # println("Lets try to learn (x2^2 + cos(x3) + 5) using regularized evolution from scratch")
48
- # @everywhere const npop = 100
49
- # @everywhere const annealing = false
50
- # @everywhere const niterations = 30
51
- # @everywhere const ncyclesperiteration = 10000
52
-
53
- # # Generate random initial populations
54
-
55
- # # Create a mapping for running the algorithm on all processes
56
- # @everywhere f = (pop,)->run(pop, ncyclesperiteration, annealing)
57
-
58
-
59
- # @everywhere allPops = [Population(npop, 3) for j=1:nthreads]
60
- # @everywhere bestScore = Inf
61
- # # Repeat this many evolutions; we collect and migrate the best
62
- # # each time.
63
- # for k=1:4
64
- # # Spawn independent evolutions
65
- # @everywhere futures = [@spawnat :any f(allPops[i]) for i=1:nthreads]
66
-
67
- # # Gather them
68
- # for i=1:nthreads
69
- # @everywhere allPops[i] = fetch(futures[i])
70
- # end
71
- # # Get best 10 models for each processes. Copy because we re-assign later.
72
- # @everywhere bestPops = deepcopy(Population([member for pop in allPops for member in bestSubPop(pop).members]))
73
- # @everywhere bestCurScoreIdx = argmin([bestPops.members[member].score for member=1:bestPops.n])
74
- # @everywhere bestCurScore = bestPops.members[bestCurScoreIdx].score
75
- # println(bestCurScore, " is the score for ", stringTree(bestPops.members[bestCurScoreIdx].tree))
76
-
77
- # # Migration
78
- # for j=1:nthreads
79
- # for k in rand(1:npop, 50)
80
- # # Copy in case one gets copied twice
81
- # @everywhere allPops[j].members[k] = deepcopy(bestPops.members[rand(1:size(bestPops.members)[1])])
82
- # end
83
- # end
84
- # end
85
-
86
-
87
-
88
-
89
-
90
- # julia> @everywhere include_string(Main, $(read("count_heads.jl", String)), "count_heads.jl")
91
-
92
- # julia> a = @spawnat :any count_heads(100000000)
93
- # Future(2, 1, 6, nothing)
94
-
95
- # julia> b = @spawnat :any count_heads(100000000)
96
- # Future(3, 1, 7, nothing)
97
-
98
- # julia> fetch(a)+fetch(b)
99
- # 100001564
100
-
101
- # allPops = [Population(npop, 3) for j=1:nthreads]
102
- # bestScore = Inf
103
- # for i=1:10
104
- # tmpPops = fetch(pmap(f, allPops))
105
- # allPops[1:nthreads] = tmpPops[1:nthreads]
106
- # # Get best 11 models for each processes
107
- # bestPops = Population([member for pop in allPops for member in bestSubPop(pop).members])
108
- # bestCurScoreIdx = argmin([bestPops.members[member].score for member=1:bestPops.n])
109
- # bestCurScore = bestPops.members[bestCurScoreIdx].score
110
- # println(bestCurScore, " is the score for ", stringTree(bestPops.members[bestCurScoreIdx].tree))
111
- # end
112
-
113
-
114
- # function update(allPops::Array{Population, 1}, bestScore::Float64)
115
- # # Map it over our workers
116
- # #global allPops = deepcopy(pmap(f, deepcopy(allPops)))
117
- # #curAllPops = deepcopy(pmap(f, allPops))
118
- # curAllPops = pmap(f, allPops)
119
- # for j=1:nthreads
120
- # allPops[j] = curAllPops[j]
121
- # end
122
-
123
- # # Get best 10 models for each processes
124
- # bestPops = Population([member for pop in allPops for member in bestSubPop(pop).members])
125
- # bestCurScoreIdx = argmin([bestPops.members[member].score for member=1:bestPops.n])
126
- # bestCurScore = bestPops.members[bestCurScoreIdx].score
127
- # if bestCurScore < bestScore
128
- # bestScore = bestCurScore
129
- # println(bestScore, " is the score for ", stringTree(bestPops.members[bestCurScoreIdx].tree))
130
- # end
131
-
132
- # # Migration
133
- # for j=1:nthreads
134
- # allPops[j].members[1:50] = deepcopy(bestPops.members[rand(1:bestPops.n, 50)])
135
- # end
136
- # return allPops, bestScore
137
- # end
138
-
139
-
140
- # function runExperiment()
141
- # # Do niterations cycles
142
- # allPops = [Population(npop, 3) for j=1:nthreads]
143
- # bestScore = Inf
144
- # for i=1:niterations
145
- # allPops, bestScore = update(allPops, bestScore)
146
- # end
147
-
148
- # return bestScore
149
- # end
150
-
151
- # runExperiment()
 
13
  bestScore = Inf
14
  # Repeat this many evolutions; we collect and migrate the best
15
  # each time.
16
+ for k=1:niterations
 
17
 
18
+ # Spawn threads to run indepdent evolutions, then gather them
19
  @inbounds Threads.@threads for i=1:nthreads
20
  allPops[i] = run(allPops[i], ncyclesperiteration, annealing)
21
  end
22
 
23
+ # Get best 10 models from each evolution. Copy because we re-assign later.
24
  bestPops = deepcopy(Population([member for pop in allPops for member in bestSubPop(pop).members]))
25
  bestCurScoreIdx = argmin([bestPops.members[member].score for member=1:bestPops.n])
26
  bestCurScore = bestPops.members[bestCurScoreIdx].score
 
35
  end
36
  end
37