【问题标题】:What is the random number generator that Armadillo uses?Armadillo 使用的随机数生成器是什么?
【发布时间】:2016-12-20 20:46:27
【问题描述】:

我正在使用 R. Armadillo C++ 库中的随机数生成器。Armadillo 允许对矩阵和向量进行高性能计算。但是,我看不到它实际实现的是哪个随机数生成器。

Rcpp Armadillo 使用的随机数生成器究竟是什么?

【问题讨论】:

  • 根据您使用的随机函数,Armadillo 对其 RNG 使用均匀分布或高斯分布。
  • @birryree 我的意思是它使用哪种算法。它是线性同余生成器还是梅森捻线器或其他什么?
  • @JonnyHenly 谢谢。在 C++11 案例中它指的是哪个库?还有系统库RNG是std:rand()吗?
  • @JonnyHenly “似乎 RcppArmadillo 使用 R 中的 RNG 作为后备” 是在文档中的某个地方吗?
  • 正是如此。

标签: c++ r random rcpp armadillo


【解决方案1】:

根据 RcppArmadillo 是针对 C++98 标准(当前默认)还是针对 C++11(可选)编译的,可能会使用两种不同的 RNG。 [...] 对于 C++98,使用系统库 RNG。它的性能可能很差,尤其是在旧版本的 Windows 上。对于 C++11,使用其库中包含的 RNG。 - RcppArmadillo Documentation

“对于 C++98,使用系统库 RNG。” - 系统库 RNG 是 std::rand(),尽管 RcppArmadillo 似乎使用 R 中的 RNG 作为后备(当未选择 C++11 时,基于 C++11 的 RNG 不可用),从而避免使用旧的基于 C++98 的 std::rand()1

“对于 C++11,使用其库中包含的 RNG。” - 这是指 C++11 <random> 库。

另一方面,也可以考虑this comment in RcppArmadilloForward.h

// using this define makes the R RNG have precedent over both the
// C++11-based RNG provided by Armadillo, as well as the C++98-based
// fallback.
//
// One can use the C++11-based on by commenting out the following
// #define and also selecting C++11 (eg via src/Makevars* or the
// DESCRIPTION file) and/or defining #define-ing ARMA_USE_CXX11_RNG
#define ARMA_RNG_ALT         RcppArmadillo/Alt_R_RNG.h

将 R RNG 作为 RcppArmadillo 的引擎打开。


1R-bloggers | RcppArmadillo 0.4.450.1.0

【讨论】:

  • 谢谢。根据您的回答,文档似乎需要更新。
  • 拉取请求总是受欢迎的。我filed an issue。请注意,DESCRIPTION 文件告诉您在此处而不是此处报告错误。
猜你喜欢
  • 1970-01-01
  • 2010-11-06
  • 2011-05-21
  • 2016-12-16
  • 2015-03-14
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多