mirror of
https://github.com/SheffieldML/GPy.git
synced 2026-05-09 03:52:39 +02:00
moved plot functionality from add to kern
This commit is contained in:
parent
26aeb5e1db
commit
9867330861
4 changed files with 17 additions and 24 deletions
|
|
@ -184,20 +184,12 @@ 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)):
|
||||||
in_sen[i, i_s] = p.input_sensitivity()
|
in_sen[i, i_s] = p.input_sensitivity()
|
||||||
return in_sen
|
return in_sen
|
||||||
|
|
||||||
def _getstate(self):
|
def _getstate(self):
|
||||||
"""
|
"""
|
||||||
Get the current state of the class,
|
Get the current state of the class,
|
||||||
|
|
|
||||||
|
|
@ -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`
|
||||||
|
|
|
||||||
|
|
@ -178,6 +178,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 TODO
|
#@cache_this TODO
|
||||||
def _psi2computations(self, Z, vp):
|
def _psi2computations(self, Z, vp):
|
||||||
|
|
@ -187,8 +192,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
|
||||||
|
|
@ -201,7 +205,7 @@ class RBF(Stationary):
|
||||||
denom = (2.*S[:,None,None,:] / l2) + 1. # N,Q
|
denom = (2.*S[:,None,None,:] / l2) + 1. # N,Q
|
||||||
half_log_denom = 0.5 * np.log(denom[:,0,0,:])
|
half_log_denom = 0.5 * np.log(denom[:,0,0,:])
|
||||||
denom_l2 = denom[:,0,0,:]*l2
|
denom_l2 = denom[:,0,0,:]*l2
|
||||||
|
|
||||||
variance_sq = float(np.square(self.variance))
|
variance_sq = float(np.square(self.variance))
|
||||||
code = """
|
code = """
|
||||||
double tmp, exponent_tmp;
|
double tmp, exponent_tmp;
|
||||||
|
|
@ -237,7 +241,7 @@ class RBF(Stationary):
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
"""
|
"""
|
||||||
|
|
||||||
support_code = """
|
support_code = """
|
||||||
#include <omp.h>
|
#include <omp.h>
|
||||||
#include <math.h>
|
#include <math.h>
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue