Take a look at the following steps:
- Let's start with the boilerplate variable initialization:
from collections import OrderedDictfrom copy import deepcopyimport simuPOP as spnum_loci = 10pop_size = 1000num_gens = 101init_ops = OrderedDict()pre_ops = OrderedDict()post_ops = OrderedDict()def init_accumulators(pop, param): accumulators = param for accumulator in accumulators: pop.vars()[accumulator] = [] return Truedef update_accumulator(pop, param): accumulator, var = param pop.vars()[accumulator].append(deepcopy(pop.vars()[var])) return Truepops = sp.Population(pop_size, loci=[1] * num_loci, infoFields=['fitness'])
Most of this code was explained in the previous recipe, but look at the very last line. There is now an infoFields ...