Ignore:
Timestamp:
07/07/21 14:38:57 (15 months ago)
Author:
Maciej Komosinski
Message:

Added niching and novelty search with limited (i.e., local) competition ("nearest neighbors" according to dissimilarity measure)

File:
1 edited

Legend:

Unmodified
Added
Removed
  • framspy/evolalg/dissimilarity/frams_dissimilarity.py

    r1139 r1145  
    66from evolalg.dissimilarity.dissimilarity import Dissimilarity
    77
     8#TODO eliminate overlap with dissimilarity.py
     9
    810
    911class FramsDissimilarity(FramsStep):
    1012
    11     def __init__(self, frams_lib, reduction="mean", output_field="dissim", *args, **kwargs):
     13    def __init__(self, frams_lib, reduction="mean", output_field="dissim", knn=None, *args, **kwargs):
    1214        super(FramsDissimilarity, self).__init__(frams_lib, *args, **kwargs)
    1315
    1416        self.output_field = output_field
    1517        self.fn_reduce = None
     18        self.knn = knn
    1619        if reduction == "mean":
    1720            self.fn_reduce = np.mean
     
    2225        elif reduction == "sum":
    2326            self.fn_reduce = np.sum
     27        elif reduction == "knn_mean":
     28            self.fn_reduce = self.knn_mean
    2429        elif reduction == "none" or reduction is None:
    2530            self.fn_reduce = None
    2631        else:
    27             raise ValueError("Unknown reduction type. Supported: mean, max, min, sum, none")
     32            raise ValueError("Unknown reduction type. Supported: mean, max, min, sum, knn_mean, none")
    2833
    2934    def reduce(self, dissim_matrix):
     
    4146            setattr(ind, self.output_field, d)
    4247        return population
     48
     49    def knn_mean(self, dissim_matrix,axis):
     50        return np.mean(np.partition(dissim_matrix, self.knn)[:,:self.knn],axis=axis)
Note: See TracChangeset for help on using the changeset viewer.