< Back to IRCAM Forum

Slow algorithm / internal patches - convert to code automatically

Dears, I wrote a very complex algorithm which consist a lot of om-loops and internal patches in which are internal patches which contains internal patches and so on. This algorithm is very slowly. I assume it’s due to a large number of internal patches. A question is: is there any possibility to automatically convert that algorithm - that means a hierarchy of a lot of internal patches and om-loops- in to the code for possibility to make function-library? Thank you, Petrh

Hi Perth,

There is no “automatic” conversion of Patch -> lisp code in OpenMusic. The patch itself is lisp code. any how, In order to optimize a patch into a lisp code, one must do it himself. If not this automatic conversion will not change the optimization. Can we see the patch?

BEst
K

dear Karim, thank you for your answer, I understood. My patch with very basic description of algorithm (including information about my computer system) is attached. Time of iteration is about 4 minutes. Is there some mistake? Thank you, have a nice evening, Petrhpetr_patch.omp (341 Bytes)

Dear Petr,

Your patch seems to be empty (???)
Did you save it before uploading it ?

Best
K

dear Karim, it’s my fault, I am sorry, patch in question is now attached, thank you for your kindness, Petrh

petr_patch.omp (52.7 KB)

Hmm…
If i understand your patch well, you want to find all repetitive sequences of n (here 5) patterns. Meaning you start with the 5 first integers, then lookup all sequences alike, then shift by one integer, etc… ?
What do you expect as output?
If this is the case, i think you are better off writing this in lisp directly.

Best
K

Hi petrh.

Interesting problem! 99% sure there’s something which can be optimised, while still patching boxes and cords :slight_smile:

Perhaps you could supply a ‘mwe’ (minimal working example), or just a simple line or two which explains what you expect as output given a certain input (and explanation of why)?

-anders

Couldn’t let go of this… does this patch here - using 'onlistloop and 'search - come near what you’re after?

check n-groups with multiple matches.omp (7.3 KB)

Hi All

I don’t know if this is what you are looking for (@petr) But it seems for me very fast. It gives the position of occurrences of all incrementally grouped integer of your list (grouped by 5). Of course if this is what you are trying to analyze we can also do a pretty printing here, and make a statistical formatted list.

BEst
K

petr_patch_is-this .omp (63.4 KB)

dear Anders, dear Karim, first of all thank you for your help and interest. It is kind of you. I also thank you for your patches. They are much more simple and correspondent with my goals. My patch is prototype. It should be a main part of sets of analytical instruments. Output from that algorithm should be:

/1./ a list of all groups which are presented in analyzed structure more then once (therefore “repetitive groups” = groups that occur repeatedly), in my patch, first output, e.g. (((2 3 4) (2 4 5))) .

/1.1/ algorithm must be able to look for n-groups, that means groups with given number of elements, group with n=4: (3 4 2 1).

/2./list of all rep.groups should contain information about how many times every group is presented in analyzed structure, in my patch, second output : (((2 3 4) 3) ((2 4 5) 6)) that means there are two groups, first (2 3 4) is present three times, second one (2 4 5) six times.

/3./resulting list should be sorted descending according to the frequency of occurrence: (((2 4 5) 6) (2 3 4) 3))) /4./ the resulting list can not contain duplicates, treelist (((2 4 5) 6) ((2 4 5) 5) (2 3 4) 3))) is unacceptable because contain group (2 4 5) twice.

MY PROBLEMS ARE:

/a./ slowness - but you sent me an alternative solution

/b./ I am not able to remove duplicates from the treelist which contains information about how many times every group is presented, thant means from treelist from second output of my algorithm, e.g: (((2 4 5) 6) ((2 4 5) 5) (2 3 4) 3))).

/c./ it would be great (I am not able to do it) if it would be possible to obtain a position of every group in original list (position of the first element /start/ position of occurrence of group), e.g: (((2 3 4) 3 (0 3 6)) (((2 4 5) 2) (9 12))) that means: there are two groups, first (2 3 4) is present three times and is possible to find it on position 0, 3 and 6, and second one (2 4 5) is present twice and is possible to find it on position 9 and 12. Original list therefore probably looks like: (2 3 4, 2 3 4, 2 3 4, 2 4 5, 2 4 5). Sure, in that case there are more n3 groups: (2 3 4) (3 4 2) (4 2 3) (2 4 5)), but for mentioned example it is acceptable I hope.

Thank you again for your help, Petr

Hi petr

I think you can get all this with the patch i’ve sent you
Best
K

Here’s something which seems to do what you prescribe:

n-groups w. multiple matches, count and positions.omp (14.0 KB)

Dear Anders, your patch/algorithm is really perfect. Thank you very much. I have to explore / study it. Can I ask you what is your job/interest/focus on? Are you from IRCAM or any other similar institution? Have a nice evening, Petr

Hi Petrh.

Can I ask you what is your job/interest/focus on?

I’m a freelance composer. But been collaborating very closely during some years with people at IRCAM, esp. Jean Bresson and Karim Haddad, where they have provided extremely valuable expertise and other resources to my work.

What about you?

Hi Anders, I work as musicologist and teacher (university, secondary school), sometimes as composer. At this time I’m preparing project about computational analysis. I would like to offer it as project for our department of musicology. Algorithm in question should by part of it. One more question: did you study programming? Or are you a self-taught person? Petr

I started to use Common Lisp and Scheme (still learning…) while, as a composer, encountering Common-Music and related music software from CCRMA and ZKM (CM, CLM, Snd, CMN). So much fun to do, and so much fun to learn! :slight_smile:

I uderstood. Can I ask you wich computer system do you use? Mac or Win?

Whatever does the job :slight_smile: However prefer Linux for most things.

Hi Anders, we were in touch in August 2020. I was looking for help with optimizing my analysis algorithm that I wrote in openmusic. You helped me and simplified my huge and slow algorithm. Thank you very much again for that. I have now applied your simplified algorithm to an analysis concept based on tracking repetitive structures in musical composition. I wrote an article about it and I want to mention in a note that you are the author of the optimization of my algorithm. I can put in there that you are a “member of the IRCAM Forum” and that your nickname is “Anders”. But I’d rather put your full name (if you agree). Will you write your name and affiliation if necessary ? Are you working somewhere at a university, a conservatory, an artist, a programmer?
Thank you, Petr Haas, Czech Republic, Prague

Of course!

Full name: Anders Vinjar, working as freelance artist

Will your article be published anywhere? Would be great to learn more about the analysis youre doing!

-anders