greenteawarrior / mobile-robotics

[CompRobo2014] Project 1: Mobile robotics - particle filters and neato robots and all that jazz.
0 stars 0 forks source link

The random.choice probabilities don't sum to one #20

Open FranzEricSchneider opened 9 years ago

FranzEricSchneider commented 9 years ago

Maybe this is a rounding error problem? The code freaks out during resampling because the particle weights don't sum to 1.

[ERROR] [WallTime: 1412653337.417724] bad callback: <bound method ParticleFilter.scan_received of <main.ParticleFilter instance at 0xa97a80c>> Traceback (most recent call last): File "/opt/ros/hydro/lib/python2.7/dist-packages/rospy/topics.py", line 682, in _invoke_callback cb(msg) File "/home/eon-alone/ros/src/mobile-robotics/particle_filter/scripts/pf_level2.py", line 482, in scan_received self.resample_particles() # resample particles to focus on areas of high density File "/home/eon-alone/ros/src/mobile-robotics/particle_filter/scripts/pf_level2.py", line 320, in resample_particles random_particle = deepcopy(np.random.choice(self.particle_cloud, p=probabilities)) File "mtrand.pyx", line 1026, in mtrand.RandomState.choice (numpy/random/mtrand/mtrand.c:7322) ValueError: probabilities do not sum to 1

cypressf commented 9 years ago
   # make sure the distribution is normalized
    self.normalize_particles()
    probabilities = [particle.w for particle in self.particle_cloud]

It looks like we're normalizing the weights just before creating the probabilities list so I don't understand why this is happening. I also haven't seen this behavior when I run the code. I'll try to reproduce the bug.

I have a few guesses as to why it may be happening, however: 1) since we are not copying the weights into the list, it may be possible that they are modified before we feed them into the random.choice() function. I doubt this is the case because we don't have multiple threads going on, except for the callback for laser scan, which executes everything in order. 2) It's not possible to normalize the particle weights because they are all zero. This would most likely do to issues with the update_with_laser_scan algorithm. I thought we fixed those issues by adding 1 to all probability densities, so I'm not sure why they would be zero. I'll look into it.