Learn R Programming

scorematchingad (version 0.1.1)

smvalues: Compute Score Matching Discrepancy Value, Gradient, and Hessian

Description

Computes a range of relevant information for investigating score matching estimators.

Usage

smvalues(smdtape, xmat, pmat, xcentres = NA * xmat, approxorder = 10)

smvalues_wsum( tape, xmat, pmat, w = NULL, xcentres = NA * xmat, approxorder = 10 )

Value

A list of

  • obj the score matching discrepancy values

  • grad the gradient of the score matching discrepancy

  • hess the Hessian of the score matching discrepancy

Arguments

smdtape

A taped score matching discrepancy. Most easily created by tape_smd().

xmat

A matrix of (multivariate) independent variables where each represents a single independent variable vector. Or a single independent variable vector that is used for all rows of pmat.

pmat

A matrix of dynamic parameters where each row specifies a new set of values for the dynamic parameters of tape. Or a single vector of dynamic parameters to use for all rows of xmat.

xcentres

A matrix of approximation for Taylor approximation centres for xmat. Use values of NA for rows that do not require Taylor approximation.

approxorder

Order of Taylor approximation

tape

An Rcpp_ADFun object (i.e. a tape of a function).

w

Weights to apply to each row of xmat for computing the weighted sum. If NULL then each row is given a weight of 1.

Details

Computes the score matching discrepancy function from scorematchingtheory or weighted sum of the score matching discrepancy function. The gradient and Hessian are returned as arrays of row-vectors with each row corresponding to a row in xmat and pmat. Convert a Hessian row-vector to a matrix using matrix(ncol = length(smdtape$xtape)).

See Also

Other tape evaluators: evaltape(), quadratictape_parts(), testquadratic()

Examples

Run this code
m <- rppi_egmodel(100)
smdtape <- tape_smd("sim", "sqrt", "sph", "ppi",
              ytape = rep(1/m$p, m$p),
              usertheta = ppi_paramvec(beta = m$beta),
              bdryw = "minsq", acut = 0.01)$smdtape
smvalues(smdtape, xmat = m$sample, pmat = m$theta[1:5])
smvalues_wsum(smdtape, m$sample, m$theta[1:5])$grad/nrow(m$sample)

Run the code above in your browser using DataLab