Пример #1
0
    def test_multipletargets_generic(
            self, makemockrulelist,
            makemockgaussianfree_multipletarget_generic):
        mockgaussianfreestatistic = makemockgaussianfree_multipletarget_generic
        mockrulelist = makemockrulelist

        actual_length = length_rule_free_gaussian(mockrulelist,
                                                  mockgaussianfreestatistic)
        n = 100000
        var1 = 100
        var2 = 150

        expected =  1 + n/2*log2(pi) - gammaln(n/2)/log(2) + 0.5*log2(n+1) + n/2*log2(n*var1)+\
                    1 + n / 2 * log2(pi) - gammaln(n / 2) / log(2) + 0.5 * log2(n + 1) + n / 2 * log2(n * var2)

        assert expected == pytest.approx(actual_length, rel=1e-3)
Пример #2
0
    def test_all_large(self):
        input_n = 100000
        input_variance = 100000
        input_log_gamma_n = gammaln(input_n / 2) / log(2)
        actual_length = gaussian_bayesian_encoding(input_n, input_variance,
                                                   input_log_gamma_n)

        expected_length = 1035207.3661371232
        assert expected_length == pytest.approx(actual_length)
Пример #3
0
    def test_variance_zero(self):
        input_n = 2
        input_variance = 0
        input_log_gamma_n = gammaln(input_n / 2) / log(2)
        actual_length = gaussian_bayesian_encoding(input_n, input_variance,
                                                   input_log_gamma_n)

        expected_length = np.inf
        assert expected_length == actual_length
Пример #4
0
    def test_n_two(self):
        input_n = 2
        input_variance = 100
        input_log_gamma_n = gammaln(input_n / 2) / log(2)
        actual_length = gaussian_bayesian_encoding(input_n, input_variance,
                                                   input_log_gamma_n)

        expected_length = 11.087833569607621
        assert expected_length == pytest.approx(actual_length)
    def test_multivariate_students_t(self, i: int):
        mixture = self._init_mixture(self.D, self.prior)

        mu = mixture.prior.m_0
        v = mixture.prior.v_0 + i

        cov = np.array([[5.5, -1.1], [-1.1, 6.6]])
        logdet_cov = np.linalg.slogdet(cov)[1]
        inv_cov = np.linalg.inv(cov)

        delta = mixture.X[i] - mu
        stud = (+gammaln((v + self.D) / 2.) - gammaln(v / 2.) -
                self.D / 2. * math.log(v) - self.D / 2. * math.log(np.pi) -
                0.5 * logdet_cov - (v + self.D) / 2. *
                math.log(1 + 1. / v * np.dot(np.dot(delta, inv_cov), delta)))

        assert_almost_equal(
            mixture._multivariate_students_t(i, mu, logdet_cov, inv_cov, v),
            stud)
Пример #6
0
    def test_multipletargets_onetarget_simple(self, makemockrulelist,
                                              makemockgaussianfree_onetarget):
        mockgaussianfreestatistic = makemockgaussianfree_onetarget
        mockrulelist = makemockrulelist

        actual_length = length_rule_free_gaussian(mockrulelist,
                                                  mockgaussianfreestatistic)
        n = 100000
        var = 3
        expected = 1 + n / 2 * log2(pi) - gammaln(
            n / 2) / log(2) + 0.5 * log2(n + 1) + n / 2 * log2(n * var)
        assert expected == pytest.approx(actual_length, rel=1e-3)
 def _cache(self, N: int):
     """Execute pre-calculations"""
     n = np.concatenate([[1], np.arange(1, self.prior.v_0 + N + 2)
                         ])  # first element is dummy for indexing
     self._log_v = np.log(n)
     self._gammaln_by_2 = np.array([gammaln(n_i / 2) for n_i in n])