Exemple #1
0
    def test_std_usage(self):
        zikm = eda.ZeroIGKdeMdl(self.x)
        np.testing.assert_allclose(zikm.x, self.x)

        assert zikm.x is not self.x
        np.testing.assert_allclose(zikm.x_nonzero, self.x[50:250])

        np.testing.assert_allclose(zikm.mdl, zikm.zi_mdl + zikm.kde_mdl)

        np.testing.assert_allclose(
            zikm.zi_mdl,
            np.log(3) + eda.MultinomialMdl(self.x != 0).mdl)

        assert zikm._bw_method == "scott"

        assert zikm.bandwidth is not None

        # test > 0 value kde same
        zikm2 = eda.ZeroIGKdeMdl(self.x[50:250])
        np.testing.assert_allclose(zikm2.kde_mdl, zikm.kde_mdl)
        np.testing.assert_allclose(zikm2.bandwidth, zikm.bandwidth)
Exemple #2
0
    def test_encode(self):
        # retrospect
        np.testing.assert_allclose(
            eda.MultinomialMdl([0]).mdl,
            eda.MultinomialMdl([0]).mdl)

        np.testing.assert_allclose(
            eda.MultinomialMdl(np.arange(10)).mdl,
            eda.MultinomialMdl(np.arange(10)).mdl)

        np.testing.assert_allclose(
            eda.MultinomialMdl([0, 1, 2, 10, -10]).mdl,
            eda.MultinomialMdl([0, 1, 2, 10, -10]).mdl)

        np.testing.assert_allclose(
            eda.MultinomialMdl([0]).encode([0, 1, 5, 100, 200, -20],
                                           use_adjescent_when_absent=True), 0)

        np.testing.assert_allclose(
            eda.MultinomialMdl([0]).encode([0, 1, 5, 100, 200, -20],
                                           use_adjescent_when_absent=False),
            np.log(200 * 2) * 5)

        np.testing.assert_allclose(
            eda.MultinomialMdl([]).encode([0, 1, 5, 100, 200, -20],
                                          use_adjescent_when_absent=False),
            np.log(200 * 2) * 6)

        np.testing.assert_allclose(
            eda.MultinomialMdl([0]).encode([0, 1, 5, 100, 200, -20]),
            np.log(200 * 2) * 5)

        assert eda.MultinomialMdl([0]).encode([]) == 0

        np.testing.assert_allclose(
            eda.MultinomialMdl([0, 0, 3, 3,
                                3]).encode([-20, 0, 2, 5, 100, 200],
                                           use_adjescent_when_absent=True),
            -np.log(0.4) * 2 - np.log(0.6) * 4)

        np.testing.assert_allclose(
            eda.MultinomialMdl([0, 0, 3, 3,
                                3]).encode([-20, 1, 1.5, 2, 100, 200],
                                           use_adjescent_when_absent=True),
            -np.log(0.4) * 2 - np.log(0.6) * 4)
Exemple #3
0
 def test_getter(self):
     mmdl = eda.MultinomialMdl([])
     assert mmdl.x.tolist() == []
     mmdl2 = eda.MultinomialMdl([0, 0, 1, 1, 1])
     assert mmdl2.x.tolist() == [0, 0, 1, 1, 1]
Exemple #4
0
 def test_multi_levels(self):
     x = [1] * 10 + [2] * 25
     _, uxcnt = np.unique(x, return_counts=True)
     mmdl = eda.MultinomialMdl(x)
     np.testing.assert_allclose(mmdl.mdl,
                                (-np.log(uxcnt / len(x)) * uxcnt).sum())
Exemple #5
0
 def test_single_level(self):
     mmdl = eda.MultinomialMdl([1] * 10)
     np.testing.assert_allclose(mmdl.mdl, np.log(10))
Exemple #6
0
 def test_empty_x(self):
     mmdl = eda.MultinomialMdl([])
     assert mmdl.mdl == 0