def test_complex(self): c = _AddOneBlock() d = _AddOneBlock() e = _TwoInputBlock() p = pipeline.Pipeline([self.a, (self.b, [c, d]), e]) out = p.process(self.data) assert out == self.data + 2 + self.data + 3
def test_clear(self): b = _ClearableBlock() internal_start = b.internal_var p = pipeline.Pipeline(b) out = p.process(self.data) assert b.internal_var == out p.clear() assert b.internal_var == internal_start
def __init__(self, config, record_thread, parent=None): super(SignalWidget, self).__init__(parent) self.cfg = config self.record_thread = record_thread self.samp_per_read = 1 self.hist = 20 self.plot_items = [] self.plot_data_items = [] self.ui = Ui_SignalWidget() self.ui.setupUi(self) self.pipeline = pipeline.Pipeline(self.cfg.conditioner) self.init_plot() self.init_button_group()
def test_parallel_to_series(self): c = _TwoInputBlock() p = pipeline.Pipeline([(self.a, self.b), c]) out = p.process(self.data) assert out == self.data + 1 + self.data + 1
def test_series_to_parallel(self): c = _AddOneBlock() p = pipeline.Pipeline([self.a, (self.b, c)]) out = p.process(self.data) assert out == [self.data + 2, self.data + 2]
def test_parallel_simple(self): p = pipeline.Pipeline((self.a, self.b)) out = p.process(self.data) assert out == [self.data + 1, self.data + 1]
def test_series_simple(self): p = pipeline.Pipeline([self.a, self.b]) out = p.process(self.data) assert out == self.data + 2
def build_pipeline(self): """ Builds the processing pipeline. Most of the pipeline is specified by the config, but we need to gather training data, build a classifier with that data, and insert the classifier into the pipeline. """ train_list = [] for i in range(self.ui.trainingList.count()): item = self.ui.trainingList.item(i) if item.checkState(): train_list.append(str(item.text())) self.training_sessions = train_list if not train_list: QtWidgets.QMessageBox().critical( self, "Error", "No sessions selected for training.", QtWidgets.QMessageBox.Ok) return # get only the labels for the selected TAC session # need to loop over available gestures to catch those with no dof labels = [] mapping = {} for gesture in self.cfg.gestures: if gesture.dof is None: labels.append(gesture.label) mapping[gesture.label] = gesture.action else: if gesture in self.tac_session.gestures: labels.append(gesture.label) mapping[gesture.label] = gesture.action file_list = filestruct.get_feature_file_list(self.cfg.data_path, self.pid, train_list) training_data = processing.read_feature_file_list(file_list, labels=labels) # get average MAV for each gesture label to auto-set boosts # warning: super hacky j = 0 start = 0 for i, feature in enumerate(self.cfg.feature_extractor.features): if 'MAV' in str(feature): start = j break else: j += feature.dim_per_channel * len(self.cfg.channels) X, y = training_data X = X[:, start:len(self.cfg.channels)] boosts = dict() for label in labels: mav_avg = np.mean(X[y == label, :], axis=1) # -np.partition(-data, N) gets N largest elements of data boosts[label] = 1 / np.mean(-np.partition(-mav_avg, 10)[:10]) self.boosts = boosts # re-create the controller to make sure it has the correct mapping self.controller = control.DBVRController( mapping=mapping, ramp_length=self.cfg.controller.ramp_length, boosts=1 if self.test else boosts) self.cfg.learner.fit(*training_data) self.pipeline = pipeline.Pipeline([ self.cfg.conditioner, self.cfg.windower, ( features.FeatureExtractor([features.MAV()], len(self.cfg.channels)), [self.cfg.feature_extractor, self.cfg.learner], ) ]) self.record_thread.set_pipeline(self.pipeline)