RCPP 中 AR(1) 的模拟.
Simulation of AR(1) in Rcpp
有没有办法用Rcpp糖调用arima.sim?到目前为止,它需要一个 R 列表作为参数这一事实一直是我最大的绊脚石。
我已经通过使用如下所示的全局定义来使其工作,但是如果我可以将其全部包含在 Rcpp 中并且不需要全局调用,我会更希望。
#include <math.h>
#include <RcppArmadillo.h>
// [[Rcpp::depends(RcppArmadillo)]]
using namespace Rcpp;
/*** R
asim_ = function(len_, rho_, burn_in_){
return(as.vector(arima.sim(n = len_, n.start = burn_in_, list(ar = c(rho_)))))
}
*/
// [[Rcpp::export]]
NumericVector asim_cxx(int x, double y, int z) {
Rcpp::Environment G = Rcpp::Environment::global_env();
Rcpp::Function asim_ = G["asim_"];
NumericVector out = asim_(x, y, z);
return(out);
}
感谢任何阅读或回复的人。我希望这不是重复的。
Rcpp 告诉大家如何使用带有命名参数的 R 函数以及如何构造列表。
您可以将代码修改为
#include <math.h>
#include <RcppArmadillo.h>
// [[Rcpp::depends(RcppArmadillo)]]
using namespace Rcpp;
// [[Rcpp::export]]
NumericVector asim_cxx(int len_, double rho_, int burn_in_) {
Function asim_("arima.sim");
NumericVector out = asim_(Named("n", len_),
Named("n.start", burn_in_),
List::create(Named("ar") = rho_));
return(out);
}
确定它被保存为asim.cxx
> sourceCpp("asim.cxx")
> asim_cxx(10, 0.827, 100)
Time Series:
Start = 1
End = 10
Frequency = 1
[1] 0.7722204 1.2900218 2.1249671 0.7970526 -0.1813897 1.7879515
[7] 1.9300430 2.6370638 1.6934178 2.0872313
相关文章:
- 如何使用Google Mock来模拟gettimeofday()
- G锁定铸造到基础上会释放模拟行为
- 有什么好的方法可以让系统调用代理允许在单元测试中进行模拟
- 落砂模拟碰撞检测C++和SFML
- 在gtest.中使用fff.h模拟系统API
- 谷歌模拟和覆盖关键字
- 用C#中的并集模拟C++嵌套结构
- 在同一模拟中使用静脉和静脉_ inet内容时出现运行时错误
- 在模拟器中使用并集来模拟CPU寄存器有多合适
- 我写了一个C++程序来模拟Enigma机器.我没有得到输出
- 如何模拟不同边数的骰子滚动?
- 模拟持久按键
- 使用SIR模型的疾病爆发模拟
- 在 c++ 中模拟输入并在 JAVA 中读取它?
- 转发变量参数列表以模拟 std::thread
- 如何在谷歌模拟中匹配 C 样式数组
- 如何使用兰德随机化模拟点击
- 模拟GPS数据,以便使用Qt与Traccar一起使用
- QKeyPress - 在Qt中模拟按键
- RCPP 中 AR(1) 的模拟.