Spaces:
Running
Running
Commit
·
6e5f7ce
1
Parent(s):
688106d
Working parallelized version
Browse files- eureqa.jl +8 -21
- paralleleureqa.jl +24 -0
eureqa.jl
CHANGED
|
@@ -1,15 +1,13 @@
|
|
| 1 |
-
using ProgressBars
|
| 2 |
-
|
| 3 |
# Define allowed operators
|
| 4 |
plus(x::Float64, y::Float64) = x+y
|
| 5 |
mult(x::Float64, y::Float64) = x*y;
|
| 6 |
|
| 7 |
# (Apparently using const for globals helps speed)
|
| 8 |
const binops = [plus, mult]
|
| 9 |
-
const unaops = [sin, cos, exp]
|
| 10 |
|
| 11 |
const nvar = 5;
|
| 12 |
-
const X = rand(100, nvar)
|
| 13 |
|
| 14 |
# Here is the function we want to learn (x2^2 + cos(x3) + 5)
|
| 15 |
const y = ((cx,)->cx^2).(X[:, 2]) + cos.(X[:, 3]) .+ 5.0;
|
|
@@ -411,30 +409,19 @@ end
|
|
| 411 |
|
| 412 |
# Cycle through regularized evolution many times,
|
| 413 |
# printing the fittest equation every 10% through
|
| 414 |
-
function run(
|
| 415 |
-
|
| 416 |
-
|
|
|
|
|
|
|
| 417 |
|
| 418 |
allT = LinRange(1.0, 0.0, ncycles)
|
| 419 |
-
|
| 420 |
-
bestScore = Inf
|
| 421 |
-
for iT in tqdm(1:size(allT)[1])
|
| 422 |
if annealing
|
| 423 |
pop = regEvolCycle(pop, allT[iT])
|
| 424 |
else
|
| 425 |
pop = regEvolCycle(pop, 0.0)
|
| 426 |
end
|
| 427 |
-
bestCurScoreIdx = argmin([pop.members[member].score for member=1:pop.n])
|
| 428 |
-
bestCurScore = pop.members[bestCurScoreIdx].score
|
| 429 |
-
if bestCurScore < bestScore
|
| 430 |
-
bestScore = bestCurScore
|
| 431 |
-
println(bestScore, " is the score for ", stringTree(pop.members[bestCurScoreIdx].tree))
|
| 432 |
-
end
|
| 433 |
end
|
| 434 |
return pop
|
| 435 |
end
|
| 436 |
-
|
| 437 |
-
println("Lets try to learn (x2^2 + cos(x3) + 5) using regularized evolution from scratch")
|
| 438 |
-
pop = run(10000, 1000, false);
|
| 439 |
-
|
| 440 |
-
|
|
|
|
|
|
|
|
|
|
| 1 |
# Define allowed operators
|
| 2 |
plus(x::Float64, y::Float64) = x+y
|
| 3 |
mult(x::Float64, y::Float64) = x*y;
|
| 4 |
|
| 5 |
# (Apparently using const for globals helps speed)
|
| 6 |
const binops = [plus, mult]
|
| 7 |
+
const unaops = [sin, cos, exp]
|
| 8 |
|
| 9 |
const nvar = 5;
|
| 10 |
+
const X = rand(100, nvar)
|
| 11 |
|
| 12 |
# Here is the function we want to learn (x2^2 + cos(x3) + 5)
|
| 13 |
const y = ((cx,)->cx^2).(X[:, 2]) + cos.(X[:, 3]) .+ 5.0;
|
|
|
|
| 409 |
|
| 410 |
# Cycle through regularized evolution many times,
|
| 411 |
# printing the fittest equation every 10% through
|
| 412 |
+
function run(
|
| 413 |
+
pop::Population,
|
| 414 |
+
ncycles::Int,
|
| 415 |
+
annealing::Bool=false,
|
| 416 |
+
)::Population
|
| 417 |
|
| 418 |
allT = LinRange(1.0, 0.0, ncycles)
|
| 419 |
+
for iT in 1:size(allT)[1]
|
|
|
|
|
|
|
| 420 |
if annealing
|
| 421 |
pop = regEvolCycle(pop, allT[iT])
|
| 422 |
else
|
| 423 |
pop = regEvolCycle(pop, 0.0)
|
| 424 |
end
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 425 |
end
|
| 426 |
return pop
|
| 427 |
end
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
paralleleureqa.jl
ADDED
|
@@ -0,0 +1,24 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
using Distributed
|
| 2 |
+
addprocs(10)
|
| 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 |
+
@everywhere f = (pop,)->run(pop, 10000, annealing)
|
| 13 |
+
allPops = pmap(f, allPops)
|
| 14 |
+
|
| 15 |
+
for pop in allPops
|
| 16 |
+
bestCurScoreIdx = argmin([pop.members[member].score for member=1:pop.n])
|
| 17 |
+
bestCurScore = pop.members[bestCurScoreIdx].score
|
| 18 |
+
if bestCurScore < bestScore
|
| 19 |
+
bestScore = bestCurScore
|
| 20 |
+
println(bestScore, " is the score for ", stringTree(pop.members[bestCurScoreIdx].tree))
|
| 21 |
+
end
|
| 22 |
+
end
|
| 23 |
+
|
| 24 |
+
|