Title: Song Classification for Dancing
1Song Classification for Dancing
- Manolis Cristodoukalis, Costas Iliopoulos, M.
Sohel Rahman, W.F. Smyth
2Classical Pattern Matching
- Input A text T T1..n, A Pattern P P1..m,
both over the alphabet ?. - Output
- Whether P occurs in T
- If yes, then the set occ(P) i Ti..im-1
P
3Example Pattern matching
Pattern P AAGCTA
Text T CAAGCTAAGCTAC
A
A
G
C
T
A
Pattern
A
A
G
C
T
A
1
10
9
11
2
3
4
5
6
7
8
12
13
Text
C
C
G
T
A
A
G
C
T
A
A
A
C
Occ(P) 2, 7
4Our Case
- Input
- Text A musical Sequence
- Pattern Rhythm
- Output
- Slightly different from Classical PM
- A extended/modified notion of PM
5Musical Sequence
- A string t t1t2tn
- ti ? ?N
- Example
- 0,50,100,200,250,300,350,400,500,550
- Significance Sequence of events!
6Musical Sequence
- A string t t1t2tn
- ti ? ?N
- Example
- 0,50,100,200,250,300,350,400,500,550
- Some (musical) event occurs at 0 ms
7Musical Sequence
- A string t t1t2tn
- ti ? ?N
- Example
- 0,50,100,200,250,300,350,400,500,550
- Some (musical) event occurs at 0 ms
- Some (musical) event occurs at 50 ms
8Musical Sequence
- A string t t1t2tn
- ti ? ?N
- Example
- 0,50,100,200,250,300,350,400,500,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
9Musical Sequence
- 0,50,100,200,250,300,350,400,500,550
- Alternative Representation (We use)
- 50,50,100,50,50,50,50,100,50
- Significance Sequence of duration of theevents!
10Musical Sequence
First Representation
0
50
100
200
250
300
350
450
500
550
50
Duration of First Event 50 0 50
11Musical Sequence
First Representation
0
50
100
200
250
300
350
450
500
550
50
50
Duration of Second Event 100 50 50
12Musical Sequence
First Representation
0
50
100
200
250
300
350
450
500
550
50
50
100
Duration of Second Event 200 100 100
13Musical Sequence
First Representation
0
50
100
200
250
300
350
400
500
550
50
50
100
50
50
50
50
100
50
Alternative Representation
14Rhythm
- A string r r1r2rm
- rj ? 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
15New Notion of Match
- Let Q?? q ? N
- Then S ? 2 ? q
- Q matches ti..i iff
- q ti ti1 ti
- 1 ? i ? i ? n
- If i i then the match is SOLID
16New Notion of Match
Let q 150
1
2
3
4
5
6
7
8
9
50
50
100
50
50
50
50
100
50
Q
50100 150 q
17New Notion of Match
Let q 150
1
2
3
4
5
6
7
8
9
50
50
100
50
50
50
50
100
50
Q
Q
100 50 150 q
18New Notion of Match
Let q 150
1
2
3
4
5
6
7
8
9
50
50
100
50
50
50
50
100
50
Q
Q
Q
Q
Q
Q
19New Notion of Match
Let q 100
1
2
3
4
5
6
7
8
9
50
50
100
50
50
50
50
100
50
Q
Q
Q
Q
Q
Q
Solid Match
20New Notion of Match
- S ? 2 ? q
- S matches ti..i iff either of following is
true - i i and ti 2q (SOLID)
- i ?? i and there exists i ? i1 ? i such that
- q ti ti1 ti1 ti11 ti1
ti - 1 ? i ? i ? n
- So, S is either solid or a tile of 2 consecutive
Qs
21New Notion of Match
Let q 100, then S ? 2q 200
1
2
3
4
5
6
7
8
9
50
50
100
50
50
50
50
100
50
S
t1 t2 100 t3
22New Notion of Match
Let q 100, then S ? 2q 200
1
2
3
4
5
6
7
8
9
50
50
100
50
50
50
50
100
50
S
S
t4 t5 100 t6 t7
23New Notion of Match
Let q 100, then S ? 2q 200
1
2
3
4
5
6
7
8
9
50
50
100
50
50
50
50
100
50
S
S
S
S
24New Notion of Match
Let q 100, then S ? 2q 200
1
2
3
4
5
6
7
8
9
50
50
100
50
50
50
50
100
50
S
S
S
S
S
Although, t2 t3 t4 200 2q
25New Notion of Match
Let q 100, then S ? 2q 200
1
2
3
4
5
6
7
8
9
50
50
100
50
50
50
50
100
50
S
S
S
S
S
S
26New Notion of Match
Let r QSS and Let q 50
1
2
3
4
5
6
7
8
9
50
50
100
50
50
50
50
100
50
Q
S
S
r
r matches t2..5
27New Notion of Match
Let r QSS and Let q 50
1
2
3
4
5
6
7
8
9
Q
S
50
50
100
50
50
50
50
100
50
S
Q
S
S
r
r
r matches t5..8
28New Notion of Match
Let r QSS and Let q 50
1
2
3
4
5
6
7
8
9
Q
S
50
50
100
50
50
50
50
100
50
S
Q
S
S
r
r
r covers t2..8
29Our Problem
- Input
- A musical Sequence t
- A rhythm r
- Output
- The longest substring ti..i that is covered by
r
30Restriction
- 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
r
50
50
100
50
50
50
50
50
100
Q
S
S
SOLID S
31Restriction
- 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
r
50
50
100
50
50
50
50
50
100
Q
S
S
r
At least one S must be Solid
32Restriction
- 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
r
50
50
100
50
50
50
50
50
100
Q
S
SOLID S
S
At least one S must be Solid
r
33Motivation
- Our aim is to classify music according to dancing
rhythm - Music seq can be considered as a series of events
corresponding to music signals - Drum beats
- Guiter picks
- Horn hits
34Motivation
- The intervals between these events characterize
how the song is danced - Basically two dancing rhythms Quick Slow
- Example
- cha-cha ? SSQQSSSQQS
- foxtrot ? SSQQSSQQ
- jive ? SSQQSQQS
35Motivation
- So solution to our problem can classify songs
according to dancing rhythms!
36Algorithm
- 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.
37Algorithm Stage 1
- We construct two arrays
- first1..? first? i iff the first
occurrence of symbol ? appears at position i. - next1..n nexti j iff the next occurrence
of symbol at ti appears at tj.
38Algorithm Stage 1
1
2
3
4
5
6
7
8
9
50
50
100
50
50
50
50
100
50
? 50, 100, assume indexed alphabet
39Algorithm Stage 1
1
2
3
4
5
6
7
8
9
50
50
100
50
50
50
50
100
50
? 50, 100, assume indexed alphabet
First occurrence of 50
first1 1
40Algorithm Stage 1
1
2
3
4
5
6
7
8
9
50
50
100
50
50
50
50
100
50
? 50, 100, assume indexed alphabet
first1 1
first2 3
First occurrence of 100
41Algorithm Stage 1
1
2
3
4
5
6
7
8
9
50
50
100
50
50
50
50
100
50
next1 2
Next occurrence of t1 50
42Algorithm Stage 1
1
2
3
4
5
6
7
8
9
50
50
100
50
50
50
50
100
50
next1 2
next2 4
Next occurrence of t2 50
43Algorithm Stage 1
1
2
3
4
5
6
7
8
9
50
50
100
50
50
50
50
100
50
next1 2
next2 4
next3 8
Next occurrence of t3 100
And so on
44Algorithm Stage 2
1
2
3
4
5
6
7
8
9
10
11
100
50
25
25
100
50
15
30
5
30
50
S
Consider an S at t5.
45Algorithm Stage 2
1
2
3
4
5
6
7
8
9
10
11
100
50
25
25
100
50
15
30
5
30
50
S
Q
46Algorithm Stage 2
1
2
3
4
5
6
7
8
9
10
11
100
50
25
25
100
50
15
30
5
30
50
S
Q
Q
47Algorithm Stage 2
1
2
3
4
5
6
7
8
9
10
11
100
50
25
25
100
50
15
30
5
30
50
S
3050 gt 50
Q
Q
So Stop!
48Algorithm Stage 2
1
2
3
4
5
6
7
8
9
10
11
100
50
25
25
100
50
15
30
5
30
50
S
Q
Q
Q
49Algorithm Stage 2
1
2
3
4
5
6
7
8
9
10
11
100
50
25
25
100
50
15
30
5
30
50
Q
S
Q
Q
Q
So we get a new sequence t? consisting of Q and S
50Algorithm Stage 3
- 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
51Algorithm Stage 3
- Construct t?? as follows
- St? 01, Qt? 1
- Construct Invalid set I where I contains the
position of 1 due to St?.
Q
Q
S
Q
Q
1
1
1
1
0
1
52Algorithm Stage 3
- Construct t?? as follows
- St? 01, Qt? 1
- Construct Invalid set I where I contains the
position of 1 due to St?.
No match can occur at position 4 because it is
not a real position in t?
Q
Q
S
Q
Q
1
2
3
5
4
1
2
3
5
6
4
I 4
1
1
0
1
1
1
53Algorithm Stage 3
- Construct r? as follows
- Sr 10, Qr 0
S
Q
0
1
0
54Algorithm Stage 3
- Construct r? as follows
- Sr 10, Qr 0
S
Q
1
2
3
1
0
0
55Algorithm Stage 3
- Find matches of r in t.
- 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
56Algorithm Stage 3
I 4
1
2
3
5
6
4
1
1
0
1
1
1
1
0
0
Bitwise Or
1
1
0
No Match!!!
57Algorithm Stage 3
I 4
1
2
3
5
6
4
1
1
0
1
1
1
1
0
0
Bitwise Or
1
0
0
No Match!!!
58Algorithm Stage 3
I 4
1
2
3
5
6
4
1
1
0
1
1
1
1
0
0
Bitwise Or
1
1
1
All 1s!!! And 3 ? I. So a MATCH!!!
59Algorithm Stage 3
I 4
1
2
3
5
6
4
1
1
0
1
1
1
1
0
0
Bitwise Or
1
1
1
All 1s!!! But, 4 ? I. So NO MATCH!!!
60Algortihm
- In this way we can find the matches then we
can easily compute the cover
61Conclusion
- 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