Skip to content

Instantly share code, notes, and snippets.

@cmd-ntrf
Last active August 29, 2015 14:07
Show Gist options
  • Save cmd-ntrf/dab979c9d9cde16aff4d to your computer and use it in GitHub Desktop.
Save cmd-ntrf/dab979c9d9cde16aff4d to your computer and use it in GitHub Desktop.
DEAP example of logbook merging
import numpy
from deap import tools
logbook1 = tools.Logbook()
logbook2 = tools.Logbook()
logbook3 = tools.Logbook()
# Filling the logbooks [...]
logbook_list = [logbook1, logbook2, logbook3]
# Resulting logbook
aggregate = tools.Logbook()
# We identify the fields we want to merge or aggregate
fields = ['avg', 'min', 'max']
# We suppose every logbook as the same number of entries
nentry = len(logbook1)
for i in range(nentry):
record = {}
for field in fields:
record[field] = numpy.mean([logbook[i][field] for logbook in logbook_list])
aggregate.record(**record)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment