source: framspy/evolalg/dissimilarity/frams_dissimilarity.py @ 1182

Last change on this file since 1182 was 1182, checked in by Maciej Komosinski, 5 weeks ago

More concise code and less redundancy in dissimilarity classes, added support for archive of genotypes, added hard limit on the number of genotype chars

File size: 935 bytes
Line 
1from abc import ABC
2
3import numpy as np
4
5from evolalg.base.frams_step import FramsStep
6from evolalg.dissimilarity.dissimilarity import Dissimilarity
7
8
9class FramsDissimilarity(FramsStep):
10
11    def __init__(self, frams_lib, reduction="mean", output_field="dissim",knn=None, *args, **kwargs):
12        super(FramsDissimilarity, self).__init__(frams_lib, *args, **kwargs)
13
14        self.output_field = output_field
15        self.fn_reduce = Dissimilarity.get_reduction_by_name(reduction)
16        self.knn = knn
17
18
19    def call(self, population):
20        super(FramsDissimilarity, self).call(population)
21        if len(population) == 0:
22            return []
23        dissim_matrix = self.frams.dissimilarity([_.genotype for _ in population], 1)
24        dissim = Dissimilarity.reduce(dissim_matrix, self.fn_reduce, self.knn)
25        for d,ind in zip(dissim, population):
26            setattr(ind, self.output_field, d)
27        return population
Note: See TracBrowser for help on using the repository browser.