mirror of
https://github.com/SheffieldML/GPy.git
synced 2026-06-23 15:48:09 +02:00
Merge branch 'params' of github.com:SheffieldML/GPy into params
This commit is contained in:
commit
f4e270ae53
11 changed files with 113 additions and 87 deletions
|
|
@ -83,7 +83,7 @@ class Add(Kern):
|
|||
from white import White
|
||||
from rbf import RBF
|
||||
#from rbf_inv import RBFInv
|
||||
#from bias import Bias
|
||||
from bias import Bias
|
||||
from linear import Linear
|
||||
#ffrom fixed import Fixed
|
||||
|
||||
|
|
@ -131,11 +131,11 @@ class Add(Kern):
|
|||
|
||||
|
||||
def gradients_Z_variational(self, dL_dKmm, dL_dpsi0, dL_dpsi1, dL_dpsi2, mu, S, Z):
|
||||
from white import white
|
||||
from rbf import rbf
|
||||
from white import White
|
||||
from rbf import RBF
|
||||
#from rbf_inv import rbfinv
|
||||
#from bias import bias
|
||||
from linear import linear
|
||||
from bias import Bias
|
||||
from linear import Linear
|
||||
#ffrom fixed import fixed
|
||||
|
||||
target = np.zeros(Z.shape)
|
||||
|
|
@ -146,15 +146,15 @@ class Add(Kern):
|
|||
for p2, is2 in zip(self._parameters_, self.input_slices):
|
||||
if p2 is p1:
|
||||
continue
|
||||
if isinstance(p2, white):
|
||||
if isinstance(p2, White):
|
||||
continue
|
||||
elif isinstance(p2, bias):
|
||||
elif isinstance(p2, Bias):
|
||||
eff_dL_dpsi1 += dL_dpsi2.sum(1) * p2.variance * 2.
|
||||
else:
|
||||
eff_dL_dpsi1 += dL_dpsi2.sum(1) * p2.psi1(z[:,is2], mu[:,is2], s[:,is2]) * 2.
|
||||
eff_dL_dpsi1 += dL_dpsi2.sum(1) * p2.psi1(Z[:,is2], mu[:,is2], S[:,is2]) * 2.
|
||||
|
||||
|
||||
target += p1.gradients_z_variational(dL_dkmm, dL_dpsi0, eff_dL_dpsi1, dL_dpsi2, mu[:,is1], s[:,is1], z[:,is1])
|
||||
target += p1.gradients_z_variational(dL_dKmm, dL_dpsi0, eff_dL_dpsi1, dL_dpsi2, mu[:,is1], S[:,is1], Z[:,is1])
|
||||
return target
|
||||
|
||||
def gradients_muS_variational(self, dL_dKmm, dL_dpsi0, dL_dpsi1, dL_dpsi2, mu, S, Z):
|
||||
|
|
@ -195,6 +195,12 @@ class Add(Kern):
|
|||
from ..plotting.matplot_dep import kernel_plots
|
||||
kernel_plots.plot(self,*args)
|
||||
|
||||
def input_sensitivity(self):
|
||||
in_sen = np.zeros((self.input_dim, self.num_params))
|
||||
for i, [p, i_s] in enumerate(zip(self._parameters_, self.input_slices)):
|
||||
in_sen[i_s, i] = p.input_sensitivity()
|
||||
return in_sen
|
||||
|
||||
def _getstate(self):
|
||||
"""
|
||||
Get the current state of the class,
|
||||
|
|
|
|||
|
|
@ -61,16 +61,20 @@ class Kern(Parameterized):
|
|||
def gradients_q_variational(self, dL_dKmm, dL_dpsi0, dL_dpsi1, dL_dpsi2, Z, posterior_variational):
|
||||
raise NotImplementedError
|
||||
|
||||
def plot_ARD(self, *args):
|
||||
"""If an ARD kernel is present, plot a bar representation using matplotlib
|
||||
|
||||
See GPy.plotting.matplot_dep.plot_ARD
|
||||
"""
|
||||
def plot_ARD(self, *args, **kw):
|
||||
if "matplotlib" in sys.modules:
|
||||
from ...plotting.matplot_dep import kernel_plots
|
||||
self.plot_ARD.__doc__ += kernel_plots.plot_ARD.__doc__
|
||||
assert "matplotlib" in sys.modules, "matplotlib package has not been imported."
|
||||
from ...plotting.matplot_dep import kernel_plots
|
||||
return kernel_plots.plot_ARD(self,*args)
|
||||
|
||||
|
||||
return kernel_plots.plot_ARD(self,*args,**kw)
|
||||
|
||||
def input_sensitivity(self):
|
||||
"""
|
||||
Returns the sensitivity for each dimension of this kernel.
|
||||
"""
|
||||
return np.zeros(self.input_dim)
|
||||
|
||||
def __add__(self, other):
|
||||
""" Overloading of the '+' operator. for more control, see self.add """
|
||||
return self.add(other)
|
||||
|
|
|
|||
|
|
@ -252,3 +252,6 @@ class Linear(Kern):
|
|||
|
||||
return np.dot(ZA, inner).swapaxes(0, 1) # NOTE: self.ZAinner \in [num_inducing x N x input_dim]!
|
||||
|
||||
def input_sensitivity(self):
|
||||
if self.ARD: return self.variances
|
||||
else: return self.variances.repeat(self.input_dim)
|
||||
|
|
|
|||
|
|
@ -182,7 +182,7 @@ class RBF(Kern):
|
|||
|
||||
return grad
|
||||
|
||||
def update_gradients_q_variational(self, dL_dKmm, dL_dpsi0, dL_dpsi1, dL_dpsi2, Z, posterior_variational):
|
||||
def gradients_q_variational(self, dL_dKmm, dL_dpsi0, dL_dpsi1, dL_dpsi2, Z, posterior_variational):
|
||||
mu = posterior_variational.mean
|
||||
S = posterior_variational.variance
|
||||
self._psi_computations(Z, mu, S)
|
||||
|
|
@ -194,9 +194,8 @@ class RBF(Kern):
|
|||
tmp = self._psi2[:, :, :, None] / self.lengthscale2 / self._psi2_denom
|
||||
grad_mu += -2.*(dL_dpsi2[:, :, :, None] * tmp * self._psi2_mudist).sum(1).sum(1)
|
||||
grad_S += (dL_dpsi2[:, :, :, None] * tmp * (2.*self._psi2_mudist_sq - 1)).sum(1).sum(1)
|
||||
|
||||
posterior_variational.mean.gradient = grad_mu
|
||||
posterior_variational.variance.gradient = grad_S
|
||||
|
||||
return grad_mu, grad_S
|
||||
|
||||
def gradients_X(self, dL_dK, X, X2=None):
|
||||
#if self._X is None or X.base is not self._X.base or X2 is not None:
|
||||
|
|
@ -383,3 +382,7 @@ class RBF(Kern):
|
|||
type_converters=weave.converters.blitz, **self.weave_options)
|
||||
|
||||
return mudist, mudist_sq, psi2_exponent, psi2
|
||||
|
||||
def input_sensitivity(self):
|
||||
if self.ARD: return 1./self.lengthscale
|
||||
else: return (1./self.lengthscale).repeat(self.input_dim)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue