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

unconstrain_draws example does not work with extra variables #982

Open
avehtari opened this issue May 23, 2024 · 3 comments
Open

unconstrain_draws example does not work with extra variables #982

avehtari opened this issue May 23, 2024 · 3 comments
Labels
bug Something isn't working

Comments

@avehtari
Copy link
Contributor

unconstrain_draws() doc has the following example

fit_mcmc$unconstrain_draws(draws = fit_mcmc$draws())

but this does not work if there are other variables (transformed parameters or generated quantities) stored in the draws, and fails with an error like

Error: Model has 469 unconstrained parameter(s), but 188800 were provided!

It is not trivial to figure out how to proceed after this error

@avehtari avehtari added the bug Something isn't working label May 23, 2024
@andrjohns
Copy link
Collaborator

Hmm I can't replicate this, the following works for me without issue:

modcode <- "
data {
  real y_mean;
}

parameters {
  real y;
}

model {
  y ~ normal(y_mean, 1);
}
generated quantities {
  vector[10] y_gq = rep_vector(y * 2, 10);
}
"
mod <- cmdstan_model(write_stan_file(modcode))
fit <- mod$sample(data = list(y_mean = 0), parallel_chains=4)
dr <- fit$draws()

fit$init_model_methods()
tes <- fit$unconstrain_draws()
tes <- fit$unconstrain_draws(draws = dr)

@avehtari
Copy link
Contributor Author

Sorry, it was grad_log_prob()

> fit$grad_log_prob(fit$unconstrain_draws(draws = dr))
Error: Model has 1 unconstrained parameter(s), but 4000 were provided!

@avehtari
Copy link
Contributor Author

After discussion with @andrjohns , this is just a case of bit unclear error message for invalid input

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants