# Path: pygp/covar/se.py
# class SqexpCFARD(CovarianceFunction):
#     def __init__(self,*args,**kwargs):
#     def get_hyperparameter_names(self):
#     def get_number_of_parameters(self):
#     def K(self, theta, x1, x2=None):
#     def Kdiag(self,theta, x1):
#     def Kgrad_theta(self, theta, x1, i):
#     def Kgrad_x(self,theta,x1,x2,d):
#     def Kgrad_xdiag(self,theta,x1,d):
#         V0 = SP.exp(2*theta[0])
#         L  = SP.exp(theta[1:1+self.n_dimensions])
#         V0 = SP.exp(2*theta[0])
#         V0 = SP.exp(2*theta[0])
#         L  = SP.exp(theta[1:1+self.n_dimensions])
#         L2 = SP.exp(2*theta[1:1+self.n_dimensions])
#         RV = SP.zeros([x1.shape[0]])
# 
# Path: pygp/covar/combinators.py
# class SumCF(CovarianceFunction):
# class ProductCF(CovarianceFunction):
# class ShiftCF(CovarianceFunction):
#     def __init__(self, covars, *args, **kw_args):
#     def get_hyperparameter_names(self):
#     def K(self, theta, x1, x2=None):
#     def Kgrad_theta(self, theta, x1, i):
#     def Kgrad_x(self, theta, x1, x2, d):
#     def Kgrad_xdiag(self, theta, x1, d):
#     def __init__(self, covars, *args, **kw_args):
#     def get_hyperparameter_names(self):
#     def K(self, theta, x1, x2=None):
#     def Kgrad_theta(self, theta, x, i):
#     def Kgrad_x(self, theta, x1, x2, d):
#     def Kgrad_xdiag(self, theta, x1, d):
#     def __init__(self, covar, replicate_indices, *args, **kw_args):
#     def get_hyperparameter_names(self):
#     def K(self, theta, x1, x2=None):
#     def Kgrad_theta(self, theta, x, i):
#     def _shift_x(self, x, T):
#             K_ = covar.K(_theta, x1, x2)
#                 K = K_
#         RV = sp.zeros([x1.shape[0], x1.shape[0]])
#         RV = sp.zeros([x1.shape[0]])
#             K = sp.ones([x1.shape[0], x1.shape[0]])
#             K = sp.ones([x1.shape[0], x2.shape[0]])
#         T = theta[covar_n_hyper:covar_n_hyper + self.n_replicates]
#         K = self.covar.K(theta[:covar_n_hyper], shift_x1, x2)
#         T = theta[covar_n_hyper:covar_n_hyper + self.n_replicates]


import unittest
import scipy as SP
import scipy.optimize.optimize as OPT
from pygp.covar import se, combinators
from pygp.gp.basic_gp import GP
from pygp.optimize.optimize import param_dict_to_list, opt_hyper
        Kd_SECF21 = self.SECF.Kd(self.logtheta[2:], self.x, 0)
        Kd_SECF22 = self.SECF.Kd(self.logtheta[2:], self.x, 1)

        Kd_SECF11 = (Kd_SECF11 * K_SECF2)
        Kd_SECF12 = (Kd_SECF12 * K_SECF2)
        Kd_SECF21 = (K_SECF1 * Kd_SECF21)
        Kd_SECF22 = (K_SECF1 * Kd_SECF22)

        for i in range(Kd_Prod1.shape[0]):
            for j in range(Kd_Prod1.shape[1]):
                self.assertAlmostEqual(Kd_Prod1[i,j], Kd_SECF11[i,j],4)
                self.assertAlmostEqual(Kd_Prod2[i,j], Kd_SECF12[i,j],4)
                self.assertAlmostEqual(Kd_Prod3[i,j], Kd_SECF21[i,j],4)
                self.assertAlmostEqual(Kd_Prod4[i,j], Kd_SECF22[i,j],4)

    def test_grad(self):
        hyper = opt_hyper(self.gpr, {'covar':self.logtheta})[0]
        hyperparams = hyper
#        X0 = param_dict_to_list(hyperparams)
#        Ifilter_x = {'covar':SP.ones(len(X0),dtype='bool')}

        def f(x):
            x_ = hyperparams
#            x_[Ifilter_x] = x
            rv =  self.gpr.LML(x_)
            #LG.debug("L("+str(x_)+")=="+str(rv))
            if SP.isnan(rv):
                return 1E6
            return rv
        

# Path: pygp/covar/se.py
# class SqexpCFARD(CovarianceFunction):
#     def __init__(self,*args,**kwargs):
#     def get_hyperparameter_names(self):
#     def get_number_of_parameters(self):
#     def K(self, theta, x1, x2=None):
#     def Kdiag(self,theta, x1):
#     def Kgrad_theta(self, theta, x1, i):
#     def Kgrad_x(self,theta,x1,x2,d):
#     def Kgrad_xdiag(self,theta,x1,d):
#         V0 = SP.exp(2*theta[0])
#         L  = SP.exp(theta[1:1+self.n_dimensions])
#         V0 = SP.exp(2*theta[0])
#         V0 = SP.exp(2*theta[0])
#         L  = SP.exp(theta[1:1+self.n_dimensions])
#         L2 = SP.exp(2*theta[1:1+self.n_dimensions])
#         RV = SP.zeros([x1.shape[0]])
# 
# Path: pygp/covar/combinators.py
# class SumCF(CovarianceFunction):
# class ProductCF(CovarianceFunction):
# class ShiftCF(CovarianceFunction):
#     def __init__(self, covars, *args, **kw_args):
#     def get_hyperparameter_names(self):
#     def K(self, theta, x1, x2=None):
#     def Kgrad_theta(self, theta, x1, i):
#     def Kgrad_x(self, theta, x1, x2, d):
#     def Kgrad_xdiag(self, theta, x1, d):
#     def __init__(self, covars, *args, **kw_args):
#     def get_hyperparameter_names(self):
#     def K(self, theta, x1, x2=None):
#     def Kgrad_theta(self, theta, x, i):
#     def Kgrad_x(self, theta, x1, x2, d):
#     def Kgrad_xdiag(self, theta, x1, d):
#     def __init__(self, covar, replicate_indices, *args, **kw_args):
#     def get_hyperparameter_names(self):
#     def K(self, theta, x1, x2=None):
#     def Kgrad_theta(self, theta, x, i):
#     def _shift_x(self, x, T):
#             K_ = covar.K(_theta, x1, x2)
#                 K = K_
#         RV = sp.zeros([x1.shape[0], x1.shape[0]])
#         RV = sp.zeros([x1.shape[0]])
#             K = sp.ones([x1.shape[0], x1.shape[0]])
#             K = sp.ones([x1.shape[0], x2.shape[0]])
#         T = theta[covar_n_hyper:covar_n_hyper + self.n_replicates]
#         K = self.covar.K(theta[:covar_n_hyper], shift_x1, x2)
#         T = theta[covar_n_hyper:covar_n_hyper + self.n_replicates]


# Path: exclude-test/test_covar.combinators.py
import unittest
import scipy as SP
import scipy.optimize.optimize as OPT
from pygp.covar import se, combinators
from pygp.gp.basic_gp import GP
from pygp.optimize.optimize import param_dict_to_list, opt_hyper

        Kd_SECF21 = self.SECF.Kd(self.logtheta[2:], self.x, 0)
        Kd_SECF22 = self.SECF.Kd(self.logtheta[2:], self.x, 1)

        Kd_SECF11 = (Kd_SECF11 * K_SECF2)
        Kd_SECF12 = (Kd_SECF12 * K_SECF2)
        Kd_SECF21 = (K_SECF1 * Kd_SECF21)
        Kd_SECF22 = (K_SECF1 * Kd_SECF22)

        for i in range(Kd_Prod1.shape[0]):
            for j in range(Kd_Prod1.shape[1]):
                self.assertAlmostEqual(Kd_Prod1[i,j], Kd_SECF11[i,j],4)
                self.assertAlmostEqual(Kd_Prod2[i,j], Kd_SECF12[i,j],4)
                self.assertAlmostEqual(Kd_Prod3[i,j], Kd_SECF21[i,j],4)
                self.assertAlmostEqual(Kd_Prod4[i,j], Kd_SECF22[i,j],4)

    def test_grad(self):
        hyper = opt_hyper(self.gpr, {'covar':self.logtheta})[0]
        hyperparams = hyper
#        X0 = param_dict_to_list(hyperparams)
#        Ifilter_x = {'covar':SP.ones(len(X0),dtype='bool')}

        def f(x):
            x_ = hyperparams
#            x_[Ifilter_x] = x
            rv =  self.gpr.LML(x_)
            #LG.debug("L("+str(x_)+")=="+str(rv))
            if SP.isnan(rv):
                return 1E6
            return rv
        

        def df(x):