예제 #1
0
파일: main.py 프로젝트: ljsmalbil/CDVAE
from cdt.causality.graph import CCDr
from cdt.causality.graph import CGNN
from cdt.causality.graph import GES
from cdt.causality.graph import LiNGAM
from cdt.causality.graph import PC
from cdt.causality.graph import CAM

from cdt.utils.graph import clr
import networkx as nx

device = torch.device('cuda' if torch.cuda.is_available() else 'cpu')

# Read the data
data = pd.read_csv('combined.csv', header=None)
true_CM = pd.read_csv('true_CM.csv', header=None)
true_CM = np.array(true_CM)

start_time = time.time()

aupr_matrix, dir_adj_matrix = CDVAE()
end_time = time.time() - start_time

print("--- Execution time : %4.4s seconds ---" % end_time)

#Retrieve SHD and AUPR
shd = SHD(true_CM, dir_adj_matrix, double_for_anticausal=False)
print('SHD:', shd)

aupr, curve = precision_recall(true_CM, aupr_matrix)
print('AUPR for aupr_matrix:', aupr)
예제 #2
0
def test_precision_recall():
    assert precision_recall(*init())
예제 #3
0
def baselines(data):
    # Tests
    start_time = time.time()

    obj = PC()
    output = obj.predict(data)

    adj_mat = nx.adjacency_matrix(output).todense()
    output = clr(adj_mat)

    output[np.isnan(output)] = 0
    output[np.isposinf(output)] = 1

    predicted = retrieve_adjacency_matrix(output)
    true_matrix = pd.read_csv('true_CM.csv', header=None)
    true_matrix = np.array(true_matrix)

    shd = SHD(np.array(true_matrix), predicted, double_for_anticausal=False)
    aupr, curve = precision_recall(np.array(true_matrix), output)

    end_time = (time.time() - start_time)
    print("--- Execution time : %4.4s seconds ---" % end_time)

    results_pc = ['PC', aupr, shd, end_time]
    print(results_pc)

    # Tests
    start_time = time.time()

    obj = GES()
    output = obj.predict(data)

    adj_mat = nx.adjacency_matrix(output).todense()
    output = clr(adj_mat)

    output[np.isnan(output)] = 0
    output[np.isposinf(output)] = 1

    predicted = retrieve_adjacency_matrix(output)
    true_matrix = pd.read_csv('true_CM.csv', header=None)
    true_matrix = np.array(true_matrix)

    shd = SHD(np.array(true_matrix), predicted, double_for_anticausal=False)
    aupr, curve = precision_recall(np.array(true_matrix), output)

    end_time = (time.time() - start_time)
    print("--- Execution time : %4.4s seconds ---" % end_time)

    results_ges = ['GES', aupr, shd, end_time]
    print(results_ges)

    # Tests
    start_time = time.time()

    obj = LiNGAM()
    output = obj.predict(data)

    adj_mat = nx.adjacency_matrix(output).todense()
    output = clr(adj_mat)

    output[np.isnan(output)] = 0
    output[np.isposinf(output)] = 1

    predicted = retrieve_adjacency_matrix(output)
    true_matrix = pd.read_csv('true_CM.csv', header=None)
    true_matrix = np.array(true_matrix)

    shd = SHD(np.array(true_matrix), predicted, double_for_anticausal=False)
    aupr, curve = precision_recall(np.array(true_matrix), output)

    end_time = (time.time() - start_time)
    print("--- Execution time : %4.4s seconds ---" % end_time)

    results_lingam = ['LiNGAM', aupr, shd, end_time]
    print(results_lingam)

    # Tests
    start_time = time.time()

    obj = CCDr()
    output = obj.predict(data)

    adj_mat = nx.adjacency_matrix(output).todense()
    output = clr(adj_mat)

    output[np.isnan(output)] = 0
    output[np.isposinf(output)] = 1

    predicted = retrieve_adjacency_matrix(output)
    true_matrix = pd.read_csv('true_CM.csv', header=None)
    true_matrix = np.array(true_matrix)

    shd = SHD(np.array(true_matrix), predicted, double_for_anticausal=False)
    aupr, curve = precision_recall(np.array(true_matrix), output)

    end_time = (time.time() - start_time)
    print("--- Execution time : %4.4s seconds ---" % end_time)

    results_ccdr = ['CCDR', aupr, shd, end_time]
    print(results_ccdr)

    return results_pc, results_ges, results_lingam, results_ccdr
예제 #4
0
파일: core.py 프로젝트: fteytaud/nevergrad
 def graph_score(self, test_graph: nx.DiGraph) -> float:
     pr_score, _ = precision_recall(self._ground_truth_graph, test_graph)
     shd_score = SHD(self._ground_truth_graph, test_graph)
     return float(pr_score - shd_score)  # Higher better
예제 #5
0
    results_ccdr = ['CCDR', aupr, shd, end_time]
    print(results_ccdr)

    return results_pc, results_ges, results_lingam, results_ccdr


# Tests
start_time = time.time()

obj = CGNN(nruns=1, train_epochs=500, test_epochs=500)
output = obj.predict(data)

adj_mat = nx.adjacency_matrix(output).todense()
output = clr(adj_mat)

output[np.isnan(output)] = 0
output[np.isposinf(output)] = 1

predicted = retrieve_adjacency_matrix(output)
true_matrix = pd.read_csv('true_CM.csv', header=None)
true_matrix = np.array(true_matrix)

shd = SHD(np.array(true_matrix), predicted, double_for_anticausal=False)
aupr, curve = precision_recall(np.array(true_matrix), output)

end_time = (time.time() - start_time)
print("--- Execution time : %4.4s seconds ---" % end_time)

results_cgnn = ['CGNN', aupr, shd, end_time]
print(results_cgnn)