From 0c2bae53f797c8a1e8c573a59e983d2b2a688fd6 Mon Sep 17 00:00:00 2001 From: marahman Date: Mon, 12 May 2014 18:45:23 +0100 Subject: [PATCH] Working with OU kernel --- GPy/kern/__init__.py | 2 +- GPy/kern/_src/stationary.py | 21 +++++++++++++++++++++ 2 files changed, 22 insertions(+), 1 deletion(-) diff --git a/GPy/kern/__init__.py b/GPy/kern/__init__.py index 1ed5e805..ab8fb523 100644 --- a/GPy/kern/__init__.py +++ b/GPy/kern/__init__.py @@ -3,7 +3,7 @@ from _src.rbf import RBF from _src.linear import Linear, LinearFull from _src.static import Bias, White from _src.brownian import Brownian -from _src.stationary import Exponential, Matern32, Matern52, ExpQuad, RatQuad, Cosine +from _src.stationary import Exponential, OU, Matern32, Matern52, ExpQuad, RatQuad, Cosine from _src.mlp import MLP from _src.periodic import PeriodicExponential, PeriodicMatern32, PeriodicMatern52 from _src.independent_outputs import IndependentOutputs, Hierarchical diff --git a/GPy/kern/_src/stationary.py b/GPy/kern/_src/stationary.py index a560f8ad..f561baa4 100644 --- a/GPy/kern/_src/stationary.py +++ b/GPy/kern/_src/stationary.py @@ -192,6 +192,27 @@ class Exponential(Stationary): def dK_dr(self, r): return -0.5*self.K_of_r(r) + +class OU(Stationary): + """ + OU kernel: + + .. math:: + + k(r) = \\sigma^2 \exp(- r) \\ \\ \\ \\ \\text{ where } r = \sqrt{\sum_{i=1}^input_dim \\frac{(x_i-y_i)^2}{\ell_i^2} } + + """ + + def __init__(self, input_dim, variance=1., lengthscale=None, ARD=False, active_dims=None, name='OU'): + super(OU, self).__init__(input_dim, variance, lengthscale, ARD, active_dims, name) + + def K_of_r(self, r): + return self.variance * np.exp(-r) + + def dK_dr(self,r): + return -1.*self.variance*np.exp(-r) + + class Matern32(Stationary): """ Matern 3/2 kernel: