mirror of
https://github.com/SheffieldML/GPy.git
synced 2026-06-08 15:05:15 +02:00
new: Added to_dict() method to Ornstein-Uhlenbeck (OU) kernel
This commit is contained in:
parent
426ba1dc27
commit
98fef6d622
2 changed files with 25 additions and 8 deletions
|
|
@ -412,7 +412,6 @@ class Exponential(Stationary):
|
||||||
# return (F, L, Qc, H, Pinf)
|
# return (F, L, Qc, H, Pinf)
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
class OU(Stationary):
|
class OU(Stationary):
|
||||||
"""
|
"""
|
||||||
OU kernel:
|
OU kernel:
|
||||||
|
|
@ -426,6 +425,23 @@ class OU(Stationary):
|
||||||
def __init__(self, input_dim, variance=1., lengthscale=None, ARD=False, active_dims=None, name='OU'):
|
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)
|
super(OU, self).__init__(input_dim, variance, lengthscale, ARD, active_dims, name)
|
||||||
|
|
||||||
|
def to_dict(self):
|
||||||
|
"""
|
||||||
|
Convert the object into a json serializable dictionary.
|
||||||
|
|
||||||
|
Note: It uses the private method _save_to_input_dict of the parent.
|
||||||
|
|
||||||
|
:return dict: json serializable dictionary containing the needed information to instantiate the object
|
||||||
|
"""
|
||||||
|
input_dict = super(OU, self)._save_to_input_dict()
|
||||||
|
input_dict["class"] = "GPy.kern.OU"
|
||||||
|
return input_dict
|
||||||
|
|
||||||
|
@staticmethod
|
||||||
|
def _build_from_input_dict(kernel_class, input_dict):
|
||||||
|
useGPU = input_dict.pop('useGPU', None)
|
||||||
|
return OU(**input_dict)
|
||||||
|
|
||||||
def K_of_r(self, r):
|
def K_of_r(self, r):
|
||||||
return self.variance * np.exp(-r)
|
return self.variance * np.exp(-r)
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -26,14 +26,15 @@ class Test(unittest.TestCase):
|
||||||
k7 = GPy.kern.Matern32(2, variance=1.0, lengthscale=[1.0,3.0], ARD=True, active_dims = [1,1])
|
k7 = GPy.kern.Matern32(2, variance=1.0, lengthscale=[1.0,3.0], ARD=True, active_dims = [1,1])
|
||||||
k8 = GPy.kern.Matern52(2, variance=2.0, lengthscale=[2.0,1.0], ARD=True, active_dims = [1,0])
|
k8 = GPy.kern.Matern52(2, variance=2.0, lengthscale=[2.0,1.0], ARD=True, active_dims = [1,0])
|
||||||
k9 = GPy.kern.ExpQuad(2, variance=3.0, lengthscale=[1.0,2.0], ARD=True, active_dims = [0,1])
|
k9 = GPy.kern.ExpQuad(2, variance=3.0, lengthscale=[1.0,2.0], ARD=True, active_dims = [0,1])
|
||||||
k10 = k1 + k1.copy() + k2 + k3 + k4 + k5 + k6
|
k10 = GPy.kern.OU(2, variance=2.0, lengthscale=[2.0, 1.0], ARD=True, active_dims=[1, 0])
|
||||||
k11 = k1 * k2 * k2.copy() * k3 * k4 * k5
|
k11 = k1 + k1.copy() + k2 + k3 + k4 + k5 + k6
|
||||||
k12 = (k1 + k2) * (k3 + k4 + k5)
|
k12 = k1 * k2 * k2.copy() * k3 * k4 * k5
|
||||||
k13 = ((k1 + k2) * k3) + k4 + k5 * k7
|
k13 = (k1 + k2) * (k3 + k4 + k5)
|
||||||
k14 = ((k1 + k2) * k3) + k4 * k5 + k8
|
k14 = ((k1 + k2) * k3) + k4 + k5 * k7
|
||||||
k15 = ((k1 * k2) * k3) + k4 * k5 + k8 + k9
|
k15 = ((k1 + k2) * k3) + k4 * k5 + k8 * k10
|
||||||
|
k16 = ((k1 * k2) * k3) + k4 * k5 + k8 + k9
|
||||||
|
|
||||||
k_list = [k1,k2,k3,k4,k5,k6,k7,k8,k9,k10,k11,k12,k13,k14,k15]
|
k_list = [k1,k2,k3,k4,k5,k6,k7,k8,k9,k10,k11,k12,k13,k14,k15,k16]
|
||||||
|
|
||||||
for kk in k_list:
|
for kk in k_list:
|
||||||
kk_dict = kk.to_dict()
|
kk_dict = kk.to_dict()
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue