source: framspy/evolalg/dissimilarity/dissimilarity.py @ 1138

Last change on this file since 1138 was 1113, checked in by Maciej Komosinski, 4 years ago

Added a framework for evolutionary algorithms cooperating with FramsticksLib?.py

File size: 956 bytes
Line 
1from abc import ABC
2
3from evolalg.base.step import Step
4import numpy as np
5
6
7class Dissimilarity(Step, ABC):
8
9    def __init__(self, reduction="mean", output_field="dissim", *args, **kwargs):
10        super(Dissimilarity, self).__init__(*args, **kwargs)
11
12        self.output_field = output_field
13        self.fn_reduce = None
14        if reduction == "mean":
15            self.fn_reduce = np.mean
16        elif reduction == "max":
17            self.fn_reduce = np.max
18        elif reduction == "min":
19            self.fn_reduce = np.min
20        elif reduction == "sum":
21            self.fn_reduce = np.sum
22        elif reduction == "none" or reduction == None:
23            self.fn_reduce = None
24        else:
25            raise ValueError("Unknown reduction type. Supported: mean, max, min, sum, none")
26
27    def reduce(self, dissim_matrix):
28        if self.fn_reduce is None:
29            return dissim_matrix
30        return self.fn_reduce(dissim_matrix, axis=1)
Note: See TracBrowser for help on using the repository browser.