stan-dev / stan-dev/rstan

New covariance function in rstan

Open
#705 3 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
R
Stars
1.1k
Forks
266
Avg merge
2h 56m
Merged PRs (30d)
1

Description

Summary:

Based on my understanding of https://github.com/stan-dev/stan/pull/2739, there should be new covariance function available to use via rstan.

Description:

It seems that these functions are not yet available.

Reproducible Steps:

Simple GP simulation model from the Stan manual:

data {

	int<lower=1> N;

	int<lower=1> D; //dimension of the GP
	vector[D] x[N]; //point where the GP is estimated
}

transformed data {
	matrix[N, N] L; //cholesky matrix
        vector[N] mu = rep_vector(0, N); //assume 0-mean
	matrix[N, N] K = gp_matern32_cov(x, 1.0, 1.0);

	for(n in 1:N)

		K[n, n] = K[n, n] + 0.1; // to ensure positive-definite matrix
	L = cholesky_decompose(K);

}

parameters {

	vector[N] eta;

}

model {

	eta ~ std_normal();

}
generated quantities {
	vector[N] y;
	y = mu + L * eta;
}

And in R:

N <- 100
D <- 2
x <- matrix(runif(N * D), nrow = N, ncol = D)
m <- stan("GP_mat32_sim.stan", data = list(x = x, N = 100, D = 2))
Current Output:

SYNTAX ERROR, MESSAGE(S) FROM PARSER:
No matches for:

gp_matern32_cov(vector[ ], real, real)

Function gp_matern32_cov not found.
error in 'model1b50107f4b65_GP_mat32_sim' at line 8, column 49

 6: transformed data {
 7: 	matrix[N, N] L; //cholesky matrix
 8: 	matrix[N, N] K = gp_matern32_cov(x, 1.0, 1.0);
                                                    ^
 9: 	for(n in 1:N)

Error in stanc(file = file, model_code = model_code, model_name = model_name, :
failed to parse Stan model 'GP_mat32_sim' due to the above error.

Expected Output:

NA

RStan Version:

rstan_2.19.2

R Version:

R version 3.6.1 (2019-07-05)

Operating System:

Win10

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with the GP_mat32_sim.stan example and the rstan_2.19.2 parser path, then compare the covariance functions described in Stan pull request 2739 with those available through rstan. Reproduce the gp_matern32_cov parsing error using stanc and confirm completion when the example model parses and runs through the R stan() call.

Written by the indexing model from the issue text.

Assessment

Tech stack
r
Domain
api, data
Issue type
Feature
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.