Last change
on this file since 1140 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:
867 bytes
|
Rev | Line | |
---|
[1113] | 1 | import Levenshtein as lev |
---|
| 2 | |
---|
| 3 | from evolalg.dissimilarity.dissimilarity import Dissimilarity |
---|
| 4 | |
---|
| 5 | |
---|
| 6 | class LevenshteinDissimilarity(Dissimilarity): |
---|
| 7 | def __init__(self, reduction="mean", output_field="dissim", *args, **kwargs): |
---|
| 8 | super(LevenshteinDissimilarity, self).__init__(reduction, output_field, *args, **kwargs) |
---|
| 9 | |
---|
| 10 | def call(self, population): |
---|
[1139] | 11 | super(LevenshteinDissimilarity, self).call(population) |
---|
[1113] | 12 | if len(population) == 0: |
---|
| 13 | return [] |
---|
| 14 | dissim = [] |
---|
| 15 | for i, p in enumerate(population): |
---|
| 16 | gen_dis = [] |
---|
| 17 | for i2, p2 in enumerate(population): |
---|
| 18 | gen_dis.append(lev.distance(p.genotype, p2.genotype)) |
---|
| 19 | dissim.append(gen_dis) |
---|
| 20 | dissim = self.reduce(dissim) |
---|
| 21 | for d, ind in zip(dissim, population): |
---|
| 22 | setattr(ind, self.output_field, d) |
---|
| 23 | return population |
---|
Note: See
TracBrowser
for help on using the repository browser.