Hello,

It looks like there are a couple of typos in the equations used in the 
function.

On Friday 07 July 2006 12:17, Faheem Mitha wrote:
> I think the bivariate normal probability distribution function
> implementation in Matplotlib is buggy. See the example code below, and
> note that the change in the x directions and the y directions is not
> uniform as it should be.
> The implementation (in mlab.py) is appended.
[snip]
>      z = Xmu**2/sigmax**2 + Ymu**2/sigmay - 2*rho*Xmu*Ymu/(sigmax*sigmay)
                                           ^ **2
>      return 1.0/(2*pi*sigmax*sigmay*(1-rho**2)) * exp( -z/(2*(1-rho**2)))
                                      ^ sqrt()

Compare to equations (1) and (2) from the link in the docstring:

http://mathworld.wolfram.com/BivariateNormalDistribution.html

I've attached a patch.

Mike


Index: lib/matplotlib/mlab.py
===================================================================
--- lib/matplotlib/mlab.py	(revision 2553)
+++ lib/matplotlib/mlab.py	(working copy)
@@ -960,8 +960,8 @@
     Ymu = Y-muy
 
     rho = sigmaxy/(sigmax*sigmay)
-    z = Xmu**2/sigmax**2 + Ymu**2/sigmay - 2*rho*Xmu*Ymu/(sigmax*sigmay)
-    return 1.0/(2*pi*sigmax*sigmay*(1-rho**2)) * exp( -z/(2*(1-rho**2)))
+    z = Xmu**2/sigmax**2 + Ymu**2/sigmay**2 - 2*rho*Xmu*Ymu/(sigmax*sigmay)
+    return 1.0/(2*pi*sigmax*sigmay*numerix.mlab.sqrt(1-rho**2)) * exp( -z/(2*(1-rho**2)))
 
 
 
-------------------------------------------------------------------------
Using Tomcat but need to do more? Need to support web services, security?
Get stuff done quickly with pre-integrated technology to make your job easier
Download IBM WebSphere Application Server v.1.0.1 based on Apache Geronimo
http://sel.as-us.falkag.net/sel?cmd=lnk&kid=120709&bid=263057&dat=121642
_______________________________________________
Matplotlib-users mailing list
Matplotlib-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/matplotlib-users

Reply via email to