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

Change all priors to use <dist_spec> #871

Merged
merged 15 commits into from
Dec 6, 2024
Merged

Change all priors to use <dist_spec> #871

merged 15 commits into from
Dec 6, 2024

Conversation

sbfnk
Copy link
Contributor

@sbfnk sbfnk commented Nov 26, 2024

Description

This PR closes #525 by changing all parameters to use the new interface.

In doing so and in order to keep this manageable the internals of handling parameters had to be updated a fair bit. This is now done similarly to delays in parameter arrays rather than named parameters. In principle this should make it easier to extend the model later with more parameters / probability distributions / time-varying parameters etc.

Things that could be added later fairly easy if deemed useful:

  1. switch delay distribution parameters to use the new stan setup for parameters (this might simplify code so probably a good idea)
  2. allow uncertain parameters of prior distributions other than delays

From tests it seems functionality has been preserved but it would be good for people to check if this is actually an improvement.

One thing to note is that now all parameters are initialised from (truncated) standard normal distributions so will have to monitor if this leads to any issues.

Initial submission checklist

  • My PR is based on a package issue and I have explicitly linked it.
  • I have tested my changes locally (using devtools::test() and devtools::check()).
  • I have added or updated unit tests where necessary.
  • I have updated the documentation if required and rebuilt docs if yes (using devtools::document()).
  • I have followed the established coding standards (and checked using lintr::lint_package()).
  • I have added a news item linked to this PR.

After the initial Pull Request

  • I have reviewed Checks for this PR and addressed any issues as far as I am able.

Copy link
Contributor

@seabbs seabbs left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Wow - this is a lot. On the face of it looks good but going to need some time to digest

Copy link
Contributor

This is how benchmark results would change (along with a 95% confidence interval in relative change) if deedb9e is merged into main:

  • ✔️default: 24.1s -> 20.8s [-28.62%, +0.99%]
  • ✔️no_delays: 26.2s -> 26.2s [-10.42%, +10.39%]
  • ✔️random_walk: 9.66s -> 9.62s [-7.59%, +6.74%]
  • 🚀stationary: 14.3s -> 11.8s [-30.72%, -3.89%]
  • ✔️uncertain: 37.4s -> 36.8s [-13.63%, +10.13%]
    Further explanation regarding interpretation and methodology can be found in the documentation.

it won't work anyway as the R code has changed too much
Copy link
Contributor

This is how benchmark results would change (along with a 95% confidence interval in relative change) if 333de46 is merged into main:

  • ✔️default: 22.4s -> 21.7s [-16.65%, +10.78%]
  • ✔️no_delays: 27s -> 27.8s [-11.93%, +18.38%]
  • ✔️random_walk: 9.69s -> 9.99s [-2.32%, +8.41%]
  • 🚀stationary: 16.1s -> 12.5s [-43.91%, -0.72%]
  • ✔️uncertain: 39.8s -> 38.4s [-14.72%, +8.04%]
    Further explanation regarding interpretation and methodology can be found in the documentation.

@sbfnk
Copy link
Contributor Author

sbfnk commented Nov 27, 2024

One thing to note is that the lengthscale prior is currently not included in this, because of the extra logic in


It might be worth deciding on a single shape of the prior and then this could also be specified as a <dist_spec> (though this currently doesn't support specifying a minimum, which would either have to be dropped or functionality added).

@sbfnk
Copy link
Contributor Author

sbfnk commented Nov 27, 2024

Related to that merging this would enable a more comprehensive exploration of parameter choices and identifiability than what's done in #855 (not requiring editing the stan model) as we can fix parameters and/or try out different distributions with different parameters.

@seabbs
Copy link
Contributor

seabbs commented Nov 27, 2024

which would either have to be dropped or functionality added

I think we would need to add this as from memory it really isn't identifiable without setting some bounds

@sbfnk
Copy link
Contributor Author

sbfnk commented Dec 2, 2024

which would either have to be dropped or functionality added

I think we would need to add this as from memory it really isn't identifiable without setting some bounds

To be explored in more detail in a future PR then as adding capability to specify a lower bound would require quite substantial changes.

@seabbs
Copy link
Contributor

seabbs commented Dec 3, 2024

I've got thursday pencilled in to go through this in detail

@seabbs seabbs self-requested a review December 3, 2024 13:32
NEWS.md Outdated Show resolved Hide resolved
R/create.R Show resolved Hide resolved
R/opts.R Show resolved Hide resolved
seabbs
seabbs previously approved these changes Dec 5, 2024
Copy link
Contributor

@seabbs seabbs left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is great I think. I was a bit sceptical as I thought it would make the models hard to follow but tbh if anything its the versus due to the reduction in control code.

I noted that the Rt prior is treated a little differently and had a few comments on that. At a high level I am happy with it as is and even think its good moving to a normal prior where that has happened (its unclear how intentional that was but I am okay with it).

I don't see any major issues. It looks like it should be relatively easy to support user set lower bounds (and hence also transition over the GP stuff. I noted it would be nice to give users an R helper so they can find the posterior for parameters they are setting but I think this can be a future issue.

I see the stan benchmarks are failing but otherwise LGTM

Note I updated the vignettes in order to look at the git diff. All looks good to me. Happy to revert or keep this as the update.

data-raw/estimate-infections.R Show resolved Hide resolved
inst/dev/recover-synthetic/rt.R Show resolved Hide resolved
inst/stan/estimate_infections.stan Show resolved Hide resolved
inst/stan/estimate_infections.stan Show resolved Hide resolved
inst/stan/functions/observation_model.stan Show resolved Hide resolved
inst/stan/functions/rt.stan Show resolved Hide resolved
man/epinow.Rd Outdated Show resolved Hide resolved
vignettes/estimate_infections_options.Rmd Outdated Show resolved Hide resolved
vignettes/estimate_infections_workflow.Rmd Outdated Show resolved Hide resolved
@seabbs
Copy link
Contributor

seabbs commented Dec 5, 2024

Wow I have caused a lot of conflicts

Co-authored-by: Sam Abbott <[email protected]>
@sbfnk
Copy link
Contributor Author

sbfnk commented Dec 6, 2024

Sorry for the confusion on rt and normal vs. lognormal.

My reasoning was: so far we asked users for the mean and SD of a lognormal distribution which we had as logR ~ normal. In the new set up we could still ask for a prior on log R but that seems unnatural if people might want different distributions. Instead I changed the prior to be a prior on R and then defaulting to lognormal with the same mean and SD as before. If I'm not mistaken this should be no change to before. Where it is normal (in the vignettes?) this was by accident and should be LogNormal.

@sbfnk
Copy link
Contributor Author

sbfnk commented Dec 6, 2024

Wow I have caused a lot of conflicts

Might be easiest to just reset and then run the action post merging

@seabbs seabbs self-requested a review December 6, 2024 10:23
seabbs
seabbs previously approved these changes Dec 6, 2024
Copy link
Contributor

@seabbs seabbs left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've reverted the vignette updating (in a lazy way but will get squashed out) and am happy for this to be merged either with or without the updated Rt priors in the vignettes and examples.

Copy link
Contributor

github-actions bot commented Dec 6, 2024

This is how benchmark results would change (along with a 95% confidence interval in relative change) if 7814bdf is merged into main:

  • ❗🐌default: 22.3s -> 24.1s [+0.48%, +15.62%]
  • ✔️no_delays: 27.9s -> 31.7s [-40.85%, +67.96%]
  • ✔️random_walk: 10s -> 12.1s [-28.8%, +70.77%]
  • ✔️stationary: 13.7s -> 13.4s [-16.05%, +12.3%]
  • ✔️uncertain: 39.6s -> 36.6s [-20.7%, +5.44%]
    Further explanation regarding interpretation and methodology can be found in the documentation.

@seabbs
Copy link
Contributor

seabbs commented Dec 6, 2024

I've reset the cmdstan actions cache to check if that is the issue (really need to get around to setting up a cache timer in the install cmdstan action).

@sbfnk
Copy link
Contributor Author

sbfnk commented Dec 6, 2024

I've switched all priors to LogNormal now. Just needs someone to re-approve.

Copy link
Contributor

github-actions bot commented Dec 6, 2024

This is how benchmark results would change (along with a 95% confidence interval in relative change) if 617ed24 is merged into main:

  • ✔️default: 22.9s -> 22.6s [-13.91%, +10.86%]
  • ✔️no_delays: 30.2s -> 27.9s [-24.27%, +9.1%]
  • ✔️random_walk: 10.2s -> 9.63s [-17.03%, +6.32%]
  • ✔️stationary: 14.7s -> 12.7s [-28.57%, +1.64%]
  • ✔️uncertain: 37.9s -> 37.5s [-8.39%, +6.14%]
    Further explanation regarding interpretation and methodology can be found in the documentation.

Copy link
Contributor

@seabbs seabbs left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@sbfnk sbfnk added this pull request to the merge queue Dec 6, 2024
Merged via the queue into main with commit 9d733d2 Dec 6, 2024
12 of 13 checks passed
@sbfnk sbfnk deleted the all-params branch December 6, 2024 15:02
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Change all priors to new dist interface, not just delays
2 participants