source: framspy/evolalg_steps/dissimilarity/frams_dissimilarity.py @ 1322

Last change on this file since 1322 was 1185, checked in by Maciej Komosinski, 2 years ago

Renamed a module; new name is "evolalg_steps"

File size: 947 bytes
Line 
1from abc import ABC
2
3import numpy as np
4
5from evolalg_steps.base.frams_step import FramsStep
6from evolalg_steps.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.