On Stack Overflow the question was asked how to numerically integrate a function over a infinite range in Rcpp, e.g. by using RcppNumerical. As an example, the integral
\[ \int_{-\infty}^{\infty} \mathrm{d}x \exp\left(-\frac{(x-\mu)^4}{2}\right) \]
was given. Using RcppNumerical is straight forward. One defines a class that extends Numer::Func for the function and an interface function that calls Numer::integrate on it:
// [[Rcpp::depends(RcppEigen)]] // [[Rcpp::depends(RcppNumerical)]] #include <RcppNumerical.h> class exp4: public Numer::Func { private: double mean; public: exp4(double mean_) : mean(mean_) {} double operator()(const double& x) const { return exp(-pow(x-mean, 4) / 2); } }; // [[Rcpp::export]] Rcpp::NumericVector integrate_exp4(const double &mean, const double &lower, const double &upper) { exp4 function(mean); double err_est; int err_code; const double result = Numer::integrate(function, lower, upper, err_est, err_code); return Rcpp::NumericVector::create(Rcpp::Named("result") = result, Rcpp::Named("error") = err_est); } This works fine for finite ranges:

The RcppArrayFire package provides an interface from R to and from the ArrayFire library, an open source library that can make use of GPUs and other hardware accelerators via CUDA or OpenCL. In order to use RcppArrayFire you will need the ArrayFire library and header files which you can build from source or use up-stream’s binary installer. See previous articles for a general introduction.
Version 0.1.0 brings to important changes: Support for sparse matrices and Mac OS

I have blogged about dqrng before, but I forgot to write about the v0.2.0 release, even though that brought a lot of changes including the fast sampling methods to CRAN:
Add R side support for selecting multiple streams for parallel usage. Implement long_jump() for Xo(ro)shiro as alternative to jump() providing fewer streams with longer period. Handle R’s RNG scope properly during initialisation. New functions dqsample and dqsample.int using an unbiased sampling algorithm.

© 2019–2023 Ralf Stubner · Datenschutzerklärung · Impressum · Powered by the Academic theme for Hugo.