In [2]:
#import autogp
import matplotlib.pyplot as plt
import numpy as np
import tensorflow as tf
In [3]:
N_all = 200
N = 50
In [12]:
array1 = 5 * np.linspace(0, 1, num=N_all)
In [13]:
array1.shape
Out[13]:
In [16]:
inputs = 5 * np.linspace(0, 1, num=N_all)[:, np.newaxis]
In [20]:
inputs.shape #200 points, unidimensional
Out[20]:
In [21]:
outputs = np.sin(inputs)
In [22]:
outputs.shape
Out[22]:
In [25]:
idx = np.arange(N_all)
idx
Out[25]:
In [27]:
np.random.shuffle(idx)
idx
Out[27]:
In [29]:
xtrain = inputs[idx[:N]] #take 50 points in inputs corresponding to this
# random indices
xtrain
Out[29]:
In [35]:
ytrain = outputs[idx[:N]] #primi 50 punti
ytrain.shape
Out[35]:
In [ ]:
data = autogp.datasets.DataSet(xtrain, ytrain) #frame the dataset in
# the way it is supposed to work with AutoGP
In [34]:
xtest = inputs[idx[N:]] #dal 50esimo in poi
xtest.shape
Out[34]:
In [36]:
ytest = outputs[idx[N:]]
ytest.shape
Out[36]:
In [ ]:
#Initialize the Gaussian process.
likelihood = autogp.likelihoods.Gaussian() #specifico la likelihood
kernel = [autogp.kernels.RadialBasis(1)] #specifico il kernel
inducing_inputs = xtrain
In [ ]:
#questa funzione andra' a costruire tutto il computational graph
#per questa determinata forma di lik e kernel
model = autogp.GaussianProcess(likelihood, kernel, inducing_inputs)
In [ ]:
optimizer = tf.train.RMSPropOptimizer(0.005) #che optimizar utilizzare
#step di ottimizzazione dove run la sessione e specifico quanti
#setp voglio fare
model.fit(data, optimizer, loo_steps=50, var_steps=50, epochs=1000)
In [ ]:
# Predict new inputs.
ypred, _ = model.predict(xtest)
In [ ]:
# Plot results
plt.plot(xtrain, ytrain, '.', mew=2)
plt.plot(xtest, ytest, 'o', mew=2)
plt.plot(xtest, ypred, 'x', mew=2)
plt.show()