-
Notifications
You must be signed in to change notification settings - Fork 1
/
figure2.py
149 lines (132 loc) · 4.31 KB
/
figure2.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
startindex=0
endindex=10
# read files to a nice format
f={}
f[0] = open("ref/chopin-mono.txt",'r')
f[1] = open("2014ON/mazurka24-4-polyoutput.txt",'r')
f[2] = open("2016MP/chopinOp24No4.txt",'r')
f[3] = open("OL1/mazurkaoutput.txt",'r')
f[4] = open("OL2/mazurkaoutput.txt",'r')
f[5] = open("MeredithTLF1MIREX2016/mazurka24-4mono.tlf1",'r')
f[6] = open("MeredithTLPMIREX2016/mazurka24-4.tlf1",'r')
f[7] = open("MeredithTLRMIREX2016/mazurka24-4.tlf1",'r')
f[8] = open("VM/VM1/output/mazurka24-4.txt",'r')
f[9] = open("VM/VM2/output/mazurka24-4input.txt",'r')
f[10] = open("SIARCT-CFP/examples/exampleData/patterns_mazurka24-4.txt")
# f[10] = open("2016IR/chopin-mono.txt",'r')
d={}
for i in range(startindex,endindex):
d[i]=f[i].readlines()
def outputtimes(text):
pitches=[]
pairs=[]
occurtimes=[]
pattimes=[]
times=[]
total=[]
for line in text:
if "," in line:
pairs.append([float(i) for i in line.split(',')])
total.append([float(i) for i in line.split(',')])
if "o" in line:
total.append('o')
if pairs != []:
times=zip(*pairs)[0]
occurtimes.append(times)
pairs=[]
if "p" in line:
total.append('p')
pattimes.append(occurtimes)
# print(len(occurtimes))
occurtimes=[]
# print(total)
olist=[]
plist=[]
for index in range(0,len(total)):
item = total[index]
if item == 'p':
plist.append(index)
if item =='o':
olist.append(index)
occurtimes=[]
pattimes=[]
record=0
for pindex in range(1,len(plist)):
for oindex in range(0,len(olist)-1):
if plist[pindex]-olist[oindex+1]>1 and oindex>=record:
occurtimes.append(zip(*total[olist[oindex]+1:olist[oindex+1]])[0])
if plist[pindex]-olist[oindex+1]==-1:
occurtimes.append(zip(*total[olist[oindex]+1:olist[oindex+1]-1])[0])
record=oindex+1
# print(record)
sub=[]
pattimes.append(occurtimes)
occurtimes=[]
# print(olist)
# print(plist)
pindex=plist[-1]
occurtimes=[]
for oindex in range(0,len(olist)-1):
if olist[oindex]>pindex:
occurtimes.append(zip(*total[olist[oindex]+1:olist[-1]])[0])
oindex=olist[-1]
occurtimes.append(zip(*total[oindex+1:])[0])
pattimes.append(occurtimes)
# print(pattimes[1])
# taking the onset and offset
startend=[]
startendpat=[]
for occtime in pattimes:
for time in occtime:
start=time[0]
end=time[-1]
startend.append([start,end])
startendpat.append(startend)
startend=[]
# print(startendpat[-1])
return startendpat
startendpat={}
flattened_list={}
startflat={}
endflat={}
totallist=[]
totalstartlist=[]
totalendlist=[]
overlaptotal={}
coverinterval={}
for i in range(startindex,endindex):
startendpat[i]=outputtimes(d[i])
flattened_list[i]=[y for x in startendpat[i] for y in x]
startflat[i]=zip(*flattened_list[i])[0]
endflat[i]=zip(*flattened_list[i])[1]
totallist=totallist+flattened_list[i]
totalstartlist=totalstartlist+list(startflat[i])
totalendlist=totalendlist+list(endflat[i])
totaltime = max(totalendlist) - min(totalendlist)
print(startendpat[0])
import numpy
dist=numpy.zeros(int(max(totalendlist)))
for time in [x * 1 for x in range(0, int(max(totalendlist)))]:
for i in range(startindex,endindex):
for j in range(0,len(startflat[i])):
if time >= startflat[i][j] and time <= endflat[i][j]:
dist[time] = dist[time] + 1
import matplotlib.pyplot as plt
import numpy
import scipy.stats as ss
plt.figure()
plt.plot(dist)
height=50
for patterns in startendpat[0]:
# c=numpy.random.rand(3,1)
height = height + 10
for occur in patterns:
print(occur)
plt.plot((occur[0], occur[1]), (height, height), color = 'red', lw=2, alpha=0.5)
plt.plot((0,0), (0,0), color='white', label="GT")
plt.ylabel('Pattern Number & Ground Truth Patterns')
plt.xlabel('Time')
plt.title('The polling curve')
plt.tight_layout()
plt.show()
# plt.savefig('Supprt.png')