# [Clarify Please]: Significant cases where noise produce negative distance

I observed that in a significant number of cases the noise added to either the steering angle or the distance will produce either a steering angle larger than the max_steering_angle or either a negative distance. Anybody else observe this behavior? Normal? Abnormal? Should I remove checking?

Traceback (most recent call last):
File "vm_main.py", line 26, in <module>
import main
File "/tmp/zlxvpbjrmf/main.py", line 363, in <module>
estimated_position = particle_filter(motions, measurements)
File "/tmp/zlxvpbjrmf/main.py", line 295, in particle_filter
p2.append(p[i].move(motions[t]))
File "/tmp/zlxvpbjrmf/main.py", line 149, in move
raise ValueError, 'Robot cant move backwards'
ValueError: Robot cant move backwards

Edit: I would like to upload an histogram of the distance distribution, however it seems I haven't the rights to. To summarize, it is almost certain I will get negative distance values in a run with test case 2.

EDIT2: Clarification required. Are the steering_noise, distance_noise and bearing_noise variances or standard deviations?

EDIT3: Clarification here: http://www.udacity-forums.com/cs373/questions/16527/variance-vs-standard-deviation-ambiguity-in-hw-3-6

# Summary: steering_noise, distance_noise and bearing_noise are STANDARD DEVIATIONS not variances.

asked 08 Mar '12, 18:42

AchilleTalon
2711513
accept rate: 0%

 3 Yes, it seems like negative distances are in principle possible given this model. Maybe some of the noise is due to very high winds. answered 08 Mar '12, 21:03 Thom Blake 4.4k●10●46●81 Or icy road. (08 Mar '12, 21:08) AchilleTalon

A negative distance should be very unlikely, with a distance noise of 5.0, and a [planned] forward motion of 20.0. If you are seeing negative values regularly, I think you need to check the calculation where the noise is used.

answered 09 Mar '12, 01:21

Phil Duby-1
2.6k21446

+1.
But theoretically possible.

(09 Mar '12, 02:40)

In the code the motion is 12.0, not 20.0. Where did you get the 20.0 value from?

And here is the link to the histogram for a normal distribution with mean 12.0 and standard deviation 5.: http://www.4shared.com/photo/TJx8pw_r/hw3-6_histogram.html?refurl=d1url

EDIT: I see, I checked again the video and Sebastian is showing the test part with 8 iterations and distance of 20. However, in my sample of code when clicking on the NEXT button, I am having 6 iterations and distance of 12. So, seems the video and the code aren't the same. Also, the steering angle shown in the video is 2pi/10, while in the code it is 2pi/20.

(09 Mar '12, 14:01)
1

Test case one says:

motions = [[2. * pi / 10, 20.] for row in range(8)]

Test case two says:

motions = [[2. * pi / 20, 12.] for row in range(number_of_iterations)]

so distances 12 and 20, and steering angles for 2 pi / 20 and 2 pi or 10 are used. Your histogram shows, you can go negative with a base distance of 12, but it should not happen very often. I am also not sure your histogram was generated correctly. I did a search on wolframalpah.com with "gaussian distribution mean 12 variance 5". That shows standard deviation as sqrt(5). The notes at the top of the sample code say the noise values are variance, not standard deviation. So your chart should use a standard deviation or sqrt(5), not 5. The graph on the wolframalpha page shows dropping to basically zero at about 5.5 and 18.5. Here is a link to that page:

gaussian distribution mean 12 variance 5

(09 Mar '12, 15:40)
2

Well, thanks I now know where is the confusion. In the notes you have the following comment:

 # A good way to include noise in the sense step is to
# add Gaussian noise, centered at zero with variance
# of self.bearing_noise to each bearing. You can do this
# with the command random.gauss(0, self.bearing_noise)


So, this clearly let you think random.gauss(0, self.bearing_noise) is taking variance as the second argument while the official documentation on http://docs.python.org/library/random.html says random.gauss(mu, sigma) is taking standard deviation as the second argument.

If you look at the code for measurement_prob(), you will see Sebastian is updating the error with the following formula:

 error *= (exp(- (error_bearing ** 2) / (self.bearing_noise ** 2) / 2.0) / sqrt(2.0 * pi * (self.bearing_noise ** 2)))


So, here the self.bearing_noise is in fact the standard deviation. Now, what about steering_noise and distance_noise?

Conclusion, the comment itself is wrong. A good way to include noise centered at zero is not to use random.gauss(0, self.bearing_noise) it is to use random.gauss(0, sqrt(self.bearing_noise)).

# Can Andy clarify if the provided values are standard deviation or variance?

(09 Mar '12, 16:01)

Noise is standard deviation, not variance. The comment is wrong.

(10 Mar '12, 13:41)
 0 But the world isn't cyclic...according to the comments at the start of the code answered 09 Mar '12, 02:59 David L Sprague 1.0k●1●10●20

You are right but it doesn't matter and here is the proof :

## First for the oreintation:

we all know that -pi/2 is equavielent to 3pi/2 and -pi/4 is equavelent to 7pi/4 so generaly -theta is equavielent to 2pi - theta

and what % (num1%num2) operator do is it asks it self what number should i subtract from num1 to be devisable by num2
So if we entered -pi/2 % 2pi
% operator will say oki if i subtracted 3pi/2 from -pi/2 it will give me 2pi so let's return 3pi/2 so the result will be 3pi/2
which is equavelent to -pi/2 but positive
we can see this in our code here :
orientation %= 2 * pi

## 2nd for position

here we apply the same analysis sence the world is cyclic so for world with size 100x100 we have the following x = -12 is equavellent to x = 88 , y = -1 is equavelent to 99 and so on
so if we got x = -1.5 for example
and we entered -1.5%100 then % operator will say oki i need to subtract 98.5 from -1.5 to be devisable by 100 so it returns to us 98.5 which is equavelent to -1.5
we can see this in our code here :
x %= world_size
y %= world_size

answered 09 Mar '12, 01:49

Ahmed Asim
37741121

2

Actually, the robot world in this assignment is documented to not be cyclic, and move() does not wrap around as the earlier assignments did.

(09 Mar '12, 02:39)

Read the comment for world size in the homework. This world is NOT cyclic. The initialization makes sure the random starting position is within those world boundaries, but movement is allowed outside of that.

(09 Mar '12, 02:39)
Question text:

Markdown Basics

• *italic* or _italic_
• **bold** or __bold__
• image?![alt text](/path/img.jpg "Title")
• numbered list: 1. Foo 2. Bar
• to add a line break simply add two spaces to where you would like the new line to be.
• basic HTML tags are also supported

### Tags:

×5,185
×252
×183
×115

Asked: 08 Mar '12, 18:42

Seen: 286 times

Last updated: 10 Mar '12, 13:41