-
Notifications
You must be signed in to change notification settings - Fork 0
/
normalize_data.py
55 lines (31 loc) · 1.13 KB
/
normalize_data.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
'''
Not yet Fully implemented.
Standardizes the data, to mean 0 and unit variance distribution.
'''
from import_words import *
import math
def normalizeSoundData(soundDataHere): # takes numpy array and normalizes it
# print("normalizing the sound data, for {} files".format(len(soundDataHere)))
for i in range(len(soundDataHere)):
# print("normalizing the sound data, for {}st chunk".format(i))
mean = np.mean(soundDataHere[i])
std = np.std(soundDataHere[i])
soundDataHere[i] = (soundDataHere[i] - mean) / std
# print("done")
return soundDataHere
def assertZeroMean(soundDataHere):
for sound in soundDataHere:
# print(np.mean(sound))
if np.mean(sound) > 0.01:
return False
return True
def assertUnitVariance(soundDataHere):
for sound in soundDataHere:
print(np.std(sound))
if math.floor(np.std(sound)) != 1 or math.ceil(np.std(sound)) != 1:
return False
return True
if __name__ == '__main__':
soundData, labels = importAllFromDir('../LL_chunks')
normalizeSoundData(soundData)
plotAll(soundData)