I want to calculate the derivative of the function f by Rcpp. I just found some resources in https://cran.r-project.org/web/packages/StanHeaders/vignettes/stanmath.html, which use stan headers and rcppEigen. Since all my program is coded by rcpparmadillio, I'm wondering how can I access to the auto-derivative functions by rcpparmadillio and stan header(May be other AD packages).
#include <RcppArmadillo.h>
// [[Rcpp::plugins("cpp11")]]
// [[Rcpp::depends(RcppArmadillo)]]
#include <RcppArmadilloExtensions/sample.h>
using namespace Rcpp;
using namespace arma;
using namespace std;
/* function */
// [[Rcpp::export]]
doule f(arma::rowvec x){
arma::mat yy=x.t()*x;
double res=arma::sun(x);
rerutn(res);
}
The (currently very new) tsetsad package does this for the context of ETS ("smoothing") time series models, relying on facilities of package TMB. This is then used by package tsets which itself uses RcppArmadillo.
All this is fairly new and I have not had a chance to poke around much myself -- but it provides a working demonstration which is quite exciting.