check.dist.gradient: Test a gradient function

Description Usage Arguments Details See Also Examples

View source: R/00dist-util.R

Description

Evaluates the gradient function of a distribution object and compares it to a numeric gradient computed from the log density function.

Usage

1
check.dist.gradient(ds, x, h=1e-7)

Arguments

ds

A distribution object with defined log density and gradient functions.

x

A point inside the support of ds.

h

An offset from x at which to evaluate the log density when computing numeric derivatives.

Details

check.dist.gradient computes the numeric derivative of ds$log.density at x in each of its coordinates and compares this to the value returned by ds$grad.log.density. If the relative error is greater than 0.001, an error is reported.

This function can be used when defining a distribution to ensure that the gradient function is implemented correctly.

See Also

make.dist

Examples

1

SamplerCompare documentation built on May 2, 2019, 7:55 a.m.