Changeset 1145

Ignore:
Timestamp:
07/07/21 14:38:57 (3 years ago)
Message:

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

Location:
framspy
Files:
4 edited

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

 r1113 class Dissimilarity(Step, ABC): def __init__(self, reduction="mean", output_field="dissim", *args, **kwargs): def __init__(self, reduction="mean", output_field="dissim", knn=None, *args, **kwargs): super(Dissimilarity, self).__init__(*args, **kwargs) self.output_field = output_field self.fn_reduce = None if reduction == "mean": self.knn = knn if reduction == "mean": # TODO change this 'elif' sequence to dictionary? self.fn_reduce = np.mean elif reduction == "max": elif reduction == "sum": self.fn_reduce = np.sum elif reduction == "none" or reduction == None: elif reduction == "knn_mean": self.fn_reduce = self.knn_mean elif reduction == "none" or reduction is None: self.fn_reduce = None else: raise ValueError("Unknown reduction type. Supported: mean, max, min, sum, none") raise ValueError("Unknown reduction type. Supported: mean, max, min, sum, knn_mean, none") def reduce(self, dissim_matrix): return dissim_matrix return self.fn_reduce(dissim_matrix, axis=1) def knn_mean(self, dissim_matrix,axis): return np.mean(np.partition(dissim_matrix, self.knn)[:,:self.knn],axis=axis)
• framspy/evolalg/dissimilarity/frams_dissimilarity.py

 r1139 from evolalg.dissimilarity.dissimilarity import Dissimilarity #TODO eliminate overlap with dissimilarity.py class FramsDissimilarity(FramsStep): def __init__(self, frams_lib, reduction="mean", output_field="dissim", *args, **kwargs): def __init__(self, frams_lib, reduction="mean", output_field="dissim", knn=None, *args, **kwargs): super(FramsDissimilarity, self).__init__(frams_lib, *args, **kwargs) self.output_field = output_field self.fn_reduce = None self.knn = knn if reduction == "mean": self.fn_reduce = np.mean elif reduction == "sum": self.fn_reduce = np.sum elif reduction == "knn_mean": self.fn_reduce = self.knn_mean elif reduction == "none" or reduction is None: self.fn_reduce = None else: raise ValueError("Unknown reduction type. Supported: mean, max, min, sum, none") raise ValueError("Unknown reduction type. Supported: mean, max, min, sum, knn_mean, none") def reduce(self, dissim_matrix): setattr(ind, self.output_field, d) return population def knn_mean(self, dissim_matrix,axis): return np.mean(np.partition(dissim_matrix, self.knn)[:,:self.knn],axis=axis)