mirror of
https://github.com/SheffieldML/GPy.git
synced 2026-05-09 03:52:39 +02:00
Merge branch 'params' of github.com:SheffieldML/GPy into params
This commit is contained in:
commit
9fa1a40ac3
8 changed files with 65 additions and 35 deletions
|
|
@ -60,6 +60,19 @@ class Param(Constrainable, ObservableArray, Gradcheckable):
|
||||||
def __init__(self, name, input_array, default_constraint=None, *a, **kw):
|
def __init__(self, name, input_array, default_constraint=None, *a, **kw):
|
||||||
super(Param, self).__init__(name=name, default_constraint=default_constraint, *a, **kw)
|
super(Param, self).__init__(name=name, default_constraint=default_constraint, *a, **kw)
|
||||||
|
|
||||||
|
def build_pydot(self,G):
|
||||||
|
import pydot
|
||||||
|
node = pydot.Node(id(self), shape='record', label=self.name)
|
||||||
|
G.add_node(node)
|
||||||
|
for o in self._observer_callables_.keys():
|
||||||
|
label = o.name if hasattr(o, 'name') else str(o)
|
||||||
|
observed_node = pydot.Node(id(o), label=label)
|
||||||
|
G.add_node(observed_node)
|
||||||
|
edge = pydot.Edge(str(id(self)), str(id(o)), color='darkorange2', arrowhead='vee')
|
||||||
|
G.add_edge(edge)
|
||||||
|
|
||||||
|
return node
|
||||||
|
|
||||||
def __array_finalize__(self, obj):
|
def __array_finalize__(self, obj):
|
||||||
# see InfoArray.__array_finalize__ for comments
|
# see InfoArray.__array_finalize__ for comments
|
||||||
if obj is None: return
|
if obj is None: return
|
||||||
|
|
|
||||||
|
|
@ -64,6 +64,30 @@ class Parameterized(Parameterizable, Pickleable, Gradcheckable):
|
||||||
self._connect_parameters()
|
self._connect_parameters()
|
||||||
del self._in_init_
|
del self._in_init_
|
||||||
|
|
||||||
|
def build_pydot(self, G=None):
|
||||||
|
import pydot
|
||||||
|
iamroot = False
|
||||||
|
if G is None:
|
||||||
|
G = pydot.Dot(graph_type='digraph')
|
||||||
|
iamroot=True
|
||||||
|
node = pydot.Node(id(self), shape='record', label=self.name)
|
||||||
|
G.add_node(node)
|
||||||
|
for child in self._parameters_:
|
||||||
|
child_node = child.build_pydot(G)
|
||||||
|
G.add_edge(pydot.Edge(node, child_node))
|
||||||
|
|
||||||
|
for o in self._observer_callables_.keys():
|
||||||
|
label = o.name if hasattr(o, 'name') else str(o)
|
||||||
|
observed_node = pydot.Node(id(o), label=label)
|
||||||
|
G.add_node(observed_node)
|
||||||
|
edge = pydot.Edge(str(id(self)), str(id(o)), color='darkorange2', arrowhead='vee')
|
||||||
|
G.add_edge(edge)
|
||||||
|
|
||||||
|
if iamroot:
|
||||||
|
return G
|
||||||
|
return node
|
||||||
|
|
||||||
|
|
||||||
def add_parameter(self, param, index=None):
|
def add_parameter(self, param, index=None):
|
||||||
"""
|
"""
|
||||||
:param parameters: the parameters to add
|
:param parameters: the parameters to add
|
||||||
|
|
|
||||||
|
|
@ -184,14 +184,6 @@ class Add(Kern):
|
||||||
target_S += b
|
target_S += b
|
||||||
return target_mu, target_S
|
return target_mu, target_S
|
||||||
|
|
||||||
def plot(self, *args, **kwargs):
|
|
||||||
"""
|
|
||||||
See GPy.plotting.matplot_dep.plot
|
|
||||||
"""
|
|
||||||
assert "matplotlib" in sys.modules, "matplotlib package has not been imported."
|
|
||||||
from ..plotting.matplot_dep import kernel_plots
|
|
||||||
kernel_plots.plot(self,*args)
|
|
||||||
|
|
||||||
def input_sensitivity(self):
|
def input_sensitivity(self):
|
||||||
in_sen = np.zeros((self.num_params, self.input_dim))
|
in_sen = np.zeros((self.num_params, self.input_dim))
|
||||||
for i, [p, i_s] in enumerate(zip(self._parameters_, self.input_slices)):
|
for i, [p, i_s] in enumerate(zip(self._parameters_, self.input_slices)):
|
||||||
|
|
|
||||||
|
|
@ -60,17 +60,6 @@ class Coregionalize(Kern):
|
||||||
def K(self, X, X2=None):
|
def K(self, X, X2=None):
|
||||||
index = np.asarray(X, dtype=np.int)
|
index = np.asarray(X, dtype=np.int)
|
||||||
|
|
||||||
#here's the old code (numpy)
|
|
||||||
#if index2 is None:
|
|
||||||
#index2 = index
|
|
||||||
#else:
|
|
||||||
#index2 = np.asarray(index2, dtype=np.int)
|
|
||||||
#false_target = target.copy()
|
|
||||||
#ii, jj = np.meshgrid(index, index2)
|
|
||||||
#ii, jj = ii.T, jj.T
|
|
||||||
#false_target += self.B[ii, jj]
|
|
||||||
|
|
||||||
|
|
||||||
if X2 is None:
|
if X2 is None:
|
||||||
target = np.empty((X.shape[0], X.shape[0]), dtype=np.float64)
|
target = np.empty((X.shape[0], X.shape[0]), dtype=np.float64)
|
||||||
code="""
|
code="""
|
||||||
|
|
|
||||||
|
|
@ -68,6 +68,14 @@ class Kern(Parameterized):
|
||||||
"""
|
"""
|
||||||
raise NotImplementedError
|
raise NotImplementedError
|
||||||
|
|
||||||
|
def plot(self, *args, **kwargs):
|
||||||
|
"""
|
||||||
|
See GPy.plotting.matplot_dep.plot
|
||||||
|
"""
|
||||||
|
assert "matplotlib" in sys.modules, "matplotlib package has not been imported."
|
||||||
|
from ..plotting.matplot_dep import kernel_plots
|
||||||
|
kernel_plots.plot(self,*args)
|
||||||
|
|
||||||
def plot_ARD(self, *args, **kw):
|
def plot_ARD(self, *args, **kw):
|
||||||
"""
|
"""
|
||||||
See :class:`~GPy.plotting.matplot_dep.kernel_plots`
|
See :class:`~GPy.plotting.matplot_dep.kernel_plots`
|
||||||
|
|
|
||||||
|
|
@ -179,6 +179,11 @@ class RBF(Stationary):
|
||||||
return denom, dist, dist_sq, psi1
|
return denom, dist, dist_sq, psi1
|
||||||
|
|
||||||
|
|
||||||
|
#@cache_this(ignore_args=(1,))
|
||||||
|
def _Z_distances(self, Z):
|
||||||
|
Zhat = 0.5 * (Z[:, None, :] + Z[None, :, :]) # M,M,Q
|
||||||
|
Zdist = 0.5 * (Z[:, None, :] - Z[None, :, :]) # M,M,Q
|
||||||
|
return Zhat, Zdist
|
||||||
|
|
||||||
@Cache_this(limit=1)
|
@Cache_this(limit=1)
|
||||||
def _psi2computations(self, Z, vp):
|
def _psi2computations(self, Z, vp):
|
||||||
|
|
@ -188,8 +193,7 @@ class RBF(Stationary):
|
||||||
M = Z.shape[0]
|
M = Z.shape[0]
|
||||||
|
|
||||||
#compute required distances
|
#compute required distances
|
||||||
Zhat = 0.5 * (Z[:, None, :] + Z[None, :, :]) # M,M,Q
|
Zhat, Zdist = self._Z_distances(Z)
|
||||||
Zdist = 0.5 * (Z[:, None, :] - Z[None, :, :]) # M,M,Q
|
|
||||||
Zdist_sq = np.square(Zdist / self.lengthscale) # M,M,Q
|
Zdist_sq = np.square(Zdist / self.lengthscale) # M,M,Q
|
||||||
|
|
||||||
#allocate memory for the things we want to compute
|
#allocate memory for the things we want to compute
|
||||||
|
|
|
||||||
|
|
@ -20,7 +20,7 @@ def meanplot(x, mu, color=Tango.colorsHex['darkBlue'], ax=None, fignum=None, lin
|
||||||
return axes.plot(x,mu,color=color,linewidth=linewidth,**kw)
|
return axes.plot(x,mu,color=color,linewidth=linewidth,**kw)
|
||||||
|
|
||||||
def gpplot(x,mu,lower,upper,edgecol=Tango.colorsHex['darkBlue'],fillcol=Tango.colorsHex['lightBlue'],ax=None,fignum=None,xlabel='x',ylabel='y',**kwargs):
|
def gpplot(x,mu,lower,upper,edgecol=Tango.colorsHex['darkBlue'],fillcol=Tango.colorsHex['lightBlue'],ax=None,fignum=None,xlabel='x',ylabel='y',**kwargs):
|
||||||
_, axes = ax_default(ax, fignum)
|
_, axes = ax_default(fignum, ax)
|
||||||
|
|
||||||
mu = mu.flatten()
|
mu = mu.flatten()
|
||||||
x = x.flatten()
|
x = x.flatten()
|
||||||
|
|
@ -39,8 +39,8 @@ def gpplot(x,mu,lower,upper,edgecol=Tango.colorsHex['darkBlue'],fillcol=Tango.co
|
||||||
plots.append(axes.fill(np.hstack((x,x[::-1])),np.hstack((upper,lower[::-1])),color=fillcol,**kwargs))
|
plots.append(axes.fill(np.hstack((x,x[::-1])),np.hstack((upper,lower[::-1])),color=fillcol,**kwargs))
|
||||||
|
|
||||||
#this is the edge:
|
#this is the edge:
|
||||||
plots.append(meanplot(x, upper,color=edgecol,linewidth=0.2,axes=axes))
|
plots.append(meanplot(x, upper,color=edgecol,linewidth=0.2,ax=axes))
|
||||||
plots.append(meanplot(x, lower,color=edgecol,linewidth=0.2,axes=axes))
|
plots.append(meanplot(x, lower,color=edgecol,linewidth=0.2,ax=axes))
|
||||||
|
|
||||||
axes.set_xlabel(xlabel)
|
axes.set_xlabel(xlabel)
|
||||||
axes.set_ylabel(ylabel)
|
axes.set_ylabel(ylabel)
|
||||||
|
|
|
||||||
|
|
@ -86,7 +86,7 @@ def plot_fit(model, plot_limits=None, which_data_rows='all',
|
||||||
m, v, lower, upper = model.predict(Xgrid)
|
m, v, lower, upper = model.predict(Xgrid)
|
||||||
Y = Y
|
Y = Y
|
||||||
for d in which_data_ycols:
|
for d in which_data_ycols:
|
||||||
gpplot(Xnew, m[:, d], lower[:, d], upper[:, d], axes=ax, edgecol=linecol, fillcol=fillcol)
|
gpplot(Xnew, m[:, d], lower[:, d], upper[:, d], ax=ax, edgecol=linecol, fillcol=fillcol)
|
||||||
ax.plot(X[which_data_rows,free_dims], Y[which_data_rows, d], 'kx', mew=1.5)
|
ax.plot(X[which_data_rows,free_dims], Y[which_data_rows, d], 'kx', mew=1.5)
|
||||||
|
|
||||||
#optionally plot some samples
|
#optionally plot some samples
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue