Exemplo n.º 1
0
 def show(self):
     mu = self.u[0]
     Cov = self.u[1] - utils.m_outer(mu, mu)
     print("%s ~ Gaussian(mu, Cov)" % self.name)
     print("  mu = ")
     print(mu)
     print("  Cov = ")
     print(str(Cov))
Exemplo n.º 2
0
 def show(self):
     mu = self.u[0]
     Cov = self.u[1] - utils.m_outer(mu, mu)
     print("%s ~ Gaussian(mu, Cov)" % self.name)
     print("  mu = ")
     print(mu)
     print("  Cov = ")
     print(str(Cov))
Exemplo n.º 3
0
 def compute_message(index, u, u_parents):
     """ . """
     if index == 0:
         return [utils.m_dot(u_parents[1][0], u[0]),
                 -0.5 * u_parents[1][0]]
     elif index == 1:
         xmu = utils.m_outer(u[0], u_parents[0][0])
         return [-0.5 * (u[1] - xmu - xmu.swapaxes(-1,-2) + u_parents[0][1]),
                 0.5]
Exemplo n.º 4
0
 def compute_message(index, u, u_parents):
     """ . """
     if index == 0:
         return [utils.m_dot(u_parents[1][0], u[0]), -0.5 * u_parents[1][0]]
     elif index == 1:
         xmu = utils.m_outer(u[0], u_parents[0][0])
         return [
             -0.5 * (u[1] - xmu - xmu.swapaxes(-1, -2) + u_parents[0][1]),
             0.5
         ]
Exemplo n.º 5
0
 def compute_u_and_g(phi, mask=True):
     #print(-phi[1])
     L = utils.m_chol(-phi[1])
     k = np.shape(phi[0])[-1]
     # Moments
     u0 = utils.m_chol_solve(L, 0.5 * phi[0])
     u1 = utils.m_outer(u0, u0) + 0.5 * utils.m_chol_inv(L)
     u = [u0, u1]
     # G
     g = (-0.5 * np.einsum('...i,...i', u[0], phi[0]) +
          0.5 * utils.m_chol_logdet(L) + 0.5 * np.log(2) * k)
     #+ 0.5 * np.log(2) * self.dims[0][0])
     return (u, g)
Exemplo n.º 6
0
 def compute_u_and_g(phi, mask=True):
     #print(-phi[1])
     L = utils.m_chol(-phi[1])
     k = np.shape(phi[0])[-1]
     # Moments
     u0 = utils.m_chol_solve(L, 0.5*phi[0])
     u1 = utils.m_outer(u0, u0) + 0.5 * utils.m_chol_inv(L)
     u = [u0, u1]
     # G
     g = (-0.5 * np.einsum('...i,...i', u[0], phi[0])
          + 0.5 * utils.m_chol_logdet(L)
          + 0.5 * np.log(2) * k)
          #+ 0.5 * np.log(2) * self.dims[0][0])
     return (u, g)
Exemplo n.º 7
0
 def compute_fixed_u_and_f(x):
     """ Compute u(x) and f(x) for given x. """
     k = np.shape(x)[-1]
     u = [x, utils.m_outer(x, x)]
     f = -k / 2 * np.log(2 * np.pi)
     return (u, f)
Exemplo n.º 8
0
 def compute_fixed_moments(x):
     """ Compute moments for fixed x. """
     return [x, utils.m_outer(x, x)]
Exemplo n.º 9
0
 def compute_fixed_u_and_f(x):
     """ Compute u(x) and f(x) for given x. """
     k = np.shape(x)[-1]
     u = [x, utils.m_outer(x,x)]
     f = -k/2*np.log(2*np.pi)
     return (u, f)
Exemplo n.º 10
0
 def compute_fixed_moments(x):
     """ Compute moments for fixed x. """
     return [x, utils.m_outer(x,x)]