Skip to content

Update index.qmd with edge case for data-fitting #631

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

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions tutorials/bayesian-differential-equations/index.qmd
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,7 @@ To make the example more realistic, we generate data as random Poisson counts ba
Poisson-distributed data are common in ecology (for instance, counts of animals detected by a camera trap).
We'll assume that the rate $\lambda$, which parameterizes the Poisson distribution, is proportional to the underlying animal densities via a constant factor $q = 1.7$.


```{julia}
sol = solve(prob, Tsit5(); saveat=0.1)
q = 1.7
Expand All @@ -108,11 +109,11 @@ Practically, this helps us to illustrate the results without needing to run over
Note we also have to take special care with the ODE solver.
For certain parameter combinations, the numerical solver may predict animal densities that are just barely below zero.
This causes errors with the Poisson distribution, which needs a non-negative mean $\lambda$.
To avoid this happening, we tell the solver to aim for small abolute and relative errors (`abstol=1e-6, reltol=1e-6`).
To avoid this happening, we tell the solver to aim for small absolute and relative errors (`abstol=1e-6, reltol=1e-6`).
We also add a fudge factor `ϵ = 1e-5` to the predicted data.
Since `ϵ` is greater than the solver's tolerance, it should overcome any remaining numerical error, making sure all predicted values are positive.
At the same time, it is so small compared to the data that it should have a negligible effect on inference.
If this approach doesn't work, there are some more ideas to try [here](https://docs.sciml.ai/DiffEqDocs/stable/basics/faq/#My-ODE-goes-negative-but-should-stay-positive,-what-tools-can-help?).
If this approach doesn't work, there are some more ideas to try [here](https://docs.sciml.ai/DiffEqDocs/stable/basics/faq/#My-ODE-goes-negative-but-should-stay-positive,-what-tools-can-help?). In the case of continuous observations (e.g. deriving from modelling chemical reactions), it is sufficient to use a Normal distribution with the mean as the data point and an appropriately chosen variance (which can also be a parameter with a prior distribution).

```{julia}
@model function fitlv(data, prob)
Expand Down
Loading