From 20cc336a7a20ec3f6cec5bfba67242f13342babf Mon Sep 17 00:00:00 2001 From: Nicolas Date: Mon, 21 Jan 2013 13:29:25 +0000 Subject: [PATCH] added periodic kernels --- GPy/kern/__init__.py | 2 +- GPy/kern/constructors.py | 57 ++++++++++++++++++++++++++++++++++++++++ 2 files changed, 58 insertions(+), 1 deletion(-) diff --git a/GPy/kern/__init__.py b/GPy/kern/__init__.py index 4a36d6d0..eae717be 100644 --- a/GPy/kern/__init__.py +++ b/GPy/kern/__init__.py @@ -2,5 +2,5 @@ # Licensed under the BSD 3-clause license (see LICENSE.txt) -from constructors import rbf, Matern32, Matern52, exponential, linear, white, bias, finite_dimensional, spline, Brownian, linear_ARD, rbf_sympy, sympykern +from constructors import rbf, Matern32, Matern52, exponential, linear, white, bias, finite_dimensional, spline, Brownian, linear_ARD, rbf_sympy, sympykern, periodic_exponential, periodic_Matern32, periodic_Matern52 from kern import kern diff --git a/GPy/kern/constructors.py b/GPy/kern/constructors.py index ab39fcb2..49639711 100644 --- a/GPy/kern/constructors.py +++ b/GPy/kern/constructors.py @@ -16,6 +16,9 @@ from bias import bias as biaspart from finite_dimensional import finite_dimensional as finite_dimensionalpart from spline import spline as splinepart from Brownian import Brownian as Brownianpart +from periodic_exponential import periodic_exponential as periodic_exponentialpart +from periodic_Matern32 import periodic_Matern32 as periodic_Matern32part +from periodic_Matern52 import periodic_Matern52 as periodic_Matern52part #TODO these s=constructors are not as clean as we'd like. Tidy the code up #using meta-classes to make the objects construct properly wthout them. @@ -196,3 +199,57 @@ def sympykern(D,k): A kernel from a symbolic sympy representation """ return kern(D,[spkern(D,k)]) + +def periodic_exponential(D=1,variance=1., lengthscale=None, period=2*np.pi,n_freq=10,lower=0.,upper=4*np.pi): + """ + Construct an periodic exponential kernel + + :param D: dimensionality, only defined for D=1 + :type D: int + :param variance: the variance of the kernel + :type variance: float + :param lengthscale: the lengthscale of the kernel + :type lengthscale: float + :param period: the period + :type period: float + :param n_freq: the number of frequencies considered for the periodic subspace + :type n_freq: int + """ + part = periodic_exponentialpart(D,variance, lengthscale, ARD) + return kern(D, [part]) + +def periodic_Matern32(D,variance=1., lengthscale=None, period=2*np.pi,n_freq=10,lower=0.,upper=4*np.pi): + """ + Construct a periodic Matern 3/2 kernel. + + :param D: dimensionality, only defined for D=1 + :type D: int + :param variance: the variance of the kernel + :type variance: float + :param lengthscale: the lengthscale of the kernel + :type lengthscale: float + :param period: the period + :type period: float + :param n_freq: the number of frequencies considered for the periodic subspace + :type n_freq: int + """ + part = periodic_Matern32part(D,variance, lengthscale, ARD) + return kern(D, [part]) + +def periodic_Matern52(D,variance=1., lengthscale=None, period=2*np.pi,n_freq=10,lower=0.,upper=4*np.pi): + """ + Construct a periodic Matern 5/2 kernel. + + :param D: dimensionality, only defined for D=1 + :type D: int + :param variance: the variance of the kernel + :type variance: float + :param lengthscale: the lengthscale of the kernel + :type lengthscale: float + :param period: the period + :type period: float + :param n_freq: the number of frequencies considered for the periodic subspace + :type n_freq: int + """ + part = periodic_Matern52part(D,variance, lengthscale, ARD) + return kern(D, [part])