Re: Markov process representation

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

  1. kpp9c

    kpp9c Guest

    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
    #1
    1. Advertising

  2. 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
    #2
    1. Advertising

  3. kpp9c

    kpp9c Guest

    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
    #3
  4. kpp9c

    Paul Rubin Guest

    "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
    #4
  5. 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
    #5
  6. kpp9c

    kpp9c Guest

    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
    #6
  7. kpp9c

    kpp9c Guest

    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
    #7
  8. kpp9c

    kpp9c Guest

    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
    #8
  9. kpp9c

    Max M Guest

    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/
    IT's Mad Science

    Phone: +45 66 11 84 94
    Mobile: +45 29 93 42 96
    Max M, Mar 16, 2006
    #9
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Replies:
    7
    Views:
    542
  2. kpp9c

    markov query

    kpp9c, Mar 14, 2006, in forum: Python
    Replies:
    5
    Views:
    488
    Robert Kern
    Mar 15, 2006
  3. Replies:
    2
    Views:
    296
  4. Replies:
    0
    Views:
    105
  5. vsv
    Replies:
    1
    Views:
    111
    Dave Burt
    Apr 11, 2006
Loading...

Share This Page