Last change
on this file since 1139 was
1139,
checked in by Maciej Komosinski, 4 years ago
|
Added --debug mode that prints names of steps; final multiple evaluation now evaluates genotypes in hall of fame instead of the last population
|
File size:
834 bytes
|
Line | |
---|
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, *args, **kwargs): |
---|
8 | super(StatisticsDeap, self).__init__(*args, **kwargs) |
---|
9 | self.stats = tools.Statistics(extract_fn) |
---|
10 | for name, fn in stats: |
---|
11 | self.stats.register(name, fn) |
---|
12 | |
---|
13 | self.logbook = tools.Logbook() |
---|
14 | self.logbook.header = ['gen'] + (self.stats.fields if self.stats else []) |
---|
15 | |
---|
16 | self.gen = 0 |
---|
17 | self.verbose = verbose |
---|
18 | |
---|
19 | def init(self): |
---|
20 | self.gen = 0 |
---|
21 | |
---|
22 | def collect(self, population): |
---|
23 | record = self.stats.compile(population) |
---|
24 | self.logbook.record(gen=self.gen, **record) |
---|
25 | self.gen += 1 |
---|
26 | if self.verbose: |
---|
27 | print(self.logbook.stream) |
---|
Note: See
TracBrowser
for help on using the repository browser.