def test_DCER_score(self): p_mat = self.p_mat graph = self.graph estimator = DCEREstimator() _test_score(estimator, p_mat, graph) with pytest.raises(ValueError): estimator.score_samples(graph=graph[1:500, 1:500])
def test_DCER_inputs(self): with pytest.raises(TypeError): DCEREstimator(directed="hey") with pytest.raises(TypeError): DCEREstimator(loops=6) graph = er_np(100, 0.5) dcere = DCEREstimator() with pytest.raises(ValueError): dcere.fit(graph[:, :99]) with pytest.raises(ValueError): dcere.fit(graph[..., np.newaxis])
def test_DCER_sample(self): np.random.seed(8888) estimator = DCEREstimator(directed=True, loops=False) g = self.graph p_mat = self.p_mat with pytest.raises(NotFittedError): estimator.sample() estimator.fit(g) with pytest.raises(ValueError): estimator.sample(n_samples=-1) with pytest.raises(TypeError): estimator.sample(n_samples="nope") B = 0.5 dc = np.random.uniform(0.25, 0.75, size=100) p_mat = np.outer(dc, dc) * B p_mat -= np.diag(np.diag(p_mat)) g = sample_edges(p_mat, directed=True) estimator.fit(g) estimator.p_mat_ = p_mat _test_sample(estimator, p_mat, n_samples=1000, atol=0.2)
def test_DCER_nparams(self): n_verts = 1000 graph = self.graph e = DCEREstimator(directed=True) e.fit(graph) assert e._n_parameters() == (n_verts + 1)
return null def compute_pvalues(p_upper, null): row = {} row["estimated_p_upper"] = p_upper ind = np.searchsorted(null, p_upper) row["pvalue"] = 1 - ind / len( null) # TODO make more exact but this is roughly right for one sided return row edge_types = ["ad", "aa", "dd", "da"] null_estimators = { "ER": EREstimator(directed=True, loops=False), "DCER": DCEREstimator(directed=True, loops=False, degree_directed=False), } rerun_test = False if rerun_test: currtime = time.time() n_null_samples = 100 statistics = [] for edge_type in edge_types: print(f"Edge type = {edge_type}") edge_type_adj = mg.to_edge_type_graph(edge_type).adj edge_type_adj = binarize(edge_type_adj) largest_connected_component(edge_type_adj)