More info on mean, std, and variance.

I had information on these rather buried, and did not have a single example
of how to compute them. Now the first part of the chapter covers this much
more thoroughly.

Also added a section on plotting exponentials. Not sure I want to retain
it; it is a bit 'light'.
This commit is contained in:
Roger Labbe 2015-03-07 15:27:56 -08:00
parent ed2af0cb50
commit 5f7c7de378
2 changed files with 5399 additions and 2101 deletions

File diff suppressed because it is too large Load Diff

View File

@ -30,7 +30,8 @@ _two_pi = 2*math.pi
def gaussian(x, mean, var):
"""returns normal distribution (pdf) for x given a Gaussian with the
specified mean and variance. All must be scalars.
specified mean and variance. x can either be a scalar or an
array-like.
gaussian (1,2,3) is equivalent to scipy.stats.norm(2,math.sqrt(3)).pdf(1)
It is quite a bit faster albeit much less flexible than the latter.
@ -39,7 +40,7 @@ def gaussian(x, mean, var):
Parameters
----------
x : scalar
x : scalar or array-like
The value for which we compute the probability
mean : scalar
@ -50,12 +51,18 @@ def gaussian(x, mean, var):
Returns
-------
probability : float
probability : float, or array-like
probability of x for the Gaussian (mean, var). E.g. 0.101 denotes
10.1%.
Examples
--------
gaussian(3, 1, 2)
gaussian([3,4,3,2,1], 1, 2)
"""
return math.exp((-0.5*(x-mean)**2)/var) / math.sqrt(_two_pi*var)
return (np.exp((-0.5*(np.asarray(x)-mean)**2)/var) /
np.sqrt(_two_pi*var))
def mul (mean1, var1, mean2, var2):