Exemplo n.º 1
0
    def _update_distribution_and_lowerbound(self, m):
        r"""
        Find maximum likelihood estimate for the shape parameter

        Messages from children appear in the lower bound as

        .. math::

           m_0 \cdot x +  m_1 \cdot \log(\Gamma(x))

        Take derivative, put it zero and solve:

        .. math::

           m_0 + m_1 \cdot d\log(\Gamma(x)) &= 0
           \\
           m_0 + m_1 \cdot \psi(x) &= 0
           \\
           x &= \psi^{-1}(-\frac{m_0}{m_1})

        where :math:`\psi^{-1}` is the inverse digamma function.
        """

        # Maximum likelihood estimate
        x = misc.invpsi(-m[0] / m[1])

        # Compute moments
        self.u = self._moments.compute_fixed_moments(x)

        return
Exemplo n.º 2
0
    def _update_distribution_and_lowerbound(self, m):
        r"""
        Find maximum likelihood estimate for the concentration parameter
        """

        a = np.ones(self.D)
        da = np.inf
        logp = m[0] + self.regularization[0]
        N = m[1] + self.regularization[1]

        # Compute sufficient statistic
        mean_logp = logp / N[...,None]

        # It is difficult to estimate values lower than 0.02 because the
        # Dirichlet distributed probability vector starts to give numerically
        # zero random samples for lower values.
        if np.any(np.isinf(mean_logp)):
            raise ValueError(
                "Cannot estimate DirichletConcentration because of infs. This "
                "means that there are numerically zero probabilities in the "
                "child Dirichlet node."
            )

        # Fixed-point iteration
        while np.any(np.abs(da / a) > 1e-5):
            a_new = misc.invpsi(
                special.psi(np.sum(a, axis=-1, keepdims=True))
                + mean_logp
            )
            da = a_new - a
            a = a_new

        self.u = self._moments.compute_fixed_moments(a)

        return
Exemplo n.º 3
0
    def _update_distribution_and_lowerbound(self, m):
        r"""
        Find maximum likelihood estimate for the shape parameter

        Messages from children appear in the lower bound as

        .. math::

           m_0 \cdot x +  m_1 \cdot \log(\Gamma(x))

        Take derivative, put it zero and solve:

        .. math::

           m_0 + m_1 \cdot d\log(\Gamma(x)) &= 0
           \\
           m_0 + m_1 \cdot \psi(x) &= 0
           \\
           x &= \psi^{-1}(-\frac{m_0}{m_1})

        where :math:`\psi^{-1}` is the inverse digamma function.
        """

        # Maximum likelihood estimate
        x = misc.invpsi(-m[0]/m[1])

        # Compute moments
        self.u = self._moments.compute_fixed_moments(x)

        return
Exemplo n.º 4
0
    def _update_distribution_and_lowerbound(self, m):
        r"""
        Find maximum likelihood estimate for the concentration parameter
        """

        a = np.ones(self.D)
        da = np.inf
        logp = m[0] + self.regularization[0]
        N = m[1] + self.regularization[1]

        # Compute sufficient statistic
        mean_logp = logp / N[..., None]

        # It is difficult to estimate values lower than 0.02 because the
        # Dirichlet distributed probability vector starts to give numerically
        # zero random samples for lower values.
        if np.any(np.isinf(mean_logp)):
            raise ValueError(
                "Cannot estimate DirichletConcentration because of infs. This "
                "means that there are numerically zero probabilities in the "
                "child Dirichlet node.")

        # Fixed-point iteration
        while np.any(np.abs(da / a) > 1e-5):
            a_new = misc.invpsi(
                special.psi(np.sum(a, axis=-1, keepdims=True)) + mean_logp)
            da = a_new - a
            a = a_new

        self.u = self._moments.compute_fixed_moments(a)

        return