Last change
on this file since 1270 was
1185,
checked in by Maciej Komosinski, 2 years ago
|
Renamed a module; new name is "evolalg_steps"
|
File size:
830 bytes
|
Line | |
---|
1 | from deap import tools |
---|
2 | |
---|
3 | from evolalg_steps.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.