GithubHelp home page GithubHelp logo

nile.stan file missing about example-models HOT 5 CLOSED

stan-dev avatar stan-dev commented on July 24, 2024
nile.stan file missing

from example-models.

Comments (5)

jrnold avatar jrnold commented on July 24, 2024

I don't remember actually adding this to the repo; to the extent I'm working on DLM stuff I'm working on a complete replacement. So I'd probably delete these examples before going back and figuring out how I did it.

from example-models.

Emaasit avatar Emaasit commented on July 24, 2024

@jrnold Do you have the current stan models for those two examples (nile & fx rates) somewhere else so I can follow along? I am trying to write dlm code for my work but there are limited examples on the internet.

from example-models.

Emaasit avatar Emaasit commented on July 24, 2024

I can't seem to find any examples for writing a generated quantities block for a Gaussian Dynamic Linear Model. I wrote the one shown below but stan produces an error. Any help will be much appreciated. @jrnold

stan_model1 <- "
// Kalman Filter (Multivariate Form)
// - no missing values
data {
int n_rows; // the number of rows/variables
int n_cols; // the number of columns/observations
matrix[n_rows, n_cols] y; // the observation matrix
vector[n_rows] mu_theta_init; // the mean at the initial state
cov_matrix[n_rows] sigma_theta_init; // covariance at the initial state

// holdout dataset
int n_rows_h;
int n_cols_h;
matrix[n_rows_h, n_cols_h] y_h;
vector[n_rows_h] mu_theta_init_h;
cov_matrix[n_rows_h] sigma_theta_init_h;
}
transformed data {
vector[n_rows] ones;
matrix[n_rows, n_rows] trans_matrix; // transition matrix
matrix[n_rows, n_rows] design_matrix; // design matrix
for (i in 1:n_rows) {
ones[i] <- 1.0;
}
trans_matrix <- diag_matrix(ones);
design_matrix <- trans_matrix;
}
parameters {
real<lower=-1.0, upper=1.0> rho;
vector<lower=0.0>[n_rows] sigma;
vector<lower=0.0>[n_rows] W_diag;
}
transformed parameters {
cov_matrix[n_rows] sigma_obs; //diagonal of observation covariance matrix of the y observations
cov_matrix[n_rows] sigma_theta; // state(system) covariance matrix of the states
sigma_theta <- diag_matrix(W_diag);
for (i in 1:n_rows) {
sigma_obs[i, i] <- pow(sigma[i], 2);
for (j in 1:(i - 1)) {
sigma_obs[i, j] <- sigma[i] * sigma[j] * rho;
sigma_obs[j, i] <- sigma_obs[i, j];
}
}
}
model {
y ~ gaussian_dlm_obs(design_matrix, trans_matrix, sigma_obs, sigma_theta, mu_theta_init, sigma_theta_init); // likelihood for gaussian dlm
}

generated quantities {
matrix[n_rows_h, n_cols_h] log_lik_h;

log_lik_h <- gaussian_dlm_obs_lpdf(y_h, design_matrix, trans_matrix, sigma_obs, sigma_theta, mu_theta_init_h, sigma_theta_init_h);
}
"

HERE IS THE ERROR MESSAGE:

ERROR at line 52

50: matrix[n_rows_h, n_cols_h] log_lik_h;
51:
52: log_lik_h <- gaussian_dlm_obs_lpdf(y_h, design_matrix, trans_matrix, sigma_obs, sigma_theta, mu_theta_init_h, sigma_theta_init_h);
^
53: }

PARSER EXPECTED:
Error in stanc(file = file, model_code = model_code, model_name = model_name, : failed to parse Stan model 'traffic-prediction1' due to the above error.

from example-models.

bob-carpenter avatar bob-carpenter commented on July 24, 2024

from example-models.

bob-carpenter avatar bob-carpenter commented on July 24, 2024

The answer is that you need to use "|" in place of the first comma in an lpdf. I'm going to change that error message for the next release as per stan-dev/stan#1940

I'm closing this issue as it looks like @jrnold has an alternative fix in mind. Re-open if I'm closing in error.

from example-models.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.