def run_experiment(): eeg = EEG(board_id=2, ip_port=6677, serial_port="COM4") exp = OnlineExperiment(eeg=eeg, model=None, num_trials=3, buffer_time=3, threshold=3) exp.run(use_eeg=False)
def main(): eeg = EEG(board_id=2, ip_port=6677, serial_port="COM6") exp = OfflineExperiment(eeg=eeg, num_trials=4, trial_length=2) trials, labels = exp.run() trials = preprocess(eeg, trials, ch_names=['C3', 'C4']) features = extract_features(eeg, trials, features=['ptp_amp', 'mean', 'skewness']) # features, labels = load_featuresNlabels_fromPKL() model, mean_acc = train_model(features, labels) print(mean_acc)
def run_experiment(model_path: str): model = pickle.load(open(model_path, 'rb')) SYNTHETIC_BOARD = -1 CYTON_DAISY = 2 eeg = EEG(board_id=SYNTHETIC_BOARD) exp = OnlineExperiment(eeg=eeg, model=model, num_trials=10, buffer_time=4, threshold=3, skip_after=8, co_learning=True, debug=False) exp.run(use_eeg=True, full_screen=True)
def offline_experiment(): SYNTHETIC_BOARD = -1 CYTON_DAISY = 2 eeg = EEG(board_id=CYTON_DAISY) exp = OfflineExperiment(eeg=eeg, num_trials=20, trial_length=5, full_screen=True, audio=False) trials, labels = exp.run() # Classification model = MLModel(trials=trials, labels=labels) session_directory = exp.session_directory model.offline_training(eeg=eeg, model_type='csp_lda') # Dump the MLModel pickle.dump(model, open(os.path.join(session_directory, 'model.pickle'), 'wb'))
def control_mouse(config: MouseConfig, model_path: str): # Init variables model = MLModel(model_path=model_path) eeg = EEG(board_id=-1) vm = VirtualMouse(eeg=eeg, model=model, mouse_actions=config.mouse_actions) # Turn EEG on eeg.on() # Start controlling the virtual mouse while True: # Monitor the movement to indicate standstill vm.monitor(r=25, counter_limit=5, interval=0.4) # Predict the label imagined by the user label = vm.predict(buffer_time=4) # Convert the label to action according to current config action = config.get_action(label=label) # Execute the action vm.execute(action=action)