INNER CODE UNIT · Python
data
mszell/geospatialdatascience · unit11_mobilityindividual/stats_utils.py:312
data = [random.normalvariate(m,v**0.5) for i in range(1000)]
def function(p,x): return numpy.exp(-(x-p[0])**2.0/2.0/p[1])/(2.0*numpy.pi*p[1])**0.5
maximum_likelihood(function, parameters, data)
# # Check that is consistent with Least Squares when "function" is a gaussian:
# mm=Parameter(0.1)
# vv=Parameter(0.1)
# def func(x): return numpy.exp(-(x-mm())**2.0/2.0/vv())/(2.0*numpy.pi*vv())**0.5
# x,y = zip(*pdf(0.1,data,out='no'))
# popt,cov,infodict,mesg,ier,pcov,chi2 = LSfit(func, [mm,vv], y, x)
# popt
#
# # And with the exact M-L values:
# mm = sum(data)/len(data)
# vv = standard_dev(data)