-
Notifications
You must be signed in to change notification settings - Fork 40
Issue1313 param bounds #1314
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
base: main
Are you sure you want to change the base?
Issue1313 param bounds #1314
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,15 +1,18 @@ | ||
| data { | ||
| int dist; // 0: exp; 1: lnorm; 2: gamma | ||
| int dist; // 0: exponential; 1: lognormal; 2: gamma | ||
| int N; | ||
| vector[N] low; | ||
| vector[N] up; | ||
| array[dist == 0] real lam_mean; | ||
| array[dist > 0] real prior_mean; | ||
| array[dist > 0] real prior_sd; | ||
| array[dist == 0] real<lower=0> lam_mean; // should not be exactly 0 | ||
| array[dist > 0] real<lower=0> prior_mean; | ||
| array[dist > 0] real<lower=0> prior_sd; | ||
| array[dist == 2] real<lower = 0> par_sigma; | ||
| } | ||
|
|
||
| transformed data { | ||
| if (dist == 0 && lam_mean[1] == 0) { | ||
| reject("lam_mean must be strictly positive, but found 0"); | ||
| } | ||
| array[dist == 2] real prior_alpha; | ||
| array[dist == 2] real prior_beta; | ||
|
|
||
|
|
@@ -20,50 +23,54 @@ transformed data { | |
| } | ||
|
|
||
| parameters { | ||
| array[dist == 0] real<lower = 0> lambda; | ||
| array[dist == 0] real<lower = 0, upper = 1> lambda_raw; | ||
| array[dist == 1] real mu; | ||
| array[dist == 1] real<lower = 0> sigma; | ||
| array[dist == 2] real<lower = 0> alpha_raw; | ||
| array[dist == 2] real<lower = 0> beta_raw; | ||
| } | ||
|
|
||
| transformed parameters{ | ||
| array[dist == 0] real lambda; | ||
| array[dist == 2] real<lower = 0> alpha; | ||
| array[dist == 2] real<lower = 0> beta; | ||
|
|
||
| if (dist == 0) { | ||
| real lb = 0.2 / lam_mean[1]; | ||
| real ub = 5 / lam_mean[1]; | ||
| lambda[1] = lb + (ub - lb) * lambda_raw[1]; | ||
| // implies: lambda[1] ~ uniform(lb, ub) | ||
| } | ||
|
|
||
| if (dist == 2) { | ||
| alpha[1] = prior_alpha[1] + par_sigma[1] * alpha_raw[1]; | ||
| beta[1] = prior_beta[1] + par_sigma[1] * beta_raw[1]; | ||
| // implies: | ||
| // alpha[1] ~ normal(prior_alpha[1], par_sigma[1]) T[prior_alpha[1],] | ||
| // beta[1] ~ normal(prior_beta[1], par_sigma[1]) T[prior_beta[2],] | ||
| } | ||
|
Comment on lines
45
to
51
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Comments claim
If the asymmetric (half-normal) prior is intentional, the comments should be corrected: Suggested fix- // implies: alpha[1] ~ normal(prior_alpha[1], par_sigma[1])
- // implies: beta[1] ~ normal(prior_beta[1], par_sigma[1])
+ // implies: alpha[1] ~ prior_alpha[1] + par_sigma[1] * half_normal(0, 1)
+ // implies: beta[1] ~ prior_beta[1] + par_sigma[1] * half_normal(0, 1)If a symmetric normal was intended instead, the Also applies to: 64-66 🤖 Prompt for AI Agents |
||
| } | ||
|
|
||
| model { | ||
| if (dist == 0) { | ||
| lambda[1] ~ uniform(1 / (5. * lam_mean[1]), 1 / (0.2 * lam_mean[1])); | ||
| for (i in 1:N) { | ||
| target += log_diff_exp(exponential_lcdf(up[i] | lambda), | ||
| exponential_lcdf(low[i] | lambda)); | ||
| } | ||
| } else if (dist == 1) { | ||
| mu[1] ~ normal(prior_mean[1], 10); | ||
| sigma[1] ~ normal(prior_sd[1], 10) T[0,]; | ||
| // T[0, ] omitted in following: it's constant with data args | ||
| sigma[1] ~ normal(prior_sd[1], 10); | ||
| for (i in 1:N) { | ||
| target += log_diff_exp(lognormal_lcdf(up[i] | mu, sigma), | ||
| lognormal_lcdf(low[i] | mu, sigma)); | ||
| } | ||
| } else if (dist == 2) { | ||
| alpha_raw[1] ~ normal(0, 1); | ||
| beta_raw[1] ~ normal(0, 1); | ||
| } | ||
|
|
||
| for(i in 1:N){ | ||
| if (dist == 0) { | ||
| target += log_diff_exp( | ||
| exponential_lcdf(up[i] | lambda), | ||
| exponential_lcdf(low[i] | lambda) | ||
| ); | ||
| } else if (dist == 1) { | ||
| target += log_diff_exp( | ||
| lognormal_lcdf(up[i] | mu, sigma), | ||
| lognormal_lcdf(low[i] | mu, sigma) | ||
| ); | ||
| } else if (dist == 2) { | ||
| target += log_diff_exp( | ||
| gamma_lcdf(up[i] | alpha, beta), | ||
| gamma_lcdf(low[i] | alpha, beta) | ||
| ); | ||
| alpha_raw[1] ~ std_normal(); | ||
| beta_raw[1] ~ std_normal(); | ||
| for (i in 1:N) { | ||
| target += log_diff_exp(gamma_lcdf(up[i] | alpha, beta), | ||
| gamma_lcdf(low[i] | alpha, beta)); | ||
| } | ||
| } | ||
| } | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Division by zero if
lam_mean[1]is exactly zero.The
lower=0bound onlam_mean(line 6) permits a value of exactly 0, which would cause division by zero here when computinglbandub. Consider usinglower=0with a runtime check or tightening to a small positive lower bound (e.g.real<lower=1e-10>).This is likely only a theoretical concern since passing a zero mean for an exponential distribution is degenerate, but it leaves an unguarded code path.
🤖 Prompt for AI Agents