def plot_UCI(): ''' plot statistics from UCI Message ''' fname = "datasets/UCI_processed/OCnodeslinks_chars.txt" max_nodes = 1901 G_times = UCI_loader.load_temporarl_edgelist(fname, max_nodes=max_nodes) graph_name = "UCI_Message" ''' dictionary of weak labels ''' labels_dict = {} print ("edge") labels_dict['edge'] = normal_util.plot_edges(G_times, graph_name) print ("acc") labels_dict['acc'] = normal_util.plot_avg_clustering(G_times, graph_name) print ("component") labels_dict['component'] = normal_util.plot_num_components_directed(G_times, graph_name) print ("weights") labels_dict['weights'] = normal_util.plot_weighted_edges(G_times, graph_name) print ("degree") labels_dict['degree'] = normal_util.plot_degree_changes(G_times, graph_name) return labels_dict
def UCI_Message(): timestamps = 196 percent_ranked = 0.05 eigen_file = "UCI_L_singular.pkl" fname = "UCI" difference = True G_times = UCI_loader.load_temporarl_edgelist( "datasets/UCI_processed/OCnodeslinks_chars.txt", max_nodes=1901) #real_events = [65,158] window1 = 7 window2 = 14 initial_window = 14 (z_shorts, z_longs, z_scores, events) = detection_with_bothwindows(eigen_file=eigen_file, timestamps=timestamps, percent_ranked=percent_ranked, window1=window1, window2=window2, initial_window=initial_window, difference=difference) scores = [] scores.append(z_shorts) scores.append(z_longs) score_labels = ["short term " + str(window1), "long term " + str(window2)] plot_anomaly_score("UCI", fname, scores, score_labels, events)
def compute_UCI_SVD(num_eigen=6, top=True): fname = "datasets/UCI_processed/OCnodeslinks_chars.txt" max_nodes = 1901 directed = True G_times = UCI_loader.load_temporarl_edgelist(fname, max_nodes=max_nodes) (Temporal_eigenvalues, activity_vecs) = SVD_perSlice(G_times, directed=directed, num_eigen=num_eigen, top=top, max_size=max_nodes) normal_util.save_object(Temporal_eigenvalues, "UCI_L_singular.pkl")
def find_factors_UCI(): fname = "datasets/UCI_processed/OCnodeslinks_chars.txt" max_nodes = 1901 G_times = UCI_loader.load_temporarl_edgelist(fname, max_nodes=max_nodes) T = toTensor(G_times, max_nodes) dim = 3 print("CPD starts") print(datetime.datetime.now()) factors = apply_parafac(T, dimension=dim) print(datetime.datetime.now()) print("CPD ends") tname = "UCI_factors.pkl" normal_util.save_object(factors, tname)
def compute_adj_SVD(outEigenFile, outVecFile, fname="datasets/OCnodeslinks_chars.txt", max_nodes=1901, UCI=True): if UCI: G_times = UCI_loader.load_temporarl_edgelist(fname, max_nodes=max_nodes) else: G_times = DBLP_loader.load_dblp_temporarl_edgelist(fname, max_nodes=max_nodes) (Temporal_eigenvalues, activity_vecs) = adj_eigenvecs_perSlice(G_times, directed=UCI) normal_util.save_object(Temporal_eigenvalues, outEigenFile) normal_util.save_object(activity_vecs, outVecFile)
def plot_UCI_allinOne(): fname = "datasets/UCI_processed/OCnodeslinks_chars.txt" max_nodes = 1901 G_times = UCI_loader.load_temporarl_edgelist(fname, max_nodes=max_nodes) LAD = [69, 70, 184, 185, 187, 188, 189, 191, 192, 194] activity = [57, 75, 78, 85, 89, 90, 104, 176, 188, 192] CPD = [13, 16, 17, 20, 22, 23, 24, 31, 38, 40, 124] label_sets = [] label_sets.append(LAD) label_sets.append(activity) label_sets.append(CPD) graph_name = "UCI_Message" normal_util.all_in_one_compare(G_times, graph_name, label_sets, True) graph_name = "UCI_Message" normal_util.all_plots_in_one(G_times, graph_name)
def find_UCI_factors(): fname = "datasets/UCI_processed/OCnodeslinks_chars.txt" max_nodes = 1901 num_timestamps = 196 G_times = UCI_loader.load_temporarl_edgelist(fname, max_nodes=max_nodes) T = toTensor(G_times) dim = 30 print("CPD starts") print(datetime.datetime.now()) factors = apply_parafac(T, dimension=dim) normal_util.save_object(factors, "UCI_factors" + str(dim) + ".pkl") print(datetime.datetime.now()) print("CPD ends") #factors = normal_util.load_object("UCI_factors1000.pkl") real_events = [65, 158] anomalies = DBSCAN_anomalies(factors, eps=3, min_samples=2, min_size=10) #anomalies = LocalOutlierFactor_anomalies(factors, n_neighbors=20) accuracy = compute_accuracy(anomalies, real_events) print(anomalies) print("prediction accuracy is " + str(accuracy))