Imagine that you're throwing a party, and your friends have elected you Music Czar. Your task is to provide continuous background music throughout the night. Each guest has provided you with a list of songs they would like to hear, but the order of the tracks is random, and styles vary wildly from one guest to another.
What's more, your guests are remorseless party machines who will undoubtedly stay up well into the next morning, so your mix will have to be several hours long. If the ordering of songs is too jumpy, the guests may revolt and trash your place. Since you would like to see your security deposit again, the mix must flow. What do you do?
THE PITCH
This can be modeled as a Traveling Salesman Problem:
- Define a complete graph G where each node is a song in your collection
- Edge weights correspond to some notion of distance between songs
- Find a simple path touching all nodes in G with minimal total weight
THE DETAILS
- The first step is to analyze the content of each song. The Echo Nest makes this incredibly easy with pyEchoNest. From this, we can model the timbral features of each song by a multivariate Gaussian. NumPy to the rescue!
- Now we have a bunch of statistical models, but we need some notion of distance between these models. The notion I'll use here is the Euclidean metric applied to a Probability Product Kernel. Some people might prefer KL divergence, but PPK induces a metric, which will allow for more accurate TSP approximations.
- Given the kernel matrix K, we can compute its corresponding distance matrix, which then forms the weights of the graph.
- Run your favorite TSP approximator on the graph, and you're set!
THE RESULTS
Exhibit A, an alphabetized playlist:
- Avalanches_-_Since_I_Left_You/(13) Frontier Psychiatrist
- Banyan_-_Anytime_At_All/(11) Sputnik
- Cake_-_Prolonging_the_Magic/(07) Sheep Go to Heaven
- Curtis_Mayfield_-_Superfly/(03) Freddie's Dead
- Elvis_Costello_-_Best_Of/(07) Elvis Costello & The Attractions - Pump It Up
- Madame_Blavatsky_Overdrive_-_Idiot_Jones_Will_Have_His_Day/07 MBO
- MC_Chris_-_Life's_A_Bitch_and_I'm_Her_Pimp/(07) Fett's Vette
- Parliament_-_Mothership_Connection/(03) Unfunky UFO
- Propellerheads_-_Decksanddrumsandrockandroll/(10) Propellerheads & David Arnold - On Her Majesty's Secret Service
- Red_Elvises_-_Surfing_in_Siberia/(05) Hungarian Dance #5
- Soundtrack_-_Lock_Stock_and_Two_Smoking_Barrels/(16) James Brown - The Payback
- Soundtrack_-_The_Big_Lebowski/(03) Elvis Costello - My Mood Swings
- Squirrel_Nut_Zippers_-_Hot/(07) Hell
- The_J.B.'s_-_Funky_Good_Time:_The_Anthology_[1]/(12) Watermelon Man
- Thievery_Corporation_-_The_Mirror_Conspiracy/(04) Lebanese Blonde
Exhibit B, the ordered mix:
- Avalanches_-_Since_I_Left_You/(13) Frontier Psychiatrist
- Banyan_-_Anytime_At_All/(11) Sputnik
- Propellerheads_-_Decksanddrumsandrockandroll/(10) Propellerheads & David Arnold - On Her Majesty's Secret Service
- Elvis_Costello_-_Best_Of/(07) Elvis Costello & The Attractions - Pump It Up
- Cake_-_Prolonging_the_Magic/(07) Sheep Go to Heaven
- Parliament_-_Mothership_Connection/(03) Unfunky UFO
- The_J.B.'s_-_Funky_Good_Time:_The_Anthology_[1]/(12) Watermelon Man
- Thievery_Corporation_-_The_Mirror_Conspiracy/(04) Lebanese Blonde
- Curtis_Mayfield_-_Superfly/(03) Freddie's Dead
- Red_Elvises_-_Surfing_in_Siberia/(05) Hungarian Dance #5
- Soundtrack_-_The_Big_Lebowski/(03) Elvis Costello - My Mood Swings
- Madame_Blavatsky_Overdrive_-_Idiot_Jones_Will_Have_His_Day/07 MBO
- MC_Chris_-_Life's_A_Bitch_and_I'm_Her_Pimp/(07) Fett's Vette
- Soundtrack_-_Lock_Stock_and_Two_Smoking_Barrels/(16) James Brown - The Payback
- Squirrel_Nut_Zippers_-_Hot/(07) Hell
THE CODE
Try it out. You can download python code for this here. You will need the following:
- An Echo Nest API key
- pyEchoNEst
- NumPy
- python-graph
- Some mp3s...

0 comments:
Post a Comment