コード例 #1
0
ファイル: test_models.py プロジェクト: zeou1/graspy
 def test_SBM_nparams(self):
     e = self.estimator.fit(self.graph, y=self.labels)
     assert e._n_parameters() == (4)
     e = SBMEstimator()
     e.fit(self.graph)
     assert e._n_parameters() == (4 + 1)
     e = SBMEstimator(directed=False)
     e.fit(self.graph)
     assert e._n_parameters() == (1 + 3)
コード例 #2
0
ファイル: test_models.py プロジェクト: zeou1/graspy
    def test_SBM_score(self):
        # tests score() and score_sample()
        B = np.array([[0.75, 0.25], [0.25, 0.75]])
        n_verts = 100
        n = np.array([n_verts, n_verts])
        tau = _n_to_labels(n)
        p_mat = _block_to_full(B, tau, shape=(n_verts * 2, n_verts * 2))
        graph = sample_edges(p_mat, directed=True)
        estimator = SBMEstimator(max_comm=4)
        _test_score(estimator, p_mat, graph)

        with pytest.raises(ValueError):
            estimator.score_samples(graph=graph[1:100, 1:100])
コード例 #3
0
ファイル: test_models.py プロジェクト: zeou1/graspy
    def test_SBM_fit_unsupervised(self):
        np.random.seed(12345)
        n_verts = 1500

        B = np.array([[0.7, 0.1, 0.1], [0.1, 0.9, 0.1], [0.05, 0.1, 0.75]])
        n = np.array([500, 500, 500])
        labels = _n_to_labels(n)
        p_mat = _block_to_full(B, labels, (n_verts, n_verts))
        p_mat -= np.diag(np.diag(p_mat))
        graph = sample_edges(p_mat, directed=True, loops=False)
        sbe = SBMEstimator(directed=True, loops=False)
        sbe.fit(graph)
        assert adjusted_rand_score(labels, sbe.vertex_assignments_) > 0.95
        assert_allclose(p_mat, sbe.p_mat_, atol=0.12)
コード例 #4
0
 def test_SBM_fit_supervised(self):
     np.random.seed(8888)
     B = np.array([
         [0.9, 0.2, 0.05, 0.1],
         [0.1, 0.7, 0.1, 0.1],
         [0.2, 0.4, 0.8, 0.5],
         [0.1, 0.2, 0.1, 0.7],
     ])
     n = np.array([500, 500, 250, 250])
     g = sbm(n, B, directed=True, loops=False)
     sbe = SBMEstimator(directed=True, loops=False)
     labels = _n_to_labels(n)
     sbe.fit(g, y=labels)
     B_hat = sbe.block_p_
     assert_allclose(B_hat, B, atol=0.01)
コード例 #5
0
ファイル: test_models.py プロジェクト: zeou1/graspy
 def setup_class(cls):
     estimator = SBMEstimator(directed=True, loops=False)
     B = np.array([[0.9, 0.1], [0.1, 0.9]])
     g = sbm([50, 50], B, directed=True)
     labels = _n_to_labels([50, 50])
     p_mat = _block_to_full(B, labels, (100, 100))
     p_mat -= np.diag(np.diag(p_mat))
     cls.estimator = estimator
     cls.p_mat = p_mat
     cls.graph = g
     cls.labels = labels
コード例 #6
0
 def setUp(self) -> None:
     estimator = SBMEstimator(directed=True, loops=False)
     B = np.array([[0.9, 0.1], [0.1, 0.9]])
     g = sbm([50, 50], B, directed=True)
     labels = _n_to_labels([50, 50])
     p_mat = _block_to_full(B, labels, (100, 100))
     p_mat -= np.diag(np.diag(p_mat))
     self.estimator = estimator
     self.p_mat = p_mat
     self.graph = g
     self.labels = labels
コード例 #7
0
ファイル: test_models.py プロジェクト: zeou1/graspy
    def test_SBM_inputs(self):
        with pytest.raises(TypeError):
            SBMEstimator(directed="hey")

        with pytest.raises(TypeError):
            SBMEstimator(loops=6)

        with pytest.raises(TypeError):
            SBMEstimator(n_components="XD")

        with pytest.raises(ValueError):
            SBMEstimator(n_components=-1)

        with pytest.raises(TypeError):
            SBMEstimator(min_comm="1")

        with pytest.raises(ValueError):
            SBMEstimator(min_comm=-1)

        with pytest.raises(TypeError):
            SBMEstimator(max_comm="ay")

        with pytest.raises(ValueError):
            SBMEstimator(max_comm=-1)

        with pytest.raises(ValueError):
            SBMEstimator(min_comm=4, max_comm=2)

        graph = er_np(100, 0.5)
        bad_y = np.zeros(99)
        sbe = SBMEstimator()
        with pytest.raises(ValueError):
            sbe.fit(graph, y=bad_y)

        with pytest.raises(ValueError):
            sbe.fit(graph[:, :99])

        with pytest.raises(ValueError):
            sbe.fit(graph[..., np.newaxis])

        with pytest.raises(TypeError):
            SBMEstimator(cluster_kws=1)

        with pytest.raises(TypeError):
            SBMEstimator(embed_kws=1)