mirror of
https://github.com/SheffieldML/GPy.git
synced 2026-05-09 12:02:38 +02:00
added sympykern as a 'kernpart' object.
now we can add sympykerns to any other kern
This commit is contained in:
parent
46754db658
commit
fb21a3589b
5 changed files with 302 additions and 1 deletions
|
|
@ -21,6 +21,7 @@ from Brownian import Brownian as Brownianpart
|
|||
#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.
|
||||
|
||||
|
||||
def rbf(D,variance=1., lengthscale=1.):
|
||||
"""
|
||||
Construct an RBF kernel
|
||||
|
|
@ -170,3 +171,20 @@ def Brownian(D,variance=1.):
|
|||
"""
|
||||
part = Brownianpart(D,variance)
|
||||
return kern(D, [part])
|
||||
|
||||
import sympy as sp
|
||||
from sympykern import spkern
|
||||
from sympy.parsing.sympy_parser import parse_expr
|
||||
|
||||
def rbf_sympy(D,variance=1., lengthscale=1.):
|
||||
"""
|
||||
Radial Basis Function covariance.
|
||||
"""
|
||||
X = [sp.var('x%i'%i) for i in range(D)]
|
||||
Z = [sp.var('z%i'%i) for i in range(D)]
|
||||
rbf_variance = sp.var('rbf_variance',positive=True)
|
||||
rbf_lengthscale = sp.var('rbf_lengthscale',positive=True)
|
||||
dist_string = ' + '.join(['(x%i-z%i)**2'%(i,i) for i in range(D)])
|
||||
dist = parse_expr(dist_string)
|
||||
f = rbf_variance*sp.exp(-dist/(2*rbf_lengthscale**2))
|
||||
return kern(D,[spkern(D,f,np.array([variance,lengthscale]))])
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue