def init(self, ): print('SOM Server init') self.host = 'localhost' self.port = 7000 self.som = som.SOM() self.som.open('cfg/test.json')
def input_to_tsp(self): os.system('cls' if os.name == 'nt' else 'clear') print(self.headerText) print("--- TESTING TCP SCENARIO ---") problemNumber = input('Choose which problem (number): ') epochs = input("Epochs: ") eta = input("Initial learning rate: ") tauEta = input("Learning rate time constant: ") sigma = input("Initial neighbourhood size: ") tauSigma = input("Neighbourhood time constant: ") plotInterval = input("Plot interval: ") time.sleep(0.7) confirmInput = input("Proceed with the chosen parameters[y/n]? ") if confirmInput == 'y': tspSOM = som.SOM(problemType='TSP', problemArg=int(problemNumber), epochs=int(epochs), sigma_0=float(sigma), tau_sigma=float(tauSigma), eta_0=float(eta), tau_eta=float(tauEta), plotInterval=int(plotInterval)) tspSOM.run() wait = input("PRESS ENTER TO EXIT TO MAIN MENU") self.state = "options"
def config_to_tsp(self): os.system('cls' if os.name == 'nt' else 'clear') print(self.headerText) print("--- LOAD BEST PARAMETER SCENARIO FOR TSP --- ") print("Supported config formats: .txt\n") print("Available scenarios:") for root, dirs, files in os.walk("../configs/tsp"): for file in files: if file.endswith('.txt'): print(file) fileName = input("\nSelect data source: ") confirmInput = input("Proceed with the chosen parameters[y/n]? ") if confirmInput == 'y': with open('../configs/tsp/' + fileName, 'r') as f: for paramLine in f: paramLine = paramLine.strip("\n") paramLine = paramLine.split(",") if (paramLine[0] == ''): continue # Skip empty lines elif (paramLine[0][0] == '#'): continue # Skip comments else: paramName = paramLine[0] paramLine.pop(0) if paramName == 'problemNumber': problemNumber = int(paramLine[0]) elif paramName == 'plotInterval': plotInterval = int(paramLine[0]) elif paramName == 'epochs': epochs = int(paramLine[0]) elif paramName == 'sigma_0': sigma_0 = float(paramLine[0]) elif paramName == 'tau_sigma': tau_sigma = int(paramLine[0]) elif paramName == 'eta_0': eta_0 = float(paramLine[0]) elif paramName == 'tau_eta': tau_eta = int(paramLine[0]) else: raise AssertionError( "Parameter: " + paramName + ", is not a valid parameter name.") tspSOM = som.SOM(problemType='TSP', problemArg=problemNumber, plotInterval=plotInterval, epochs=epochs, sigma_0=sigma_0, tau_sigma=tau_sigma, eta_0=eta_0, tau_eta=tau_eta) tspSOM.run() wait = input("PRESS ENTER TO EXIT TO MAIN MENU") self.state = "options" pass
def build_SOM(db_path, query, N, path = None, random_seed=21893698, dimensions = None, \ normalization_mode = 'None', ID = False, initial_weights = None, lr = 1, sigma = 0.5, cyclic = None, cyclic_norms = None, cyclic_modes = None): # Create a som with get_data.EDataDB(db_path) as db: db.open() db.c.execute(query) data = db.c.fetchall() print('Analysing %d points...' % (len(data), )) somap = som.SOM(data, random_seed=random_seed, dimensions=dimensions, normalization_mode=normalization_mode, ID=ID, learning_rate=lr, sigma=sigma, cyclic=cyclic, cyclic_norms=cyclic_norms, cyclic_modes=cyclic_modes) # Initialize weights if initial_weights is None: somap.random_weights_init(somap.data) if initial_weights is not None: somap._weights = initial_weights # Train SOM somap.train(N) # Generate informative maps somap.generate_distance_map() somap.generate_activation_response() # # Build winners and members # somap.build_winners() # somap.build_cluster_members() # Save SOM if path != None: with open(path, 'wb') as out_f: pickle.dump(somap, out_f) return somap
def input_to_icp(self): os.system('cls' if os.name == 'nt' else 'clear') print(self.headerText) print("--- TESTING ICP SCENARIO ---") epochs = input("Epochs: ") gridSize = input("Grid size: ") eta = input("Initial learning rate: ") tauEta = input("Learning rate time constant: ") sigma = input("Initial neighbourhood size: ") tauSigma = input("Neighbourhood time constant: ") plotInterval = input("Plot interval: ") testInterval = input("Test interval: ") nmbrOfCases = input("Number of training cases to use: ") fillIn = input("Fill in non-classified nodes wrt neighbours[y/n]: ") if fillIn == "y": fillIn = True else: fillIn = False time.sleep(0.7) confirmInput = input("Proceed with the chosen parameters[y/n]? ") if confirmInput == 'y': icpSOM = som.SOM(problemType='ICP', problemArg=None, gridSize=int(gridSize), initialWeightRange=(0, 1), epochs=int(epochs), sigma_0=float(sigma), tau_sigma=float(tauSigma), eta_0=float(eta), tau_eta=float(tauEta), plotInterval=int(plotInterval), testInterval=int(testInterval), fillIn=True, nmbrOfCases=int(nmbrOfCases)) icpSOM.run() wait = input("PRESS ENTER TO EXIT TO MAIN MENU") self.state = "options"
training_set_df = pd.read_csv(training_set_path) print( time.strftime("%H:%M:%S") + ' training set shape: ' + str(training_set_df.shape)) # find all the ohlc files as well ohlc_files = ohlc_file_helper.get_files_in_directory(ohlc_files_path, '.csv') ohlc_date_map = list(ohlc_file_helper.build_ohlc_date_map(ohlc_files)) print(time.strftime("%H:%M:%S") + ' training SOM') training_set = training_set_df.iloc[:100, 1:(example_len + 1)].values print(training_set) num_training = 20 #400 sm = som.SOM(20, 30, example_len, num_training) sm.train(training_set) # plt.imshow(np.reshape(s.get_weights(), [30, 30, 3])) # plt.show() #Get output grid image_grid = sm.get_centroids() #Plot plt.imshow(image_grid) plt.title('SOM') plt.show()
def setUp(self): self.som = som.SOM([]) self.som.col_sz = 4 self.som.row_sz = 4
extracted = pd.DataFrame() for label in col_label: extracted[label] = foods[label] features = extracted.iloc[:, 3:].as_matrix() vs = [] for i in range(len(extracted.index)): vs.append(som.NamedVector(extracted.iloc[i, 1], extracted.iloc[i, 3:].as_matrix())) random.shuffle(vs) for v in vs: v.dump() msom = som.SOM(vs) #msom.arranged() #msom.fission() msom.execute_with_animation('result.txt') #----------- #while msom.update_som_assign(): # pass #msom.reassign_all() #----------- #----------- #msom.update_som_repeatedly(200) #msom.clustering() #-----------
# TODO: Spiking SOM from pyqtgraph.Qt import QtGui, QtCore import som import visualization import dataset # Obtain data from video and visualize it data_set_instance = dataset.DataSet() data_set_instance.visualize_data() data = data_set_instance.merge_data_set() # Perform SOM training som_map = som.SOM(data, proto_dim=2, learning_rate_init=0.001, save_after=None) visual = visualization.SomVisualization(som=som_map) visual.run()