-
-
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
Add particle filter exercise notebook #33
base: main
Are you sure you want to change the base?
Conversation
Check out this pull request on See visual diffs & provide feedback on Jupyter Notebooks. Powered by ReviewNB |
The particle filter tracks the position of a robot that has noisy sensors and noisy controls. I think that it can still be greatly improved. One thing that I think can be better is to ditch the |
@@ -0,0 +1,391 @@ | |||
{ |
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.
Line #68. i = pytensor.shared(np.array([0]))
why are you creating shared variables for i, j? Sounds like they should be recurrent outputs that get updated?
In general the only time you need shared variables is to handle RNGs in Scan (scan limitation) or to have implicit inputs / share inputs across functions
Reply via ReviewNB
@@ -0,0 +1,391 @@ | |||
{ |
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.
Line #142. [particles, weights], _ = pytensor.scan(
if you have updates in the inner functions (which you will have with rng.foo(), plus your other use of updates for indices (which I don't think you want), you need to forward the updates to the outmost pytensor function, otherwise they won't work
Reply via ReviewNB
What do you mean, they should definitely work. Maybe you defining custom updates is messing PyTensor identification of the default randomstream updates. You do need to forward all updates from nested functions to the final compiled pytensor function.
Why can't you? Perhaps because of the odd use of shared variables?
What do you mean?
indices should be regular non shared variables that are recursed (so parts of outputs_info) |
Bigger picture, how do you suggest we turn this into an exercise notebook? One concern is just to give enough intro content and break it in incremental parts, that should be a no biggie. The other is the use of Scan which is a bit advanced, and I wasn't sure I wanted to touch in the workshop. We will need to give a bit of scaffolding for it. Specially with the use of rngs inside which requires explicitly handling updates. |
You just update the data in subsequent calls to pytensor, or you mean something more fancy? |
@@ -0,0 +1,391 @@ | |||
{ |
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.
Line #3. particles = rng.normal(loc=mean, scale=std, size=(n_particles, 3))
normal will do the implicit broadcast of loc and scale
Reply via ReviewNB
@@ -0,0 +1,391 @@ | |||
{ |
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.
Line #16. particles = pt.set_subtensor(particles[:, 2], particles[:, 2] % (2 * np.pi))
what is this line doing?
Reply via ReviewNB
@@ -0,0 +1,391 @@ | |||
{ |
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.
Line #3. func = pytensor.function([], [estimate_mean, estimate_std, particles, log_weights])
this will need some updates=updates
that are collected (for the RNGs in the scan). IIRC even with the default updates of RandomStreams you need them manually for the scan
Reply via ReviewNB
This tries to add a particle filter as per my comment from #24
I ran into a bunch of problems though.
RandomStream
objects inside ofscan
, so that makes it hard for me to userng.some_method
as I would like to have been able to do.scan
behave as a while loop, which is what I really need to happen in thesystematic_resample
systematic_resample
loop is a mess. I need to update some indices, but I'm clearly botching the indexing or the sharing or the updates. Any guidance there would be great.TODO: