Learn R Programming

scorematchingad

The goal of scorematchingad is to enable fast implementation of score matching estimators through the use of automatic differentiation in the CppAD library. Such implementation is best done by either contributing to this package or creating a new package that links to this package. On linux with the gcc compiler it is possible to create estimators for new models interactively using customll() (I am pondering how it is that this feature only works on linux with gcc).

See the file DESCRIPTION for a slightly longer description, and ./R/scorematchingad-package.R (equivalently help(scorematchingad, scorematchingad) from within R) for an even longer description. The built-in help for R packages is well populated.

Installation

You can install the development version of scorematchingad from GitHub with:

# install.packages("devtools")
devtools::install_github("kasselhingee/scorematchingad")

Example

Some models are already incorporated into scorematchingad. Below is an example of estimating the Polynomially-Tilted Pairwise Interaction model (Scealy and Wood, 2023) for compositional data:

library(scorematchingad)
model <- rppi_egmodel(100)
estalr <- ppi(model$sample,
              paramvec = ppi_paramvec(betap = -0.5, p = ncol(model$sample)),
              trans = "alr")

This is an example of obtaining a tape of the score matching discrepancy of a custom likelihood for compositional data, which most naturally lies on the simplex:

myll <- customll("a1type dirichlet(const veca1 &u, const veca1 &beta) {
  size_t d  = u.size();
  a1type y(0.);  // initialize summation at 0
  for(size_t i = 0; i < d; i++)
  {   y   += beta[i] * log(u[i]);
  }
  return y;
}")

tapes <- buildsmdtape("sim", "identity", "sim", 
 myll, rep(1/3, 3), rep(NA, 3), 
 bdryw="minsq", acut = 0.01)

Using scorematchingad in Other Packages [draft notes]

  • Avoid including the implementations of wrap and as for veca1, mata1 etc except in RcppExports.cpp. This makes sure that the speciailsations definitions are not duplicated for each .cpp file in your ./src directory. In practise you can get the scorematchingad types by including just the _forward.h header file.

Copy Link

Version

Install

install.packages('scorematchingad')

Monthly Downloads

206

Version

0.1.1

License

GPL (>= 3)

Issues

Pull Requests

Stars

Forks

Maintainer

Kassel Liam Hingee

Last Published

January 8th, 2025

Functions in scorematchingad (0.1.1)

evaltape

Evaluate a CppAD Tape Many Times
microbiome

16s Microbiome Data for Soil-Transmitted Helminths
ppi

Estimation of Polynomially-Tilted Pairwise Interaction (PPI) Model
ppi_robust

Robustly Estimate Parameters of the PPI Distribution
ppi_cW

Quickly Generate a Vector of Windham Exponents for the PPI Model
print,Rcpp_ADFun

Print or show a summary of an Rcpp_ADFun
scorematchingad-package

scorematchingad: Score Matching Estimation by Automatic Differentiation
ppi_param_tools

PPI Parameter Tools
rsymmetricmatrix

Quickly Generate a Symmetric Matrix for Testing and Examples
ppi_mmmm

A PPI Score-Matching Marginal Moment Matching Estimator (dimension=3 only)
rppi

Simulate from a PPI Model
quadratictape_parts

Evaluate the Hessian and Gradient Offset of a Taped Quadratic Function
tape_Hessian

Tape the Hessian of a CppAD Tape
smvalues

Compute Score Matching Discrepancy Value, Gradient, and Hessian
scorematchingtheory

Introduction to Score Matching
tape_smd

Build CppAD Tapes for Score Matching
tape_uld

Generate a tape of a custom unnormalised log-density
tape_Jacobian

Tape the Jacobian of CppAD Tape
tape_logJacdet

Tape the log of Jacobian determinant of a CppAD Tape
testquadratic

Test Whether a CppAD Tape is a Quadratic Function
tape_gradoffset

Tape the Gradient Offset of a Quadratic CppAD Tape
tape_swap

Switch Dynamic and Independent Values of a Tape
vMF

Score Matching Estimator for the von-Mises Fisher Distribution
vMF_robust

Robust Fitting of von Mises Fisher
Bingham

Score Matching Estimators for the Bingham Distribution
FB

Estimate the Fisher-Bingham Distribution
Rcpp_ADFun-class

A Class for CppAD Tapes
cppad_search

Iterative Score Matching Estimator Using Conjugate-Gradient Descent
dppi

Improper Log-Density of the PPI Model
Windham_populationinverse

Inverse Transform for the Population Parameters Under Windham Weights
Windham

Windham Robustification of Point Estimators for Exponential Family Distributions
cppad_closed

Score Matching Estimator for Quadratic-Form Score Matching Discrepancies