#!/usr/bin/env python2
# -*- coding: utf-8 -*-
"""
Created on Sun Sep 15 23:51:02 2019

@author: sourish
"""

import numpy as np
import random
from __future__ import division
import matplotlib.pyplot as plot

from sklearn.gaussian_process import GaussianProcessRegressor

from sklearn.gaussian_process.kernels import WhiteKernel, RBF

x = np.arange(-15, 15, 0.1)
n = len(x)
x = np.reshape(x,(n,1))

## Sinc function
f = np.sin(x)/x
plot.scatter(x,f)

### Simulate error and mix with f

e = [random.gauss(mu=0,sigma=0.1) for _ in range(len(x))]
e = np.reshape(e,(n,1))
y = f+e

plot.scatter(x,y)

## Now pretend we don't know anything about f
## and we have only x and y

kernel = RBF() + WhiteKernel() 

gpr = GaussianProcessRegressor(kernel=kernel,random_state=0).fit(x, y)
gpr.score(x, y)

y_hat = gpr.predict(x) 
y_hat = np.reshape(y_hat,(n,1))

plot.scatter(x,y)
plot.scatter(x,y_hat)
