Learn R Programming

kergp (version 0.5.7)

checkGrad: Check the Gradient Provided in a covMan Object

Description

Check the gradient provided in a covMan object.

Usage

checkGrad(object, sym = TRUE,
          x1 = NULL, n1 = 10,
          x2 = NULL, n2 = NULL,
          XLower = NULL, XUpper = NULL,
          plot = TRUE)

Value

A list of results related to the Jacobians

test

Max of the absolute difference between the gradient obtained by numeric differentiation and the gradient provided by the kernel object.

Jnum, J

Jacobians (arrays) computed with numDeriv::jacobian and provided by the kernel object.

x1, x2, K

The matrices used for the check, and the matrix of kernel values with dimension c(n1, n2). The element x2 can be NULL if the determination of the matrix x2 was not necessary.

Arguments

object

A covMan object.

sym

Logical. If TRUE, the check is done assuming that x2 is identical to x1, so the provided values for x2 and n2 (if any) will be ignored.

x1

Matrix to be used as the first argument of the kernel.

n1

Number of rows for the matrix x1. Used only when x1 is not provided.

x2

Matrix to be used as the second argument of the kernel.

n2

Number of rows for the matrix x2. Used only when x2 is not provided.

XLower

Vector of lower bounds to draw x1 and x2 when needed.

XUpper

Vector of upper bounds to draw x1 and x2 when needed.

plot

Logical. If TRUE, a plot is shown comparing the two arrays of gradients.

Caution

For now the function only works when object has class "covMan".

Author

Yves Deville

Details

Each of the two matrices x1 and x2 with n1 and n2 rows can be given or instead be drawn at random. The matrix of kernel values with dimension c(n1, n2) is computed, together with its gradient with dimension c(n1, n2, npar) where npar is the number of parameters of the kernel. A numerical differentiation w.r.t. the kernel parameters is performed for the kernel value at x1 and x2, and the result is compared to that provided by the kernel function (the function described in the slot named "kernel" of object). Note that the value of the parameter vector is the value provided by coef(object) and it can be changed by using the replacement method `coef<-` if needed.