mirror of
https://github.com/SheffieldML/GPy.git
synced 2026-05-15 06:52:39 +02:00
eq_ode1 working but test failing?
This commit is contained in:
parent
09de9d7195
commit
98b9dc0163
3 changed files with 12 additions and 35 deletions
|
|
@ -150,33 +150,6 @@ def white(input_dim,variance=1.):
|
|||
part = parts.white.White(input_dim,variance)
|
||||
return kern(input_dim, [part])
|
||||
|
||||
def eq_ode1(output_dim, W=None, rank=1, kappa=None, length_scale=1., decay=None, delay=None):
|
||||
"""Covariance function for first order differential equation driven by an exponentiated quadratic covariance.
|
||||
|
||||
This outputs of this kernel have the form
|
||||
.. math::
|
||||
\frac{\text{d}y_j}{\text{d}t} = \sum_{i=1}^R w_{j,i} f_i(t-\delta_j) +\sqrt{\kappa_j}g_j(t) - d_jy_j(t)
|
||||
|
||||
where :math:`R` is the rank of the system, :math:`w_{j,i}` is the sensitivity of the :math:`j`th output to the :math:`i`th latent function, :math:`d_j` is the decay rate of the :math:`j`th output and :math:`f_i(t)` and :math:`g_i(t)` are independent latent Gaussian processes goverened by an exponentiated quadratic covariance.
|
||||
|
||||
:param output_dim: number of outputs driven by latent function.
|
||||
:type output_dim: int
|
||||
:param W: sensitivities of each output to the latent driving function.
|
||||
:type W: ndarray (output_dim x rank).
|
||||
:param rank: If rank is greater than 1 then there are assumed to be a total of rank latent forces independently driving the system, each with identical covariance.
|
||||
:type rank: int
|
||||
:param decay: decay rates for the first order system.
|
||||
:type decay: array of length output_dim.
|
||||
:param delay: delay between latent force and output response.
|
||||
:type delay: array of length output_dim.
|
||||
:param kappa: diagonal term that allows each latent output to have an independent component to the response.
|
||||
:type kappa: array of length output_dim.
|
||||
|
||||
.. Note: see first order differential equation examples in GPy.examples.regression for some usage.
|
||||
"""
|
||||
part = parts.eq_ode1.Eq_ode1(output_dim, W, rank, kappa, length_scale, decay, delay)
|
||||
return kern(2, [part])
|
||||
|
||||
|
||||
def exponential(input_dim,variance=1., lengthscale=None, ARD=False):
|
||||
"""
|
||||
|
|
|
|||
|
|
@ -747,7 +747,7 @@ class Kern_check_model(Model):
|
|||
if kernel==None:
|
||||
kernel = GPy.kern.rbf(1)
|
||||
if X==None:
|
||||
X = np.random.randn(num_samples, kernel.input_dim)
|
||||
X = np.random.normal(size=(num_samples, kernel.input_dim))
|
||||
if dL_dK==None:
|
||||
if X2==None:
|
||||
dL_dK = np.ones((X.shape[0], X.shape[0]))
|
||||
|
|
@ -844,7 +844,7 @@ class Kern_check_dKdiag_dX(Kern_check_model):
|
|||
def _set_params(self, x):
|
||||
self.X=x.reshape(self.X.shape)
|
||||
|
||||
def kern_test(kern, X=None, X2=None, output_ind=None, verbose=False):
|
||||
def kern_test(kern, X=None, X2=None, output_ind=None, verbose=False, X_positive=False):
|
||||
"""This function runs on kernels to check the correctness of their implementation. It checks that the covariance function is positive definite for a randomly generated data set.
|
||||
|
||||
:param kern: the kernel to be tested.
|
||||
|
|
@ -858,12 +858,16 @@ def kern_test(kern, X=None, X2=None, output_ind=None, verbose=False):
|
|||
pass_checks = True
|
||||
if X==None:
|
||||
X = np.random.randn(10, kern.input_dim)
|
||||
if X_positive:
|
||||
X = abs(X)
|
||||
if output_ind is not None:
|
||||
X[:, output_ind] = np.random.randint(kern.output_dim, X.shape[0])
|
||||
X[:, output_ind] = np.random.randint(kern.parts[0].output_dim, X.shape[0])
|
||||
if X2==None:
|
||||
X2 = np.random.randn(20, kern.input_dim)
|
||||
if X_positive:
|
||||
X2 = abs(X2)
|
||||
if output_ind is not None:
|
||||
X2[:, output_ind] = np.random.randint(kern.output_dim, X2.shape[0])
|
||||
X2[:, output_ind] = np.random.randint(kern.parts[0].output_dim, X2.shape[0])
|
||||
|
||||
if verbose:
|
||||
print("Checking covariance function is positive definite.")
|
||||
|
|
|
|||
|
|
@ -36,12 +36,12 @@ class KernelTests(unittest.TestCase):
|
|||
def test_eq_sympykernel(self):
|
||||
if SYMPY_AVAILABLE:
|
||||
kern = GPy.kern.eq_sympy(5, 3)
|
||||
self.assertTrue(GPy.kern.kern_test(kern, verbose=verbose))
|
||||
self.assertTrue(GPy.kern.kern_test(kern, output_ind=3, verbose=verbose))
|
||||
|
||||
def test_eq_ode1kernel(self):
|
||||
def test_ode1_eqkernel(self):
|
||||
if SYMPY_AVAILABLE:
|
||||
kern = GPy.kern.eq_ode1(3)
|
||||
self.assertTrue(GPy.kern.kern_test(kern, verbose=verbose))
|
||||
kern = GPy.kern.ode1_eq(3)
|
||||
self.assertTrue(GPy.kern.kern_test(kern, output_ind=1, verbose=verbose, X_positive=True))
|
||||
|
||||
def test_rbf_invkernel(self):
|
||||
kern = GPy.kern.rbf_inv(5)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue