Learn R Programming

⚠️There's a newer version (0.1.1) of this package.Take me there.

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

165

Version

0.0.67

License

GPL (>= 3)

Issues

Pull Requests

Stars

Forks

Maintainer

Kassel Liam Hingee

Last Published

July 25th, 2024

Functions in scorematchingad (0.0.67)

quadratictape_parts

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

Quickly Generate a Vector of Windham Exponents for the PPI Model
microbiome

16s Microbiome Data for Soil-Transmitted Helminths
ppi_mmmm

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

Robustly Estimate Parameters of the PPI Distribution
evalll

Evaluate a custom log-likelihood function
evaltape

Evaluate a CppAD Tape Many Times
ppi

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

Build New Tapes from Existing Tapes
vMF

Score Matching Estimator for the von-Mises Fisher Distribution
vMF_robust

Robust Fitting of von Mises Fisher
scorematchingad-package

scorematchingad: Score Matching Estimation by Automatic Differentiation
scorematchingtheory

Introduction to Score Matching
ppi_param_tools

PPI Parameter Tools
smvalues

Compute Score Matching Discrepancy Value, Gradient, and Hessian
testquadratic

Test Whether a CppAD Tape is a Quadratic Function
rppi

Simulate from a PPI Model
rsymmetricmatrix

Quickly Generate a Symmetric Matrix for Testing and Examples
dppi

Improper Log-Density of the PPI Model
Windham_populationinverse

Inverse Transform for the Population Parameters Under Windham Weights
ADFun

A Class for Storing a CppAD Tape (ADFun) Object
buildsmdtape

Build CppAD Tapes for Score Matching
cppad_closed

Score Matching Estimator for Quadratic-Form Score Matching Discrepancies
Windham

Windham Robustification of Point Estimators for Exponential Family Distributions
customll

Compile a custom log-likelihood function.
FB

Estimate the Fisher-Bingham Distribution
cppad_search

Iterative Score Matching Estimator Using Conjugate-Gradient Descent
Bingham

Score Matching Estimators for the Bingham Distribution