# 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


import numpy as np
import pdb
import matplotlib.pylab as plt
from scipy import special
from .context import aep
from .datautils import step, spiral
        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')
    model.optimise(method='adam', alpha=1.0,
                   maxiter=50000, mb_size=M, adam_lr=0.001)
    plot(model)
    plt.show()
    plt.savefig('/tmp/aep_dgpr_1D_stoc.pdf')


def run_banana_stoc():

    def gridParams():
        mins = [-3.25, -2.85]
        maxs = [3.65, 3.4]
        nGrid = 50
        xspaced = np.linspace(mins[0], maxs[0], nGrid)
        yspaced = np.linspace(mins[1], maxs[1], nGrid)
        xx, yy = np.meshgrid(xspaced, yspaced)
        Xplot = np.vstack((xx.flatten(), yy.flatten())).T
        return mins, maxs, xx, yy, Xplot

    def plot(m):
        col1 = '#0172B2'
        col2 = '#CC6600'
        mins, maxs, xx, yy, Xplot = gridParams()

# 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/dgprh_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

        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')
    model.optimise(method='adam', alpha=1.0,
                   maxiter=50000, mb_size=M, adam_lr=0.001)
    plot(model)
    plt.show()
    plt.savefig('/tmp/aep_dgpr_1D_stoc.pdf')


def run_banana_stoc():

    def gridParams():
        mins = [-3.25, -2.85]
        maxs = [3.65, 3.4]
        nGrid = 50
        xspaced = np.linspace(mins[0], maxs[0], nGrid)
        yspaced = np.linspace(mins[1], maxs[1], nGrid)
        xx, yy = np.meshgrid(xspaced, yspaced)
        Xplot = np.vstack((xx.flatten(), yy.flatten())).T
        return mins, maxs, xx, yy, Xplot

    def plot(m):
        col1 = '#0172B2'
        col2 = '#CC6600'
        mins, maxs, xx, yy, Xplot = gridParams()

        mf, vf = m.predict_f(Xplot)