File size: 1,095 Bytes
6e5f7ce
a369299
 
6e5f7ce
 
 
 
 
a369299
6e5f7ce
a369299
 
6e5f7ce
 
a369299
 
 
 
 
 
 
6e5f7ce
a369299
 
 
 
 
 
 
 
 
6e5f7ce
a369299
6e5f7ce
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
using Distributed
const nthreads = 10
addprocs(nthreads)
@everywhere include("eureqa.jl")

println("Lets try to learn (x2^2 + cos(x3) + 5) using regularized evolution from scratch")
const npop = 100
const annealing = false
const niterations = 10
bestScore = Inf

# Generate random initial populations
allPops = [Population(npop, 3) for i=1:nthreads]

# Create a mapping for running the algorithm on all processes
@everywhere f = (pop,)->run(pop, 1000, annealing)

# Do niterations cycles
for i=1:niterations
    # Map it over our workers
    global allPops = deepcopy(pmap(f, allPops))

    # Get best 10 models for each processes
    bestPops = Population(vcat(map(((pop,)->bestSubPop(pop).members), allPops)...))
    for pop in bestPops
        bestCurScoreIdx = argmin([pop.members[member].score for member=1:pop.n])
        bestCurScore = pop.members[bestCurScoreIdx].score
        if bestCurScore < bestScore
            global bestScore = bestCurScore
            println(bestScore, " is the score for ", stringTree(pop.members[bestCurScoreIdx].tree))
        end
    end
    exit()
end