Ejemplo n.º 1
0
    def apply(self, data, meta=None):
        all_ceps = []
        for ch in data:
            ceps, mspec, spec = mfcc(ch)
            all_ceps.append(ceps.ravel())

        return to_np_array(all_ceps)
Ejemplo n.º 2
0
    def apply(self, data, meta=None):
        all_ceps = []
        for ch in data:
            ceps, mspec, spec = mfcc(ch)
            all_ceps.append(ceps.ravel())

        return to_np_array(all_ceps)
Ejemplo n.º 3
0
    def apply_one(self, fft_mag, meta):
        num_time_samples = (fft_mag.shape[-1] -
                            1) * 2  # revert FFT shape change

        X = fft_mag**2
        for ch in X:
            ch /= np.sum(ch + 1e-12)

        psd = X  # pdf

        out = []

        #[0,1,2] -> [[0,1], [1,2]]
        for start_freq, end_freq in zip(self.freq_ranges[:-1],
                                        self.freq_ranges[1:]):
            start_index = np.floor(
                (start_freq / meta.sampling_frequency) * num_time_samples)
            end_index = np.floor(
                (end_freq / meta.sampling_frequency) * num_time_samples)
            selected = psd[:, start_index:end_index]

            entropies = -np.sum(selected * np.log2(selected + 1e-12),
                                axis=selected.ndim - 1) / np.log2(end_index -
                                                                  start_index)
            if self.flatten:
                out.append(entropies.ravel())
            else:
                out.append(entropies)

        if self.flatten:
            return np.concatenate(out)
        else:
            return to_np_array(out)
Ejemplo n.º 4
0
def upper_right_triangle(matrix):
    accum = []
    for i in range(matrix.shape[0]):
        for j in range(i + 1, matrix.shape[1]):
            accum.append(matrix[i, j])

    return to_np_array(accum)
Ejemplo n.º 5
0
def upper_right_triangle(matrix):
    accum = []
    for i in range(matrix.shape[0]):
        for j in range(i+1, matrix.shape[1]):
            accum.append(matrix[i, j])

    return to_np_array(accum)
Ejemplo n.º 6
0
    def apply_one(self, fft_mag, meta):
        num_time_samples = (fft_mag.shape[-1] - 1) * 2 # revert FFT shape change

        X = fft_mag ** 2
        for ch in X:
            ch /= np.sum(ch + 1e-12)

        psd = X # pdf

        out = []

        #[0,1,2] -> [[0,1], [1,2]]
        for start_freq, end_freq in zip(self.freq_ranges[:-1], self.freq_ranges[1:]):
            start_index = np.floor((start_freq / meta.sampling_frequency) * num_time_samples)
            end_index = np.floor((end_freq / meta.sampling_frequency) * num_time_samples)
            selected = psd[:, start_index:end_index]

            entropies = - np.sum(selected * np.log2(selected + 1e-12), axis=selected.ndim-1) / np.log2(end_index - start_index)
            if self.flatten:
                out.append(entropies.ravel())
            else:
                out.append(entropies)

        if self.flatten:
            return np.concatenate(out)
        else:
            return to_np_array(out)
Ejemplo n.º 7
0
    def apply(self, datas, meta):
        if datas.ndim >= 3:
            out = []
            for d in datas:
                out.append(self.apply_one(d, meta))

            return to_np_array(out)
        else:
            return self.apply_one(datas, meta)
Ejemplo n.º 8
0
    def apply(self, datas, meta):
        if datas.ndim >= 3:
            out = []
            for d in datas:
                out.append(self.apply_one(d, meta))

            return to_np_array(out)
        else:
            return self.apply_one(datas, meta)
Ejemplo n.º 9
0
    def apply(self, X, meta=None):
        if self.window_secs is None:
            return X.reshape([1] + list(X.shape))

        num_windows = meta.data_length_sec / self.window_secs
        samples_per_window = self.window_secs * int(meta.sampling_frequency)
        samples_used = num_windows * samples_per_window
        samples_dropped = X.shape[-1] - samples_used
        X = Slice(samples_dropped).apply(X)
        out = np.split(X, num_windows, axis=X.ndim - 1)
        out = to_np_array(out)
        return out
Ejemplo n.º 10
0
    def apply(self, X, meta=None):
        if self.window_secs is None:
            return X.reshape([1] + list(X.shape))

        num_windows = meta.data_length_sec / self.window_secs
        samples_per_window = self.window_secs * int(meta.sampling_frequency)
        samples_used = num_windows * samples_per_window
        samples_dropped = X.shape[-1] - samples_used
        X = Slice(samples_dropped).apply(X)
        out = np.split(X, num_windows, axis=X.ndim-1)
        out = to_np_array(out)
        return out
Ejemplo n.º 11
0
 def apply(self, X, meta):
     if meta.data_type == 'preictal':
         num_windows = (meta.data_length_sec / self.window_secs) * self.gen_factor
         samples_per_window = self.window_secs * int(meta.sampling_frequency) / self.gen_factor
         samples_used = num_windows * samples_per_window
         samples_dropped = X.shape[-1] - samples_used
         X = Slice(samples_dropped).apply(X)
         pieces = np.split(X, num_windows, axis=X.ndim-1)
         pieces_per_window = self.gen_factor
         gen = [np.concatenate(pieces[i:i+pieces_per_window], axis=pieces[0].ndim - 1) for i in range(0, num_windows - self.gen_factor + 1)]
         gen = to_np_array(gen)
         return gen
     else:
         return self.windower.apply(X, meta)
Ejemplo n.º 12
0
 def apply(self, X, meta):
     if meta.data_type == 'preictal':
         num_windows = (meta.data_length_sec /
                        self.window_secs) * self.gen_factor
         samples_per_window = self.window_secs * int(
             meta.sampling_frequency) / self.gen_factor
         samples_used = num_windows * samples_per_window
         samples_dropped = X.shape[-1] - samples_used
         X = Slice(samples_dropped).apply(X)
         pieces = np.split(X, num_windows, axis=X.ndim - 1)
         pieces_per_window = self.gen_factor
         gen = [
             np.concatenate(pieces[i:i + pieces_per_window],
                            axis=pieces[0].ndim - 1)
             for i in range(0, num_windows - self.gen_factor + 1)
         ]
         gen = to_np_array(gen)
         return gen
     else:
         return self.windower.apply(X, meta)
Ejemplo n.º 13
0
 def apply_one(self, data, meta=None):
     return to_np_array([hfd(ch, self.kmax) for ch in data])
Ejemplo n.º 14
0
 def apply_one(self, X, meta=None):
     return to_np_array([self.pfd_for_ch(ch) for ch in X])
Ejemplo n.º 15
0
 def apply_one(self, data, meta=None):
     return to_np_array([hfd(ch, self.kmax) for ch in data])
Ejemplo n.º 16
0
 def apply_one(self, X, meta=None):
     return to_np_array([self.pfd_for_ch(ch) for ch in X])