10
10
11
11
12
12
######################################### Test Notes ###########################################
13
- # All the benchmark results of loaded files (e.g. ". /TestData/benchmark_returned_results/") #
13
+ # All the benchmark results of loaded files (e.g. "tests /TestData/benchmark_returned_results/")#
14
14
# are obtained from the code of causal-learn as of commit #
15
15
# https://github.com/cmu-phil/causal-learn/commit/b51d788 (07-08-2022). #
16
16
# #
23
23
24
24
25
25
BENCHMARK_TXTFILE_TO_MD5 = {
26
- ". /TestData/data_linear_10.txt" : "95a17e15038d4cade0845140b67c05a6" ,
27
- ". /TestData/data_discrete_10.txt" : "ccb51c6c1946d8524a8b29a49aef2cc4" ,
28
- ". /TestData/graph.10.txt" : "4970d4ecb8be999a82a665e5f5e0825b" ,
29
- ". /TestData/test_ges_simulated_linear_gaussian_data.txt" : "0d2490eeb9ee8ef3b18bf21d7e936e1e" ,
30
- ". /TestData/test_ges_simulated_linear_gaussian_CPDAG.txt" : "aa0146777186b07e56421ce46ed52914" ,
31
- ". /TestData/benchmark_returned_results/linear_10_ges_local_score_BIC_none_none.txt" : "3accb3673d2ccb4c110f3703d60fe702" ,
32
- ". /TestData/benchmark_returned_results/discrete_10_ges_local_score_BDeu_none_none.txt" : "eebd11747c1b927b2fdd048a55c8c3a5" ,
26
+ "tests /TestData/data_linear_10.txt" : "95a17e15038d4cade0845140b67c05a6" ,
27
+ "tests /TestData/data_discrete_10.txt" : "ccb51c6c1946d8524a8b29a49aef2cc4" ,
28
+ "tests /TestData/graph.10.txt" : "4970d4ecb8be999a82a665e5f5e0825b" ,
29
+ "tests /TestData/test_ges_simulated_linear_gaussian_data.txt" : "0d2490eeb9ee8ef3b18bf21d7e936e1e" ,
30
+ "tests /TestData/test_ges_simulated_linear_gaussian_CPDAG.txt" : "aa0146777186b07e56421ce46ed52914" ,
31
+ "tests /TestData/benchmark_returned_results/linear_10_ges_local_score_BIC_none_none.txt" : "3accb3673d2ccb4c110f3703d60fe702" ,
32
+ "tests /TestData/benchmark_returned_results/discrete_10_ges_local_score_BDeu_none_none.txt" : "eebd11747c1b927b2fdd048a55c8c3a5" ,
33
33
}
34
34
35
35
INCONSISTENT_RESULT_GRAPH_ERRMSG = "Returned graph is inconsistent with the benchmark. Please check your code with the commit b51d788."
@@ -47,8 +47,8 @@ class TestGES(unittest.TestCase):
47
47
# Load data from file "data_linear_10.txt". Run GES with local_score_BIC.
48
48
def test_ges_load_linear_10_with_local_score_BIC (self ):
49
49
print ('Now start test_ges_load_linear_10_with_local_score_BIC ...' )
50
- data_path = ". /TestData/data_linear_10.txt"
51
- truth_graph_path = ". /TestData/graph.10.txt"
50
+ data_path = "tests /TestData/data_linear_10.txt"
51
+ truth_graph_path = "tests /TestData/graph.10.txt"
52
52
data = np .loadtxt (data_path , skiprows = 1 )
53
53
truth_dag = txt2generalgraph (truth_graph_path ) # truth_dag is a GeneralGraph instance
54
54
truth_cpdag = dag2cpdag (truth_dag )
@@ -58,7 +58,7 @@ def test_ges_load_linear_10_with_local_score_BIC(self):
58
58
res_map = ges (data , score_func = 'local_score_BIC' , maxP = None , parameters = None ) # Run GES and obtain the estimated graph (res_map is Dict object,which contains the updated steps, the result causal graph and the result score.)
59
59
60
60
benchmark_returned_graph = np .loadtxt (
61
- ". /TestData/benchmark_returned_results/linear_10_ges_local_score_BIC_none_none.txt" )
61
+ "tests /TestData/benchmark_returned_results/linear_10_ges_local_score_BIC_none_none.txt" )
62
62
assert np .all (res_map ['G' ].graph == benchmark_returned_graph ), INCONSISTENT_RESULT_GRAPH_ERRMSG
63
63
shd = SHD (truth_cpdag , res_map ['G' ])
64
64
print (f" ges(data, score_func='local_score_BIC', maxP=None, parameters=None)\t SHD: { shd .get_shd ()} of { num_edges_in_truth } " )
@@ -73,9 +73,9 @@ def test_ges_simulate_linear_gaussian_with_local_score_BIC(self):
73
73
truth_DAG_directed_edges = {(0 , 1 ), (0 , 3 ), (1 , 2 ), (1 , 3 ), (2 , 3 ), (2 , 4 ), (3 , 4 )}
74
74
truth_CPDAG_directed_edges = {(0 , 3 ), (1 , 3 ), (2 , 3 ), (2 , 4 ), (3 , 4 )}
75
75
truth_CPDAG_undirected_edges = {(0 , 1 ), (1 , 2 ), (2 , 1 ), (1 , 0 )}
76
- truth_CPDAG = np .loadtxt (". /TestData/test_ges_simulated_linear_gaussian_CPDAG.txt" )
76
+ truth_CPDAG = np .loadtxt ("tests /TestData/test_ges_simulated_linear_gaussian_CPDAG.txt" )
77
77
78
- ###### Simulation configuration: code to generate ". /TestData/test_ges_simulated_linear_gaussian_data.txt" ######
78
+ ###### Simulation configuration: code to generate "tests /TestData/test_ges_simulated_linear_gaussian_data.txt" ######
79
79
# np.random.seed(42)
80
80
# linear_weight_minabs, linear_weight_maxabs, linear_weight_netative_prob = 0.5, 0.9, 0.5
81
81
# sample_size = 10000
@@ -89,10 +89,10 @@ def test_ges_simulate_linear_gaussian_with_local_score_BIC(self):
89
89
# mixing_matrix = np.linalg.inv(np.eye(num_of_nodes) - adjacency_matrix)
90
90
# exogenous_noise = np.random.normal(0, 1, (num_of_nodes, sample_size))
91
91
# data = (mixing_matrix @ exogenous_noise).T
92
- # np.savetxt(". /TestData/test_ges_simulated_linear_gaussian_data.txt", data)
93
- ###### Simulation configuration: code to generate ". /TestData/test_ges_simulated_linear_gaussian_data.txt" ######
92
+ # np.savetxt("tests /TestData/test_ges_simulated_linear_gaussian_data.txt", data)
93
+ ###### Simulation configuration: code to generate "tests /TestData/test_ges_simulated_linear_gaussian_data.txt" ######
94
94
95
- data = np .loadtxt (". /TestData/test_ges_simulated_linear_gaussian_data.txt" )
95
+ data = np .loadtxt ("tests /TestData/test_ges_simulated_linear_gaussian_data.txt" )
96
96
97
97
# Run GES with default parameters: score_func='local_score_BIC', maxP=None, parameters=None
98
98
res_map = ges (data , score_func = 'local_score_BIC' , maxP = None , parameters = None )
@@ -105,8 +105,8 @@ def test_ges_simulate_linear_gaussian_with_local_score_BIC(self):
105
105
# Load data from file "data_discrete_10.txt". Run GES with local_score_BDeu.
106
106
def test_ges_load_discrete_10_with_local_score_BDeu (self ):
107
107
print ('Now start test_ges_load_discrete_10_with_local_score_BDeu ...' )
108
- data_path = ". /TestData/data_discrete_10.txt"
109
- truth_graph_path = ". /TestData/graph.10.txt"
108
+ data_path = "tests /TestData/data_discrete_10.txt"
109
+ truth_graph_path = "tests /TestData/graph.10.txt"
110
110
data = np .loadtxt (data_path , skiprows = 1 )
111
111
truth_dag = txt2generalgraph (truth_graph_path ) # truth_dag is a GeneralGraph instance
112
112
truth_cpdag = dag2cpdag (truth_dag )
@@ -115,7 +115,7 @@ def test_ges_load_discrete_10_with_local_score_BDeu(self):
115
115
# Run GES with local_score_BDeu.
116
116
res_map = ges (data , score_func = 'local_score_BDeu' , maxP = None , parameters = None )
117
117
benchmark_returned_graph = np .loadtxt (
118
- ". /TestData/benchmark_returned_results/discrete_10_ges_local_score_BDeu_none_none.txt" )
118
+ "tests /TestData/benchmark_returned_results/discrete_10_ges_local_score_BDeu_none_none.txt" )
119
119
assert np .all (res_map ['G' ].graph == benchmark_returned_graph ), INCONSISTENT_RESULT_GRAPH_ERRMSG
120
120
shd = SHD (truth_cpdag , res_map ['G' ])
121
121
print (f" ges(data, score_func='local_score_BDeu', maxP=None, parameters=None)\t SHD: { shd .get_shd ()} of { num_edges_in_truth } " )
0 commit comments