Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

detect if model has no parameters and run fixed param sampler automatically #953

Closed
mitzimorris opened this issue Dec 3, 2020 · 1 comment · Fixed by #954
Closed

detect if model has no parameters and run fixed param sampler automatically #953

mitzimorris opened this issue Dec 3, 2020 · 1 comment · Fixed by #954

Comments

@mitzimorris
Copy link
Member

Summary:

When running the sampler on a model which doesn't have any parameters, the command program should be
able to detect whether or not the model has no parameters, and in this case, it should run fixed_param automatically.

Description:

It is extremely annoying to get the "fixed_param" error message when trying to use Stan programs to produce simulated data.

check here:

if (model.num_params_r() == 0 && algo->value() != "fixed_param") {
info("Must use algorithm=fixed_param for model that has no parameters.");
return_code = stan::services::error_codes::CONFIG;

instead of quitting, the reasonable thing to do is run the non-adaptive sampler for the specified number of sampling iterations.

Reproducible Steps:

here's a datagen program in Stan:

// generate parameters, data, outcomes for poisson regression 
transformed data {
  int N_obs = 20;               // specify constants
}
generated quantities {
  int N = N_obs;
  int y_sim[N_obs];
  vector[N_obs] x_sim; 
  vector[N_obs] pop_sim;
  real alpha_sim;
  real beta_sim;
  real phi_sim;
  real mu[N_obs];  // mean

  alpha_sim = normal_rng(0, 1);  // simulate parameters
  beta_sim = normal_rng(0, 1);   // from prior
  while (1) {
    phi_sim = normal_rng(0, 1);
    if (phi_sim > 0) break;
  }

  for (n in 1:N_obs) {           // simulate data from params
    pop_sim[n] = uniform_rng(500,2500);
    x_sim[n] = uniform_rng(0.01,0.99);
    mu[n] = log(pop_sim[n]) + alpha_sim + x_sim[n] * beta_sim;
    y_sim[n] = neg_binomial_2_log_rng(mu[n], phi_sim);
  }
}

Current Output:

Run the Stan sampler - error message: "Must use algorithm=fixed_param for model that has no parameters."

Expected Output:

Describe what you expect the output to be. Knowing the correct behavior is also very useful.

Should just work.

Current Version:

v2.25.0

@rok-cesnovar
Copy link
Member

Closed this one by mistake.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
2 participants