make.c.dist: Define a probability distribution object with C log-density

Description Usage Arguments Details Value See Also

View source: R/00dist-util.R

Description

Defines a probability distribution object for use with compare.samplers with log-density implemented in C.

Usage

1
2
make.c.dist(ndim, name, c.log.density, c.context = NULL,
             name.expression = NULL, mean = NULL, cov = NULL)

Arguments

ndim

The size of the distribution's state space.

name

A human-readable name for the distribution.

c.log.density

A C function returning the log-density and gradient of the target distribution.

c.context

An opaque object passed to c.log.density

name.expression

A name for the distribution in plotmath notation. Used in preference to name in plot functions when available.

mean

A vector specifying the true mean of the distribution.

cov

A matrix specifying the true covariance of the distribution.

Details

See make.dist for discussion of ndim, name, name.expression, mean, and cov.

c.log.density is a string containing the symbol name of a C function that computes the log density and log density gradient of the target distribution. It has the type log_density_t, defined in SamplerCompare.h as:

1
2
3
4
5
6
7
typedef double log_density_t(dist_t *ds, double *x,
                             int compute_grad, double *grad);
typedef struct {
  log_density_t *log_dens;
  SEXP context;
  int ndim;
} dist_t;

The ds structure defines the distribution, where the log_dens element is a pointer to the function named by c.log.density, the context element is a SEXP containing the c.context parameter, and ndim is the ndim parameter to make.c.dist.

The x parameter is an ndim-long array of doubles containing the location at which to evaluate the log-density, which the log_density_t should return.

If compute_grad is nonzero, the function should compute the gradient of the log density and store it in the double array pointed to by grad. If for some reason it cannot do this, it should call the R-internal error function to report an error to the user. If the implementor does not plan to sample from the distribution with a method that computes gradients, this can reduce implementation effort.

The details of this interface are described in greater detail in “R/C Glue in SamplerCompare”.

Value

A scdist object.

See Also

compare.samplers, make.dist, “R/C Glue in SamplerCompare” (vignette)


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