def create_plot_for_measurements(path, dir=None): if dir is None: full_path = os.path.join(path, 'plots_upper_limit') elif type(dir) is str: full_path = os.path.join(path, dir) if not os.path.exists(full_path): os.mkdir(full_path) i = 0 yell_colors = [(0.4, 0.4, 0, c) for c in np.linspace(0, 1, 1000)] cmapred = mcolors.LinearSegmentedColormap.from_list('mycmap', yell_colors, N=5) green_colors = [(173 / 255, 1, 47 / 255, c) for c in np.linspace(0, 1, 1000)] cmapblue = mcolors.LinearSegmentedColormap.from_list('mycmap', green_colors, N=5) fp = 1000 f = np.linspace(0, 60000, fp) t = np.linspace(0, 2.4, int(fp * 2.4)) Sxx = np.full((len(f), len(t)), 0) plt.figure(figsize=(12, 6)) plt.pcolormesh(t, f, Sxx) # fig = plt.figure(figsize=(8,8)) # ax = fig.add_subplot(111) for file in os.listdir(path): # if i == 4: # break if '.csv' in file: time, signal = open_file(os.path.join(path, file)) # time = get_real_time(time) if time is not None: f, t, Sxx = get_stft(time, signal) png_file = os.path.join(full_path, file.replace('.csv', '.png')) # # plt.plot(Sxx) # ax.pcolormesh(t, f, np.abs(Sxx), rasterized= plt.contourf(t, f, np.abs(Sxx), cmap=cmapred) plt.pcolormesh(t, f, np.abs(Sxx), cmap=cmapblue) # plt.hold(True) print(f" {png_file} plotted.") # i += 1 # x0, x1 = ax.get_xlim() # y0, y1 = ax.get_ylim() # ax.imshow(img, extent=[x0, x1, y0, y1], aspect='auto') # fig.savefig('/tmp/test.png') plt.title('Spektrogram transformaty Gabora') plt.ylabel('Częstotliwość [Hz]') plt.xlabel('Czas [s]') upper_limit = 60000 plt.ylim((0, upper_limit)) plt.savefig('full_stft_all_mes3.png') # plt.show() return
def create_plots_for_measuerements(path, dir=None): if dir is None: full_path = os.path.join(path, 'plots_upper_limit') elif type(dir) is str: full_path = os.path.join(path, dir) if not os.path.exists(full_path): os.mkdir(full_path) for file in os.listdir(path): if '.csv' in file: time, signal = open_file(os.path.join(path, file)) # time = get_real_time(time) if time is not None: # f, t, Sxx = get_stft(time, signal) png_file = os.path.join(full_path, file.replace('.csv', '.png')) plot_stft(time, signal, save=png_file, upper_limit=65000) print(f"File {png_file} is saved.")
import numpy as np from random import randint import file_reader import neural_network_keras from neural_network import NeuralNetwork, get_accuracy, error data_test = file_reader.open_file('mnist_test.csv') data_train = file_reader.open_file('mnist_train.csv') training_data = file_reader.normalize_data(data_train) training_labels = file_reader.normalize_labels(data_train) one_hot_train_labels = file_reader.label_to_one_hot(training_labels) test_data = file_reader.normalize_data(data_test) test_labels = file_reader.normalize_labels(data_test) one_hot_test_labels = file_reader.label_to_one_hot(test_labels) # print(one_hot_train_labels) # print('INITIALIZE NETWORK') model = NeuralNetwork(training_data, one_hot_train_labels, 128, 0.5) print('Number of Epochs: ') epochs = int(input()) print('1.) Use built from scratch network') print('2.) Use keras network') option = int(input()) if option == 1:
min_dis = min_local assign_to = i final_cluster[assign_to][1].append(p) #print("remining points:",len(initial_points)-total) total_points = 0 for f in final_cluster: total_points += len(f[1]) assert (total_points == len(initial_points) ), "diff length between final cluster and initial points!" return final_cluster '==============================================' initial_points = fr.open_file() initial_cluster = {} initial_cluster[0] = initial_points vi.show_scatter(initial_cluster) sample_points = sample(initial_points) small_cluster = {} small_cluster[0] = sample_points vi.show_scatter(small_cluster) k = int(sys.argv[2]) sample_cluster = bottom_up(sample_points, k) cluster_dicts = {}
if temp_dis < min_dis: min_dis = temp_dis tree0 = tree tree1 = next_tree n0 = tree0[0] n1 = tree1[0] sumx = n0[2] + n1[2] sumy = n0[3] + n1[3] sumn = n0[4] + n1[4] new_node = (sumx / sumn, sumy / sumn, sumx, sumy, sumn) new_tree = [new_node, tree0, tree1] cluster_trees.remove(tree0) cluster_trees.remove(tree1) cluster_trees.append(new_tree) return cluster_trees def top_down(): pass '====================================================================================' test = [(0, 0), (1, 2), (2, 1), (4, 1), (5, 0), (5, 3)] read = fr.open_file() final = bottom_up(read, 20) vi.show_scatter(final)