Last change
on this file since 1167 was
1147,
checked in by Maciej Komosinski, 3 years ago
|
Multi-criteria optimization, can optionally include diversity is one criterion
|
File size:
824 bytes
|
Line | |
---|
1 | from deap import tools |
---|
2 | |
---|
3 | from evolalg.statistics.statistics import Statistics |
---|
4 | |
---|
5 | |
---|
6 | class MultiStatistics(Statistics): |
---|
7 | def __init__(self, stats, verbose=True, *args, **kwargs): |
---|
8 | super(MultiStatistics, self).__init__(*args, **kwargs) |
---|
9 | self._org_stats = stats |
---|
10 | self.stats = tools.MultiStatistics(**stats) |
---|
11 | self.logbook = tools.Logbook() |
---|
12 | self.logbook.header = ['gen'] + (self.stats.fields if self.stats else []) |
---|
13 | self.verbose = verbose |
---|
14 | self.gen = 0 |
---|
15 | |
---|
16 | def init(self): |
---|
17 | for v in self._org_stats.values(): |
---|
18 | v.init() |
---|
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.