-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathPFMath.py
More file actions
100 lines (70 loc) · 2.12 KB
/
PFMath.py
File metadata and controls
100 lines (70 loc) · 2.12 KB
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
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
"""
Created on Tue Jun 6 10:02:25 2017
@author: Phtc-LD
"""
import numpy as np
def NormalisationMfcc(m):
min = np.min(m)
max = np.max(m)
for i in range(0,len(m)):
for j in range(0,len(m[0])):
m[i][j] = (m[i][j] - min)/(max - min)
return m
def minWithFiltre(maIntra,counter,seuil,cluster):
minIndex = -1
minIndex2 = -1
listIndex = []
for i in range(0,len(maIntra)):
if(counter[i]>8):
listIndex.append([i,maIntra[i][0]])
listIndex = sorted(listIndex, key=lambda tup: tup[1])
minIndex = listIndex[0][0]
sum = 0
for i in range(0,7):
if(cluster[i]==minIndex):
sum = sum + 1
if(sum>2):
minIndex = listIndex[1][0]
print("listIndex {}".format(listIndex))
return minIndex
def ModifWrongValues(a):
for i in range(0,len(a)):
if(np.sum(a[i]) > 10):
for j in range(0,len(a[i])):
a[i][j] = 0
return a
def seuilPitch(a,seuil):
for i in range(0,len(a)):
for j in range(0,len(a[i])):
if(a[i][j]<seuil):
a[i][j] = 0
else:
a[i][j] = 1
return a
def TailleBoucle(cluster):
taille = 0
for i in range(0,len(cluster) - 2):
if(cluster[i] != cluster[i+1] and cluster[i+1] != cluster[i+2]):
taille = taille + 1
if taille/len(cluster) > 0.25:
taille=16
else:
taille=8
print("taille boucle : {}".format(taille))
return taille
def DEucl(a1,a2):
return np.linalg.norm(a1-a2)
def kl(p, q):
meanP = np.mean(p)
meanQ = np.mean(q)
varP = np.var(p)
varQ = np.var(q)
return varP/varQ + varQ/varP + (meanP - meanQ)*(1/varP + 1/varQ)
def MatrixSimi(ma):
maSimilarity = np.zeros([len(ma),len(ma)])
for i in range(0,len(ma)):
for j in range(0,len(ma)):
maSimilarity[i][j] = kl(ma[i],ma[j])
return maSimilarity