Sequences in list
Hi All, I wonder could someone help me with this? What I want to do is search through a list of letters and look for adjacent groups of letters that form sequences, not in the usual way of matching say abc to another appearance later on in the list but to look for transposed patterns. The groups of letters can be made up of between 2 to 4 letters. It is not know beforehand how the groups are formed, so I can't say here is a group, look for a sequence formed from this. There must be at least three appearances of the groups for the sequence to be pass. More than one sequence may show in a list, i.e. first abc, bcd and cde followed by bd, df, fa, ac at some later point. Ideally I would like to know the start and end position of the sequence/sequences. I'm looking for patterns such as these: ['a', 'b', 'c', 'b', 'c', 'd', 'c', 'd', 'e'] ['a', 'c', 'f', 'c', 'e', 'h', 'e', 'g', 'c'] ['c', 'a', 'a', 'f', 'f', 'd', 'd', 'b'] But these would be wrong: ['a', 'b', 'c', 'b', 'c', 'd', 'c', 'd', 'e', 'f', 'a', 'd'] - This one fails because of the 'jump' of the last group of three letters in relation to the others. To pass the last group would need to have been def. However, the previous three groups are ok and would be passed as a sequence. ['a', 'c', 'f', 'a', 'f', 'e', 'e', 'g', 'c'] - Here, although the first and last groups have a similar sequence this would fail because of the intervening group (afe) not following the pattern. Thanks for any help, Malcolm -- http://mail.python.org/mailman/listinfo/python-list
Re: Sequences in list
Hi Michael, Thanks for a quick response, I appreciate it. I will have to get back to you tomorrow, as I can't check what you've given me right now. I presume the fact that you mention the word note in your code you have realised that I'm trying to search for musical sequences. I tried to put my problem across in the way I did, not mentioning music, so as not to confuse the matter. So simply put, I'm checking a list for musical sequences, without having any idea as to how they might be formed. Thanks, Malcolm -- http://mail.python.org/mailman/listinfo/python-list
Re: Sequences in list
Iâve had chance to look at your code. I had an idea that I the answer to my problem some how involved breaking down the list into groups and that the notes would be easier to work with as numbers. However, I think your âmake_diffsâ function is really a very cunning way to go about things ï I would have never have thought of that! As to the latest update, that is very welcome and will allow me to analyse the results given in more detail. In answer to your questions â Are your search sequences really limited to 4 notes? â No, just used that as an example How long are the pieces you are searching? â Anything from the length of a phrase to perhaps 32 bars, though maybe longer at some later date. Do you not need to care about note lengths, only pitches. â While Iâve been trying to figure out a way to do this Iâve just concentrated on pitches, but it would be great to be able to look at the note lengths as well. Are you really (as I inferred from your examples) looking only at a 7-tone scale â Yes, for the time being Your code will identify sequences in a list, but how to index them? I have an idea, which seems ridiculously long-winded, but should work. First, put the groups from the âmake_diffsâ function into a list and do a search for the sequence identified from the âcompare_formsâ function using the âKnuth-Morris-Prattâ function in the python cookbook. Then the positions in that list will obviously be the same as those in the original. Next is the problem of the interval between the individual groups of the sequence. Using something along the lines of your âmake_diffsâ it should be a simple matter to see by what interval the groups in the sequence are transposed. Hmmâ those last two paragraphs come across as the ranting of a mad man. Iâm off home to see if something like that worksâ All the best and thanks again for the help, Malcolm -- http://mail.python.org/mailman/listinfo/python-list
Markov chain with extras?
Hi All, Could someone show me how to do this? I want to generate a list using a Markov chain, however, as well as using the previous two items in the list to decide the current choice I want the decision to be also dependant on an item at the current position in another list. I hope this explains thing clearly enough. Thanks, Malcolm -- http://mail.python.org/mailman/listinfo/python-list
Re: Markov chain with extras?
Hi, I think is more easy explained as two linked markov chains. So given one list the other can be generated. Thanks, Malcolm -- http://mail.python.org/mailman/listinfo/python-list
Re: Markov chain with extras?
Hi Tiissa, Thanks for the reply. I want to use it for music. So given list 1 (melody), list 2 (chords) could be generated by a Markov chain. Also, given the chords the melody could be generated again by a chain. I haven't had time to play around with your code and as I've only been studying python for about six months I don't quite understand what's going on. This might already do what I want, I just need to think in terms of notes and chords. Thanks, Malcolm -- http://mail.python.org/mailman/listinfo/python-list
Re: Markov chain with extras?
Hi Gentlemen, First off, thanks for the work/time you've put into this - much appreciated! Let me play around with the code and I'll get back to you tomorrow. Malcolm -- http://mail.python.org/mailman/listinfo/python-list
