English 字幕

← 03-35 Resampling Wheel Solution


Showing Revision 2 created 06/07/2017 by Udacity Robot.

  1. [Narrator] So, here's my implementation of the resampling step,
  2. and it follows the same logic that I gave you in the diagram
  3. We're creating a new set of particles called P3; it's an empty set in the beginning,
  4. and inside this routine, every time I resample,
  5. I add a particle from the previous particle set with the index index.
  6. So, that's the main loop over here, and at the end I assign P3 back to P.
  7. So, that's the resampling step.
  8. My very first index is drawn at random.
  9. This is a uniform random sampler of all the indices,
  10. and then I had this running variable beta that I set to 0.0,
  11. and I cache away the max of W just to be slightly faster.
  12. You don't have to do this; they come in over here.
  13. Doesn't really matter if we have max over here,
  14. but then I go and produce exactly N particles, and the way I do this
  15. I add to beta a uniform random that is twice as large
  16. and maximum in the range as my max weight W.
  17. Now, 2 times max weight W will be a very large step,
  18. but by adding a random variable that sits between 0 and 1,
  19. I have uniformity in 0 and 2 times MW,
  20. and then while this beta variable is larger than the weight of the current index,
  21. I subtract this weight from my beta value
  22. and I increment index by 1 modulo N
  23. the total number of particles, and when it's smaller I'm done.
  24. I can just take that particle, add it, append it, and repeat.
  25. So, this entire procedure over here is somewhat involved
  26. if you got that right I'm impressed.
  27. I hope you learn something from doing it.
  28. It happens to be really easy to program once you know what to do,
  29. and every time we write a particle filter you can just reuse it.
  30. You never have to think about it again because there's nothing
  31. domain specific in this specific procedure over here.
  32. So, let's run it; if I run it nothing happens to that empty set.
  33. So, let me print out the resulting set of particles.
  34. So, now I have a print P over here.
  35. Let me run it, and of course, I'm going to get 1000 particles, right?
  36. A lot of particles but let's look through them.
  37. If you just look at the first value over here, they are all about the same.
  38. They are all between 76 and 82.
  39. The second one--they're all about 42, 44, 43, 41, 39, 38.
  40. So, what you've gotten here is a set of particles
  41. that are all co-located .
  42. So, instead of having a complete random set of particles, like we had before,
  43. the resampling step--we can see this already gives me particles
  44. of very similar X and Y positions.
  45. Now it turns out the orientations are not very similar.
  46. They jump like crazy, and the reason is--
  47. --well, if you think about it, we only have 1 location so far,
  48. our distances to landmarks are independent of the orientation.
  49. Such as that our orientation plays no role in the projected measurement,
  50. and therefore has no role in the selection.
  51. Let me make the point, again; here's our 4 landmarks,
  52. and we measure the distances to those.
  53. A robot facing this direction has a certain set of distances.
  54. A robot facing a different direction, like this one,
  55. has the exact same set of distances.
  56. Therefore, in our particle future, the heading direction plays no role.