如何使用RcppArmadillo绘制多项式分布式样本? [英] How do I draw multinomial distributed samples with RcppArmadillo?

查看:65
本文介绍了如何使用RcppArmadillo绘制多项式分布式样本?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

问题是我有一个变量arma::mat prob_vec,想要与R中的rmultinom(1, 1, prob_vec)等效的东西.

The problem is that I have a variable arma::mat prob_vec and want something equivalent to rmultinom(1, 1, prob_vec) in R.

我发现RcppArmadillo提供的rmultinom函数有一个奇怪的参数要求,这与R中的要求不同!因此它不会通过编译.

I found the rmultinom function provided by RcppArmadillo has a weird argument requirement which is different from that in R! So it won't pass the compilation.

我只想知道如何在RcppArmadillo或Armadillo中绘制所需的样本.如果我需要获取指针或转换我的prob_vec变量,请告诉我怎么做.

I just wanna know how to draw the desired sample in RcppArmadillo, or equivalently in Armadillo. If I need to get the pointer or convert my prob_vec variable, please tell me how.

非常感谢!

推荐答案

您在RcppArmadillo的友好邻里合著者:我可以向您保证,它不提供rmultinom,但Rcpp可以提供.实际上,它只是像grep会告诉您的那样直接传递给R:

Your friendly neighbourhood co-author of RcppArmadillo here: I can assure you that it does not provide rmultinom, but Rcpp does. In fact, it simply passes through to R itself as a quick grep would have told you:

  inline void rmultinom(int n, double* prob, int k, int* rn) 
         { return ::rmultinom(n, prob, k, rn); }

因此,我建议您首先针对R API编写一个五行C程序,以确保您知道如何让rmultinom做您想做的事,然后使用Rcpp和RcppArmadillo做同样的事情向量中的数据上.

So I would suggest your first write a five-line C program against the R API to make sure you know how to have rmultinom do what you want it to do, and then use Rcpp and RcppArmadillo to do the same thing on the data in your vector.

这篇关于如何使用RcppArmadillo绘制多项式分布式样本?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆