-
Notifications
You must be signed in to change notification settings - Fork 0
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
Deterministic filter-like device #8
Conversation
b060d22
to
0e27238
Compare
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.
Good - think I undesrstand this - one typo I'll commit, and some of my train of thought running through the tests.
|
||
obj <- dust2_cpu_sir_unfilter_alloc(base, time_start, time, dt, data, 1, 0) | ||
ptr <- obj[[1]] | ||
expect_equal(dust2_cpu_sir_unfilter_run(ptr, NULL, FALSE), f(pars1)) |
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.
So this one with NULL, FALSE
uses base
- which happens to be the same as pars1. We could have said f(base)
on the end.
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.
General comment - I find it quite easy to forget what the args are with the functions... Lots of looking up
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.
yeah, I'll sort this out in one push once we get an actual interface to any of this stuff - none of these functions will be the ones we call in the end!
|
||
obj <- dust2_cpu_sir_unfilter_alloc(pars, time_start, time, dt, data, 1, 3) | ||
ptr <- obj[[1]] | ||
expect_equal(dust2_cpu_sir_unfilter_run(ptr, NULL, TRUE), f(pars)) |
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.
Here, pars[[1 .. 3]] is an entry for each group, and f(pars) gives us 3 results, so a summed-log-likelihood over time, for each of the 3 groups.
time <- c(4, 8, 12, 16) | ||
data <- lapply(1:4, function(i) { | ||
lapply(seq_len(n_groups), function(j) list(incidence = 2 * (i - 1) + j)) | ||
}) |
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.
So data[[1 .. 4]] each contain 3 incidence points, one for each group.
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.
and the 1 .. 4 in data refer to the 4 timesteps
dt <- 1 | ||
|
||
expect_error( | ||
dust2_cpu_sir_unfilter_alloc(pars, 5, time, dt, data, 1, 0), |
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.
2nd arg (5) is r_time_start.
We expect (and get) errors if r_time_start >= length(time)
Merge after #2, contains those commitsMerge after #11, contains those commitsThis PR implements a particle-filter-like method for computing likelihoods out of a time series model by comparing to data periodically. It is the limit case of a particle filter to one particle, and has been used as the "deterministic" method in sircovid/dust1/etc.
The name
unfilter
is temporary, we'll probably come up with something better later.The core implementation is in
inst/dust2/filter.hpp
- you'll see it's pretty straightforward - we loop over all times in the data set, do the comparison to data and accumulate a likelihood. The R wrapper around this then returns that likelihood out of the container back to R.We'll complicate this shortly with things like returning trajectories as the model runs.
The time handling, and in particular the conversion to
steps_
is pretty gross and addressed somewhat in #12, which we might use here soonThe current version only allows using initial conditions from the model, this is addressed in #13