Velocity Reviews > Re: Markov process representation

# Re: Markov process representation

kpp9c
Guest
Posts: n/a

 03-15-2006
This is wicked! I am trying to get it to work and am frantically fixing
tabs and spaces... but isn't line 50:

self._all_states |= set(key[i] for key in probabilities)

an error? isn't it supposed to be:

self._all_states != set(key[i] for key in probabilities)

Scott David Daniels
Guest
Posts: n/a

 03-15-2006
kpp9c wrote:
> This is wicked! I am trying to get it to work and am frantically fixing
> tabs and spaces...

It was cut and pasted from working code (which I pasted back to test).

> but isn't line 50:
>
> self._all_states |= set(key[i] for key in probabilities)
>
> an error? isn't it supposed to be:
>
> self._all_states != set(key[i] for key in probabilities)
>

Nope. self._all_states is a set. I am collecting all mentioned states
from the key. Another way to do it is:
self._all_states = set()
for key in probabilities:
self._all_states = set(key)
-- key is a order-tuple of states.

--Scott David Daniels
http://www.velocityreviews.com/forums/(E-Mail Removed)

kpp9c
Guest
Posts: n/a

 03-16-2006
try as i might i still get an error:

File "markov.py", line 50
self._all_states |= set(key[i] for key in probabilities)

I am running:

Python 2.3 (#1, Sep 13 2003, 00:49:11)
[GCC 3.3 20030304 (Apple Computer, Inc. build 1495)] on darwin

If that helps any...

Thanks!

Paul Rubin
Guest
Posts: n/a

 03-16-2006
"kpp9c" <(E-Mail Removed)> writes:
> self._all_states |= set(key[i] for key in probabilities)
> I am running:
> Python 2.3 (#1, Sep 13 2003, 00:49:11)

generator comprehensions are new in 2.4. Try:

self._all_states |= set([key[i] for key in probabilities])

This does temporarily use more memory.

Jack Diederich
Guest
Posts: n/a

 03-16-2006
On Wed, Mar 15, 2006 at 04:50:31PM -0800, Paul Rubin wrote:
> "kpp9c" <(E-Mail Removed)> writes:
> > self._all_states |= set(key[i] for key in probabilities)
> > I am running:
> > Python 2.3 (#1, Sep 13 2003, 00:49:11)

>
> generator comprehensions are new in 2.4. Try:
>
> self._all_states |= set([key[i] for key in probabilities])

And sets aren't a builtin in 2.3

try:
set()
except NameError:
import sets
set = sets.Set

-Jack

kpp9c
Guest
Posts: n/a

 03-16-2006
yes looking at this code i see a few things i haven't seem before. I am
on Mac OS X 10.3.x and updating the python seems like a non trivial
task at the moment.. i will try that and see where that gets me. Thanks.

kpp9c
Guest
Posts: n/a

 03-16-2006
oh ... uhmm .. i don't follow what you are saying... where should i put
those lines... should the import thing go on top?

kpp9c
Guest
Posts: n/a

 03-16-2006
hee hee .... works fine ... but kinda slow on my old machine... really
time for a new laptop haha!

still this code is so beautiful! *^-^*

Max M
Guest
Posts: n/a

 03-16-2006
Jack Diederich wrote:
> On Wed, Mar 15, 2006 at 04:50:31PM -0800, Paul Rubin wrote:
>
>>"kpp9c" <(E-Mail Removed)> writes:
>>
>>> self._all_states |= set(key[i] for key in probabilities)
>>>I am running:
>>>Python 2.3 (#1, Sep 13 2003, 00:49:11)

>>
>>generator comprehensions are new in 2.4. Try:
>>
>> self._all_states |= set([key[i] for key in probabilities])

>
>
> And sets aren't a builtin in 2.3
>
> try:
> set()
> except NameError:
> import sets
> set = sets.Set

nitpick:

try:
set
except NameError:
from sets import Set as set

--

hilsen/regards Max M, Denmark

http://www.mxm.dk/

Phone: +45 66 11 84 94
Mobile: +45 29 93 42 96