Exemplo n.º 1
0
    def test_opt_soft_shape_error_1(self):
        A = np.zeros((2, 3), dtype=np.float64)
        scvecs = np.zeros((3, 4))
        scvecs[:, 0] = 1.0

        with pytest.raises(ValueError,
                           match="Rotation matrix isn't quadratic."):
            _opt_soft(scvecs, A)
Exemplo n.º 2
0
    def test_opt_soft_shape_error_3(self):
        A = np.zeros((1, 1), dtype=np.float64)
        scvecs = np.zeros((1, 1))
        scvecs[:, 0] = 1.0

        with pytest.raises(
                ValueError,
                match=
                r"Expected the rotation matrix to be at least of shape \(2, 2\)",
        ):
            _opt_soft(scvecs, A)
Exemplo n.º 3
0
    def test_opt_soft_shape_error_2(self):
        A = np.zeros((3, 3), dtype=np.float64)
        scvecs = np.zeros((2, 4))
        scvecs[:, 0] = 1.0

        with pytest.raises(
                ValueError,
                match=
                "The dimensions of the rotation matrix don't match with the number of Schur vectors.",
        ):
            _opt_soft(scvecs, A)
Exemplo n.º 4
0
    def test_opt_soft_nelder_mead_mu1000(self, svecs_mu1000: np.ndarray,
                                         A_mu1000: np.ndarray):
        A, chi, fopt = _opt_soft(svecs_mu1000, A_mu1000)

        crispness = np.true_divide(5 - fopt, 5)

        assert_allclose(crispness, 0.804, atol=0.0025)
Exemplo n.º 5
0
    def test_opt_soft_nelder_mead_mu0(self, svecs_mu0: np.ndarray,
                                      A_mu0: np.ndarray):
        A, chi, fopt = _opt_soft(svecs_mu0, A_mu0)

        crispness = np.true_divide(3 - fopt, 3)

        assert_allclose(crispness, 0.973, atol=1e-3)
Exemplo n.º 6
0
    def test_opt_soft_nelder_mead_more(self):
        kmin, kmax = 2, 8
        kopt = []
        ks = np.arange(kmin, kmax)

        for mu_ in [10, 50, 100, 200, 500, 1000]:
            mu_ = mu(mu_)
            P, sd = get_known_input(mu_)
            X, _, _ = _do_schur(P, eta=sd, m=kmax)

            crisp = [-np.inf] * (kmax - kmin)
            for j, k in enumerate(range(kmin, kmax)):
                svecs = X[:, :k]
                A = _initialize_rot_matrix(svecs)

                _, _, fopt = _opt_soft(svecs, A)
                crisp[j] = (k - fopt) / k

            kopt.append(ks[np.argmax(crisp)])

        np.testing.assert_array_equal(kopt, [3, 3, 3, 2, 2, 7])