mirror of
https://github.com/SheffieldML/GPy.git
synced 2026-05-10 12:32:40 +02:00
fixed a bug in constructor of periodic_matern52
This commit is contained in:
parent
70189a387b
commit
db7485b906
3 changed files with 24 additions and 12 deletions
|
|
@ -91,12 +91,14 @@ class GPBase(Model):
|
||||||
else:
|
else:
|
||||||
raise NotImplementedError, "Cannot define a frame with more than two input dimensions"
|
raise NotImplementedError, "Cannot define a frame with more than two input dimensions"
|
||||||
|
|
||||||
def plot(self, plot_limits=None, which_data='all', which_parts='all', resolution=None, levels=20, samples=0, fignum=None, ax=None):
|
def plot(self, plot_limits=None, which_data='all', which_parts='all', resolution=None, levels=20, samples=0, fignum=None, ax=None, fixed_inputs=[], linecol=Tango.colorsHex['darkBlue'],fillcol=Tango.colorsHex['lightBlue']):
|
||||||
"""
|
"""
|
||||||
TODO: Docstrings!
|
TODO: Docstrings!
|
||||||
|
|
||||||
:param levels: for 2D plotting, the number of contour levels to use
|
:param levels: for 2D plotting, the number of contour levels to use
|
||||||
is ax is None, create a new figure
|
is ax is None, create a new figure
|
||||||
|
|
||||||
|
fixed_inputs: a list of tuple [(i,v), (i,v)...], specifying that input index i should be set to value v.
|
||||||
"""
|
"""
|
||||||
# TODO include samples
|
# TODO include samples
|
||||||
if which_data == 'all':
|
if which_data == 'all':
|
||||||
|
|
@ -106,15 +108,25 @@ class GPBase(Model):
|
||||||
fig = pb.figure(num=fignum)
|
fig = pb.figure(num=fignum)
|
||||||
ax = fig.add_subplot(111)
|
ax = fig.add_subplot(111)
|
||||||
|
|
||||||
if self.X.shape[1] == 1:
|
plotdims = self.input_dim - len(fixed_inputs)
|
||||||
|
|
||||||
|
if plotdims == 1:
|
||||||
|
|
||||||
Xu = self.X * self._Xscale + self._Xoffset # NOTE self.X are the normalized values now
|
Xu = self.X * self._Xscale + self._Xoffset # NOTE self.X are the normalized values now
|
||||||
|
|
||||||
Xnew, xmin, xmax = x_frame1D(Xu, plot_limits=plot_limits)
|
fixed_dims = np.array([i for i,v in fixed_inputs])
|
||||||
m, _, lower, upper = self.predict(Xnew, which_parts=which_parts)
|
freedim = np.setdiff1d(np.arange(self.input_dim),fixed_dims)
|
||||||
|
|
||||||
|
Xnew, xmin, xmax = x_frame1D(Xu[:,freedim], plot_limits=plot_limits)
|
||||||
|
Xgrid = np.empty((Xnew.shape[0],self.input_dim))
|
||||||
|
Xgrid[:,freedim] = Xnew
|
||||||
|
for i,v in fixed_inputs:
|
||||||
|
Xgrid[:,i] = v
|
||||||
|
|
||||||
|
m, _, lower, upper = self.predict(Xgrid, which_parts=which_parts)
|
||||||
for d in range(m.shape[1]):
|
for d in range(m.shape[1]):
|
||||||
gpplot(Xnew, m[:, d], lower[:, d], upper[:, d], axes=ax)
|
gpplot(Xnew, m[:, d], lower[:, d], upper[:, d], axes=ax, edgecol=linecol, fillcol=fillcol)
|
||||||
ax.plot(Xu[which_data], self.likelihood.data[which_data, d], 'kx', mew=1.5)
|
ax.plot(Xu[which_data,freedim], self.likelihood.data[which_data, d], 'kx', mew=1.5)
|
||||||
ymin, ymax = min(np.append(self.likelihood.data, lower)), max(np.append(self.likelihood.data, upper))
|
ymin, ymax = min(np.append(self.likelihood.data, lower)), max(np.append(self.likelihood.data, upper))
|
||||||
ymin, ymax = ymin - 0.1 * (ymax - ymin), ymax + 0.1 * (ymax - ymin)
|
ymin, ymax = ymin - 0.1 * (ymax - ymin), ymax + 0.1 * (ymax - ymin)
|
||||||
ax.set_xlim(xmin, xmax)
|
ax.set_xlim(xmin, xmax)
|
||||||
|
|
|
||||||
|
|
@ -83,7 +83,7 @@ def coregionalisation_toy2(optim_iters=100):
|
||||||
Y = np.vstack((Y1,Y2))
|
Y = np.vstack((Y1,Y2))
|
||||||
|
|
||||||
k1 = GPy.kern.rbf(1) + GPy.kern.bias(1)
|
k1 = GPy.kern.rbf(1) + GPy.kern.bias(1)
|
||||||
k2 = GPy.kern.Coregionalise(2,1)
|
k2 = GPy.kern.coregionalise(2,1)
|
||||||
k = k1.prod(k2,tensor=True)
|
k = k1.prod(k2,tensor=True)
|
||||||
m = GPy.models.GPRegression(X,Y,kernel=k)
|
m = GPy.models.GPRegression(X,Y,kernel=k)
|
||||||
m.constrain_fixed('.*rbf_var',1.)
|
m.constrain_fixed('.*rbf_var',1.)
|
||||||
|
|
@ -114,7 +114,7 @@ def coregionalisation_toy(optim_iters=100):
|
||||||
Y = np.vstack((Y1,Y2))
|
Y = np.vstack((Y1,Y2))
|
||||||
|
|
||||||
k1 = GPy.kern.rbf(1)
|
k1 = GPy.kern.rbf(1)
|
||||||
k2 = GPy.kern.Coregionalise(2,2)
|
k2 = GPy.kern.coregionalise(2,2)
|
||||||
k = k1.prod(k2,tensor=True)
|
k = k1.prod(k2,tensor=True)
|
||||||
m = GPy.models.GPRegression(X,Y,kernel=k)
|
m = GPy.models.GPRegression(X,Y,kernel=k)
|
||||||
m.constrain_fixed('.*rbf_var',1.)
|
m.constrain_fixed('.*rbf_var',1.)
|
||||||
|
|
@ -149,7 +149,7 @@ def coregionalisation_sparse(optim_iters=100):
|
||||||
Z = np.hstack((np.random.rand(num_inducing,1)*8,np.random.randint(0,2,num_inducing)[:,None]))
|
Z = np.hstack((np.random.rand(num_inducing,1)*8,np.random.randint(0,2,num_inducing)[:,None]))
|
||||||
|
|
||||||
k1 = GPy.kern.rbf(1)
|
k1 = GPy.kern.rbf(1)
|
||||||
k2 = GPy.kern.Coregionalise(2,2)
|
k2 = GPy.kern.coregionalise(2,2)
|
||||||
k = k1.prod(k2,tensor=True) + GPy.kern.white(2,0.001)
|
k = k1.prod(k2,tensor=True) + GPy.kern.white(2,0.001)
|
||||||
|
|
||||||
m = GPy.models.SparseGPRegression(X,Y,kernel=k,Z=Z)
|
m = GPy.models.SparseGPRegression(X,Y,kernel=k,Z=Z)
|
||||||
|
|
|
||||||
|
|
@ -227,7 +227,7 @@ def periodic_Matern52(input_dim, variance=1., lengthscale=None, period=2 * np.pi
|
||||||
:param n_freq: the number of frequencies considered for the periodic subspace
|
:param n_freq: the number of frequencies considered for the periodic subspace
|
||||||
:type n_freq: int
|
:type n_freq: int
|
||||||
"""
|
"""
|
||||||
part = parts.periodic_Matern52part(input_dim, variance, lengthscale, period, n_freq, lower, upper)
|
part = parts.periodic_Matern52.PeriodicMatern52(input_dim, variance, lengthscale, period, n_freq, lower, upper)
|
||||||
return kern(input_dim, [part])
|
return kern(input_dim, [part])
|
||||||
|
|
||||||
def prod(k1,k2,tensor=False):
|
def prod(k1,k2,tensor=False):
|
||||||
|
|
@ -296,5 +296,5 @@ def independent_outputs(k):
|
||||||
"""
|
"""
|
||||||
for sl in k.input_slices:
|
for sl in k.input_slices:
|
||||||
assert (sl.start is None) and (sl.stop is None), "cannot adjust input slices! (TODO)"
|
assert (sl.start is None) and (sl.stop is None), "cannot adjust input slices! (TODO)"
|
||||||
parts = [independent_outputs.IndependentOutputs(p) for p in k.parts]
|
_parts = [parts.independent_outputs.IndependentOutputs(p) for p in k.parts]
|
||||||
return kern(k.input_dim+1,parts)
|
return kern(k.input_dim+1,_parts)
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue