Song Classification for Dancing Manolis Cristodoukalis Costas Iliopoulos

  • Slides: 61
Download presentation
Song Classification for Dancing Manolis Cristodoukalis, Costas Iliopoulos, M. Sohel Rahman, W. F. Smyth

Song Classification for Dancing Manolis Cristodoukalis, Costas Iliopoulos, M. Sohel Rahman, W. F. Smyth 28 Aug, 2006 PSC 2006 1

Classical Pattern Matching n n Input: A text T = T[1. . n], A

Classical Pattern Matching n n Input: A text T = T[1. . n], A Pattern P = P[1. . m], both over the alphabet . Output: n n Whether P occurs in T If yes, then the set occ(P) = {i | T[i. . i+m 1] = P} 28 Aug, 2006 PSC 2006 2

Example – Pattern matching Pattern P = AAGCTA Text T = CAAGCTAC A A

Example – Pattern matching Pattern P = AAGCTA Text T = CAAGCTAC A A G C T A Pattern A A G C T A 1 Text 2 3 4 5 6 7 8 9 10 11 12 13 C A A G C T A C Occ(P) = {2, 7} 28 Aug, 2006 PSC 2006 3

Our Case n Input: n n n Text Pattern A musical Sequence Rhythm Output:

Our Case n Input: n n n Text Pattern A musical Sequence Rhythm Output: n n Slightly different from Classical PM A ‘extended/modified’ notion of PM 28 Aug, 2006 PSC 2006 4

Musical Sequence n A string t = t[1]t[2]…t[n] n n t[i] N+ Example: n

Musical Sequence n A string t = t[1]t[2]…t[n] n n t[i] N+ Example: n n [0, 50, 100, 250, 300, 350, 400, 550] Significance: Sequence of events! 28 Aug, 2006 PSC 2006 5

Musical Sequence n A string t = t[1]t[2]…t[n] n n t[i] N+ Example: n

Musical Sequence n A string t = t[1]t[2]…t[n] n n t[i] N+ Example: n n [0, 50, 100, 250, 300, 350, 400, 550] Some (musical) event occurs at 0 ms 28 Aug, 2006 PSC 2006 6

Musical Sequence n A string t = t[1]t[2]…t[n] n n t[i] N+ Example: n

Musical Sequence n A string t = t[1]t[2]…t[n] n n t[i] N+ Example: n n n [0, 50, 100, 250, 300, 350, 400, 550] Some (musical) event occurs at 0 ms Some (musical) event occurs at 50 ms 28 Aug, 2006 PSC 2006 7

Musical Sequence n A string t = t[1]t[2]…t[n] n n t[i] N+ Example: n

Musical Sequence n A string t = t[1]t[2]…t[n] n n t[i] N+ Example: n n n [0, 50, 100, 250, 300, 350, 400, 550] Some (musical) event occurs at 0 ms Some (musical) event occurs at 50 ms Some (musical) event occurs at 100 ms And so on… 28 Aug, 2006 PSC 2006 8

Musical Sequence n n [0, 50, 100, 250, 300, 350, 400, 550] Alternative Representation

Musical Sequence n n [0, 50, 100, 250, 300, 350, 400, 550] Alternative Representation (We use) n n [50, 100, 50, 50, 100, 50] Significance: Sequence of “duration” of theevents! 28 Aug, 2006 PSC 2006 9

Musical Sequence First Representation 0 50 100 250 300 350 450 500 550 50

Musical Sequence First Representation 0 50 100 250 300 350 450 500 550 50 Duration of First Event = 50 – 0 = 50 28 Aug, 2006 PSC 2006 10

Musical Sequence First Representation 0 50 50 100 250 300 350 450 500 550

Musical Sequence First Representation 0 50 50 100 250 300 350 450 500 550 50 Duration of Second Event = 100 – 50 = 50 28 Aug, 2006 PSC 2006 11

Musical Sequence First Representation 0 50 50 100 50 200 250 300 350 450

Musical Sequence First Representation 0 50 50 100 50 200 250 300 350 450 500 550 100 Duration of Second Event = 200 – 100 = 100 28 Aug, 2006 PSC 2006 12

Musical Sequence First Representation 0 50 50 100 200 250 50 300 50 350

Musical Sequence First Representation 0 50 50 100 200 250 50 300 50 350 50 400 50 100 550 50 Alternative Representation 28 Aug, 2006 PSC 2006 13

Rhythm n A string r = r[1]r[2]…r[m] n n n r[j] {Q, S} Q

Rhythm n A string r = r[1]r[2]…r[m] n n n r[j] {Q, S} Q means a quick(er) event S means a slow(er) event S is double the length (duration) of Q Exact length of Q or S is not a priori known 28 Aug, 2006 PSC 2006 14

New Notion of Match n n n Let Q q N+ Then S 2

New Notion of Match n n n Let Q q N+ Then S 2 q Q matches t[i. . i’] iff n q = t[i] + t[i+1] + … + t[i’] n n 1 i i’ n If i = i’ then the match is SOLID 28 Aug, 2006 PSC 2006 15

New Notion of Match Let q = 150 1 2 3 4 5 6

New Notion of Match Let q = 150 1 2 3 4 5 6 7 8 9 50 50 100 50 Q 50+100 = 150 = q 28 Aug, 2006 PSC 2006 16

New Notion of Match Let q = 150 1 2 3 4 5 6

New Notion of Match Let q = 150 1 2 3 4 5 6 7 8 9 50 50 100 50 Q Q 100 + 50 = 150 = q 28 Aug, 2006 PSC 2006 17

New Notion of Match Let q = 150 1 2 3 4 5 6

New Notion of Match Let q = 150 1 2 3 4 5 6 7 8 9 50 50 100 50 Q Q 28 Aug, 2006 Q Q Q PSC 2006 Q 18

New Notion of Match Let q = 100 1 2 3 4 5 6

New Notion of Match Let q = 100 1 2 3 4 5 6 7 8 9 50 50 100 50 Q Q Q Solid Match 28 Aug, 2006 PSC 2006 19

New Notion of Match n n S 2 q S matches t[i. . i’]

New Notion of Match n n S 2 q S matches t[i. . i’] iff either of following is true: n n i = i’ and t[i] = 2 q (SOLID) i i’ and there exists i i 1 i’ such that n n n q = t[i] + t[i+1] + … + t[i 1] = t[i 1+1] + t[i+1] + … + t[i’] 1 i i’ n So, S is either solid or a tile of 2 consecutive Q’s 28 Aug, 2006 PSC 2006 20

New Notion of Match Let q = 100, then S 2 q = 200

New Notion of Match Let q = 100, then S 2 q = 200 1 2 3 4 5 6 7 8 9 50 50 100 50 S t[1] + t[2] = 100 = t[3] 28 Aug, 2006 PSC 2006 21

New Notion of Match Let q = 100, then S 2 q = 200

New Notion of Match Let q = 100, then S 2 q = 200 1 2 3 4 5 6 7 8 9 50 50 100 50 S S t[4] + t[5] = 100 = t[6] + t[7] 28 Aug, 2006 PSC 2006 22

New Notion of Match Let q = 100, then S 2 q = 200

New Notion of Match Let q = 100, then S 2 q = 200 1 2 3 4 5 6 7 8 9 50 50 100 50 S S 28 Aug, 2006 PSC 2006 23

New Notion of Match Let q = 100, then S 2 q = 200

New Notion of Match Let q = 100, then S 2 q = 200 1 2 3 4 5 6 7 8 9 50 50 100 50 S S S Although, t[2] + t[3] + t[4] = 200 = 2 q 28 Aug, 2006 PSC 2006 24

New Notion of Match Let q = 100, then S 2 q = 200

New Notion of Match Let q = 100, then S 2 q = 200 1 2 3 4 5 6 7 8 9 50 50 100 50 S S 28 Aug, 2006 S S PSC 2006 25

New Notion of Match Let r = QSS and Let q = 50 1

New Notion of Match Let r = QSS and Let q = 50 1 2 3 4 5 6 7 8 9 50 50 100 50 Q S S r r matches t[2. . 5] 28 Aug, 2006 PSC 2006 26

New Notion of Match Let r = QSS and Let q = 50 1

New Notion of Match Let r = QSS and Let q = 50 1 2 3 4 5 6 7 Q 50 50 100 Q S 50 9 S 50 S r 28 Aug, 2006 50 8 50 100 50 S r r matches t[5. . 8] PSC 2006 27

New Notion of Match Let r = QSS and Let q = 50 1

New Notion of Match Let r = QSS and Let q = 50 1 2 3 4 5 6 7 Q 50 50 100 Q S 50 50 8 9 S 50 100 50 S r r r covers t[2. . 8] 28 Aug, 2006 PSC 2006 28

Our Problem n Input: n n n A musical Sequence t A rhythm r

Our Problem n Input: n n n A musical Sequence t A rhythm r Output: n The longest substring t[i. . i’] that is covered by r 28 Aug, 2006 PSC 2006 29

Restriction n For each match of r, at least one S must be solid

Restriction n For each match of r, at least one S must be solid Let r = QSS and Let q = 50 1 2 3 4 5 6 7 8 9 50 50 50 100 r 50 50 100 Q S SOLID S 28 Aug, 2006 S PSC 2006 30

Restriction n For each match of r, at least one S must be solid

Restriction n For each match of r, at least one S must be solid Let r = QSS and Let q = 50 1 2 3 4 5 6 7 8 9 50 50 50 100 r 50 50 100 Q S At least one S must be Solid 28 Aug, 2006 S r PSC 2006 31

Restriction n For each match of r, at least one S must be solid

Restriction n For each match of r, at least one S must be solid Let r = QSS and Let q = 50 1 2 3 4 5 6 7 8 9 50 50 50 100 r 50 50 100 Q At least one S must be Solid 28 Aug, 2006 PSC 2006 S r S SOLID S 32

Motivation n n Our aim is to classify music according to dancing rhythm Music

Motivation n n Our aim is to classify music according to dancing rhythm Music seq can be considered as a series of events corresponding to music signals n n n Drum beats Guiter picks Horn hits 28 Aug, 2006 PSC 2006 33

Motivation n The intervals between these events characterize how the song is danced Basically

Motivation n The intervals between these events characterize how the song is danced Basically two dancing rhythms: Quick & Slow Example: n n n cha-cha SSQQS foxtrot SSQQ jive SSQQSQQS 28 Aug, 2006 PSC 2006 34

Motivation n So solution to our problem can classify songs according to dancing rhythms!

Motivation n So solution to our problem can classify songs according to dancing rhythms! 28 Aug, 2006 PSC 2006 35

Algorithm n n n Stage 1: Find all occurrences of S for a chosen

Algorithm n n n Stage 1: Find all occurrences of S for a chosen value such that /2 . Stage 2: Transform areas around each S into sequences of Q. Stage 3: Find the matches of r and consequently the cover. 28 Aug, 2006 PSC 2006 36

Algorithm: Stage 1 n We construct two arrays: n n first[1. . | |]:

Algorithm: Stage 1 n We construct two arrays: n n first[1. . | |]: first[ ] = i iff the first occurrence of symbol appears at position i. next[1. . n]: next[i] = j iff the next occurrence of symbol at t[i] appears at t[j]. 28 Aug, 2006 PSC 2006 37

Algorithm: Stage 1 1 2 3 4 5 6 7 8 9 50 50

Algorithm: Stage 1 1 2 3 4 5 6 7 8 9 50 50 100 50 = {50, 100}, assume indexed alphabet 28 Aug, 2006 PSC 2006 38

Algorithm: Stage 1 1 2 3 4 5 6 7 8 9 50 50

Algorithm: Stage 1 1 2 3 4 5 6 7 8 9 50 50 100 50 = {50, 100}, assume indexed alphabet first[1] = 1 28 Aug, 2006 First occurrence of 50 PSC 2006 39

Algorithm: Stage 1 1 2 3 4 5 6 7 8 9 50 50

Algorithm: Stage 1 1 2 3 4 5 6 7 8 9 50 50 100 50 = {50, 100}, assume indexed alphabet first[1] = 1 first[2] = 3 28 Aug, 2006 First occurrence of 100 PSC 2006 40

Algorithm: Stage 1 1 2 3 4 5 6 7 8 9 50 50

Algorithm: Stage 1 1 2 3 4 5 6 7 8 9 50 50 100 50 next[1] = 2 28 Aug, 2006 Next occurrence of t[1] = 50 PSC 2006 41

Algorithm: Stage 1 1 2 3 4 5 6 7 8 9 50 50

Algorithm: Stage 1 1 2 3 4 5 6 7 8 9 50 50 100 50 next[1] = 2 28 Aug, 2006 next[2] = 4 Next occurrence of t[2] = 50 PSC 2006 42

Algorithm: Stage 1 1 2 3 4 5 6 7 8 9 50 50

Algorithm: Stage 1 1 2 3 4 5 6 7 8 9 50 50 100 50 next[1] = 2 next[3] = 8 next[2] = 4 Next occurrence of t[3] = 100 And so on… 28 Aug, 2006 PSC 2006 43

Algorithm: Stage 2 1 2 3 4 5 6 7 8 9 10 11

Algorithm: Stage 2 1 2 3 4 5 6 7 8 9 10 11 … 100 50 25 25 100 50 15 30 50 … S Consider an S at t[5]. 28 Aug, 2006 PSC 2006 44

Algorithm: Stage 2 1 2 3 4 5 6 7 8 9 10 11

Algorithm: Stage 2 1 2 3 4 5 6 7 8 9 10 11 … 100 50 25 25 100 50 15 30 50 … S 28 Aug, 2006 Q PSC 2006 45

Algorithm: Stage 2 1 2 3 4 5 6 7 8 9 10 11

Algorithm: Stage 2 1 2 3 4 5 6 7 8 9 10 11 … 100 50 25 25 100 50 15 30 50 … S 28 Aug, 2006 Q Q PSC 2006 46

Algorithm: Stage 2 1 2 3 4 5 6 7 8 9 10 11

Algorithm: Stage 2 1 2 3 4 5 6 7 8 9 10 11 … 100 50 25 25 100 50 15 30 50 … S 28 Aug, 2006 Q Q PSC 2006 30+50 > 50 So Stop! 47

Algorithm: Stage 2 1 2 3 4 5 6 7 8 9 10 11

Algorithm: Stage 2 1 2 3 4 5 6 7 8 9 10 11 … 100 50 25 25 100 50 15 30 50 … Q 28 Aug, 2006 S Q Q PSC 2006 48

Algorithm: Stage 2 1 2 3 4 5 6 7 8 9 10 11

Algorithm: Stage 2 1 2 3 4 5 6 7 8 9 10 11 … 100 50 25 25 100 50 15 30 50 … Q Q So we get a new sequence t consisting of Q and S 28 Aug, 2006 PSC 2006 49

Algorithm: Stage 3 n n Here we get t consisting of Q and S.

Algorithm: Stage 3 n n Here we get t consisting of Q and S. We first want to find the matches of r in t. Define St S in t , Qt Q in t Define Sr S in r, Qr Q in r 28 Aug, 2006 PSC 2006 50

Algorithm: Stage 3 n Construct t as follows: n n St = 01, Qt

Algorithm: Stage 3 n Construct t as follows: n n St = 01, Qt = 1 Construct Invalid set I where I contains the position of 1 due to St. Q 1 Q S 1 1 0 28 Aug, 2006 Q Q 1 1 PSC 2006 51

Algorithm: Stage 3 n Construct t as follows: n n St = 01, Qt

Algorithm: Stage 3 n Construct t as follows: n n St = 01, Qt = 1 Construct Invalid set I where I contains the position of 1 due to St. Q Q S Q Q 1 2 3 4 5 6 1 1 0 1 1 1 28 Aug, 2006 PSC 2006 No match can occur at position 4 because it is not a ‘real’ position in t I = {4} 52

Algorithm: Stage 3 n Construct r as follows: n Sr = 10, Qr =

Algorithm: Stage 3 n Construct r as follows: n Sr = 10, Qr = 0 S Q 0 1 28 Aug, 2006 0 PSC 2006 53

Algorithm: Stage 3 n Construct r as follows: n Sr = 10, Qr =

Algorithm: Stage 3 n Construct r as follows: n Sr = 10, Qr = 0 S Q 1 2 3 1 0 0 28 Aug, 2006 PSC 2006 54

Algorithm: Stage 3 n Find matches of r’ in t’’. n n n Perform

Algorithm: Stage 3 n Find matches of r’ in t’’. n n n Perform bitwise or at each position. If the result is all 1 and the position is not in invalid set then a match Otherwise no match 28 Aug, 2006 PSC 2006 55

Algorithm: Stage 3 n Find matches of r’ in t’’. 1 2 3 4

Algorithm: Stage 3 n Find matches of r’ in t’’. 1 2 3 4 5 6 1 1 0 0 I = {4} Bitwise Or 1 1 0 No Match!!! 28 Aug, 2006 PSC 2006 56

Algorithm: Stage 3 n Find matches of r’ in t’’. 1 2 3 4

Algorithm: Stage 3 n Find matches of r’ in t’’. 1 2 3 4 5 6 1 1 0 0 I = {4} Bitwise Or 1 0 0 No Match!!! 28 Aug, 2006 PSC 2006 57

Algorithm: Stage 3 n Find matches of r’ in t’’. 1 2 3 4

Algorithm: Stage 3 n Find matches of r’ in t’’. 1 2 3 4 5 6 1 1 0 0 I = {4} Bitwise Or 1 1 1 All 1’s!!! And 3 I. So a MATCH!!! 28 Aug, 2006 PSC 2006 58

Algorithm: Stage 3 n Find matches of r’ in t’’. 1 2 3 4

Algorithm: Stage 3 n Find matches of r’ in t’’. 1 2 3 4 5 6 1 1 0 0 I = {4} Bitwise Or 1 1 1 All 1’s!!! But, 4 I. So NO MATCH!!! 28 Aug, 2006 PSC 2006 59

Algortihm n In this way we can find the matches & then we can

Algortihm n In this way we can find the matches & then we can easily compute the cover 28 Aug, 2006 PSC 2006 60

Conclusion n n In practical cases size of the rhuthm is 10 13. So

Conclusion n n In practical cases size of the rhuthm is 10 13. So we have assumed m to be constant. It would be interesting, however, to remove the dependency on m It would be interesting to remove the restriction of one S being Solid Applying another restriction on the number of additions in the numeric text may turn out to be useful 28 Aug, 2006 PSC 2006 61