Ejemplo n.º 1
0
    def test_P_2_LR(
        self,
        P_2: np.ndarray,
        minChi_P_2_LR: np.ndarray,
        crispness_values_P_2_LR: np.ndarray,
        optimal_crispness_P_2_LR: np.float64,
        n_m_P_2_LR: np.int64,
        top_eigenvalues_P_2_LR: np.ndarray,
        method: str,
    ):
        if method == "krylov":
            pytest.importorskip("mpi4py")
            pytest.importorskip("petsc4py")
            pytest.importorskip("slepc4py")

        g = GPCCA(P_2, eta=None, z="LR", method=method)

        # The following very crude minChi testing is necessary,
        # since the initial guess for the rotation matrix and thus minChi can vary.
        minChi = g.minChi(2, 12)
        assert len(minChi) == len(minChi_P_2_LR)
        assert minChi[0] > -1e-08
        assert minChi[1] > -1e-08
        assert minChi[3] > -1e-01
        assert minChi[10] > -1e-08

        g.optimize({"m_min": 2, "m_max": 12})
        n_m = g.n_m

        assert_allclose(g.crispness_values, crispness_values_P_2_LR)
        assert_allclose(g.optimal_crispness, optimal_crispness_P_2_LR)
        assert_allclose(n_m, n_m_P_2_LR)
        assert_allclose(g.top_eigenvalues, top_eigenvalues_P_2_LR)
        assert_allclose(g.dominant_eigenvalues, top_eigenvalues_P_2_LR[:n_m])
Ejemplo n.º 2
0
    def test_use_minChi(self):
        kmin, kmax = 2, 9
        kopt = []

        for mu_ in [10, 50, 100, 200, 500, 1000]:
            P, sd = get_known_input(mu(mu_))
            g = GPCCA(P, eta=sd)
            minChi = g.minChi(kmin, kmax)

            kopt.append(kmax - 1 - np.argmax(np.flipud(minChi[1:-1])))

        np.testing.assert_array_equal(kopt, [3] * 5 + [7])
Ejemplo n.º 3
0
 def test_k_input(self, P: np.ndarray, sd: np.ndarray):
     g = GPCCA(P, eta=sd)
     with pytest.raises(
             ValueError,
             match=r"m_min \(5\) must be smaller than m_max \(3\)."):
         g.minChi(m_min=5, m_max=3)
Ejemplo n.º 4
0
 def test_too_small_kkmin(self, P: np.ndarray, sd: np.ndarray):
     g = GPCCA(P, eta=sd)
     with pytest.raises(
             ValueError,
             match=r"There is no point in clustering into `0` clusters."):
         g.minChi(m_min=0, m_max=10)