Goal: Test the influence of the graph Laplacian type.
Conclusion: The normalized Laplacian provides better accuracy (~3%).
Observations:
Pname = 'laplacian'
Pvalues = ['normalized', 'unnormalized', 'normalized', 'unnormalized']
# Regenerate the graph or the features at each iteration.
regen_graph = True
regen_features = True
regen_baseline = False
p = {}
# Preprocessing.
# Graph.
p['data_scaling_graph'] = 'features'
p['K'] = 10 + 1 # 5 to 10 + 1 for self-reference
p['dm'] = 'euclidean'
p['Csigma'] = 1
p['diag'] = True
p['laplacian'] = 'normalized'
# Feature extraction.
p['m'] = 128 # 64, 128, 512
p['ls'] = 1
p['ld'] = 10
p['le'] = None
p['lg'] = 100
# Classification.
p['scale'] = None
p['Nvectors'] = 6
p['svm_type'] = 'C'
p['kernel'] = 'linear'
p['C'] = 1
p['nu'] = 0.5
p['majority_voting'] = False
# HDF5 data stores.
p['folder'] = 'data'
p['filename_gtzan'] = 'gtzan.hdf5'
p['filename_audio'] = 'audio.hdf5'
p['filename_graph'] = 'graph.hdf5'
p['filename_features'] = 'features.hdf5'
# Dataset (10,100,644 | 5,100,149 | 2,10,644).
p['Ngenres'] = 5
p['Nclips'] = 100
p['Nframes'] = 149
# Added white noise.
p['noise_std'] = 0
# Graph.
p['tol'] = 1e-5
# Feature extraction.
p['rtol'] = 1e-5 # 1e-3, 1e-5, 1e-7
p['N_inner'] = 500
p['N_outer'] = 50
# Classification.
p['test_size'] = 0.1
p['Ncv'] = 20
p['dataset_classification'] = 'Z'
import numpy as np
import time
texperiment = time.time()
# Result dictionary.
res = ['accuracy', 'accuracy_std']
res += ['sparsity', 'atoms_D']
res += ['objective_g', 'objective_h', 'objective_i', 'objective_j']
res += ['time_features', 'iterations_inner', 'iterations_outer']
res = dict.fromkeys(res)
for key in res.keys():
res[key] = []
def separator(name, parameter=False):
if parameter:
name += ', {} = {}'.format(Pname, p[Pname])
dashes = 20 * '-'
print('\n {} {} {} \n'.format(dashes, name, dashes))
# Fair comparison when tuning parameters.
# Randomnesses: dictionary initialization, training and testing sets.
np.random.seed(1)
#%run gtzan.ipynb
#%run audio_preprocessing.ipynb
if not regen_graph:
separator('Graph')
%run audio_graph.ipynb
if not regen_features:
separator('Features')
%run audio_features.ipynb
# Hyper-parameter under test.
for p[Pname] in Pvalues:
if regen_graph:
separator('Graph', True)
%run audio_graph.ipynb
if regen_features:
separator('Features', True)
p['filename_features'] = 'features_{}_{}.hdf5'.format(Pname, p[Pname])
%run audio_features.ipynb
separator('Classification', True)
%run audio_classification.ipynb
# Collect results.
for key in res:
res[key].append(globals()[key])
# Baseline, i.e. classification with spectrograms.
p['dataset_classification'] = 'X'
p['scale'] = 'minmax' # Todo: should be done in pre-processing.
if regen_baseline:
res['baseline'] = []
res['baseline_std'] = []
for p[Pname] in Pvalues:
separator('Baseline', True)
%run audio_classification.ipynb
res['baseline'].append(accuracy)
res['baseline_std'].append(accuracy_std)
else:
separator('Baseline')
%run audio_classification.ipynb
res['baseline'] = len(Pvalues) * [accuracy]
res['baseline_std'] = accuracy_std
-------------------- Graph, laplacian = normalized -------------------- Data: (149000, 96), float32 Elapsed time: 216.73 seconds All self-referenced in the first column: True dist in [0.0, 1.72983384132] w in [0.00189454166684, 1.0] Ones on the diagonal: 149000 (over 149000) assert: True W in [0.0, 1.0] Datasets: L_data : (2359600,), float32 L_indices : (2359600,), int32 L_indptr : (149001,) , int32 L_shape : (2,) , int64 W_data : (2359600,), float32 W_indices : (2359600,), int32 W_indptr : (149001,) , int32 W_shape : (2,) , int64 Attributes: K = 11 dm = euclidean Csigma = 1 diag = True laplacian = normalized Overall time: 225.98 seconds -------------------- Features, laplacian = normalized -------------------- Attributes: sr = 22050 labels = ['blues' 'classical' 'country' 'disco' 'hiphop' 'jazz' 'metal' 'pop' 'reggae' 'rock'] Datasets: Xa: (10, 100, 644, 2, 1024) , float32 Xs: (10, 100, 644, 2, 96) , float32 Full dataset: size: N=1,288,000 x n=96 -> 123,648,000 floats dim: 123,648 features per clip shape: (10, 100, 644, 2, 96) <class 'h5py._hl.dataset.Dataset'> Reduced dataset: size: N=149,000 x n=96 -> 14,304,000 floats dim: 28,608 features per clip shape: (5, 100, 149, 2, 96) <type 'numpy.ndarray'> Data: (149000, 96), float32 Attributes: K = 11 dm = euclidean Csigma = 1 diag = True laplacian = normalized Datasets: L_data : (2359600,), float32 L_indices : (2359600,), int32 L_indptr : (149001,) , int32 L_shape : (2,) , int64 W_data : (2359600,), float32 W_indices : (2359600,), int32 W_indptr : (149001,) , int32 W_shape : (2,) , int64 Size X: 13.6 M --> 54.6 MiB Size Z: 18.2 M --> 72.8 MiB Size D: 12.0 k --> 48.0 kiB Size E: 12.0 k --> 48.0 kiB Elapsed time: 2734 seconds
Inner loop: 1302 iterations g(Z) = ||X-DZ||_2^2 = 7.104504e+04 rdiff: 0.000143436189521 i(Z) = ||Z||_1 = 5.698367e+04 j(Z) = tr(Z^TLZ) = 8.738621e+03
Global objective: 1.367673e+05
Outer loop: 8 iterations Z in [-0.172690629959, 1.08530604839] Sparsity of Z: 3,702,669 non-zero entries out of 19,072,000 entries, i.e. 19.4%.
D in [-0.027598535642, 0.895244240761] d in [0.999999582767, 1.00000035763] Constraints on D: True
Datasets: D : (128, 96) , float32 X : (5, 100, 149, 2, 96) , float32 Z : (5, 100, 149, 2, 128) , float32 Attributes: sr = 22050 labels = ['blues' 'classical' 'country' 'disco' 'hiphop' 'jazz' 'metal' 'pop' 'reggae' 'rock'] Overall time: 2741 seconds -------------------- Classification, laplacian = normalized -------------------- Software versions: numpy: 1.8.2 sklearn: 0.14.1 Attributes: sr = 22050 labels = ['blues' 'classical' 'country' 'disco' 'hiphop' 'jazz' 'metal' 'pop' 'reggae' 'rock'] Datasets: D : (128, 96) , float32 X : (5, 100, 149, 2, 96) , float32 Z : (5, 100, 149, 2, 128) , float32 Full dataset: size: N=149,000 x n=128 -> 19,072,000 floats dim: 38,144 features per clip shape: (5, 100, 149, 2, 128) <class 'h5py._hl.dataset.Dataset'> Reduced dataset: size: N=149,000 x n=128 -> 19,072,000 floats dim: 38,144 features per clip shape: (5, 100, 149, 2, 128) <type 'numpy.ndarray'> Flattened frames: size: N=149,000 x n=128 -> 19,072,000 floats dim: 38,144 features per clip shape: (5, 100, 298, 128) Truncated and grouped: size: N=135,000 x n=128 -> 17,280,000 floats dim: 34,560 features per clip shape: (5, 100, 6, 45, 128) Truncated and grouped: size: N=135,000 x n=128 -> 17,280,000 floats dim: 34,560 features per clip shape: (5, 100, 6, 45, 128) Feature vectors: size: N=6,000 x n=128 -> 768,000 floats dim: 1,536 features per clip shape: (5, 100, 6, 2, 128)
5 genres: blues, classical, country, disco, hiphop Training data: (3600, 128), float64 Testing data: (2400, 128), float64 Training labels: (3600,), uint8 Testing labels: (2400,), uint8 Accuracy: 76.7 % 5 genres: blues, classical, country, disco, hiphop Training data: (300, 1536), float64 Testing data: (200, 1536), float64 Training labels: (300,), uint8 Testing labels: (200,), uint8 Feature vectors accuracy: 63.5 % Clips accuracy: 68.5 % 5 genres: blues, classical, country, disco, hiphop Data: (6000, 128), float64 Labels: (6000,), uint8 Ratio: 5400.0 training, 600.0 testing 77 (+/- 1.8) <- [78 76 76 77 72 77 74 79 78 77] 78 (+/- 1.8) <- [77 78 78 75 81 77 80 76 78 80] 78 (+/- 1.4) <- [78 77 80 76 79 80 77 78 79 76] 78 (+/- 1.9) <- [77 73 78 79 78 79 79 76 80 78] 79 (+/- 0.7) <- [78 78 78 78 78 79 78 78 80 77] 79 (+/- 1.6) <- [80 79 78 80 81 81 77 80 77 78] 78 (+/- 1.4) <- [80 78 79 78 78 75 80 77 76 78] 78 (+/- 1.7) <- [74 78 81 77 77 79 79 76 76 77] 79 (+/- 1.0) <- [78 80 80 79 78 77 78 78 79 77] 79 (+/- 1.2) <- [78 79 77 78 79 77 78 78 79 81] 79 (+/- 2.2) <- [80 81 77 76 81 79 81 75 79 78] 78 (+/- 1.2) <- [80 78 79 79 76 77 77 77 79 77] 78 (+/- 1.9) <- [79 77 77 76 76 79 80 74 79 75] 78 (+/- 2.3) <- [78 77 83 74 75 77 77 76 78 79] 79 (+/- 1.4) <- [78 77 79 78 79 81 81 79 79 77] 79 (+/- 1.8) <- [80 78 78 80 76 76 77 78 81 78] 78 (+/- 1.3) <- [78 79 79 77 80 76 76 78 79 77] 78 (+/- 1.1) <- [78 79 78 78 76 79 77 77 80 78] 78 (+/- 0.9) <- [75 77 77 78 78 78 78 78 76 77] 78 (+/- 1.4) <- [77 80 78 74 76 78 78 77 77 77] Accuracy: 78.3 (+/- 1.67) Mean time (20 cv): 20.35 seconds Overall time: 410.97 seconds -------------------- Graph, laplacian = unnormalized -------------------- Data: (149000, 96), float32 Elapsed time: 166.93 seconds All self-referenced in the first column: True dist in [0.0, 1.47301745415] w in [0.00517621124163, 1.0] Ones on the diagonal: 149000 (over 149000) assert: True W in [0.0, 1.0] Datasets: L_data : (2394468,), float32 L_indices : (2394468,), int32 L_indptr : (149001,) , int32 L_shape : (2,) , int64 W_data : (2394468,), float32 W_indices : (2394468,), int32 W_indptr : (149001,) , int32 W_shape : (2,) , int64 Attributes: K = 11 dm = euclidean Csigma = 1 diag = True laplacian = unnormalized Overall time: 176.87 seconds -------------------- Features, laplacian = unnormalized -------------------- Attributes: sr = 22050 labels = ['blues' 'classical' 'country' 'disco' 'hiphop' 'jazz' 'metal' 'pop' 'reggae' 'rock'] Datasets: Xa: (10, 100, 644, 2, 1024) , float32 Xs: (10, 100, 644, 2, 96) , float32 Full dataset: size: N=1,288,000 x n=96 -> 123,648,000 floats dim: 123,648 features per clip shape: (10, 100, 644, 2, 96) <class 'h5py._hl.dataset.Dataset'> Reduced dataset: size: N=149,000 x n=96 -> 14,304,000 floats dim: 28,608 features per clip shape: (5, 100, 149, 2, 96) <type 'numpy.ndarray'> Data: (149000, 96), float32 Attributes: K = 11 dm = euclidean Csigma = 1 diag = True laplacian = unnormalized Datasets: L_data : (2394468,), float32 L_indices : (2394468,), int32 L_indptr : (149001,) , int32 L_shape : (2,) , int64 W_data : (2394468,), float32 W_indices : (2394468,), int32 W_indptr : (149001,) , int32 W_shape : (2,) , int64 Size X: 13.6 M --> 54.6 MiB Size Z: 18.2 M --> 72.8 MiB Size D: 12.0 k --> 48.0 kiB Size E: 12.0 k --> 48.0 kiB Elapsed time: 3144 seconds
Inner loop: 1441 iterations g(Z) = ||X-DZ||_2^2 = 9.315121e+04 rdiff: 0.000746224531602 i(Z) = ||Z||_1 = 5.053609e+04 j(Z) = tr(Z^TLZ) = 8.245592e+03
Global objective: 1.519329e+05
Outer loop: 4 iterations Z in [-0.1504381001, 0.431620627642] Sparsity of Z: 6,688,349 non-zero entries out of 19,072,000 entries, i.e. 35.1%.
D in [-0.068669103086, 0.870086312294] d in [0.999999642372, 1.00000035763] Constraints on D: True
Datasets: D : (128, 96) , float32 X : (5, 100, 149, 2, 96) , float32 Z : (5, 100, 149, 2, 128) , float32 Attributes: sr = 22050 labels = ['blues' 'classical' 'country' 'disco' 'hiphop' 'jazz' 'metal' 'pop' 'reggae' 'rock'] Overall time: 3153 seconds -------------------- Classification, laplacian = unnormalized -------------------- Software versions: numpy: 1.8.2 sklearn: 0.14.1 Attributes: sr = 22050 labels = ['blues' 'classical' 'country' 'disco' 'hiphop' 'jazz' 'metal' 'pop' 'reggae' 'rock'] Datasets: D : (128, 96) , float32 X : (5, 100, 149, 2, 96) , float32 Z : (5, 100, 149, 2, 128) , float32 Full dataset: size: N=149,000 x n=128 -> 19,072,000 floats dim: 38,144 features per clip shape: (5, 100, 149, 2, 128) <class 'h5py._hl.dataset.Dataset'> Reduced dataset: size: N=149,000 x n=128 -> 19,072,000 floats dim: 38,144 features per clip shape: (5, 100, 149, 2, 128) <type 'numpy.ndarray'> Flattened frames: size: N=149,000 x n=128 -> 19,072,000 floats dim: 38,144 features per clip shape: (5, 100, 298, 128) Truncated and grouped: size: N=135,000 x n=128 -> 17,280,000 floats dim: 34,560 features per clip shape: (5, 100, 6, 45, 128) Truncated and grouped: size: N=135,000 x n=128 -> 17,280,000 floats dim: 34,560 features per clip shape: (5, 100, 6, 45, 128) Feature vectors: size: N=6,000 x n=128 -> 768,000 floats dim: 1,536 features per clip shape: (5, 100, 6, 2, 128)
5 genres: blues, classical, country, disco, hiphop Training data: (3600, 128), float64 Testing data: (2400, 128), float64 Training labels: (3600,), uint8 Testing labels: (2400,), uint8 Accuracy: 72.6 % 5 genres: blues, classical, country, disco, hiphop Training data: (300, 1536), float64 Testing data: (200, 1536), float64 Training labels: (300,), uint8 Testing labels: (200,), uint8 Feature vectors accuracy: 63.0 % Clips accuracy: 71.5 % 5 genres: blues, classical, country, disco, hiphop Data: (6000, 128), float64 Labels: (6000,), uint8 Ratio: 5400.0 training, 600.0 testing 74 (+/- 2.0) <- [73 72 75 76 69 75 75 73 74 74] 74 (+/- 2.3) <- [73 74 73 68 77 75 72 75 73 75] 75 (+/- 1.6) <- [76 75 76 76 74 76 74 71 77 74] 74 (+/- 2.1) <- [75 68 76 74 74 76 75 74 74 73] 74 (+/- 1.3) <- [75 72 72 73 73 74 75 72 75 73] 75 (+/- 1.6) <- [74 73 74 76 75 78 75 77 73 74] 74 (+/- 1.0) <- [73 73 73 74 74 73 72 72 75 75] 74 (+/- 1.7) <- [74 74 73 75 71 78 72 73 73 72] 75 (+/- 1.9) <- [73 77 74 76 74 71 75 74 73 78] 75 (+/- 2.0) <- [77 73 76 73 73 74 75 73 73 79] 75 (+/- 1.6) <- [78 77 76 72 75 74 75 72 75 76] 74 (+/- 1.6) <- [76 73 73 74 70 73 74 74 75 75] 74 (+/- 1.9) <- [77 72 75 74 73 76 74 73 75 70] 74 (+/- 2.1) <- [75 72 76 72 73 72 69 74 73 76] 74 (+/- 1.2) <- [75 72 74 74 72 73 74 71 73 75] 74 (+/- 2.2) <- [78 74 75 75 72 77 73 74 73 70] 75 (+/- 1.3) <- [74 74 74 73 76 73 75 75 77 73] 74 (+/- 1.4) <- [74 73 73 72 72 76 74 73 76 73] 74 (+/- 1.8) <- [74 75 75 72 77 72 76 73 71 73] 74 (+/- 1.0) <- [75 74 73 73 74 74 74 76 73 72] Accuracy: 74.3 (+/- 1.81) Mean time (20 cv): 19.83 seconds Overall time: 401.12 seconds -------------------- Graph, laplacian = normalized -------------------- Data: (149000, 96), float32 Elapsed time: 172.01 seconds All self-referenced in the first column: True dist in [0.0, 1.52197754383] w in [0.00556439952925, 1.0] Ones on the diagonal: 149000 (over 149000) assert: True W in [0.0, 1.0] Datasets: L_data : (2413902,), float32 L_indices : (2413902,), int32 L_indptr : (149001,) , int32 L_shape : (2,) , int64 W_data : (2413902,), float32 W_indices : (2413902,), int32 W_indptr : (149001,) , int32 W_shape : (2,) , int64 Attributes: K = 11 dm = euclidean Csigma = 1 diag = True laplacian = normalized Overall time: 182.17 seconds -------------------- Features, laplacian = normalized -------------------- Attributes: sr = 22050 labels = ['blues' 'classical' 'country' 'disco' 'hiphop' 'jazz' 'metal' 'pop' 'reggae' 'rock'] Datasets: Xa: (10, 100, 644, 2, 1024) , float32 Xs: (10, 100, 644, 2, 96) , float32 Full dataset: size: N=1,288,000 x n=96 -> 123,648,000 floats dim: 123,648 features per clip shape: (10, 100, 644, 2, 96) <class 'h5py._hl.dataset.Dataset'> Reduced dataset: size: N=149,000 x n=96 -> 14,304,000 floats dim: 28,608 features per clip shape: (5, 100, 149, 2, 96) <type 'numpy.ndarray'> Data: (149000, 96), float32 Attributes: K = 11 dm = euclidean Csigma = 1 diag = True laplacian = normalized Datasets: L_data : (2413902,), float32 L_indices : (2413902,), int32 L_indptr : (149001,) , int32 L_shape : (2,) , int64 W_data : (2413902,), float32 W_indices : (2413902,), int32 W_indptr : (149001,) , int32 W_shape : (2,) , int64 Size X: 13.6 M --> 54.6 MiB Size Z: 18.2 M --> 72.8 MiB Size D: 12.0 k --> 48.0 kiB Size E: 12.0 k --> 48.0 kiB Elapsed time: 3170 seconds
Inner loop: 1458 iterations g(Z) = ||X-DZ||_2^2 = 7.079712e+04 rdiff: 0.000297394692829 i(Z) = ||Z||_1 = 5.690532e+04 j(Z) = tr(Z^TLZ) = 7.918162e+03
Global objective: 1.356206e+05
Outer loop: 11 iterations Z in [-0.157225385308, 1.02839124203] Sparsity of Z: 3,731,115 non-zero entries out of 19,072,000 entries, i.e. 19.6%.
D in [-0.0245641116053, 0.89549434185] d in [0.999999642372, 1.00000035763] Constraints on D: True
Datasets: D : (128, 96) , float32 X : (5, 100, 149, 2, 96) , float32 Z : (5, 100, 149, 2, 128) , float32 Attributes: sr = 22050 labels = ['blues' 'classical' 'country' 'disco' 'hiphop' 'jazz' 'metal' 'pop' 'reggae' 'rock'] Overall time: 3180 seconds -------------------- Classification, laplacian = normalized -------------------- Software versions: numpy: 1.8.2 sklearn: 0.14.1 Attributes: sr = 22050 labels = ['blues' 'classical' 'country' 'disco' 'hiphop' 'jazz' 'metal' 'pop' 'reggae' 'rock'] Datasets: D : (128, 96) , float32 X : (5, 100, 149, 2, 96) , float32 Z : (5, 100, 149, 2, 128) , float32 Full dataset: size: N=149,000 x n=128 -> 19,072,000 floats dim: 38,144 features per clip shape: (5, 100, 149, 2, 128) <class 'h5py._hl.dataset.Dataset'> Reduced dataset: size: N=149,000 x n=128 -> 19,072,000 floats dim: 38,144 features per clip shape: (5, 100, 149, 2, 128) <type 'numpy.ndarray'> Flattened frames: size: N=149,000 x n=128 -> 19,072,000 floats dim: 38,144 features per clip shape: (5, 100, 298, 128) Truncated and grouped: size: N=135,000 x n=128 -> 17,280,000 floats dim: 34,560 features per clip shape: (5, 100, 6, 45, 128) Truncated and grouped: size: N=135,000 x n=128 -> 17,280,000 floats dim: 34,560 features per clip shape: (5, 100, 6, 45, 128) Feature vectors: size: N=6,000 x n=128 -> 768,000 floats dim: 1,536 features per clip shape: (5, 100, 6, 2, 128)
5 genres: blues, classical, country, disco, hiphop Training data: (3600, 128), float64 Testing data: (2400, 128), float64 Training labels: (3600,), uint8 Testing labels: (2400,), uint8 Accuracy: 76.4 % 5 genres: blues, classical, country, disco, hiphop Training data: (300, 1536), float64 Testing data: (200, 1536), float64 Training labels: (300,), uint8 Testing labels: (200,), uint8 Feature vectors accuracy: 62.5 % Clips accuracy: 71.5 % 5 genres: blues, classical, country, disco, hiphop Data: (6000, 128), float64 Labels: (6000,), uint8 Ratio: 5400.0 training, 600.0 testing 76 (+/- 2.2) <- [77 75 76 77 70 76 74 77 78 77] 78 (+/- 1.7) <- [77 76 77 73 78 76 80 78 76 79] 78 (+/- 1.2) <- [79 78 78 76 78 79 77 76 78 75] 77 (+/- 2.0) <- [79 71 75 77 78 76 77 76 77 76] 77 (+/- 1.2) <- [77 76 77 77 76 78 79 75 78 75] 78 (+/- 1.4) <- [78 77 76 79 77 80 75 78 76 79] 77 (+/- 1.5) <- [79 76 76 78 77 74 79 75 78 77] 77 (+/- 1.6) <- [76 75 78 77 76 80 75 75 75 77] 78 (+/- 1.2) <- [75 79 78 78 77 76 76 78 79 78] 77 (+/- 2.0) <- [79 75 77 76 77 74 75 76 77 81] 78 (+/- 1.7) <- [79 79 79 75 80 76 78 74 78 79] 77 (+/- 1.4) <- [76 77 79 76 77 75 75 79 78 78] 77 (+/- 1.5) <- [79 76 76 77 76 78 78 75 78 74] 76 (+/- 1.8) <- [78 76 80 73 75 75 75 75 77 77] 78 (+/- 1.7) <- [75 79 79 76 78 80 81 78 76 77] 78 (+/- 2.2) <- [79 76 79 80 75 76 77 75 81 75] 78 (+/- 1.9) <- [76 77 77 78 80 75 77 79 80 74] 78 (+/- 1.4) <- [76 81 78 77 78 77 76 76 77 78] 77 (+/- 0.9) <- [79 76 76 76 78 77 77 77 76 75] 77 (+/- 1.5) <- [77 77 78 72 76 76 76 75 77 75] Accuracy: 77.3 (+/- 1.74) Mean time (20 cv): 21.67 seconds Overall time: 437.96 seconds -------------------- Graph, laplacian = unnormalized -------------------- Data: (149000, 96), float32 Elapsed time: 175.21 seconds All self-referenced in the first column: True dist in [0.0, 1.47113442421] w in [0.00576181244105, 1.0] Ones on the diagonal: 149000 (over 149000) assert: True W in [0.0, 1.0] Datasets: L_data : (2410344,), float32 L_indices : (2410344,), int32 L_indptr : (149001,) , int32 L_shape : (2,) , int64 W_data : (2410344,), float32 W_indices : (2410344,), int32 W_indptr : (149001,) , int32 W_shape : (2,) , int64 Attributes: K = 11 dm = euclidean Csigma = 1 diag = True laplacian = unnormalized Overall time: 184.53 seconds -------------------- Features, laplacian = unnormalized -------------------- Attributes: sr = 22050 labels = ['blues' 'classical' 'country' 'disco' 'hiphop' 'jazz' 'metal' 'pop' 'reggae' 'rock'] Datasets: Xa: (10, 100, 644, 2, 1024) , float32 Xs: (10, 100, 644, 2, 96) , float32 Full dataset: size: N=1,288,000 x n=96 -> 123,648,000 floats dim: 123,648 features per clip shape: (10, 100, 644, 2, 96) <class 'h5py._hl.dataset.Dataset'> Reduced dataset: size: N=149,000 x n=96 -> 14,304,000 floats dim: 28,608 features per clip shape: (5, 100, 149, 2, 96) <type 'numpy.ndarray'> Data: (149000, 96), float32 Attributes: K = 11 dm = euclidean Csigma = 1 diag = True laplacian = unnormalized Datasets: L_data : (2410344,), float32 L_indices : (2410344,), int32 L_indptr : (149001,) , int32 L_shape : (2,) , int64 W_data : (2410344,), float32 W_indices : (2410344,), int32 W_indptr : (149001,) , int32 W_shape : (2,) , int64 Size X: 13.6 M --> 54.6 MiB Size Z: 18.2 M --> 72.8 MiB Size D: 12.0 k --> 48.0 kiB Size E: 12.0 k --> 48.0 kiB Elapsed time: 3641 seconds
Inner loop: 1624 iterations g(Z) = ||X-DZ||_2^2 = 1.020493e+05 rdiff: 0.000117322325577 i(Z) = ||Z||_1 = 4.728914e+04 j(Z) = tr(Z^TLZ) = 6.951408e+03
Global objective: 1.562898e+05
Outer loop: 5 iterations Z in [-0.0730217769742, 0.239454746246] Sparsity of Z: 7,842,042 non-zero entries out of 19,072,000 entries, i.e. 41.1%.
D in [-0.0284309070557, 0.800033926964] d in [0.999999523163, 1.00000035763] Constraints on D: True
Datasets: D : (128, 96) , float32 X : (5, 100, 149, 2, 96) , float32 Z : (5, 100, 149, 2, 128) , float32 Attributes: sr = 22050 labels = ['blues' 'classical' 'country' 'disco' 'hiphop' 'jazz' 'metal' 'pop' 'reggae' 'rock'] Overall time: 3652 seconds -------------------- Classification, laplacian = unnormalized -------------------- Software versions: numpy: 1.8.2 sklearn: 0.14.1 Attributes: sr = 22050 labels = ['blues' 'classical' 'country' 'disco' 'hiphop' 'jazz' 'metal' 'pop' 'reggae' 'rock'] Datasets: D : (128, 96) , float32 X : (5, 100, 149, 2, 96) , float32 Z : (5, 100, 149, 2, 128) , float32 Full dataset: size: N=149,000 x n=128 -> 19,072,000 floats dim: 38,144 features per clip shape: (5, 100, 149, 2, 128) <class 'h5py._hl.dataset.Dataset'> Reduced dataset: size: N=149,000 x n=128 -> 19,072,000 floats dim: 38,144 features per clip shape: (5, 100, 149, 2, 128) <type 'numpy.ndarray'> Flattened frames: size: N=149,000 x n=128 -> 19,072,000 floats dim: 38,144 features per clip shape: (5, 100, 298, 128) Truncated and grouped: size: N=135,000 x n=128 -> 17,280,000 floats dim: 34,560 features per clip shape: (5, 100, 6, 45, 128) Truncated and grouped: size: N=135,000 x n=128 -> 17,280,000 floats dim: 34,560 features per clip shape: (5, 100, 6, 45, 128) Feature vectors: size: N=6,000 x n=128 -> 768,000 floats dim: 1,536 features per clip shape: (5, 100, 6, 2, 128)
5 genres: blues, classical, country, disco, hiphop Training data: (3600, 128), float64 Testing data: (2400, 128), float64 Training labels: (3600,), uint8 Testing labels: (2400,), uint8 Accuracy: 70.5 % 5 genres: blues, classical, country, disco, hiphop Training data: (300, 1536), float64 Testing data: (200, 1536), float64 Training labels: (300,), uint8 Testing labels: (200,), uint8 Feature vectors accuracy: 63.0 % Clips accuracy: 67.0 % 5 genres: blues, classical, country, disco, hiphop Data: (6000, 128), float64 Labels: (6000,), uint8 Ratio: 5400.0 training, 600.0 testing 72 (+/- 1.8) <- [73 70 71 70 68 73 72 70 73 73] 72 (+/- 1.7) <- [71 73 72 68 74 73 70 73 70 71] 72 (+/- 2.2) <- [73 75 73 70 72 75 71 68 73 70] 72 (+/- 2.4) <- [72 65 73 73 72 74 73 71 71 71] 71 (+/- 1.3) <- [73 69 72 71 70 72 70 70 72 69] 74 (+/- 1.1) <- [74 73 74 73 74 75 73 74 72 71] 72 (+/- 1.3) <- [73 72 71 73 73 69 70 71 71 72] 72 (+/- 1.3) <- [70 72 72 71 69 74 70 70 71 72] 72 (+/- 1.3) <- [70 73 71 73 72 70 74 71 73 73] 73 (+/- 1.3) <- [74 71 74 71 74 71 71 73 71 74] 72 (+/- 1.6) <- [73 74 71 69 72 71 73 69 73 70] 71 (+/- 1.1) <- [70 71 71 72 68 70 71 72 72 71] 71 (+/- 1.9) <- [72 72 73 72 70 72 67 69 70 68] 71 (+/- 2.0) <- [72 69 73 69 71 70 67 71 70 73] 72 (+/- 1.2) <- [71 71 69 72 72 71 72 73 70 73] 72 (+/- 2.3) <- [76 72 69 74 69 71 71 70 74 68] 72 (+/- 1.7) <- [71 73 72 71 72 68 71 72 73 69] 73 (+/- 1.5) <- [74 71 71 72 72 72 70 71 75 74] 72 (+/- 1.4) <- [70 73 70 70 74 72 71 72 70 70] 71 (+/- 1.7) <- [70 73 70 71 71 70 72 73 72 67] Accuracy: 71.9 (+/- 1.78) Mean time (20 cv): 21.83 seconds Overall time: 441.54 seconds -------------------- Baseline -------------------- Software versions: numpy: 1.8.2 sklearn: 0.14.1 Attributes: sr = 22050 labels = ['blues' 'classical' 'country' 'disco' 'hiphop' 'jazz' 'metal' 'pop' 'reggae' 'rock'] Datasets: D : (128, 96) , float32 X : (5, 100, 149, 2, 96) , float32 Z : (5, 100, 149, 2, 128) , float32 Full dataset: size: N=149,000 x n=96 -> 14,304,000 floats dim: 28,608 features per clip shape: (5, 100, 149, 2, 96) <class 'h5py._hl.dataset.Dataset'> Reduced dataset: size: N=149,000 x n=96 -> 14,304,000 floats dim: 28,608 features per clip shape: (5, 100, 149, 2, 96) <type 'numpy.ndarray'> Flattened frames: size: N=149,000 x n=96 -> 14,304,000 floats dim: 28,608 features per clip shape: (5, 100, 298, 96) Truncated and grouped: size: N=135,000 x n=96 -> 12,960,000 floats dim: 25,920 features per clip shape: (5, 100, 6, 45, 96) Truncated and grouped: size: N=135,000 x n=96 -> 12,960,000 floats dim: 25,920 features per clip shape: (5, 100, 6, 45, 96) Feature vectors: size: N=6,000 x n=96 -> 576,000 floats dim: 1,152 features per clip shape: (5, 100, 6, 2, 96)
5 genres: blues, classical, country, disco, hiphop Training data: (3600, 96), float64 Testing data: (2400, 96), float64 Training labels: (3600,), uint8 Testing labels: (2400,), uint8 Accuracy: 68.8 % 5 genres: blues, classical, country, disco, hiphop Training data: (300, 1152), float64 Testing data: (200, 1152), float64 Training labels: (300,), uint8 Testing labels: (200,), uint8 Feature vectors accuracy: 62.1 % Clips accuracy: 68.5 % 5 genres: blues, classical, country, disco, hiphop Data: (6000, 96), float64 Labels: (6000,), uint8 Ratio: 5400.0 training, 600.0 testing 69 (+/- 2.2) <- [70 68 71 67 64 67 70 68 72 66] 69 (+/- 1.4) <- [71 68 67 67 72 69 67 70 69 70] 70 (+/- 2.0) <- [71 69 73 68 68 71 71 68 71 66] 69 (+/- 1.4) <- [70 67 66 67 67 70 68 70 70 68] 70 (+/- 2.4) <- [71 69 72 68 70 75 71 68 68 66] 71 (+/- 0.7) <- [71 71 70 70 71 71 70 69 70 70] 70 (+/- 1.4) <- [70 68 72 69 69 67 71 69 70 69] 70 (+/- 1.5) <- [69 70 68 71 65 70 70 69 70 69] 69 (+/- 1.7) <- [68 69 68 69 68 65 70 70 69 72] 69 (+/- 1.8) <- [72 69 66 68 69 66 69 69 70 71] 70 (+/- 1.4) <- [71 70 69 69 69 69 73 70 71 68] 70 (+/- 1.6) <- [71 70 71 68 69 69 73 68 69 71] 69 (+/- 1.3) <- [69 70 66 68 69 70 68 71 68 68] 69 (+/- 2.0) <- [71 66 68 66 67 69 66 69 69 72] 70 (+/- 1.1) <- [69 70 72 68 69 70 69 71 71 69] 70 (+/- 2.0) <- [72 71 69 71 67 68 71 72 69 67] 70 (+/- 1.6) <- [67 71 69 69 68 70 71 71 72 69] 70 (+/- 0.9) <- [70 68 71 70 68 70 69 69 71 69] 70 (+/- 1.2) <- [72 71 69 69 71 69 72 70 68 69] 69 (+/- 1.7) <- [67 70 71 67 67 72 67 70 70 69] Accuracy: 69.7 (+/- 1.71) Mean time (20 cv): 17.10 seconds Overall time: 346.41 seconds
print('{} = {}'.format(Pname, Pvalues))
for key, value in res.items():
if key is not 'atoms_D':
print('res[\'{}\'] = {}'.format(key, value))
def plot(*args, **kwargs):
plt.figure(figsize=(8,5))
x = range(len(Pvalues))
log = 'log' in kwargs and kwargs['log'] is True
pltfunc = plt.semilogy if log else plt.plot
params = {}
params['linestyle'] = '-'
params['marker'] = '.'
params['markersize'] = 10
for i, var in enumerate(args):
if 'err' in kwargs:
pltfunc = plt.errorbar
params['yerr'] = res[kwargs['err'][i]]
params['capsize'] = 5
pltfunc(x, res[var], label=var, **params)
for i,j in zip(x, res[var]):
plt.annotate('{:.2f}'.format(j), xy=(i,j), xytext=(5,5), textcoords='offset points')
margin = 0.25
params['markersize'] = 10
plt.xlim(-margin, len(Pvalues)-1+margin)
if 'ylim' in kwargs:
plt.ylim(kwargs['ylim'])
plt.title('{} vs {}'.format(', '.join(args), Pname))
plt.xlabel(Pname)
plt.ylabel(' ,'.join(args))
plt.xticks(x, Pvalues)
plt.grid(True); plt.legend(loc='best'); plt.show()
def div(l):
div = Pvalues if Pname is l else [p[l]]
return np.array([1 if v is None else v for v in div])
# Classification results.
res['chance'] = len(Pvalues) * [100./p['Ngenres']]
res['chance_std'] = 0
err=['accuracy_std', 'baseline_std', 'chance_std']
plot('accuracy', 'baseline', 'chance', err=err, ylim=[0,100])
# Features extraction results.
if regen_features:
plot('objective_g', 'objective_h', 'objective_i', 'objective_j', log=True)
# Unweighted objectives.
print('g(Z) = ||X-DZ||_2^2, h(Z) = ||Z-EX||_2^2, i(Z) = ||Z||_1, j(Z) = tr(Z^TLZ)')
res['objective_g_un'] = res['objective_g'] / div('ld')
res['objective_h_un'] = res['objective_h'] / div('le')
res['objective_i_un'] = res['objective_i'] / div('ls')
res['objective_j_un'] = res['objective_j'] / div('lg')
plot('objective_g_un', 'objective_h_un', 'objective_i_un', 'objective_j_un', log=True)
plot('sparsity', ylim=[0,100])
plot('time_features')
plot('iterations_inner')
plot('iterations_outer')
for i, fig in enumerate(res['atoms_D']):
print('Dictionary atoms for {} = {}'.format(Pname, Pvalues[i]))
fig.show()
print('Experiment time: {:.0f} seconds'.format(time.time() - texperiment))
laplacian = ['normalized', 'unnormalized', 'normalized', 'unnormalized'] res['accuracy_std'] = [1.6699758813960304, 1.8111826630378531, 1.7384282092996781, 1.775878303826024] res['objective_j'] = [8738.6207580566406, 8245.5917358398438, 7918.1617736816406, 6951.4076232910156] res['objective_i'] = [56983.671875, 50536.09375, 56905.32421875, 47289.140625] res['objective_h'] = [0, 0, 0, 0] res['objective_g'] = [71045.0390625, 93151.2109375, 70797.119140625, 102049.2578125] res['baseline'] = [69.729166666666742, 69.729166666666742, 69.729166666666742, 69.729166666666742] res['time_features'] = [2733.9047298431396, 3144.330353975296, 3170.067512989044, 3640.6458139419556] res['baseline_std'] = 1.71029866625 res['sparsity'] = [19.414162122483223, 35.06894400167785, 19.563312709731544, 41.118089345637586] res['iterations_inner'] = [1302, 1441, 1458, 1624] res['iterations_outer'] = [8, 4, 11, 5] res['accuracy'] = [78.341666666666683, 74.339166666666699, 77.310833333333335, 71.877500000000055]
/usr/lib/python2.7/dist-packages/numpy/ma/core.py:3847: UserWarning: Warning: converting a masked element to nan. warnings.warn("Warning: converting a masked element to nan.")
g(Z) = ||X-DZ||_2^2, h(Z) = ||Z-EX||_2^2, i(Z) = ||Z||_1, j(Z) = tr(Z^TLZ)
Dictionary atoms for laplacian = normalized Dictionary atoms for laplacian = unnormalized Dictionary atoms for laplacian = normalized Dictionary atoms for laplacian = unnormalized Experiment time: 15549 seconds
/usr/lib/pymodules/python2.7/matplotlib/figure.py:371: UserWarning: matplotlib is currently using a non-GUI backend, so cannot show the figure "matplotlib is currently using a non-GUI backend, "