예제 #1
0
def sample_features(model, data, state):
    K, D = state.Z.shape[1], state.X.shape[1]

    Lambda = np.dot(state.Z.T, state.Z) / state.sigma_sq_n + np.eye(K) / state.sigma_sq_f
    h = np.dot(state.Z.T, state.X) / state.sigma_sq_n

    # we can ignore the constant factors because they don't depend on Z
    pot = gaussians.Potential(h.T, psd_matrices.FullMatrix(Lambda[nax, :, :]), 0.)
    return pot.to_distribution().sample().T
예제 #2
0
def evidence(model, data, state):
    K, D = state.Z.shape[1], state.X.shape[1]

    Lambda = np.dot(state.Z.T, state.Z) / state.sigma_sq_n + np.eye(K) / state.sigma_sq_f
    h = np.dot(state.Z.T, state.X) / state.sigma_sq_n

    # we can ignore the constant factors because they don't depend on Z
    pot = gaussians.Potential(h.T, psd_matrices.FullMatrix(Lambda[nax, :, :]), 0.)
    return pot.integral().sum()
def cond_U(X, obs, V, ssq_U, ssq_N):
    N, K, D = X.shape[0], V.shape[0], X.shape[1]
    if np.all(obs):
        Lambda = np.diag(1. / ssq_U) + np.dot(V, V.T) / ssq_N
        Lambda = Lambda[nax, :, :]
    else:
        Lambda = np.zeros((N, K, K))
        for i in range(N):
            idxs = np.where(obs[i, :])[0]
            V_curr = V[:, idxs]
            Lambda[i, :, :] = np.diag(1. / ssq_U) + np.dot(V_curr, V_curr.T) / ssq_N
    h = np.dot(X * obs, V.T) / ssq_N
    return gaussians.Potential(h, psd_matrices.FullMatrix(Lambda), 0.)
예제 #4
0
 def from_moments_diag(mu, sigma_sq, Z=0.):
     return Distribution(mu, psd_matrices.FullMatrix(np.diag(sigma_sq)), Z)
예제 #5
0
 def from_moments_full(mu, Sigma, Z=0.):
     return Distribution(mu, psd_matrices.FullMatrix(Sigma), Z)
예제 #6
0
 def from_moments_full(mu, Sigma):
     return Distribution(mu, psd_matrices.FullMatrix(Sigma)).to_potential()