stan-dev / cmdstan

CmdStan, the command line interface to Stan
https://mc-stan.org/users/interfaces/cmdstan
BSD 3-Clause "New" or "Revised" License
212 stars 93 forks source link

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

Closed mitzimorris closed 3 years ago

mitzimorris commented 3 years ago

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: https://github.com/stan-dev/cmdstan/blob/9b711ed1bd13db3d29c3df682333abe3813abb10/src/cmdstan/command.hpp#L390-L392

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 commented 3 years ago

Closed this one by mistake.