def build(sData, mapsize=None, mask=None, mapshape='planar', lattice='rect', normalization='var', initialization='pca', neighborhood='gaussian', training='batch', radius_train='linear', name='sompyMap', components_to_plot=None): """ :param data: data to be clustered, represented as a matrix of n rows, as inputs and m cols as input features :param neighborhood: neighborhood object calculator. Options are: - gaussian - bubble - manhattan (not implemented yet) - cut_gaussian (not implemented yet) - epanechicov (not implemented yet) :param normalization: normalizer object calculator. Options are: - var :param mapsize: tuple/list defining the dimensions of the som. If single number is provided is considered as the number of nodes. :param mask: mask :param mapshape: shape of the som. Options are: - planar - toroid (not implemented yet) - cylinder (not implemented yet) :param lattice: type of lattice. Options are: - rect - hexa :param initialization: method to be used for initialization of the som. Options are: - pca - random :param name: name used to identify the som :param training: Training mode (seq, batch) """ if normalization and type(normalization) == str: normalizer = [] for i in range(len(sData._data[0])): normalizer.append(NormalizerFactory.build(normalization)) elif normalization and type(normalization) == list: normalizer = [] for i in range(len(sData._data[0])): normalizer.append(NormalizerFactory.build(normalization[i])) else: normalizer = sData._normalizer neighborhood_calculator = NeighborhoodFactory.build(neighborhood) return SOMMap(sData._data, neighborhood_calculator, normalizer, mapsize, mask, mapshape, lattice, initialization, training, radius_train, name, sData.component_names, components_to_plot, sData.isNormalized)
def load(file, data=None): import pickle dico = pickle.load(open(file, 'rb')) normalizer = None neighborhood_calculator = NeighborhoodFactory.build( dico['neighborhood']) sm = SOMMap(data, neighborhood_calculator, normalizer, mapsize=dico['mapsize'], mask=dico['mask'], mapshape=dico['mapshape'], lattice=dico['lattice'], initialization=dico['initialization'], training=dico['training'], radius_train=dico['radius_train'], name=dico['name'], component_names=dico['comp_names'], components_to_plot=None) if dico['normalization']: #normalizer = NormalizerFactory.build(dico['normalization']) sm._normalizer = dico['normalization'] #sm._normalizer.params= dico['norm_params'] #sm._normalizer.normalized = True if dico['normalization'] is not None else False sm.codebook.matrix = dico['codebook'] sm.codebook.initialized = dico['codebookinitialized'] sm._dim = dico['dim'] return sm
def genetic_with_local_search(random_constructor, edgelist): population = genetic_algorithm(edgelist, random_constructor, 5, 1.2, 10) neighborhood_factory = NeighborhoodFactory(edgelist, 'Reversal') best = None for p in population: new = local_search(p, best_improvement, neighborhood_factory) if best == None or new < best: best = new print('New best is {}'.format(best.obj)) return best
def build(data, mapsize=None, mask=None, mapshape='planar', lattice='rect', normalization='var', initialization='pca', neighborhood='gaussian', training='batch', name='sompy', component_names=None): """ :param data: data to be clustered, represented as a matrix of n rows, as inputs and m cols as input features :param neighborhood: neighborhood object calculator. Options are: - gaussian - bubble - manhattan (not implemented yet) - cut_gaussian (not implemented yet) - epanechicov (not implemented yet) :param normalization: normalizer object calculator. Options are: - var :param mapsize: tuple/list defining the dimensions of the som. If single number is provided is considered as the number of nodes. :param mask: mask :param mapshape: shape of the som. Options are: - planar - toroid (not implemented yet) - cylinder (not implemented yet) :param lattice: type of lattice. Options are: - rect - hexa (not implemented yet) :param initialization: method to be used for initialization of the som. Options are: - pca - random :param name: name used to identify the som :param training: Training mode (seq, batch) """ if normalization: normalizer = NormalizatorFactory.build(normalization) else: normalizer = None neighborhood_calculator = NeighborhoodFactory.build(neighborhood) return SOM(data, neighborhood_calculator, normalizer, mapsize, mask, mapshape, lattice, initialization, training, name, component_names)
def build(data, mapsize, mask=None, mapshape='planar', lattice='rect', normalization='var', initialization='pca', neighborhood='gaussian', training='batch', name='sompy'): """ :param data: data to be clustered, represented as a matrix of n rows, as inputs and m cols as input features :param neighborhood: neighborhood object calculator. Options are: - gaussian - bubble - manhattan (not implemented yet) - cut_gaussian (not implemented yet) - epanechicov (not implemented yet) :param normalization: normalizer object calculator. Options are: - var :param mapsize: tuple/list defining the dimensions of the som. If single number is provided is considered as the number of nodes. :param mask: mask :param mapshape: shape of the som. Options are: - planar - toroid (not implemented yet) - cylinder (not implemented yet) :param lattice: type of lattice. Options are: - rect - hexa (not implemented yet) :param initialization: method to be used for initialization of the som. Options are: - pca - random :param name: name used to identify the som :param training: Training mode (seq, batch) """ normalizer = NormalizatorFactory.build(normalization) if normalization else None neighborhood_calculator = NeighborhoodFactory.build(neighborhood) return SOM(data, neighborhood_calculator, normalizer, mapsize, mask, mapshape, lattice, initialization, training, name)
if len(sys.argv) < 4: logging.error('Help: main.py [filename] [neighborhood] [heuristic]') exit(-1) filename = sys.argv[1] edgelist, k, L, M = parse_input(filename) #logging.debug("n={} k={} L={}".format(len(vertices), k, L)) sorted_edgelist = [] for u in range(len(edgelist)): for v in range(u+1, len(edgelist[u])): sorted_edgelist.append((u,v,edgelist[u][v])) sorted_edgelist = sorted(sorted_edgelist, key=lambda x: x[2]) #logging.debug(sorted_edgelist) neighborhood_factory = NeighborhoodFactory(edgelist, sys.argv[2]) local_iterations = 20 grasp_iterations = 10 gvns_iterations = 10 tabu_iterations = 20 tabu_length = 10 delta_eval = True heuristic = sys.argv[3] if heuristic == 'deterministic_construction' or heuristic == 'dc': heuristic = "deterministic_construction" solution = construct_deterministic(edgelist, sorted_edgelist, len(edgelist), k, L, M) elif heuristic == 'random_construction' or heuristic == 'rc':