# Path: examples/datautils.py
# def step(x):
# 	y = x.copy()
# 	y[y < 0.0] = 0.0
# 	y[y > 0.0] = 1.0
# 	return y + 0.05*np.random.randn(x.shape[0], 1)
# 
# def spiral(no_samples, noise=0.0):
# 	def genSpiral(N, delta):
# 		X = np.zeros((N, 2))
# 		for i in range(N):
# 			r = i * 5.0 / N
# 			t = 1.75 * i / N * 2.0 * np.pi + delta
# 			x = r * np.sin(t) + (2*np.random.rand() - 1) * noise
# 			y = r * np.cos(t) + (2*np.random.rand() - 1) * noise
# 			X[i, :] = np.array([x, y])
# 		return X
# 
# 	N = int(no_samples / 2.0)
# 	pos_x = genSpiral(N, 0)
# 	neg_x = genSpiral(N, np.pi)
# 	x = np.vstack((pos_x, neg_x))
# 	y = np.ones((2*N, 1))
# 	y[N:] = -1
# 	return x, y
# 
# Path: examples/context.py



import numpy as np
import pdb
import matplotlib.pylab as plt
from .datautils import step, spiral
from .context import vfe, aep
        my, vy = model.predict_y(Xtest, alpha)
        my = np.reshape(my, ytest.shape)
        vy = np.reshape(vy, ytest.shape)
        rmse = np.sqrt(np.mean((my - ytest)**2))
        ll = np.mean(-0.5 * np.log(2 * np.pi * vy) - 0.5 * (ytest - my)**2 / vy)
        nlml, _ = model.objective_function(model.get_hypers(), alpha)
        print 'alpha=%.3f, train ml=%3f, test rmse=%.3f, ll=%.3f' % (alpha, nlml, rmse, ll)
        # plot(model, Xtrain, ytrain)
        # plt.show()

    # should produce something like this
    # alpha=0.001, train ml=-64.573021, test rmse=0.169, ll=0.348
    # alpha=0.100, train ml=-64.616618, test rmse=0.169, ll=0.348
    # alpha=0.200, train ml=-64.626655, test rmse=0.169, ll=0.348
    # alpha=0.300, train ml=-64.644053, test rmse=0.169, ll=0.348
    # alpha=0.500, train ml=-64.756588, test rmse=0.169, ll=0.348
    # alpha=0.700, train ml=-68.755871, test rmse=0.169, ll=0.350
    # alpha=0.800, train ml=-72.153441, test rmse=0.167, ll=0.349
    # alpha=1.000, train ml=-71.305002, test rmse=0.169, ll=0.303


def run_regression_1D_aep():
    np.random.seed(42)

    print "create dataset ..."
    Xtrain, ytrain, Xtest, ytest = create_dataset()

    alphas = [0.001, 0.1, 0.2, 0.3, 0.5, 0.7, 0.8, 1]
    for alpha in alphas:
        M = 20

# Path: examples/datautils.py
# def step(x):
# 	y = x.copy()
# 	y[y < 0.0] = 0.0
# 	y[y > 0.0] = 1.0
# 	return y + 0.05*np.random.randn(x.shape[0], 1)
# 
# def spiral(no_samples, noise=0.0):
# 	def genSpiral(N, delta):
# 		X = np.zeros((N, 2))
# 		for i in range(N):
# 			r = i * 5.0 / N
# 			t = 1.75 * i / N * 2.0 * np.pi + delta
# 			x = r * np.sin(t) + (2*np.random.rand() - 1) * noise
# 			y = r * np.cos(t) + (2*np.random.rand() - 1) * noise
# 			X[i, :] = np.array([x, y])
# 		return X
# 
# 	N = int(no_samples / 2.0)
# 	pos_x = genSpiral(N, 0)
# 	neg_x = genSpiral(N, np.pi)
# 	x = np.vstack((pos_x, neg_x))
# 	y = np.ones((2*N, 1))
# 	y[N:] = -1
# 	return x, y
# 
# Path: examples/context.py



# Path: examples/gpr_alpha_examples.py
import numpy as np
import pdb
import matplotlib.pylab as plt
from .datautils import step, spiral
from .context import vfe, aep

        my, vy = model.predict_y(Xtest, alpha)
        my = np.reshape(my, ytest.shape)
        vy = np.reshape(vy, ytest.shape)
        rmse = np.sqrt(np.mean((my - ytest)**2))
        ll = np.mean(-0.5 * np.log(2 * np.pi * vy) - 0.5 * (ytest - my)**2 / vy)
        nlml, _ = model.objective_function(model.get_hypers(), alpha)
        print 'alpha=%.3f, train ml=%3f, test rmse=%.3f, ll=%.3f' % (alpha, nlml, rmse, ll)
        # plot(model, Xtrain, ytrain)
        # plt.show()

    # should produce something like this
    # alpha=0.001, train ml=-64.573021, test rmse=0.169, ll=0.348
    # alpha=0.100, train ml=-64.616618, test rmse=0.169, ll=0.348
    # alpha=0.200, train ml=-64.626655, test rmse=0.169, ll=0.348
    # alpha=0.300, train ml=-64.644053, test rmse=0.169, ll=0.348
    # alpha=0.500, train ml=-64.756588, test rmse=0.169, ll=0.348
    # alpha=0.700, train ml=-68.755871, test rmse=0.169, ll=0.350
    # alpha=0.800, train ml=-72.153441, test rmse=0.167, ll=0.349
    # alpha=1.000, train ml=-71.305002, test rmse=0.169, ll=0.303


def run_regression_1D_aep():
    np.random.seed(42)

    print "create dataset ..."
    Xtrain, ytrain, Xtest, ytest = create_dataset()

    alphas = [0.001, 0.1, 0.2, 0.3, 0.5, 0.7, 0.8, 1]
    for alpha in alphas:
        M = 20

        model = aep.SGPR(Xtrain, ytrain, M)