# Path: examples/context.py

# 
# 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 scipy import special
from .context import aep
from .datautils import step, spiral
from .context import config
    np.random.seed(42)

    print "create dataset ..."
    N = 200
    X = np.random.rand(N, 1)
    Y = np.sin(12 * X) + 0.5 * np.cos(25 * X) + np.random.randn(N, 1) * 0.2
    # plt.plot(X, Y, 'kx', mew=2)

    def plot(m):
        xx = np.linspace(-0.5, 1.5, 100)[:, None]
        # mean, var = m.predict_f(xx)
        samples, mf, vf = m.predict_f(xx, config.PROP_MC)
        zu = m.sgp_layers[0].zu
        mean_u, var_u = m.predict_f(zu)
        plt.figure()
        plt.plot(X, Y, 'kx', mew=2)
        # plt.plot(xx, mean, 'b', lw=2)
        # plt.fill_between(
        #     xx[:, 0],
        #     mean[:, 0] - 2 * np.sqrt(var[:, 0]),
        #     mean[:, 0] + 2 * np.sqrt(var[:, 0]),
        #     color='blue', alpha=0.2)
        plt.plot(np.tile(xx[np.newaxis, :], [200, 1]))
        plt.errorbar(zu, mean_u, yerr=2 * np.sqrt(var_u), fmt='ro')
        plt.xlim(-0.1, 1.1)

    # inference
    print "create model and optimize ..."
    M = 20
    hidden_size = [2]

# Path: examples/context.py

# 
# 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/dgpr_aep_examples.py
import numpy as np
import pdb
import matplotlib.pylab as plt
from scipy import special
from .context import aep
from .datautils import step, spiral
from .context import config

    np.random.seed(42)

    print "create dataset ..."
    N = 200
    X = np.random.rand(N, 1)
    Y = np.sin(12 * X) + 0.5 * np.cos(25 * X) + np.random.randn(N, 1) * 0.2
    # plt.plot(X, Y, 'kx', mew=2)

    def plot(m):
        xx = np.linspace(-0.5, 1.5, 100)[:, None]
        # mean, var = m.predict_f(xx)
        samples, mf, vf = m.predict_f(xx, config.PROP_MC)
        zu = m.sgp_layers[0].zu
        mean_u, var_u = m.predict_f(zu)
        plt.figure()
        plt.plot(X, Y, 'kx', mew=2)
        # plt.plot(xx, mean, 'b', lw=2)
        # plt.fill_between(
        #     xx[:, 0],
        #     mean[:, 0] - 2 * np.sqrt(var[:, 0]),
        #     mean[:, 0] + 2 * np.sqrt(var[:, 0]),
        #     color='blue', alpha=0.2)
        plt.plot(np.tile(xx[np.newaxis, :], [200, 1]))
        plt.errorbar(zu, mean_u, yerr=2 * np.sqrt(var_u), fmt='ro')
        plt.xlim(-0.1, 1.1)

    # inference
    print "create model and optimize ..."
    M = 20
    hidden_size = [2]

    model = aep.SDGPR(X, Y, M, hidden_size, lik='Gaussian')