diff scripts/map_and_average.py @ 62:4425a4918102 branch-tests

fixed indices for feature components
author Maria Panteli <m.x.panteli@gmail.com>
date Thu, 21 Sep 2017 17:35:07 +0100
parents d118b6ca8370
children
line wrap: on
line diff
--- a/scripts/map_and_average.py	Thu Sep 21 15:25:20 2017 +0100
+++ b/scripts/map_and_average.py	Thu Sep 21 17:35:07 2017 +0100
@@ -73,6 +73,22 @@
     return trainset, valset, testset
 
 
+def limit_to_n_seconds(dataset, n_sec=30.0, win_sec=8.0):
+    X, Y, Yaudio = dataset
+    uniq_audio, uniq_counts = np.unique(Yaudio, return_counts=True)
+    frame_sr = 2.0
+    max_n_frames = np.int(np.floor((n_sec - win_sec) * frame_sr))
+    X_new, Y_new, Yaudio_new = [], [], []
+    for audio in uniq_audio:
+        idx = np.where(Yaudio==audio)[0]
+        if len(idx) > max_n_frames:
+            idx = idx[:max_n_frames]
+        X_new.append(X[idx, :])
+        Y_new.append(Y[idx])
+        Yaudio_new.append(Yaudio[idx])
+    return [np.concatenate(X_new), np.concatenate(Y_new), np.concatenate(Yaudio_new)]
+
+
 def get_feat_inds(n_dim=840):
     '''assume frame with 840 features and return indices for each feature
     '''