check.dist.gradient: Test a gradient function

View source: R/00dist-util.R

check.dist.gradientR Documentation

Test a gradient function

Description

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

Usage

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

  check.dist.gradient(N2weakcor.dist, runif(2))

SamplerCompare documentation built on April 24, 2023, 9:09 a.m.