Beispiel #1
0
def gaussian_meanfield(gaussian_globals, node_potentials, label_stats):
    # Ref. Eq 39
    # gaussian_globals = E_{q(\mu, \Sigma)}[t(\mu, \Sigma)] here q(\mu, \Sigma) is posterior which is NIW. Shape = (K, 4, 4)
    # label_stats = E_{q(z)}[t(z)] -> categorical expected statistics. Shape = (batch_size, K)
    # stats = E_{q(z)}[t(z)] -> Gaussian expected statistics Shape = (batch_size, 4, 4)
    # node_potentials = r(\phi, y) Shape = (batch_size, 4, 4)
    #print gaussian_globals.shape, node_potentials.shape, label_stats.shape
    global_potentials = np.tensordot(label_stats, gaussian_globals, [1, 0])
    natparam = node_potentials + global_potentials #using Eq. 39
    stats = gaussian.expectedstats(natparam)
    #print stats.shape
    kl = np.tensordot(node_potentials, stats, 3) - gaussian.logZ(natparam)
    return natparam, stats, kl
Beispiel #2
0
def gaussian_meanfield(gaussian_globals, node_potentials, label_stats):
    global_potentials = np.tensordot(label_stats, gaussian_globals, [1, 0])
    natparam = node_potentials + global_potentials
    stats = gaussian.expectedstats(natparam)
    kl = np.tensordot(node_potentials, stats, 3) - gaussian.logZ(natparam)
    return natparam, stats, kl
Beispiel #3
0
def gaussian_kl(gaussian_globals, label_stats, natparam, stats):
    global_potentials = np.tensordot(label_stats, gaussian_globals, [1, 0])
    return np.tensordot(natparam - global_potentials, stats, 3) - gaussian.logZ(natparam)