Rev | Line | |
---|
[1113] | 1 | from deap import tools |
---|
| 2 | |
---|
| 3 | from evolalg.statistics.statistics import Statistics |
---|
| 4 | |
---|
| 5 | |
---|
| 6 | class StatisticsDeap(Statistics): |
---|
| 7 | def __init__(self, stats, extract_fn=lambda ind: ind.fitness, verbose=True): |
---|
| 8 | self.stats = tools.Statistics(extract_fn) |
---|
| 9 | for name, fn in stats: |
---|
| 10 | self.stats.register(name, fn) |
---|
| 11 | |
---|
| 12 | self.logbook = tools.Logbook() |
---|
| 13 | self.logbook.header = ['gen'] + (self.stats.fields if self.stats else []) |
---|
| 14 | |
---|
| 15 | self.gen = 0 |
---|
| 16 | self.verbose = verbose |
---|
| 17 | |
---|
| 18 | def init(self): |
---|
| 19 | self.gen = 0 |
---|
| 20 | |
---|
| 21 | def collect(self, population): |
---|
| 22 | record = self.stats.compile(population) |
---|
| 23 | self.logbook.record(gen=self.gen, **record) |
---|
| 24 | self.gen += 1 |
---|
| 25 | if self.verbose: |
---|
| 26 | print(self.logbook.stream) |
---|
Note: See
TracBrowser
for help on using the repository browser.