Esempio n. 1
0
def find_synthetic_factors(fname):
    fname = "datasets/SBM_processed/" + fname + ".txt"
    max_nodes = 500
    num_timestamps = 151
    G_times = SBM_loader.load_temporarl_edgelist(fname)
    T = toTensor(G_times)
    dim = 30
    print("CPD starts")
    print(datetime.datetime.now())
    factors = apply_parafac(T, dimension=dim)
    normal_util.save_object(factors, "SBM_factors" + str(dim) + ".pkl")
    print(datetime.datetime.now())
    print("CPD ends")

    #factors = normal_util.load_object("SBM_factors30.pkl")

    real_events = [16, 31, 61, 76, 91, 106, 136]
    '''
    either can be an option here
    '''
    anomalies = LocalOutlierFactor_anomalies(factors, n_neighbors=20)
    #anomalies = DBSCAN_anomalies(factors, eps=3, min_samples=2, min_size=10)
    accuracy = compute_accuracy(anomalies, real_events)
    print(anomalies)
    print("prediction accuracy is " + str(accuracy))
Esempio n. 2
0
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")
Esempio n. 3
0
def compute_legis_SVD(num_eigen=6, top=True):
    fname = "datasets/USLegis_processed/LegisEdgelist.txt"
    directed = False

    G_times = USLegis_loader.load_legis_temporarl_edgelist(fname)
    max_nodes = 102
    (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, "USLegis_L_singular.pkl")
Esempio n. 4
0
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)
Esempio n. 5
0
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)
Esempio n. 6
0
def find_canVote_factors():
    fname = "datasets/canVote_processed/canVote_edgelist.txt"
    G_times = canVote_loader.load_canVote_temporarl_edgelist(fname)

    T = toTensor(G_times)
    dim = 10
    print("CPD starts")
    print(datetime.datetime.now())
    factors = apply_parafac(T, dimension=dim)
    print(datetime.datetime.now())
    print("CPD ends")
    normal_util.save_object(factors, "canVote_factors" + str(dim) + ".pkl")

    anomalies = LocalOutlierFactor_anomalies(factors, n_neighbors=7)
    print(anomalies)
Esempio n. 7
0
def compute_canVote_SVD(num_eigen=338, top=True):
    fname = "datasets/canVote_processed/canVote_edgelist.txt"
    directed = True
    G_times = canVote_loader.load_canVote_temporarl_edgelist(fname)
    max_len = 0
    for G in G_times:
        if (len(G) > max_len):
            max_len = len(G)
    print(max_len)
    max_nodes = max_len
    (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, "canVote_L_singular.pkl")
Esempio n. 8
0
def find_USLegis_factors():
    fname = "datasets/USLegis_processed/LegisEdgelist.txt"
    G_times = USLegis_loader.load_legis_temporarl_edgelist(fname)
    T = toTensor(G_times)

    dim = 10
    print("CPD starts")
    print(datetime.datetime.now())
    factors = apply_parafac(T, dimension=dim)
    print(datetime.datetime.now())
    print("CPD ends")
    normal_util.save_object(factors, "USLegis_factors" + str(dim) + ".pkl")

    real_events = [3, 7]

    anomalies = LocalOutlierFactor_anomalies(factors, n_neighbors=5)
    accuracy = compute_accuracy(anomalies, real_events)
    print(anomalies)
    print("prediction accuracy is " + str(accuracy))
Esempio n. 9
0
def compute_synthetic_SVD(fname, num_eigen=499, top=True):

    edgefile = "datasets/SBM_processed/" + fname + ".txt"
    '''
    careful
    '''

    max_nodes = 1000

    max_time = 151
    directed = False

    G_times = SBM_loader.load_temporarl_edgelist(edgefile)

    (Temporal_eigenvalues, activity_vecs) = SVD_perSlice(G_times,
                                                         directed=directed,
                                                         num_eigen=num_eigen,
                                                         top=top,
                                                         max_size=max_nodes)
    #print (Temporal_eigenvalues)
    normal_util.save_object(Temporal_eigenvalues, fname + ".pkl")
Esempio n. 10
0
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))