Exemple #1
0
def test_scratch_CGNN():
    data = pd.read_csv('{}/../datasets/NUM_LUCAS.csv'.format(
        os.path.dirname(os.path.realpath(__file__)))).iloc[:50, :3]

    # Finding the structure of the graph
    # List results
    # print(nx.adj_matrix(ugraph).todense().shape)
    # Orient the edges of the graph

    Cgnn = CGNN(nruns=1, train_epochs=2, test_epochs=2)
    assert type(Cgnn.predict(data)) == nx.DiGraph

    return 0
def test_multiprocessing_CGNN():
    data = pd.read_csv('{}/../datasets/NUM_LUCAS.csv'.format(
        os.path.dirname(os.path.realpath(__file__)))).iloc[:50, :3]

    # Finding the structure of the graph
    Fsgnn = FSGNN(train_epochs=5, test_epochs=5, l1=0.006, njobs=2)

    ugraph = Fsgnn.predict(data, threshold=1e-2)
    # List results
    # print(nx.adj_matrix(ugraph).todense().shape)
    # Orient the edges of the graph
    Cgnn = CGNN(nruns=6, njobs=2, train_epochs=2, test_epochs=2)
    assert type(Cgnn.predict(data, graph=ugraph)) == nx.DiGraph
    return 0
def test_pipeline_CGNN():
    data = pd.read_csv('{}/../datasets/NUM_LUCAS.csv'.format(os.path.dirname(os.path.realpath(__file__)))).iloc[:50, :3]

    # Finding the structure of the graph
    Fsgnn = FSGNN()

    ugraph = Fsgnn.predict(data, train_epochs=5, test_epochs=5, threshold=1e-2, l1=0.006)
    # List results
    # print(nx.adj_matrix(ugraph).todense().shape)
    # Orient the edges of the graph

    Cgnn = CGNN(nb_runs=1, train_epochs=2, test_epochs=2)
    Cgnn.predict(data, graph=ugraph)
    return 0
type_variables["ses"] = "Numerical"
type_variables["eth"] = "Categorical"
type_variables["psu"] = "Categorical"
type_variables["stra"] = "Categorical"
type_variables["bmi"] = "Numerical"
type_variables["wt"] = "Numerical"
type_variables["bmi_two_class"] = "Categorical"

#Fsgnn = FSGNN()
#start_time = time.time()
#ugraph = Fsgnn.create_skeleton_from_data(data)
#print("--- Execution time : %s seconds ---" % (time.time() - start_time))
#ugraph.plot()
# List results
#pd.DataFrame(ugraph.list_edges())

from cdt.causality.graph import CGNN

Cgnn = CGNN(backend="TensorFlow")
start_time = time.time()
#dgraph = Cgnn.predict(data, graph=ugraph, type_variables = type_variables)

dgraph = Cgnn.create_graph_from_data(data, type_variables=type_variables)

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

# Plot the output graph
dgraph.plot()
# Print output results :
print(dgraph.list_edges())
Exemple #5
0
    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


# 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)