demo_gaussian.py
Go to the documentation of this file.
00001 # Copyright Jim Bosch 2010-2012.
00002 # Distributed under the Boost Software License, Version 1.0.
00003 #    (See accompanying file LICENSE_1_0.txt or copy at
00004 #          http://www.boost.org/LICENSE_1_0.txt)
00005 
00006 import numpy
00007 import gaussian
00008 
00009 mu = numpy.zeros(2, dtype=float)
00010 sigma = numpy.identity(2, dtype=float)
00011 sigma[0, 1] = 0.15
00012 sigma[1, 0] = 0.15
00013 
00014 g = gaussian.bivariate_gaussian(mu, sigma)
00015 
00016 r = numpy.linspace(-40, 40, 1001)
00017 x, y = numpy.meshgrid(r, r)
00018 
00019 z = g(x, y)
00020 
00021 s = z.sum() * (r[1] - r[0])**2
00022 print "sum (should be ~ 1):", s
00023 
00024 xc = (z * x).sum() / z.sum()
00025 print "x centroid (should be ~ %f): %f" % (mu[0], xc)
00026 
00027 yc = (z * y).sum() / z.sum()
00028 print "y centroid (should be ~ %f): %f" % (mu[1], yc)
00029 
00030 xx = (z * (x - xc)**2).sum() / z.sum()
00031 print "xx moment (should be ~ %f): %f" % (sigma[0,0], xx)
00032 
00033 yy = (z * (y - yc)**2).sum() / z.sum()
00034 print "yy moment (should be ~ %f): %f" % (sigma[1,1], yy)
00035 
00036 xy = 0.5 * (z * (x - xc) * (y - yc)).sum() / z.sum()
00037 print "xy moment (should be ~ %f): %f" % (sigma[0,1], xy)


boost_numpy
Author(s): Jim Bosch, Ankit Daftery
autogenerated on Fri Aug 28 2015 10:10:40