Gaussian Process Rstan examples

444 views
Skip to first unread message

tmr...@gmail.com

unread,
Jan 21, 2015, 3:31:21 PM1/21/15
to stan-...@googlegroups.com
Hello everyone,

I am a long time R user.  Heard a lot good things about Stan, so I'm trying it.

I am working on Guassian Process.  My model is 1 - exp(-lambda * x)

I am doing Bayesian parameter estimation on lambda.  So, Bayesian estimation using GP.  I am wondering if there is any tutorial.

Also, I have tried the Rstan vignette code, no GP examples.  It was slow, I am watching beach ball spinning.  Is that normal?

Anyhow, any help is appreciated.

Thanks,

Mike

Bob Carpenter

unread,
Jan 21, 2015, 5:00:59 PM1/21/15
to stan-...@googlegroups.com
There are GP examples in the manual. MCMC is slower than
optimization, so don't expect miracles.

The spinning beach ball is usually just for compilation.
It takes on the order of 10s to compile a model with clang++
at optimization 3 and about 30s with g++. But it's worth it
for speed later on.

Others know much more about GPs than me. We have people
working on specialized Kronecker products for structured
GP problems that should provide speedups in some cases.

- Bob
> --
> You received this message because you are subscribed to the Google Groups "Stan users mailing list" group.
> To unsubscribe from this group and stop receiving emails from it, send an email to stan-users+...@googlegroups.com.
> For more options, visit https://groups.google.com/d/optout.

tmr...@gmail.com

unread,
Jan 21, 2015, 8:18:58 PM1/21/15
to stan-...@googlegroups.com
Hi Bob,

Thanks for the quick response.  I did find a GP example in the manual.  I am working on it, I have looked at GP from Rasmussen's book.

In the manual, I do not see how Bayesian parameter estimation is done in Stan.  Am I overlooking something?

Also, I see code like this, which I do not understand,

data {
       int<lower=1> N1;
       vector
[N1] x1;
       vector
[N1] y1;
       
int<lower=1> N2;
       vector
[N2] x2;
                                       
     }
     transformed data
{
                                   
       int<lower=1> N;
       vector
[N1+N2] x;
       vector
[N1+N2] mu;
       cov_matrix
[N1+N2] Sigma;
       N
<- N1 + N2;
                                   
       for (n in 1:N1) x[n] <- x1[n];
   for (n in 1:N2) x[N1 + n] <- x2[n];
       for (i in 1:N) mu[i] <- 0;
       
for (i in 1:N)
                                       
         for (j in 1:N)
           
Sigma[i,j] <- exp(-pow(x[i] - x[j],2))
       + if_else(i==j, 0.1, 0.0);                                
}
parameters
{
                                   
  vector[N2] y2;
}
 model {
       vector
[N] y;
       
for (n in 1:N1) y[n] <- y1[n];
       
for (n in 1:N2) y[N1 + n] <- y2[n];

                                       
       y ~ multi_normal(mu,Sigma);
     
}
           

I think this is Stan language?  And the right thing to do is build the model in Stan, then run it in R.

That means I have to learn the Stan language.

Also, Why rstan is not on CRAN?

Thanks,

Mike

Bob Carpenter

unread,
Jan 22, 2015, 2:57:25 PM1/22/15
to stan-...@googlegroups.com

> On Jan 21, 2015, at 8:18 PM, tmr...@gmail.com wrote:
>
> Hi Bob,
>
> Thanks for the quick response. I did find a GP example in the manual. I am working on it, I have looked at GP from Rasmussen's book.
>
> In the manual, I do not see how Bayesian parameter estimation is done in Stan. Am I overlooking something?

Yes. There are examples of parameter estimation. See
section 13.3, Fitting a Gaussian Process.
Yes

> then run it in R.

We also have Python and command-line interfaces as well as
contributed MATLAB and Julia interfaces. You can run Stan anywhere
and get the same answers.

> That means I have to learn the Stan language.

I'm afraid if you want to write Stan models, you'll need at least
a passing familiarity with the language in which they're written.

> Also, Why rstan is not on CRAN?

Size of our library dependencies.

Ben's working on using BH and RcppEigen for dependencies and we may get
onto CRAN soon. You'll still need to install a C++ toolchain (unless
you're on Linux, in which case you probably already have one), so it won't
be a simple one-touch CRAN install. (In this it is like Rcpp.)

- Bob

tmr...@gmail.com

unread,
Jan 22, 2015, 6:56:46 PM1/22/15
to stan-...@googlegroups.com
Yes, I am working on learning the STAN language.  I suppose the learning curve is not steep, so I should pick it up quickly.

R is my native language, so I'm really looking forward to the debut day on CRAN.  

For now, I will dig into section 13.3 for parameter estimation.

Mike
Reply all
Reply to author
Forward
0 new messages