mirror of
https://github.com/SheffieldML/GPy.git
synced 2026-05-07 19:12:40 +02:00
added polynomial kernel
This commit is contained in:
parent
7d41001ae1
commit
beebf6933a
2 changed files with 43 additions and 0 deletions
|
|
@ -10,6 +10,7 @@ from _src.independent_outputs import IndependentOutputs, Hierarchical
|
||||||
from _src.coregionalize import Coregionalize
|
from _src.coregionalize import Coregionalize
|
||||||
from _src.ssrbf import SSRBF # TODO: ZD: did you remove this?
|
from _src.ssrbf import SSRBF # TODO: ZD: did you remove this?
|
||||||
from _src.ODE_UY import ODE_UY
|
from _src.ODE_UY import ODE_UY
|
||||||
|
from _src.poly import Poly
|
||||||
#from _src.ODE_UYC import ODE_UYC ADD THIS FILE TO THE REPO!!
|
#from _src.ODE_UYC import ODE_UYC ADD THIS FILE TO THE REPO!!
|
||||||
#from _src.ODE_st import ODE_st
|
#from _src.ODE_st import ODE_st
|
||||||
# TODO: put this in an init file somewhere
|
# TODO: put this in an init file somewhere
|
||||||
|
|
|
||||||
42
GPy/kern/_src/poly.py
Normal file
42
GPy/kern/_src/poly.py
Normal file
|
|
@ -0,0 +1,42 @@
|
||||||
|
# Copyright (c) 2014, James Hensman
|
||||||
|
# Licensed under the BSD 3-clause license (see LICENSE.txt)
|
||||||
|
|
||||||
|
import numpy as np
|
||||||
|
from kern import Kern
|
||||||
|
from ...util.misc import param_to_array
|
||||||
|
from ...core.parameterization import Param
|
||||||
|
from ...core.parameterization.transformations import Logexp
|
||||||
|
class Poly(Kern):
|
||||||
|
"""
|
||||||
|
Polynomial kernel
|
||||||
|
"""
|
||||||
|
|
||||||
|
def __init__(self, input_dim, variance=1., order=3., active_dims=None, name='poly'):
|
||||||
|
super(Poly, self).__init__(input_dim, active_dims, name)
|
||||||
|
self.variance = Param('variance', variance, Logexp())
|
||||||
|
self.add_parameter(self.variance)
|
||||||
|
self.order=order
|
||||||
|
|
||||||
|
def K(self, X, X2=None):
|
||||||
|
return (self._dot_product(X, X2) + 1.)**self.order * self.variance
|
||||||
|
|
||||||
|
def _dot_product(self, X, X2=None):
|
||||||
|
if X2 is None:
|
||||||
|
return np.dot(X, X.T)
|
||||||
|
else:
|
||||||
|
return np.dot(X, X2.T)
|
||||||
|
|
||||||
|
def Kdiag(self, X):
|
||||||
|
return self.variance*(np.square(X).sum(1) + 1.)**self.order
|
||||||
|
|
||||||
|
def update_gradients_full(self, dL_dK, X, X2=None):
|
||||||
|
self.variance.gradient = np.sum(dL_dK * (self._dot_product(X, X2) + 1.)**self.order)
|
||||||
|
|
||||||
|
def update_gradients_diag(self, dL_dKdiag, X):
|
||||||
|
raise NotImplementedError
|
||||||
|
|
||||||
|
def gradients_X(self, dL_dK, X, X2=None):
|
||||||
|
raise NotImplementedError
|
||||||
|
|
||||||
|
def gradients_X_diag(self, dL_dKdiag, X):
|
||||||
|
raise NotImplementedError
|
||||||
Loading…
Add table
Add a link
Reference in a new issue