utility function to check the gradient of the gp

def checkGradient(self,h=1e-6,verbose=True):
        """ utility function to check the gradient of the gp """
        grad_an = self.LMLgrad()
        grad_num = {}
        params0 = self.params.copy()
        for key in list(self.params.keys()):
            paramsL = params0.copy()
            paramsR = params0.copy()
            grad_num[key] = SP.zeros_like(self.params[key])
            e = SP.zeros(self.params[key].shape[0])
            for i in range(self.params[key].shape[0]):
                e[i] = 1
                paramsL[key]=params0[key]-h*e
                paramsR[key]=params0[key]+h*e
                lml_L = self.LML(paramsL)
                lml_R = self.LML(paramsR)
                grad_num[key][i] = (lml_R-lml_L)/(2*h)
                e[i] = 0
            if verbose:
                print(('%s:'%key))
                print((abs(grad_an[key]-grad_num[key])))
                print('')
        self.setParams(params0)