From 06dd27c634a87fe86596bf09790061dbf6255fb9 Mon Sep 17 00:00:00 2001 From: James Hensman Date: Mon, 24 Feb 2014 14:49:20 +0000 Subject: [PATCH] input senitivity in stationary --- GPy/kern/_src/stationary.py | 54 ++++--------------------------------- 1 file changed, 5 insertions(+), 49 deletions(-) diff --git a/GPy/kern/_src/stationary.py b/GPy/kern/_src/stationary.py index dde26e63..e8586d07 100644 --- a/GPy/kern/_src/stationary.py +++ b/GPy/kern/_src/stationary.py @@ -35,6 +35,9 @@ class Stationary(Kern): def K_of_r(self, r): raise NotImplementedError, "implement the covaraiance functino and a fn of r to use this class" + def dK_dr(self, r): + raise NotImplementedError, "implement the covaraiance functino and a fn of r to use this class" + def K(self, X, X2=None): r = self._scaled_dist(X, X2) return self.K_of_r(r) @@ -92,55 +95,8 @@ class Stationary(Kern): def gradients_X_diag(self, dL_dKdiag, X): return np.zeros(X.shape) - def add(self, other, tensor=False): - if not tensor: - return StatAdd(self, other) - else: - return super(Stationary, self).add(other, tensor) - - def prod(self, other, tensor=False): - if not tensor: - return StatProd(self, other) - else: - return super(Stationary, self).prod(other, tensor) - - - -class StatAdd(Stationary): - """ - Addition of two Stationary kernels on the same space is still stationary. - - If you need to add two (stationary) kernels on separate spaces, use the generic add class. - """ - def __init__(self, k1, k2): - assert isinstance(k1, Stationary) - assert isinstance(k2, Stationary) - self.k1, self.k2 = k1, k2 - self.add_parameters(k1, k2) - - def K_of_r(self, r): - return self.k1.K(r) + self.k2.K(r) - - def dK_dr(self, r): - return self.k1.dK_dr + self.k2.dK_dr(r) - -class StatProd(Stationary): - """ - Product of two Stationary kernels on the same space is still stationary. - - If you need to multiply two (stationary) kernels on separate spaces, use the generic Prod class. - """ - def __init__(self, k1, k2): - assert isinstance(k1, Stationary) - assert isinstance(k2, Stationary) - self.k1, self.k2 = k1, k2 - self.add_parameters(k1, k2) - - def K_of_r(self, r): - return self.k1.K(r) * self.k2.K(r) - - def dK_dr(self, r): - return self.k1.dK_dr(r) * self.k2.K_of_r(r) + self.k2.dK_dr(r) * self.k1.K_of_r(r) + def input_sensitivity(self): + return np.ones(self.input_dim)/self.lengthscale class Exponential(Stationary): def __init__(self, input_dim, variance=1., lengthscale=None, ARD=False, name='Exponential'):