Skip to content

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

@mitzimorris

Description

@mitzimorris

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions