def time_space_positions(edge_of_square, timestep, path): """ input: edge_of_square float, spatial edge of cell in meters timestep float, time edge of cell in seconds path string, path to file output: input_coordinates numpy array, coordinates for model creation time_frame_sums numpy array shape_of_grid[0]x1, sum of measures over every timeframe overall_sum number (np.float64 or np.int64), sum of all measures shape_of_grid T numpy array shape_of_grid[0]x1, time positions of measured values uses: loading_data(), number_of_edges(), hist_params(), cartesian_product() objective: to find central positions of cels of grid """ data = dio.loading_data(path) shape_of_grid = number_of_cells(data, edge_of_square, timestep) print(shape_of_grid) central_points, overall_sum = hist_params(data, shape_of_grid) input_coordinates = cartesian_product(*central_points) return input_coordinates, overall_sum, shape_of_grid
def iteration_over_space(path, C, COV, densities, structure, k, edge_of_square, timestep, hours_of_measurement, prefix): """ input: output: uses: objective: """ hist_probs, input_coordinates, shape_of_grid =\ histogram_of_probabilities(path, C, COV, densities, structure, k, edge_of_square, timestep) data = dio.loading_data(path) prumer = np.ones_like(hist_probs) * len(data) / len(input_coordinates) nula = np.zeros_like(hist_probs) t_max = int(shape_of_grid[0]) x_max = int(shape_of_grid[1]) y_max = int(shape_of_grid[2]) prvni_kolo = 1 diff_model = [] diff_nuly = [] diff_prumery = [] while t_max >= 2: diff_m = [] diff_n = [] diff_p = [] x_max = int(shape_of_grid[1]) y_max = int(shape_of_grid[2]) while min(x_max, y_max) >= 2: model = np.histogramdd(input_coordinates, bins=[t_max, x_max, y_max], range=None, normed=False, weights=hist_probs)[0] # !!! tady neni vyreseno, kdyz by ta data obsahovala hodnoty realita = np.histogramdd(data, bins=[t_max, x_max, y_max], range=None, normed=False, weights=None)[0] nuly = np.histogramdd(input_coordinates, bins=[t_max, x_max, y_max], range=None, normed=False, weights=nula)[0] prumery = np.histogramdd(input_coordinates, bins=[t_max, x_max, y_max], range=None, normed=False, weights=prumer)[0] diff = np.sum(np.abs(realita - model)) if prvni_kolo == 1: lrn.model_visualisation(model, realita, [t_max, x_max, y_max], hours_of_measurement, prefix) prvni_kolo = 0 print('shape of grid: ', t_max, ' ', x_max, ' ', y_max) print('realita minus model: ', diff) print('realita minus nuly: ', np.sum(np.abs(realita - nuly))) print('realita minus prumery: ', np.sum(np.abs(realita - prumery))) diff_m.append(diff) diff_n.append(np.sum(np.abs(realita - nuly))) diff_p.append(np.sum(np.abs(realita - prumery))) x_max = int(x_max / 2) y_max = int(y_max / 2) t_max = int(t_max / 2) diff_model.append(diff_m) diff_nuly.append(diff_n) diff_prumery.append(diff_p) ### shape of grid by pak byla nejaka promenna... return diff_model, diff_nuly, diff_prumery
#!/usr/bin/env python2 import numpy as np import python_module as pm #import tested_doors_python_module as pm import dataset_io as dio #c = dio.loading_data('../data/training_two_weeks_01.txt') #c = dio.loading_data('../data/10_weeks_doors.txt') c = dio.loading_data('../../../data/greg_door_2016_min/training_data.txt') #a = np.array([0, 7200, 14400, 21600, 28800, 36000, 43200, 50400, 57600, 64800, 72000, 79200]) #b = np.array([0,0,1,1,0,0,1,1,0, 0,1, 1]) #c = np.c_[a, b] """ with open('../data/data.txt', 'r') as f: i = 0 for line in f: #print(line) b = np.array(map(float, list(line[1:-2].split(', ')))) a = np.arange(len(b)) * 600 #print('a: ' + str(np.shape(a))) #print('b: ' + str(np.shape(b))) c = np.c_[a, b] #print('c: ' + str(np.shape(c))) #print(c) i += 1 model = pm.python_function_update(c) if i == 14: break else:
def model_above_data(path, C, COV, density_integrals, structure, k, edge_of_square, timestep, prefix, visualise, average): """ input: path string, path to file C numpy array kxd, matrix of k d-dimensional cluster centres COV numpy array kxdxd, matrix of covariance matrices density_integrals numpy array kx1, matrix of ratios between measurements and grid cells belonging to the clusters structure list(int, list(floats), list(floats)), number of non-hypertime dimensions, list of hypertime radii nad list of wavelengths k positive integer, number of clusters edge_of_square float, spatial edge of cell in default units (meters) timestep float, time edge of cell in default units (seconds) prefix string, string to differ model visualisations visualise boolean, to create graph or not average float, average value per cell in testing data output: model numpy array (shape_of_grid), grid of modeled frequencies(stat) reality numpy array (shape_of_grid), grid of measured frequencies(stat) uses: params_for_model(), dio.loading_data(), difference_visualisation_3d(), difference_visualisation_2d(), np.ones_like(), np.zeros_like(), np.histogramdd(), np.sum(), np.max(), np.min() objective: """ freqs, input_coordinates, shape_of_grid =\ params_for_model(path, C, COV, density_integrals, structure, k, edge_of_square, timestep) data = dio.loading_data(path) average = np.ones_like(freqs) * average zero = np.zeros_like(freqs) model = np.histogramdd(input_coordinates, bins=shape_of_grid, range=None, normed=False, weights=freqs)[0] reality = np.histogramdd(data, bins=shape_of_grid, range=None, normed=False, weights=None)[0] zeros = np.histogramdd(input_coordinates, bins=shape_of_grid, range=None, normed=False, weights=zero)[0] averages = np.histogramdd(input_coordinates, bins=shape_of_grid, range=None, normed=False, weights=average)[0] diff = (np.sum((reality - model)**2))**0.5 error_of_averages = (np.sum((reality - averages)**2))**0.5 error_of_zeros = (np.sum((reality - zeros)**2))**0.5 if visualise: if len(shape_of_grid) == 3: hours_of_measurement = (np.max(data[:, 0]) - np.min(data[:, 0]))\ / (60*60) starting_hour = (np.min(data[:, 0]) % (60 * 60 * 24)) / (60 * 60 * 24) difference_visualisation_3d(model, reality, shape_of_grid, hours_of_measurement, starting_hour, prefix) elif len(shape_of_grid) == 2: difference_visualisation_2d(model, reality, shape_of_grid, prefix) print('\nshape of grid [t, x, y]: ' + str(shape_of_grid)) print('distance between measurement and model: ' + str(diff)) print('distance between measurement and zeros: ' + str(error_of_zeros)) print('distance between measurement and mean value: ' + (error_of_averages)) return model, reality
#!/usr/bin/env python2 import numpy as np #import python_module as pm import tested_doors_python_module as pm import dataset_io as dio #c = dio.loading_data('../data/training_two_weeks_01.txt') #c = dio.loading_data('../data/10_weeks_doors.txt') c = dio.loading_data('../data/training_data.txt') #a = np.array([0, 7200, 14400, 21600, 28800, 36000, 43200, 50400, 57600, 64800, 72000, 79200]) #b = np.array([0,0,1,1,0,0,1,1,0, 0,1, 1]) #c = np.c_[a, b] """ with open('../data/data.txt', 'r') as f: i = 0 for line in f: #print(line) b = np.array(map(float, list(line[1:-2].split(', ')))) a = np.arange(len(b)) * 600 #print('a: ' + str(np.shape(a))) #print('b: ' + str(np.shape(b))) c = np.c_[a, b] #print('c: ' + str(np.shape(c))) #print(c) i += 1 model = pm.python_function_update(c) if i == 14: break else: