greenteawarrior / mobile-robotics

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

normal function is 10x faster #30

Closed cypressf closed 10 years ago

cypressf commented 10 years ago

I tested my normal function by comparing its output to that of norm.pdf

from scipy.stats import norm
import math

def normal(x, sigma, mu=0.0):
    """
    See equation at http://en.wikipedia.org/wiki/Normal_distribution
    """
    power = -(x-mu)**2 / (2.0*sigma**2.0)
    multiple = (1.0 / (sigma * math.sqrt(2.0 * math.pi)))
    return multiple * math.e**power

mu = 0.0
sigma = 0.05
x = 0
norm.pdf(loc=mu, scale=sigma, x=x)
7.9788456080286538
normal(x,sigma,mu=mu)
7.978845608028654