Example #1
0
 def test_entropy(self):
     with paddle.fluid.dygraph.guard(self.place):
         np.testing.assert_allclose(
             self._paddle_beta.entropy(),
             scipy.stats.beta.entropy(self.alpha, self.beta),
             rtol=RTOL.get(str(self._paddle_beta.alpha.numpy().dtype)),
             atol=ATOL.get(str(self._paddle_beta.alpha.numpy().dtype)))
 def test_entropy(self):
     with paddle.fluid.dygraph.guard(self.place):
         np.testing.assert_allclose(
             self._paddle_diric.entropy(),
             scipy.stats.dirichlet.entropy(self.concentration),
             rtol=RTOL.get(str(self.concentration.dtype)),
             atol=ATOL.get(str(self.concentration.dtype)))
Example #3
0
    def test_log_prob(self):
        value = [np.random.rand(*self._paddle_beta.alpha.shape)]

        for v in value:
            with paddle.fluid.dygraph.guard(self.place):
                np.testing.assert_allclose(
                    self._paddle_beta.log_prob(paddle.to_tensor(v)),
                    scipy.stats.beta.logpdf(v, self.alpha, self.beta),
                    rtol=RTOL.get(str(self._paddle_beta.alpha.numpy().dtype)),
                    atol=ATOL.get(str(self._paddle_beta.alpha.numpy().dtype)))
 def test_variance(self):
     with paddle.static.program_guard(self.program):
         [out] = self.executor.run(self.program,
                                   feed=self.feeds,
                                   fetch_list=[self._paddle_diric.variance])
         np.testing.assert_allclose(
             out,
             scipy.stats.dirichlet.var(self.concentration),
             rtol=RTOL.get(str(self.concentration.dtype)),
             atol=ATOL.get(str(self.concentration.dtype)))
 def test_mean(self):
     with paddle.static.program_guard(self.program):
         [mean] = self.executor.run(self.program,
                                    feed=self.feeds,
                                    fetch_list=[self._paddle_beta.mean])
         np.testing.assert_allclose(mean,
                                    scipy.stats.beta.mean(
                                        self.alpha, self.beta),
                                    rtol=RTOL.get(str(self.alpha.dtype)),
                                    atol=ATOL.get(str(self.alpha.dtype)))
    def test_log_prob(self):
        value = [np.random.rand(*self.concentration.shape)]
        value = [v / v.sum() for v in value]

        for v in value:
            with paddle.fluid.dygraph.guard(self.place):
                np.testing.assert_allclose(
                    self._paddle_diric.log_prob(paddle.to_tensor(v)),
                    scipy.stats.dirichlet.logpdf(v, self.concentration),
                    rtol=RTOL.get(str(self.concentration.dtype)),
                    atol=ATOL.get(str(self.concentration.dtype)))
 def test_log_prob(self):
     with paddle.static.program_guard(self.program):
         random_number = np.random.rand(*self.concentration.shape)
         random_number = random_number / random_number.sum()
         feeds = dict(self.feeds, value=random_number)
         value = paddle.static.data('value', random_number.shape,
                                    random_number.dtype)
         out = self._paddle_diric.log_prob(value)
         [out] = self.executor.run(self.program,
                                   feed=feeds,
                                   fetch_list=[out])
         np.testing.assert_allclose(
             out,
             scipy.stats.dirichlet.logpdf(random_number, self.concentration),
             rtol=RTOL.get(str(self.concentration.dtype)),
             atol=ATOL.get(str(self.concentration.dtype)))
 def test_log_prob(self):
     with paddle.static.program_guard(self.program):
         value = paddle.static.data('value', self._paddle_beta.alpha.shape,
                                    self._paddle_beta.alpha.dtype)
         prob = self._paddle_beta.log_prob(value)
         random_number = np.random.rand(*self._paddle_beta.alpha.shape)
         feeds = dict(self.feeds, value=random_number)
         [prob] = self.executor.run(self.program,
                                    feed=feeds,
                                    fetch_list=[prob])
         np.testing.assert_allclose(prob,
                                    scipy.stats.beta.logpdf(
                                        random_number, self.alpha,
                                        self.beta),
                                    rtol=RTOL.get(str(self.alpha.dtype)),
                                    atol=ATOL.get(str(self.alpha.dtype)))