Google Summer of Code 2016 Only A Few Hours Left

bachmeier via Digitalmars-d-announce digitalmars-d-announce at puremagic.com
Sat Feb 20 12:39:58 PST 2016


On Saturday, 20 February 2016 at 15:00:50 UTC, jmh530 wrote:
> On Saturday, 20 February 2016 at 13:31:03 UTC, bachmeier wrote:
>> On Friday, 19 February 2016 at 21:50:43 UTC, jmh530 wrote:
>>> On Friday, 19 February 2016 at 21:10:45 UTC, Dave wrote:
>>
>>> Alternately, you could try calling pystan or rstan from D. If 
>>> you make any progress on these approaches, I would be 
>>> interested.
>>
>> If it has an R interface, it also has a D interface using my 
>> rdlang project. I will look at it when I get some free time.
>
> R is the most popular way to use Stan I think. rstan is the 
> library.

I looked at rstan. I've heard of it but never used it. AFAICT, 
the computationally intensive part is done by the call to stan() 
from within the R code. Therefore there are no efficiency issues 
with calling D -> R -> stan.

I took the easy road and ran the given R code directly. Here is 
my program:

import rinsided, rdlang.r, rdlang.vector;

void main() {
   evalRQ(`library(rstan)`);
   evalRQ(`y <- 
read.table('https://raw.github.com/wiki/stan-dev/rstan/rats.txt', 
header = TRUE)`);
   evalRQ(`x <- c(8, 15, 22, 29, 36)`);
   evalRQ(`xbar <- mean(x)`);
   evalRQ(`N <- nrow(y)`);
   evalRQ(`T <- ncol(y)`);
   evalRQ(`rats_fit <- stan(file = 
'https://raw.githubusercontent.com/stan-dev/example-models/master/bugs_examples/vol1/rats/rats.stan')`);
   auto stanOutput = RVector(evalR(`attr(rats_fit, 
"sim")[[1]][[1]][[1]]`));
   stanOutput.print();
}

stanOutput is a D struct holding a pointer to that particular 
part of the output. Without more knowledge of rats_fit, I can't 
go further. You could also pass D data into R (y, x, xbar, ...) 
but I didn't see a reason to do that here. Nonetheless this is 
what you want, a way to call rstan from D, and then access the 
results from your D program.


More information about the Digitalmars-d-announce mailing list