[SciPy-User] scipy.stats.uniform gives strange behavior (error?)

Jason Rennie jrennie at gmail.com
Tue Aug 3 15:53:57 EDT 2010


Sounds like you're accidentally counting both fence-posts when you should
only be counting one.  Try summing densities from the middle of the buckets:

f =  rv.pdf(arange(delta+delta/2., len(grid)*delta+delta/2.,delta))*delta

Jason

On Tue, Aug 3, 2010 at 3:35 PM, nicky van foreest <vanforeest at gmail.com>wrote:

> Hi,
>
> It seems that the sum over the density of the uniform distribution
> does not always produces 1 (after proper division). Here is the code:
>
> ====
> #!/usr/bin/env python
>
> from numpy import *
> from scipy.stats import  uniform
>
> start = 0.; end = 2.; delta = 0.005; grid = arange(start,end,delta)
>
> rv = uniform(loc=1., scale = 0.1)
>
> f =  rv.pdf(arange(delta, len(grid)*delta,delta))*delta   # 1
> print  sum(f)
> print f
> ======
>
> The result:
>
> 1.05
> [ 0.    0.    0.    0.    0.    0.    0.    0.    0.    0.    0.    0.
>  0.
>  0.    0.    0.    0.    0.    0.    0.    0.    0.    0.    0.    0.    0.
>  0.    0.    0.    0.    0.    0.    0.    0.    0.    0.    0.    0.    0.
>  0.    0.    0.    0.    0.    0.    0.    0.    0.    0.    0.    0.    0.
>  0.    0.    0.    0.    0.    0.    0.    0.    0.    0.    0.    0.    0.
>  0.    0.    0.    0.    0.    0.    0.    0.    0.    0.    0.    0.    0.
>  0.    0.    0.    0.    0.    0.    0.    0.    0.    0.    0.    0.    0.
>  0.    0.    0.    0.    0.    0.    0.    0.    0.    0.    0.    0.    0.
>  0.    0.    0.    0.    0.    0.    0.    0.    0.    0.    0.    0.    0.
>  0.    0.    0.    0.    0.    0.    0.    0.    0.    0.    0.    0.    0.
>  0.    0.    0.    0.    0.    0.    0.    0.    0.    0.    0.    0.    0.
>  0.    0.    0.    0.    0.    0.    0.    0.    0.    0.    0.    0.    0.
>  0.    0.    0.    0.    0.    0.    0.    0.    0.    0.    0.    0.    0.
>  0.    0.    0.    0.    0.    0.    0.    0.    0.    0.    0.    0.    0.
>  0.    0.    0.    0.    0.    0.    0.    0.    0.    0.    0.    0.    0.
>  0.    0.    0.    0.    0.05  0.05  0.05  0.05  0.05  0.05  0.05  0.05
>  0.05  0.05  0.05  0.05  0.05  0.05  0.05  0.05  0.05  0.05  0.05  0.05
>  0.05  0.    0.    0.    0.    0.    0.    0.    0.    0.    0.    0.    0.
>  0.    0.    0.    0.    0.    0.    0.    0.    0.    0.    0.    0.    0.
>  0.    0.    0.    0.    0.    0.    0.    0.    0.    0.    0.    0.    0.
>  0.    0.    0.    0.    0.    0.    0.    0.    0.    0.    0.    0.    0.
>  0.    0.    0.    0.    0.    0.    0.    0.    0.    0.    0.    0.    0.
>  0.    0.    0.    0.    0.    0.    0.    0.    0.    0.    0.    0.    0.
>  0.    0.    0.    0.    0.    0.    0.    0.    0.    0.    0.    0.    0.
>  0.    0.    0.    0.    0.    0.    0.    0.    0.    0.    0.    0.    0.
>  0.    0.    0.    0.    0.    0.    0.    0.    0.    0.    0.    0.    0.
>  0.    0.    0.    0.    0.    0.    0.    0.    0.    0.    0.    0.    0.
>  0.    0.    0.    0.    0.    0.    0.    0.    0.    0.    0.    0.    0.
>  0.    0.    0.    0.    0.    0.    0.    0.    0.    0.    0.    0.    0.
>  0.    0.    0.    0.    0.    0.    0.    0.    0.    0.    0.    0.    0.
>  0.    0.    0.    0.    0.    0.    0.    0.    0.    0.    0.  ]
>
> This is weird, since the sum must be 1. Moreover, if I change line #1 into:
>
> f =  rv.pdf(arange(0., len(grid)*delta,delta))*delta   # 1
>
> I get a sum of 1, as it should.
>
> If I change delta to 0.05 I get 1.0 in both cases.
>
> Does anybody have an idea about how this strange behavior may occur?
>
> Thanks
>
> Nicky
> _______________________________________________
> SciPy-User mailing list
> SciPy-User at scipy.org
> http://mail.scipy.org/mailman/listinfo/scipy-user
>



-- 
Jason Rennie
Research Scientist, ITA Software
617-714-2645
http://www.itasoftware.com/
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.scipy.org/pipermail/scipy-user/attachments/20100803/7ded50db/attachment.html>


More information about the SciPy-User mailing list