# 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
    model.optimise(method='L-BFGS-B', alpha=1, maxiter=5000, disp=False)
    my, vy = model.predict_y(Xtest)
    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(), Xtrain.shape[0], 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=1.000, train ml=-51.385404, test rmse=0.168, ll=0.311


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

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

    alpha = 1 # other alpha is not valid here
    M = 20
    model = aep.SDGPR(Xtrain, ytrain, M, hidden_sizes=[2])
    model.optimise(method='adam', alpha=1, maxiter=5000, disp=False)
    my, vy = model.predict_y(Xtest)
    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)

# 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

    model.optimise(method='L-BFGS-B', alpha=1, maxiter=5000, disp=False)
    my, vy = model.predict_y(Xtest)
    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(), Xtrain.shape[0], 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=1.000, train ml=-51.385404, test rmse=0.168, ll=0.311


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

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

    alpha = 1 # other alpha is not valid here
    M = 20
    model = aep.SDGPR(Xtrain, ytrain, M, hidden_sizes=[2])
    model.optimise(method='adam', alpha=1, maxiter=5000, disp=False)
    my, vy = model.predict_y(Xtest)
    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(), Xtrain.shape[0], alpha)