R

Using dqrng as user-supplied RNG

My dqrng package has some quite old issues, one is “More distribution functions” where I brought forward the idea to support additional distribution functions within dqrng, which currently only supports uniform, normal and exponential distributions. I still think this would be a good idea, but it would also be nice if one could simply plug into the large number of distribution functions that have been implemented for R already. Fortunately this is possible via the mechanism described in User-supplied Random Number Generation.

Roulette-wheel selection for dqrng (part 2)

I have blogged about weighted sampling before. There I found that the stochastic acceptance method suggested by Lipowski and Lipowska (2012) (also at https://arxiv.org/abs/1109.3627) is very promising: // [[Rcpp::depends(dqrng,BH,sitmo)]] #include <Rcpp.h> #include <dqrng_distribution.h> auto rng = dqrng::generator<>(42); // [[Rcpp::export]] Rcpp::IntegerVector sample_prob(int size, Rcpp::NumericVector prob) { Rcpp::IntegerVector result(Rcpp::no_init(size)); double max_prob = Rcpp::max(prob); uint32_t n(prob.length()); std::generate(result.begin(), result.end(), [n, prob, max_prob] () { while (true) { int index = (*rng)(n); if (dqrng::uniform01((*rng)()) < prob[index] / max_prob) return index + 1; } }); return result; } For relatively even weight distributions, as created by runif(n) or sample(n), performance is good, especially for larger populations:

Choosing a new default RNG for dqrng

Currently the dqrng package supports only xoroshiro128+ and xoshiro256+ from https://prng.di.unimi.it/ (see also Blackman and Vigna 2021). These RNGs should only be used for creating floating point numbers, which was the case for dqrng originally. However, dqsample and dqrrademacher make use of the full bit pattern. So it would be better to support the ** and/or ++ variants for both RNGs and make one of them the default. This would be a breaking change, of course.

dqrng v0.3.1 and tikzDevice v0.12.5

Today dqrng version 0.3.1 made it unto CRAN and is now propagating to the mirrors. Kyle Butts provided the implementation for the new dqrrademacher method for drawing Rademacher weights. The Rademacher distribution is equivalent to flipping a fair coin, which can be efficiently implementd by using the raw bit pattern from the RNG directly. See also #50 and #49. Kyle also suggested a way to support random draws from a multivariate normal distribution by using code from the mvtnorm package, c.

swephR v0.3.1

This morning swephR version 0.3.1 made it unto CRAN and is now propagating to the mirrors. The goal of swephR is to provide an R interface to the Swiss Ephemeris (SE), a high precision ephemeris based upon the DE431 ephemeris from NASA’s JPL. It covers the time range 13201 BCE to 17191 CE. This version of swephR fixes various function declaration isn’t a prototype warnings that CRAN now counts as important.

tikzDevice v0.12.4

Yesterday tikzDevice version 0.12.4 made it unto CRAN and is now propagating to the mirrors. The tikzDevice package provides a graphics output device for R that records plots in a LaTeX-friendly format. The device transforms plotting commands issued by R functions into LaTeX code blocks. When included in a paper typeset by LaTeX, these blocks are interpreted with the help of TikZ—a graphics package for TeX and friends written by Till Tantau.

Roulette-wheel selection for dqrng

There is a long standing issue with my {dqrng} package: weighted sampling. Since implementing fast un-weighted sampling methods quite some time ago, I have now started looking into possibilities for weighted sampling. The issue contains a reference to a blog post that is by now only available via the wayback machine. This blog post shows a stochastic acceptance method suggested by Lipowski and Lipowska (2012) (also at https://arxiv.org/abs/1109.3627), which appears very promising.

dqrng v0.3.0

Today dqrng version 0.3.0 made it unto CRAN and is now propagating to the mirrors. This release contains a breaking change: The initial state of dqrng’s RNG is based on R’s RNG, which used to advance R’s RNG state. The implementation has been changed to preserve R’s RNG state, which is less surprising but can change the outcome of current scripts. (#44 fixing #43) In addition, the generation of uniform random numbers now takes a short-cut for min == max and throws an error for min > max (#34 fixing #33)

swephR v0.3.0

This afternoon swephR version 0.3.0 made it unto CRAN and is now propagating to the mirrors. The goal of swephR is to provide an R interface to the Swiss Ephemeris (SE), a high precision ephemeris based upon the DE431 ephemeris from NASA’s JPL. It covers the time range 13201 BCE to 17191 CE. This new version comes with two important changes. First, Victor has finished the laborious task of making all functions from SE’s C API available to R.

tikzDevice v0.12.3

Yesterday tikzDevice version 0.12.3 made it unto CRAN and is now propagating to the mirrors. The tikzDevice package provides a graphics output device for R that records plots in a LaTeX-friendly format. The device transforms plotting commands issued by R functions into LaTeX code blocks. When included in a paper typeset by LaTeX, these blocks are interpreted with the help of TikZ—a graphics package for TeX and friends written by Till Tantau.