Hungarian Algorithm (Munkres) in SC?

Also worth pointing out that SC does include 2 neural-net classes, NeuralNet and TermanWang.

of course it does! It’s the Fizz Buzz phenomena - the hardest things about managing programmers is stopping them writing code

That’s funny bc there’s even less of a culture of programming in Max and Pd land :wink:

hjh

1 Like

Yeah, but he excluded PD completely and said SC is “sort of” a programming language.

@smoge and @tedmoore, I’ve gone ahead and implemented Munkres as a sclang C++ primitive. I’ve been using Ted’s lovely SC class since March and it works great, but I wanted to speed it up. Going C++ speeds it up by a huge factor. For example, a 100x100 matrix takes ~ 1.5s to solve using Ted’s class, and 0.00051s using the C++ primitive. With the C++ version, it becomes something you can do over and over again rather than treating it like a huge operation you have to carefully manage.

I’ve tested it thoroughly against Ted’s class, which I’d tested before and gives the correct results, and as far as I can see the C++ primitive always returns the correct results.

I’ve also written a wrapper for the primitive in SC, so you can simply call it on any 2-dimensional Array (e.g [[1,2],[3,4]]) by calling .hungarianSolve.

This is my first time writing a primitive, so I’m currently learning about how best to create a pull request in the hope of positioning it as a candidate for inclusion in a future version of SC.

I do think this a very useful algorithm for music and would be something natural to include in SC.

1 Like

I love this. Where is the code? I’d love to give it a try!

Here’s the PR, @tedmoore!

2 Likes

@smoge i’m using the voice-leading example at the end of your “simple implementation” earlier in this thread in the help for the method — i assume that’s ok?

first off thanks! I will use this I expect!

the voice-leading example

tiny thought: you might want to tweak the order and/or number of the chord tones so that the solution doesn’t look trivial!

1 Like

@semiquaver cool! Yes I had the same thought and did make the notes more complex in the PR. But come to think of it, you’re right that changing the order as well would be nice. Will do.

Of course, it’s ok! I’m glad it was useful.

1 Like