ASPN ActiveState Programmer Network
ActiveState
/ Home / Perl / PHP / Python / Tcl / XSLT /
/ Safari / My ASPN /
Cookbooks | Documentation | Mailing Lists | Modules | News Feeds | Products | User Groups


Recent Messages
List Archives
About the List
List Leaders
Subscription Options

View Subscriptions
Help

View by Topic
ActiveState
.NET Framework
Open Source
Perl
PHP
Python
Tcl
Web Services
XML & XSLT

View by Category
Database
General
SOAP
System Administration
Tools
User Interfaces
Web Programming
XML Programming


MyASPN >> Mail Archive >> scipy-dev
scipy-dev
Re: [SciPy-dev] PyEM problem
by David Cournapeau other posts by this author
Nov 16 2006 3:34AM messages near this date
Re: [SciPy-dev] ARPACK wrapper | [SciPy-dev] Problem converting from scipy_distutils to numpy.distutils
Axel Brink wrote:
>  Dear David,
> 
>  I run into a problem when trying your PyEM example "Creating, sampling 
>  and plotting a mixture":
> 
>  Python 2.4.3 (#1, Jun 13 2006, 11:46:08)
>  [GCC 4.1.1 20060525 (Red Hat 4.1.1-1)] on linux2
>  Type "help", "copyright", "credits" or "license" for more information.
>  >>> import numpy as N
>  >>> import pylab as P
>  >>> from scipy.sandbox.pyem import GM
>  using scipy.cluster.vq
>  >>>
>  >>> #------------------------------
>  ... # Hyper parameters:
>  ... #   - K:    number of clusters
>  ... #   - d:    dimension
>  ... k   = 3
>  >>> d   = 2
>  >>>
>  >>> #-------------------------------------------------------
>  ... # Values for weights, mean and (diagonal) variances
>  ... #   - the weights are an array of rank 1
>  ... #   - mean is expected to be rank 2 with one row for one component
>  ... #   - variances are also expteced to be rank 2. For diagonal, one row
>  ... #   is one diagonal, for full, the first d rows are the first 
>  variance,
>  ... #   etc... In this case, the variance matrix should be k*d rows and d
>  ... #   colums
>  ... w   = N.array([0.2, 0.45, 0.35])
>  >>> mu  = N.array([[4.1, 3], [1, 5], [-2, -3]])
>  >>> va  = N.array([[1, 1.5], [3, 4], [2, 3.5]])
>  >>>
>  >>> #-----------------------------------------
>  ... # First method: directly from parameters:
>  ... # Both methods are equivalents.
>  ... gm      = GM.fromvalues(w, mu, va)
>  >>>
>  >>> #-------------------------------------
>  ... # Second method to build a GM instance:
>  ... gm      = GM(k, d, mode = 'diag')
>  >>> # The set_params checks that w, mu, and va corresponds to k, d and m
>  ... gm.set_params(w, mu, va)
>  Traceback (most recent call last):
>   File "<stdin>", line 2, in ?
>  AttributeError: GM instance has no attribute 'set_params'
> 
> 
>  I also tried 'set_param', but this doesn't help either:
> 
>  >>> gm.set_param(w, mu, va)
>  Traceback (most recent call last):
>   File "<stdin>", line 1, in ?
>   File 
>  "/usr/lib/python2.4/site-packages/scipy/sandbox/pyem/gauss_mix.py", 
>  line 84, in set_param
>     raise GmParamError("Number of given components is %d, expected %d"
>  NameError: global name 'shape' is not defined
> 
>  Numpy version: 1.0.1.dev3436
>  Scipy version: 0.5.2.dev2319
>  Can you help me out or point me to someone else who can? Thanks in 
>  advance.
Thank you for your interest in pyem.

First, may I request that next time, you set a ticket to scipy tracker ? 
It is easier to track things, and everybody has access to it.

Now, there are actually 3 problems in the code ! A syntax error, as you 
spot; the example is also wrong because I inverted d and k: GM.__init__ 
requires first the number of dimension, then the number of components... 
The error should have been obvious, if there wasn't a third error, that 
is an error in the raised exception string !

I will update the code + doc accordingly, everything should be available 
in svn in a few minutes,

cheers,

David
_______________________________________________
Scipy-dev mailing list
Scipy-dev@[...].org
http://projects.scipy.org/mailman/listinfo/scipy-dev

Privacy Policy | Email Opt-out | Feedback | Syndication
© ActiveState Software Inc. All rights reserved