Exemplo n.º 1
0
    def compute_moments_and_cgf(self, phi, mask=True):
        r"""
        Compute the moments and :math:`g(\phi)`.

        .. math::

           \overline{\mathbf{u}}
           = \mathrm{E}[x]
           = N \cdot \begin{bmatrix}
             \frac{e^{\phi_1}}{\sum_i e^{\phi_i}}
             & \cdots &
             \frac{e^{\phi_D}}{\sum_i e^{\phi_i}} \end{bmatrix}
        """
        # Compute the normalized probabilities in a numerically stable way
        (p, logsum_p) = misc.normalized_exp(phi[0])
        N = np.expand_dims(self.N, -1)
        u0 = N * p
        u = [u0]
        g = -np.squeeze(N * logsum_p, axis=-1)
        return (u, g)
Exemplo n.º 2
0
    def compute_moments_and_cgf(self, phi, mask=True):
        r"""
        Compute the moments and :math:`g(\phi)`.

        .. math::

           \overline{\mathbf{u}}
           = \mathrm{E}[x]
           = N \cdot \begin{bmatrix}
             \frac{e^{\phi_1}}{\sum_i e^{\phi_i}}
             & \cdots &
             \frac{e^{\phi_D}}{\sum_i e^{\phi_i}} \end{bmatrix}
        """
        # Compute the normalized probabilities in a numerically stable way
        (p, logsum_p) = misc.normalized_exp(phi[0])
        N = np.expand_dims(self.N, -1)
        u0 = N * p
        u = [u0]
        g = -np.squeeze(N * logsum_p, axis=-1)
        return (u, g)
Exemplo n.º 3
0
 def random(self, *phi, plates=None):
     r"""
     Draw a random sample from the distribution.
     """
     (p, _) = misc.normalized_exp(phi[0])
     return random.multinomial(self.N, p, size=plates)
Exemplo n.º 4
0
 def random(self, *phi, plates=None):
     r"""
     Draw a random sample from the distribution.
     """
     (p, _) = misc.normalized_exp(phi[0])
     return random.multinomial(self.N, p, size=plates)