Spaces:
Running
Running
AutonLabTruth
commited on
Commit
•
65bc891
1
Parent(s):
4fca5d2
Refactored regEvolCycle, performance still normal
Browse files- julia/regEvolCycle.jl +44 -0
- julia/sr.jl +1 -45
julia/regEvolCycle.jl
ADDED
@@ -0,0 +1,44 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
# Pass through the population several times, replacing the oldest
|
2 |
+
# with the fittest of a small subsample
|
3 |
+
function regEvolCycle(pop::Population, T::Float32, curmaxsize::Integer,
|
4 |
+
frequencyComplexity::Array{Float32, 1})::Population
|
5 |
+
# Batch over each subsample. Can give 15% improvement in speed; probably moreso for large pops.
|
6 |
+
# but is ultimately a different algorithm than regularized evolution, and might not be
|
7 |
+
# as good.
|
8 |
+
if fast_cycle
|
9 |
+
shuffle!(pop.members)
|
10 |
+
n_evol_cycles = round(Integer, pop.n/ns)
|
11 |
+
babies = Array{PopMember}(undef, n_evol_cycles)
|
12 |
+
|
13 |
+
# Iterate each ns-member sub-sample
|
14 |
+
@inbounds Threads.@threads for i=1:n_evol_cycles
|
15 |
+
best_score = Inf32
|
16 |
+
best_idx = 1+(i-1)*ns
|
17 |
+
# Calculate best member of the subsample:
|
18 |
+
for sub_i=1+(i-1)*ns:i*ns
|
19 |
+
if pop.members[sub_i].score < best_score
|
20 |
+
best_score = pop.members[sub_i].score
|
21 |
+
best_idx = sub_i
|
22 |
+
end
|
23 |
+
end
|
24 |
+
allstar = pop.members[best_idx]
|
25 |
+
babies[i] = iterate(allstar, T, curmaxsize, frequencyComplexity)
|
26 |
+
end
|
27 |
+
|
28 |
+
# Replace the n_evol_cycles-oldest members of each population
|
29 |
+
@inbounds for i=1:n_evol_cycles
|
30 |
+
oldest = argmin([pop.members[member].birth for member=1:pop.n])
|
31 |
+
pop.members[oldest] = babies[i]
|
32 |
+
end
|
33 |
+
else
|
34 |
+
for i=1:round(Integer, pop.n/ns)
|
35 |
+
allstar = bestOfSample(pop)
|
36 |
+
baby = iterate(allstar, T, curmaxsize, frequencyComplexity)
|
37 |
+
#printTree(baby.tree)
|
38 |
+
oldest = argmin([pop.members[member].birth for member=1:pop.n])
|
39 |
+
pop.members[oldest] = baby
|
40 |
+
end
|
41 |
+
end
|
42 |
+
|
43 |
+
return pop
|
44 |
+
end
|
julia/sr.jl
CHANGED
@@ -37,51 +37,7 @@ include("simulatedAnnealing.jl")
|
|
37 |
|
38 |
include("Population.jl")
|
39 |
|
40 |
-
|
41 |
-
# Pass through the population several times, replacing the oldest
|
42 |
-
# with the fittest of a small subsample
|
43 |
-
function regEvolCycle(pop::Population, T::Float32, curmaxsize::Integer,
|
44 |
-
frequencyComplexity::Array{Float32, 1})::Population
|
45 |
-
# Batch over each subsample. Can give 15% improvement in speed; probably moreso for large pops.
|
46 |
-
# but is ultimately a different algorithm than regularized evolution, and might not be
|
47 |
-
# as good.
|
48 |
-
if fast_cycle
|
49 |
-
shuffle!(pop.members)
|
50 |
-
n_evol_cycles = round(Integer, pop.n/ns)
|
51 |
-
babies = Array{PopMember}(undef, n_evol_cycles)
|
52 |
-
|
53 |
-
# Iterate each ns-member sub-sample
|
54 |
-
@inbounds Threads.@threads for i=1:n_evol_cycles
|
55 |
-
best_score = Inf32
|
56 |
-
best_idx = 1+(i-1)*ns
|
57 |
-
# Calculate best member of the subsample:
|
58 |
-
for sub_i=1+(i-1)*ns:i*ns
|
59 |
-
if pop.members[sub_i].score < best_score
|
60 |
-
best_score = pop.members[sub_i].score
|
61 |
-
best_idx = sub_i
|
62 |
-
end
|
63 |
-
end
|
64 |
-
allstar = pop.members[best_idx]
|
65 |
-
babies[i] = iterate(allstar, T, curmaxsize, frequencyComplexity)
|
66 |
-
end
|
67 |
-
|
68 |
-
# Replace the n_evol_cycles-oldest members of each population
|
69 |
-
@inbounds for i=1:n_evol_cycles
|
70 |
-
oldest = argmin([pop.members[member].birth for member=1:pop.n])
|
71 |
-
pop.members[oldest] = babies[i]
|
72 |
-
end
|
73 |
-
else
|
74 |
-
for i=1:round(Integer, pop.n/ns)
|
75 |
-
allstar = bestOfSample(pop)
|
76 |
-
baby = iterate(allstar, T, curmaxsize, frequencyComplexity)
|
77 |
-
#printTree(baby.tree)
|
78 |
-
oldest = argmin([pop.members[member].birth for member=1:pop.n])
|
79 |
-
pop.members[oldest] = baby
|
80 |
-
end
|
81 |
-
end
|
82 |
-
|
83 |
-
return pop
|
84 |
-
end
|
85 |
|
86 |
# Cycle through regularized evolution many times,
|
87 |
# printing the fittest equation every 10% through
|
|
|
37 |
|
38 |
include("Population.jl")
|
39 |
|
40 |
+
include("regEvolCycle.jl")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
41 |
|
42 |
# Cycle through regularized evolution many times,
|
43 |
# printing the fittest equation every 10% through
|