Spaces:
Running
Running
File size: 1,810 Bytes
eb2dca9 65bc891 eb2dca9 |
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 38 39 40 41 42 43 44 45 46 47 |
import Random: shuffle!
# Pass through the population several times, replacing the oldest
# with the fittest of a small subsample
function regEvolCycle(pop::Population, T::Float32, curmaxsize::Integer,
frequencyComplexity::Array{Float32, 1})::Population
# Batch over each subsample. Can give 15% improvement in speed; probably moreso for large pops.
# but is ultimately a different algorithm than regularized evolution, and might not be
# as good.
if fast_cycle
shuffle!(pop.members)
n_evol_cycles = round(Integer, pop.n/ns)
babies = Array{PopMember}(undef, n_evol_cycles)
# Iterate each ns-member sub-sample
@inbounds Threads.@threads for i=1:n_evol_cycles
best_score = Inf32
best_idx = 1+(i-1)*ns
# Calculate best member of the subsample:
for sub_i=1+(i-1)*ns:i*ns
if pop.members[sub_i].score < best_score
best_score = pop.members[sub_i].score
best_idx = sub_i
end
end
allstar = pop.members[best_idx]
babies[i] = iterate(allstar, T, curmaxsize, frequencyComplexity)
end
# Replace the n_evol_cycles-oldest members of each population
@inbounds for i=1:n_evol_cycles
oldest = argmin([pop.members[member].birth for member=1:pop.n])
pop.members[oldest] = babies[i]
end
else
for i=1:round(Integer, pop.n/ns)
allstar = bestOfSample(pop)
baby = iterate(allstar, T, curmaxsize, frequencyComplexity)
#printTree(baby.tree)
oldest = argmin([pop.members[member].birth for member=1:pop.n])
pop.members[oldest] = baby
end
end
return pop
end
|