def run(
        self,
        signal_list,
        sampling_freq_list,
        event_times_list,
        wavelet="haar",
        num_coefficients_kept=10,
        normalize=True,
        **kwargs
    ):
        # features, feature_times for each trial
        features_list = []
        feature_times_list = []
        for signal, sampling_freq, event_times in zip(signal_list, sampling_freq_list, event_times_list):
            features, feature_times, _, _ = generate_spike_windows(signal, sampling_freq, event_times, **kwargs)
            features_list.append(features)
            feature_times_list.append(feature_times)

        # unify features before getting wavelet_coefficients
        total_len = 0
        for features in features_list:
            total_len += len(features)

        unified_features = numpy.empty((total_len,) + features_list[0].shape[1:])
        begin = 0
        end = 0
        unpacking_index = {}
        for i, features in enumerate(features_list):
            end = begin + len(features)
            unified_features[begin:end] = features
            unpacking_index[i] = [begin, end]
            begin = end

        wavelet_coefficients = get_wavelet_coefficients(unified_features, wavelet, num_coefficients_kept)
        if normalize:
            means = numpy.average(wavelet_coefficients, axis=0)
            stds = numpy.std(wavelet_coefficients, axis=0)
            wavelet_coefficients = (wavelet_coefficients - means) / stds

        # deunify wavelet_coefficients before returning them
        wavelet_coefficients_list = []
        for i in range(len(features_list)):
            begin, end = unpacking_index[i]
            wavelet_coefficients_list.append(wavelet_coefficients[begin:end])

        return [wavelet_coefficients_list, feature_times_list]
示例#2
0
 def run(self, signal, sampling_freq, event_times, **kwargs):
     return generate_spike_windows(signal, sampling_freq, event_times, 
             **kwargs)[:2]