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