# Path: examples/context.py



import numpy as np
import pdb
import matplotlib.pylab as plt
    import GPy
from .context import aep, ep
from scipy import special
    from operator import xor
    from scipy import special

    Y = np.vstack((A, B, C))
    labels = np.hstack((np.zeros(A.shape[0]), np.ones(
        B.shape[0]), np.ones(C.shape[0]) * 2))

    # inference
    print "inference ..."
    M = 20
    D = 5
    lvm_aep = aep.SGPLVM(Y, D, M, lik='Gaussian')
    lvm_aep.optimise(method='L-BFGS-B', alpha=0.1, maxiter=2000)

    lvm = ep.SGPLVM(Y, D, M, lik='Gaussian')
    lvm.update_hypers(lvm_aep.get_hypers())
    # # a quick hack to initialise the factors
    # lvm.sgp_layer.t1 = np.tile(lvm_aep.sgp_layer.theta_2[np.newaxis, :, :] / lvm.N, [lvm.N, 1, 1])
    # lvm.sgp_layer.t2 = np.tile(lvm_aep.sgp_layer.theta_1[np.newaxis, :, :, :] / lvm.N, [lvm.N, 1, 1, 1])
    # lvm.sgp_layer.update_posterior()
    # lvm.tx1 = lvm_aep.factor_x1
    # lvm.tx2 = lvm_aep.factor_x2
    lvm.inference(alpha=0.1, no_epochs=10, parallel=True, decay=0.5)

    ls = np.exp(lvm.sgp_layer.ls)
    print ls
    inds = np.argsort(ls)
    plt.figure()
    mx, vx = lvm.get_posterior_x()
    plt.scatter(mx[:, inds[0]], mx[:, inds[1]], c=labels)
    zu = lvm.sgp_layer.zu
    plt.plot(zu[:, inds[0]], zu[:, inds[1]], 'ko')

# Path: examples/context.py



# Path: examples/gplvm_ep_examples.py
import numpy as np
import pdb
import matplotlib.pylab as plt
    import GPy
from .context import aep, ep
from scipy import special
    from operator import xor
    from scipy import special


    Y = np.vstack((A, B, C))
    labels = np.hstack((np.zeros(A.shape[0]), np.ones(
        B.shape[0]), np.ones(C.shape[0]) * 2))

    # inference
    print "inference ..."
    M = 20
    D = 5
    lvm_aep = aep.SGPLVM(Y, D, M, lik='Gaussian')
    lvm_aep.optimise(method='L-BFGS-B', alpha=0.1, maxiter=2000)

    lvm = ep.SGPLVM(Y, D, M, lik='Gaussian')
    lvm.update_hypers(lvm_aep.get_hypers())
    # # a quick hack to initialise the factors
    # lvm.sgp_layer.t1 = np.tile(lvm_aep.sgp_layer.theta_2[np.newaxis, :, :] / lvm.N, [lvm.N, 1, 1])
    # lvm.sgp_layer.t2 = np.tile(lvm_aep.sgp_layer.theta_1[np.newaxis, :, :, :] / lvm.N, [lvm.N, 1, 1, 1])
    # lvm.sgp_layer.update_posterior()
    # lvm.tx1 = lvm_aep.factor_x1
    # lvm.tx2 = lvm_aep.factor_x2
    lvm.inference(alpha=0.1, no_epochs=10, parallel=True, decay=0.5)

    ls = np.exp(lvm.sgp_layer.ls)
    print ls
    inds = np.argsort(ls)
    plt.figure()
    mx, vx = lvm.get_posterior_x()
    plt.scatter(mx[:, inds[0]], mx[:, inds[1]], c=labels)
    zu = lvm.sgp_layer.zu
    plt.plot(zu[:, inds[0]], zu[:, inds[1]], 'ko')

    plt.show()