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))
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]
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 ]
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)
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)
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)
def compute_fixed_moments(x): """ Compute moments for fixed x. """ return [x, utils.m_outer(x, x)]
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)
def compute_fixed_moments(x): """ Compute moments for fixed x. """ return [x, utils.m_outer(x,x)]