def main(args, **kwargs): X = utils.load_raw(args) train_size = int(X.shape[0] * 0.7) if (args.cs): random_time_step = rd.randint(0, train_size) top_k = int(args.random_rate/100 * X.shape[1]) if (top_k < 1): top_k = 1 top_k_index = utils.largest_indices(X[random_time_step], top_k) top_k_index = np.sort(top_k_index)[0] if (args.top_k_random): top_k_index = np.random.randint(X.shape[1], size=top_k_index.shape[0]) X = X[:train_size, top_k_index] dataset = args.dataset.split('_')[0] print('Data Shape: {}'.format(X.shape)) print("Time period you want to know ? h='Hour', d='Day', m='Month'") time_period = input() if (dataset=='abilene'): if (time_period=='h'): data = np.array([np.mean(X[i: i+12], axis=0) for i in range(0, X.shape[0]-X.shape[0]%12, 12)]) elif (time_period=='d'): data = np.array([np.mean(X[i: i+288], axis=0) for i in range(0, X.shape[0]-X.shape[0]%288, 288)]) elif (time_period=='m'): data = np.array([np.mean(X[i: i+8640], axis=0) for i in range(0, X.shape[0]-X.shape[0]%8640, 8640)]) elif (dataset=='geant'): if (time_period=='h'): data = np.array([np.mean(X[i: i+4], axis=0) for i in range(0, X.shape[0]-X.shape[0]%4, 4)]) elif (time_period=='d'): data = np.array([np.mean(X[i: i+96], axis=0) for i in range(0, X.shape[0]-X.shape[0]%96, 96)]) elif (time_period=='m'): data = np.array([np.mean(X[i: i+2880], axis=0) for i in range(0, X.shape[0]-X.shape[0]%2880, 2880)]) elif (dataset=='brain'): if (time_period=='h'): data = np.array([np.mean(X[i: i+60], axis=0) for i in range(0, X.shape[0]-X.shape[0]%60, 60)]) elif (time_period=='d'): data = np.array([np.mean(X[i: i+1440], axis=0) for i in range(0, X.shape[0]-X.shape[0]%1440, 1440)]) elif (time_period=='m'): print('Brain data was measured under 7 days!!') # data = data.reshape(-1, 1) print('MAX: {}, MIN: {}'.format(np.max(data), np.min(data))) # if not os.path.exists(os.path.join(os.getcwd(), 'plot_traffic')): os.mkdir('plot_traffic') # plt.hist(data, bins=12, color='green', range=(np.min(data), np.max(data)), log=True, density=1) # plt.title(dataset + '_' + time_period) # plt.savefig('plot_traffic/' + dataset + '_' + time_period + '.png') var = np.var(data, axis=0) if (time_period=='h'): print('Variance of {} by Hour: {}'.format(dataset, var)) elif (time_period=='d'): print('Variance of {} by Day: {}'.format(dataset, var)) elif (time_period=='m'): print('Variance of {} by Month: {}'.format(dataset, var))
def get_phi(args, top_k_index): X = utils.load_raw(args) G = np.zeros((top_k_index.shape[0], X.shape[1])) for i, j in enumerate(G): j[top_k_index[i]] = 1 return G
def get_R(args): X = utils.load_raw(args) k_sparse = int(args.random_rate / 100 * X.shape[1]) R = np.zeros((k_sparse, X.shape[1])) for i in range(R.shape[1]): d = np.random.randint(R.shape[0] * 2) if d < k_sparse: R[d, i] = 1 else: continue return R
def test_load_roadnet_ca(self): path = raw_roadnet_ca graph = load_raw(path) assert is_weighted(graph) is False assert is_directed(graph) is False assert graph.has_edge('418', '5') assert graph.has_edge('108', '13') assert graph.has_edge('3248', '19') assert graph.has_edge('108', '8') is False assert graph.has_edge('16', '14') is False dump_graphml(graph, processed_roadnet_ca)
def test_load_usair97(self): path = raw_usair97 graph = load_raw(path) assert is_weighted(graph) is True assert is_directed(graph) is False assert graph['2']['1']['weight'] == 0.0436 assert graph['13']['6']['weight'] == 0.0143 assert graph['144']['8']['weight'] == 0.2746 assert graph['119']['95']['weight'] == 0.0323 assert graph.has_edge('321', '163') is False assert graph.has_edge('230', '168') is False dump_graphml(graph, processed_usair97)
def test_load_openflights(self): path = raw_openflights graph = load_raw(path) assert is_weighted(graph) is False assert is_directed(graph) is True assert graph.has_edge('2', '4') assert graph.has_edge('4', '2') assert graph.has_edge('482', '61') assert graph.has_edge('592', '308') assert graph.has_edge('551', '375') assert graph.has_edge('375', '551') is False dump_graphml(graph, processed_openflights)
def test_load_roadnet_pa(self): path = raw_roadnet_pa graph = load_raw(path) assert is_weighted(graph) is False assert is_directed(graph) is False assert graph.has_edge('6299', '1') assert graph.has_edge('1', '6299') assert graph.has_edge('98292', '98290') assert graph.has_edge('450790', '450673') assert graph.has_edge('1068204', '592388') assert graph.has_edge('783720', '733101') is False assert graph.has_edge('290980', '168570') is False assert graph.has_edge('98260', '98318') is False dump_graphml(graph, processed_roadmap_pa)
def test_load_power(self): path = raw_power graph = load_raw(path) assert is_weighted(graph) is False assert is_directed(graph) is False assert graph.has_edge('387', '1') assert graph.has_edge('1813', '1308') assert graph.has_edge('1517', '1440') assert graph.has_edge('1527', '1440') assert graph.has_edge('4599', '4580') assert graph.has_edge('3797', '4724') is False assert graph.has_edge('2475', '1070') is False assert graph.has_edge('420', '425') is False assert graph.has_edge('465', '4576') is False dump_graphml(graph, processed_power)
def get_psi(args, samples=10000, iterator=100): X = utils.load_raw(args) X = X[:samples, :] X_temp = np.array([np.max(X[args.seq_len_x + i: \ args.seq_len_x + i + args.seq_len_y], axis=0) for i in range(samples - args.seq_len_x - args.seq_len_y)]).T size_D = int(math.sqrt(X.shape[1])) D = RandomDictionary(size_D, size_D) psi, _ = KSVD(D, MatchingPursuit, int(args.random_rate / 100 * X.shape[1])).fit( X_temp, iterator) return psi
def load_image(self, path): file = self.bucket.get_object(path) bytes = file.read() return load_raw(bytes)