Exemple #1
0
def gaussian_mixture_logpdf(x, w, mu, Sigma):
    # Shape(x)      = (N, D)
    # Shape(w)      = (K,)
    # Shape(mu)     = (K, D)
    # Shape(Sigma)  = (K, D, D)
    # Shape(result) = (N,)

    # Dimensionality
    D = np.shape(x)[-1]

    # Cholesky decomposition of the covariance matrix
    U = utils.m_chol(Sigma)

    # Reshape x:
    # Shape(x)     = (N, 1, D)
    x = np.expand_dims(x, axis=-2)

    # (x-mu) and (x-mu)'*inv(Sigma)*(x-mu):
    # Shape(v)     = (N, K, D)
    # Shape(z)     = (N, K)
    v = x - mu
    z = np.einsum('...i,...i', v, utils.m_chol_solve(U, v))

    # Log-determinant of Sigma:
    # Shape(ldet)  = (K,)
    ldet = utils.m_chol_logdet(U)

    # Compute log pdf for each cluster:
    # Shape(lpdf)  = (N, K)
    lpdf = utils.gaussian_logpdf(z, 0, 0, ldet, D)
Exemple #2
0
 def compute_fixed_u_and_f(Lambda):
     """ Compute u(x) and f(x) for given x. """
     k = np.shape(Lambda)[-1]
     ldet = utils.m_chol_logdet(utils.m_chol(Lambda))
     u = [Lambda, ldet]
     f = -(k + 1) / 2 * ldet
     return (u, f)
Exemple #3
0
def gaussian_mixture_logpdf(x, w, mu, Sigma):
    # Shape(x)      = (N, D)
    # Shape(w)      = (K,)
    # Shape(mu)     = (K, D)
    # Shape(Sigma)  = (K, D, D)
    # Shape(result) = (N,)

    # Dimensionality
    D = np.shape(x)[-1]

    # Cholesky decomposition of the covariance matrix
    U = utils.m_chol(Sigma)

    # Reshape x:
    # Shape(x)     = (N, 1, D)
    x = np.expand_dims(x, axis=-2)

    # (x-mu) and (x-mu)'*inv(Sigma)*(x-mu):
    # Shape(v)     = (N, K, D)
    # Shape(z)     = (N, K)
    v = x - mu
    z = np.einsum('...i,...i', v, utils.m_chol_solve(U, v))

    # Log-determinant of Sigma:
    # Shape(ldet)  = (K,)
    ldet = utils.m_chol_logdet(U)

    # Compute log pdf for each cluster:
    # Shape(lpdf)  = (N, K)
    lpdf = utils.gaussian_logpdf(z, 0, 0, ldet, D)
Exemple #4
0
 def compute_fixed_u_and_f(Lambda):
     """ Compute u(x) and f(x) for given x. """
     k = np.shape(Lambda)[-1]
     ldet = utils.m_chol_logdet(utils.m_chol(Lambda))
     u = [Lambda,
          ldet]
     f = -(k+1)/2 * ldet
     return (u, f)
Exemple #5
0
 def _compute_moments_and_cgf(phi, mask=True):
     U = utils.m_chol(-phi[0])
     k = np.shape(phi[0])[-1]
     #k = self.dims[0][0]
     logdet_phi0 = utils.m_chol_logdet(U)
     u0 = phi[1][..., np.newaxis, np.newaxis] * utils.m_chol_inv(U)
     u1 = -logdet_phi0 + utils.m_digamma(phi[1], k)
     u = [u0, u1]
     g = phi[1] * logdet_phi0 - special.multigammaln(phi[1], k)
     return (u, g)
Exemple #6
0
 def _compute_moments_and_cgf(phi, mask=True):
     U = utils.m_chol(-phi[0])
     k = np.shape(phi[0])[-1]
     #k = self.dims[0][0]
     logdet_phi0 = utils.m_chol_logdet(U)
     u0 = phi[1][...,np.newaxis,np.newaxis] * utils.m_chol_inv(U)
     u1 = -logdet_phi0 + utils.m_digamma(phi[1], k)
     u = [u0, u1]
     g = phi[1] * logdet_phi0 - special.multigammaln(phi[1], k)
     return (u, g)
Exemple #7
0
 def compute_fixed_moments(Lambda):
     """ Compute moments for fixed x. """
     ldet = utils.m_chol_logdet(utils.m_chol(Lambda))
     u = [Lambda, ldet]
     return u
Exemple #8
0
 def compute_fixed_moments(Lambda):
     """ Compute moments for fixed x. """
     ldet = utils.m_chol_logdet(utils.m_chol(Lambda))
     u = [Lambda,
          ldet]
     return u