# Re: Markov process representation

Discussion in 'Python' started by kpp9c, Mar 15, 2006.

1. ### kpp9cGuest

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 for key in probabilities)

an error? isn't it supposed to be:

self._all_states != set(key for key in probabilities)
kpp9c, Mar 15, 2006

2. ### Scott David DanielsGuest

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 for key in probabilities)
>
> an error? isn't it supposed to be:
>
> self._all_states != set(key 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
Scott David Daniels, Mar 15, 2006

3. ### kpp9cGuest

try as i might i still get an error:

File "markov.py", line 50
self._all_states |= set(key 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!
kpp9c, Mar 16, 2006
4. ### Paul RubinGuest

"kpp9c" <> writes:
> self._all_states |= set(key 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 for key in probabilities])

This does temporarily use more memory.
Paul Rubin, Mar 16, 2006
5. ### Jack DiederichGuest

On Wed, Mar 15, 2006 at 04:50:31PM -0800, Paul Rubin wrote:
> "kpp9c" <> writes:
> > self._all_states |= set(key 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 for key in probabilities])

And sets aren't a builtin in 2.3

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

-Jack
Jack Diederich, Mar 16, 2006
6. ### kpp9cGuest

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, Mar 16, 2006
7. ### kpp9cGuest

oh ... uhmm .. i don't follow what you are saying... where should i put
those lines... should the import thing go on top?
kpp9c, Mar 16, 2006
8. ### kpp9cGuest

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

still this code is so beautiful! *^-^*
kpp9c, Mar 16, 2006
9. ### Max MGuest

Jack Diederich wrote:
> On Wed, Mar 15, 2006 at 04:50:31PM -0800, Paul Rubin wrote:
>
>>"kpp9c" <> writes:
>>
>>> self._all_states |= set(key 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 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/