예제 #1
0
    def combined_dataset(cls, ids, window_length):
        dataset = Dataset.empty()
        for id in ids:
            session = cls.from_api(id)
            windows = list(session.window_gen(window_length=window_length))
            dataset = dataset + session.dataset(windows)

        return dataset
예제 #2
0
    def full_dataset_gen(cls, window_length, count=1, sessions=None):

        if sessions is None:
            Print.info("Fetching sessions")
            sessions = Session.fetch_all(only_real=True,
                                         include_timeframes=True)

        for _ in range(count):
            dataset = Dataset.empty()
            for session in sessions:
                windows = list(session.window_gen(window_length=window_length))
                dataset = dataset + session.dataset(windows=windows)

            yield dataset
예제 #3
0
    def dataset(self, windows, remove_seconds=0):
        if len(windows) == 0:
            return Dataset.empty()

        n_samples = len(windows)
        n_channels = len(self.ch_names)
        window_length = np.shape(windows)[1]

        X = np.empty([n_samples, n_channels, window_length])
        y = np.empty([n_samples], dtype=np.int8)

        for i, window in enumerate(windows):
            X[i] = window[:, 0:n_channels].T
            y[i] = int(max(window[:, -1]))

        if remove_seconds > 0:
            change_points = []
            action_labels = []
            for i in range(1, len(y), 1):
                if y[i] != y[i - 1]:
                    change_points.append(i)
                    action_labels.append(np.max(y[i - 1:i + 1]))

            remove_distance = (250 * remove_seconds) / window_length
            keep_indices = []
            for i in range(len(y)):
                label = y[i]
                if label == 0:
                    viable = True
                    for point in change_points:
                        if np.abs(i - point) <= remove_distance:
                            viable = False
                    if viable:
                        keep_indices.append(i)
                else:
                    keep_indices.append(i)

            X = X[keep_indices]
            y = y[keep_indices]

        return Dataset(X, y, self.person_id, self.id)