Changeset 1271
- Timestamp:
- 08/04/23 01:30:21 (17 months ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
framspy/evolalg/base/experiment_niching_abc.py
r1195 r1271 1 1 import time 2 2 from abc import ABC, abstractmethod 3 from tkinter import W4 3 5 4 import numpy as np … … 29 28 self.fit = fit 30 29 self.normalize = normalize 31 self.knn_niching = knn_niching 30 self.knn_niching = knn_niching # this parameter is used for local novelty and local niching 32 31 self.knn_nslc = knn_nslc 33 32 self.archive_size=archive_size 34 if popsize < self.knn_niching: 35 self.knn_niching = popsize - 2 36 if popsize < self.knn_nslc: 37 self.knn_nslc = popsize - 2 33 34 # np.argpartition requires these parameters to be at most popsize-2; popsize is decreased by 1 because we remove_diagonal() 35 if self.knn_niching > popsize - 2: 36 raise ValueError("knn_niching (%d) should be at most popsize-2 (%d)" % (self.knn_niching, popsize-2)) 37 if self.knn_nslc > popsize - 2: 38 raise ValueError("knn_nslc (%d) should be at most popsize-2 (%d)" % (self.knn_nslc, popsize-2)) 39 38 40 39 41 def transform_indexes(self, i, index_array): … … 41 43 42 44 def normalize_dissim(self, dissim_matrix): 43 dissim_matrix = remove_diagonal(np.array(dissim_matrix)) 45 dissim_matrix = remove_diagonal(np.array(dissim_matrix)) # on the diagonal we usually have zeros (an individual is identical with itself, so the dissimilarity is 0). In some techniques we need to find "k" most similar individuals, so we remove the diagonal so that self-similarity of individuals does not interfere with finding "k" other most similar individuals. The matrix from square n*n turns into n*(n-1). 44 46 if self.normalize == "none": 45 47 return dissim_matrix … … 72 74 else: 73 75 raise Exception("Wrong fit type: ", self.fit, 74 f" cho se correct one or implement new behavior")76 f" choose the correct one or implement a new behavior.") 75 77 population_structures.update_archive(dissim_matrix, population_archive) 76 78 … … 90 92 temp_dissim, index_array, axis=-1)) 91 93 temp_fitness = population[i].rawfitness 92 population_of_most_ different= list(94 population_of_most_similar = list( 93 95 map(population.__getitem__, self.transform_indexes(i, index_array))) 94 96 temp_ind_fit = sum( 95 [1 for ind in population_of_most_ differentif ind.rawfitness < temp_fitness])97 [1 for ind in population_of_most_similar if ind.rawfitness < temp_fitness]) 96 98 population[i].fitness = DeapFitness( 97 99 tuple((dissim_value, temp_ind_fit))) … … 165 167 166 168 if type(self.population_structures.population[0].fitness) == DeapFitness: 167 self.population_structures.population = self.make_new_population_nsga2( 169 self.population_structures.population = self.make_new_population_nsga2( # used both for nsga2 and nslc 168 170 self.population_structures.population, pmut, pxov) 169 171 else: … … 184 186 def get_args_for_parser(): 185 187 parser = ExperimentABC.get_args_for_parser() 186 parser.add_argument("-dissim",type= int, default= "frams",187 help="Dissimilarity measure type. Avail ible -2:emd, -1:lev, 1:frams1 (default}, 2:frams2")188 parser.add_argument("-fit",type= str, default= 189 help="Fitness type, availible types: niching, novelty, nsga2, nslc and raw (default}")190 parser.add_argument("-archive",type= int, default= 188 parser.add_argument("-dissim",type= int, default=1, 189 help="Dissimilarity measure type. Available: -3:freq, -2:dens, -1:Leven, 1:frams-struct (default}, 2:frams-descr") 190 parser.add_argument("-fit",type= str, default="raw", 191 help="Fitness type, availible types: niching, novelty, knn_niching (local), knn_novelty (local), nsga2, nslc and raw (default)") 192 parser.add_argument("-archive",type= int, default=50, 191 193 help="Maximum archive size") 192 194 parser.add_argument("-normalize",type= str, default= "max", 193 help="What normalization use for dissimilarity matrix, max (default}, sum and none") 194 parser.add_argument("-knn",type= int, default= 0, 195 help="Nearest neighbors parameter for local novelty/niching, if knn==0 global is performed. Default: 0") 195 help="What normalization to use for the dissimilarity matrix: max (default}, sum, or none") 196 parser.add_argument("-knn_niching",type= int, default=5, 197 help="The number of nearest neighbors for local novelty/niching. If knn==0, global is performed. Default: 5") 198 parser.add_argument("-knn_nslc",type= int, default=5, 199 help="The number of nearest neighbors for NSLC. If knn==0, global is performed. Default: 5") 196 200 return parser 197 201
Note: See TracChangeset
for help on using the changeset viewer.