[Scipy-svn] r3091 - trunk/Lib/sandbox/pyem/examples

scipy-svn@scip... scipy-svn@scip...
Mon Jun 11 02:07:48 CDT 2007


Author: cdavid
Date: 2007-06-11 02:07:43 -0500 (Mon, 11 Jun 2007)
New Revision: 3091

Added:
   trunk/Lib/sandbox/pyem/examples/plotexamples.py
Log:
Add a plotting example.

Added: trunk/Lib/sandbox/pyem/examples/plotexamples.py
===================================================================
--- trunk/Lib/sandbox/pyem/examples/plotexamples.py	2007-06-11 07:01:12 UTC (rev 3090)
+++ trunk/Lib/sandbox/pyem/examples/plotexamples.py	2007-06-11 07:07:43 UTC (rev 3091)
@@ -0,0 +1,42 @@
+#! /usr/bin/env python
+# Last Change: Mon Jun 11 03:00 PM 2007 J
+
+# This is a simple test to check whether plotting ellipsoides of confidence and
+# isodensity contours match
+import numpy as N
+from numpy.testing import set_package_path, restore_path
+
+import pylab as P
+
+set_package_path()
+import pyem
+restore_path()
+
+# Generate a simple mixture model, plot its confidence ellipses + isodensity
+# curves for both diagonal and full covariance matrices
+d = 3
+k = 3
+dim = [0, 2]
+# diag model
+w, mu, va = pyem.GM.gen_param(d, k)
+dgm = pyem.GM.fromvalues(w, mu, va)
+# full model
+w, mu, va = pyem.GM.gen_param(d, k, 'full', spread = 1)
+fgm = pyem.GM.fromvalues(w, mu, va)
+
+def plot_model(gm, dim):
+    X, Y, Z, V = gm.density_on_grid(dim = dim)
+    h = gm.plot(dim = dim)
+    [i.set_linestyle('-.') for i in h]
+    P.contour(X, Y, Z, V)
+    data = gm.sample(200)
+    P.plot(data[:, dim[0]], data[:,dim[1]], '.')
+
+# Plot the contours and the ellipsoids of confidence
+P.subplot(2, 1, 1)
+plot_model(dgm, dim)
+
+P.subplot(2, 1, 2)
+plot_model(fgm, dim)
+
+P.show()



More information about the Scipy-svn mailing list