Spaces:
Running
Running
Commit
·
c9adc43
1
Parent(s):
c88d0b9
Fix #10 issue with hall of fame not saving
Browse files- julia/sr.jl +10 -41
julia/sr.jl
CHANGED
|
@@ -1,6 +1,5 @@
|
|
| 1 |
import Optim
|
| 2 |
import Printf: @printf
|
| 3 |
-
import Random: shuffle!
|
| 4 |
|
| 5 |
const maxdegree = 2
|
| 6 |
const actualMaxsize = maxsize + maxdegree
|
|
@@ -626,49 +625,19 @@ end
|
|
| 626 |
|
| 627 |
# Mutate the best sampled member of the population
|
| 628 |
function iterateSample(pop::Population, T::Float32)::PopMember
|
|
|
|
|
|
|
| 629 |
end
|
| 630 |
|
| 631 |
# Pass through the population several times, replacing the oldest
|
| 632 |
# with the fittest of a small subsample
|
| 633 |
function regEvolCycle(pop::Population, T::Float32)::Population
|
| 634 |
-
|
| 635 |
-
|
| 636 |
-
|
| 637 |
-
|
| 638 |
-
|
| 639 |
-
n_evol_cycles = round(Integer, pop.n/ns)
|
| 640 |
-
babies = Array{PopMember}(undef, n_evol_cycles)
|
| 641 |
-
|
| 642 |
-
# Iterate each ns-member sub-sample
|
| 643 |
-
@inbounds Threads.@threads for i=1:n_evol_cycles
|
| 644 |
-
best_score = Inf32
|
| 645 |
-
best_idx = 1+(i-1)*ns
|
| 646 |
-
# Calculate best member of the subsample:
|
| 647 |
-
for sub_i=1+(i-1)*ns:i*ns
|
| 648 |
-
if pop.members[sub_i].score < best_score
|
| 649 |
-
best_score = pop.members[sub_i].score
|
| 650 |
-
best_idx = sub_i
|
| 651 |
-
end
|
| 652 |
-
end
|
| 653 |
-
allstar = pop.members[best_idx]
|
| 654 |
-
babies[i] = iterate(allstar, T)
|
| 655 |
-
end
|
| 656 |
-
|
| 657 |
-
# Replace the n_evol_cycles-oldest members of each population
|
| 658 |
-
@inbounds for i=1:n_evol_cycles
|
| 659 |
-
oldest = argmin([pop.members[member].birth for member=1:pop.n])
|
| 660 |
-
pop.members[oldest] = babies[i]
|
| 661 |
-
end
|
| 662 |
-
else
|
| 663 |
-
for i=1:round(Integer, pop.n/ns)
|
| 664 |
-
allstar = bestOfSample(pop)
|
| 665 |
-
baby = iterate(allstar, T)
|
| 666 |
-
#printTree(baby.tree)
|
| 667 |
-
oldest = argmin([pop.members[member].birth for member=1:pop.n])
|
| 668 |
-
pop.members[oldest] = baby
|
| 669 |
-
end
|
| 670 |
end
|
| 671 |
-
|
| 672 |
return pop
|
| 673 |
end
|
| 674 |
|
|
@@ -830,13 +799,13 @@ function fullRun(niterations::Integer;
|
|
| 830 |
hallOfFame = HallOfFame()
|
| 831 |
|
| 832 |
for i=1:npopulations
|
| 833 |
-
future = @
|
| 834 |
push!(allPops, future)
|
| 835 |
end
|
| 836 |
|
| 837 |
# # 2. Start the cycle on every process:
|
| 838 |
@sync for i=1:npopulations
|
| 839 |
-
@async allPops[i] = @
|
| 840 |
end
|
| 841 |
println("Started!")
|
| 842 |
cycles_complete = npopulations * niterations
|
|
@@ -914,7 +883,7 @@ function fullRun(niterations::Integer;
|
|
| 914 |
end
|
| 915 |
|
| 916 |
@async begin
|
| 917 |
-
allPops[i] = @
|
| 918 |
tmp_pop = run(cur_pop, ncyclesperiteration, verbosity=verbosity)
|
| 919 |
for j=1:tmp_pop.n
|
| 920 |
if rand() < 0.1
|
|
|
|
| 1 |
import Optim
|
| 2 |
import Printf: @printf
|
|
|
|
| 3 |
|
| 4 |
const maxdegree = 2
|
| 5 |
const actualMaxsize = maxsize + maxdegree
|
|
|
|
| 625 |
|
| 626 |
# Mutate the best sampled member of the population
|
| 627 |
function iterateSample(pop::Population, T::Float32)::PopMember
|
| 628 |
+
allstar = bestOfSample(pop)
|
| 629 |
+
return iterate(allstar, T)
|
| 630 |
end
|
| 631 |
|
| 632 |
# Pass through the population several times, replacing the oldest
|
| 633 |
# with the fittest of a small subsample
|
| 634 |
function regEvolCycle(pop::Population, T::Float32)::Population
|
| 635 |
+
for i=1:round(Integer, pop.n/ns)
|
| 636 |
+
baby = iterateSample(pop, T)
|
| 637 |
+
#printTree(baby.tree)
|
| 638 |
+
oldest = argmin([pop.members[member].birth for member=1:pop.n])
|
| 639 |
+
pop.members[oldest] = baby
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 640 |
end
|
|
|
|
| 641 |
return pop
|
| 642 |
end
|
| 643 |
|
|
|
|
| 799 |
hallOfFame = HallOfFame()
|
| 800 |
|
| 801 |
for i=1:npopulations
|
| 802 |
+
future = @spawn Population(npop, 3)
|
| 803 |
push!(allPops, future)
|
| 804 |
end
|
| 805 |
|
| 806 |
# # 2. Start the cycle on every process:
|
| 807 |
@sync for i=1:npopulations
|
| 808 |
+
@async allPops[i] = @spawn run(fetch(allPops[i]), ncyclesperiteration, verbosity=verbosity)
|
| 809 |
end
|
| 810 |
println("Started!")
|
| 811 |
cycles_complete = npopulations * niterations
|
|
|
|
| 883 |
end
|
| 884 |
|
| 885 |
@async begin
|
| 886 |
+
allPops[i] = @spawn let
|
| 887 |
tmp_pop = run(cur_pop, ncyclesperiteration, verbosity=verbosity)
|
| 888 |
for j=1:tmp_pop.n
|
| 889 |
if rand() < 0.1
|