2

DEAP 示例(Python 框架)中有一段代码:

# Evaluate the entire population
fitnesses = list(map(toolbox.evaluate, pop))
for ind, fit in zip(pop, fitnesses):
    ind.fitness.values = fit

他们为什么使用mapfor?为什么不只是:

for ind in pop:
    ind.fitness.values = toolbox.evaluate(ind)
4

1 回答 1

2

I'm one of the DEAP developer.

We use the map so that we can easily parallelize the evaluation by replacing the map by a parallel map.

Later in the examples, we use a toolbox with a map registered in it (__buitins__.map) that can be replaced by multiprocessing.Pool.map or scoop.futures.map. You can look at the documentation for how to distribute the evaluation here

于 2013-12-18T18:45:34.580 回答