[Tutor] Automaton/transitional grammar query

kevin parks kp8 at mac.com
Mon Oct 12 16:09:24 CEST 2009

> > You might be interested in Steven Wolfram's book, "A New Kind of
> > Science" and the many examples on his web site:
> > http://www.wolframscience.com/ See Wikipedia as well. This is a very
> > rich area.

Thanks. That was just the kind of reference I was looking for.  
I am sure i wont be able to grok the math bits but maybe i can begin  
to understand
thsese ideas on a conceptual level. I will look for this in the book  

> > When you introduce the random element you are generating Markov  
> chains.

That's what i thought. I would be interested in playing with some  
simple, 1st and 2nd order markov chains too, but i just want to define  
the transition tables with the elements and their probabilities and  
generate. Most of the Markov stuff i see out there is big and knotty  
and way more than i need.

> > I don't understand why you want to flatten outlist; when I run your
> > program I get one number per line, not one generation per line as  
> you
> > show above.

That's odd. Anyway in my program I am printing the list twice. The  
first time outlist is printed it is nested one level deep. That is  
just scaffolding. Then i pick through it one item per line having  
flattened it and print it in a format that my other program can read.

I been using that flatten function since 1970. Prolly pilfered from  
Tim Peters or Effbot. Remember them guys? Awesome dudes. I wonder if  
they even use python anymore. Anyway that is from way before itertools  
was even a glimmer. Additionally, your flatten function doesn't work  
for me actually. I get:

NameError: global name 'chain' is not defined

> >> enumerate() is simpler:

Thanks. enumerate is also still somewhat new to me.

> > I don't think you will get an infinite loop. You may have a grammar
> > that generates a stable or repeating pattern but I don't think you
> > will be able to detect that without trying it.

Yeah i don't mean an infinite loop, but more like a perpetual dance  
back and forth between to items
that point to each other. I think I need to be careful when i define  
the rules that i don't get something like that... say if 1 goes to 4  
but 4's rule is go to 1, for example.

> > our rules, instead of being just a list of numbers, become a list of
> > probability mappings. I think you want to apply the probabilities to
> > the whole sequence, so a single rule might be (using your example)
> > 1: [ ((2. 5), .7), ((2. 4), .3) ]
> >
> > Then change the apply_rules function to choose one of the  
> possibilites
> > using your windex() function.

I'll roll this around in my pea sized brain and see if i can put this  
suggestion to work.

Thanks Kent!

Hopefully I will get this going and my psudo-markov thingy happening  
too. These things are fun for making patterns. I like these powerful  
little pea shooters.


More information about the Tutor mailing list