Hi all,
I am new to Pymc3 and Gaussian Processes so I apologize if this question seems trivial or I am missing something fundamental. I am trying to model a scalar function with multiple inputs. I have successfully done this using Pymc3 for a 2d toy function ( f(x,y) where x and y are coordinates ). However, I am unable to extend my model for a function with three inputs. I am trying to model now a toy function of the form f(x,y,z)=cos(x)+cos(y)+cos(z) + 2*(x2 + y2 + z**2). The code I am using is:
import numpy as np
from numpy.linalg import inv
import matplotlib.pyplot as plt
import theano
import theano.tensor.nlinalg
import theano.tensor as tt
import pymc3 as pm
#Define Test Function
def true_funct(x,y,z):
val = np.cos(x) + np.cos(y) + np.cos(z) + 2*(x2 + y2 + z**2)
return val
Create Observations
n_points = 40
noise_true = 0.001
data_x = np.random.uniform(-1,1,n_points)
data_y = np.random.uniform(-1,1,n_points)
data_z = np.random.uniform(-1,1,n_points)
X_train = np.concatenate((data_x[:,None],data_y[:,None],data_z[:,None]),axis=1)
Y_true = true_funct(data_x,data_y,data_z)[:,None]
Y_train = Y_true + np.random.normal(0,noise_true, Y_true.shape[0])[:,None]
sigma_noise = noise_true
with pm.Model() as model:
#List of Prior parameters
#-------------------------------
l_scale = pm.HalfCauchy('l_scale', 1, shape=3) #length scale parameter
sigma_f = pm.HalfCauchy('sigma_f', 1) #amplitude parameter
sigma_noise = pm.HalfCauchy('sigma_noise', .1)
#build the mean and cov matrix
cov_funct=pm.gp.cov.ExpQuad(3,l_scale)*sigma_f**2.
cov_funct=cov_funct(X_train)
K = tt.fill_diagonal(cov_funct, sigma_f**2. + sigma_noise**2.)
mean_func = pm.gp.mean.Zero()
obs = pm.MvNormal('obs', mean_func(X_train), K, observed=Y_train)
trace = pm.sample(1000,chains=1,cores=1, step=pm.NUTS())
pm.traceplot(trace, var_names=[‘sigma_f’,‘l_scale’]);
The issue I am having is that the length scales I get are extremely large and I pretty much get a constant response when sampling the GP at new locations. I have used successfully the above code for a function with: f(x,y) = sin(norm(x,y)) but I am having difficulty now with the three input case and I do not see why.
Thank you very much in advance for your time and apologies if this has been asked before.