rcpp11

Multi-armed bandits with Rcpp

泪湿孤枕 提交于 2020-01-06 07:07:38
问题 I am translating the epsilon-greedy algorithm for multiarmed bandits from here. This is a rather nice demonstration of the power and elegance of Rcpp. However, the results from this version do not tally with the one that is mentioned in the link above. I am aware that this is probably a very niche question but have no other venue to post this on! A summary of the code is as follows. Basically, we have a set of arms, each of which pays out a reward with a pre-defined probability and our job is

Multi-armed bandits with Rcpp

馋奶兔 提交于 2020-01-06 07:06:46
问题 I am translating the epsilon-greedy algorithm for multiarmed bandits from here. This is a rather nice demonstration of the power and elegance of Rcpp. However, the results from this version do not tally with the one that is mentioned in the link above. I am aware that this is probably a very niche question but have no other venue to post this on! A summary of the code is as follows. Basically, we have a set of arms, each of which pays out a reward with a pre-defined probability and our job is

Declare a variable as a reference in Rcpp

血红的双手。 提交于 2019-12-28 12:44:29
问题 In C++, we can declare a variable as a reference. int a = 10; int& b = a; If we set b=15 , a also changes. I want to do the similar thing in Rcpp. List X = obj_from_R["X"]; IntegerVector x_i = X[index]; x_i = value; I want to update an object from R called X by inserting a value to one of its vector. The code above did not work, so I tried this: IntegerVector& x_i = X[index]; and received an error. error: non-const lvalue reference to type 'IntegerVector' (aka 'Vector<13>') cannot bind to a

Is there performance difference between NumericVector and vector<double>?

筅森魡賤 提交于 2019-12-23 14:06:29
问题 Suppose one uses NumericVector and the other uses vector<double> in their Rcpp code. Is there notable difference between the two usages, especially in performance? 回答1: Generally, yes. All of the Rcpp(11) types are "thin proxy objects" (which we talk about in several places, talks, slide decks, my book, ...) around the underlying SEXP objects. That means no copies are made when you go from R to C++, and when you go back from C++ to R. Using standard C++ types like std::vector<T> , however,

Is there performance difference between NumericVector and vector<double>?

时光怂恿深爱的人放手 提交于 2019-12-23 14:05:29
问题 Suppose one uses NumericVector and the other uses vector<double> in their Rcpp code. Is there notable difference between the two usages, especially in performance? 回答1: Generally, yes. All of the Rcpp(11) types are "thin proxy objects" (which we talk about in several places, talks, slide decks, my book, ...) around the underlying SEXP objects. That means no copies are made when you go from R to C++, and when you go back from C++ to R. Using standard C++ types like std::vector<T> , however,

Error in loadNamespace(i, c(lib.loc, .libPaths()), versionCheck = vI[[i]]) : there is no package called ‘Rcpp’ [duplicate]

三世轮回 提交于 2019-12-12 03:02:21
问题 This question already has answers here : Error in loadNamespace(name) : there is no package called 'Rcpp' (6 answers) Closed 3 years ago . Basically I want to use wordcloud function. I'm working through R console. But I could use Rstudio if thats the problem. When I use wordcloud(r_stats_text_corpus) Error: could not find function "wordcloud" I also tried library("wordcloud") Error in loadNamespace(i, c(lib.loc, .libPaths()), versionCheck = vI[[i]]) : there is no package called ‘Rcpp’ Error:

Declare a variable as a reference in Rcpp

怎甘沉沦 提交于 2019-11-29 00:41:20
In C++, we can declare a variable as a reference. int a = 10; int& b = a; If we set b=15 , a also changes. I want to do the similar thing in Rcpp. List X = obj_from_R["X"]; IntegerVector x_i = X[index]; x_i = value; I want to update an object from R called X by inserting a value to one of its vector. The code above did not work, so I tried this: IntegerVector& x_i = X[index]; and received an error. error: non-const lvalue reference to type 'IntegerVector' (aka 'Vector<13>') cannot bind to a temporary of type 'Proxy' (aka 'generic_proxy<19>') coatless This question gets asked a lot in differing

Closest point to a path

旧城冷巷雨未停 提交于 2019-11-28 12:36:27
I have two sets of points, called path and centers . For each point in path , I would like an efficient method for finding the ID of the closest point in centers . I would like to do this in R. Below is a simple reproducible example. set.seed(1) n <- 10000 x <- 100*cumprod(1 + rnorm(n, 0.0001, 0.002)) y <- 50*cumprod(1 + rnorm(n, 0.0001, 0.002)) path <- data.frame(cbind(x=x, y=y)) centers <- expand.grid(x=seq(0, 500,by=0.5) + rnorm(1001), y=seq(0, 500, by=0.2) + rnorm(2501)) centers$id <- seq(nrow(centers)) x and y are coordinates. I would like to add a column to the path data.frame that has