예제 #1
0
def demo_copy_phrase_wrapper():
    # We need to train a dummy model
    num_x_p = 100
    num_x_n = 900

    x_p = mean_pos + var_pos * np.random.randn(num_ch, num_x_p, dim_x)
    x_n = mean_neg + var_neg * np.random.randn(num_ch, num_x_n, dim_x)
    y_p = [1] * num_x_p
    y_n = [0] * num_x_n

    train_x = np.concatenate((x_p, x_n), 1)
    train_y = np.concatenate((y_p, y_n), 0)
    permutation = np.random.permutation(train_x.shape[1])
    train_x = train_x[:, permutation, :]
    train_y = train_y[permutation]

    train_x = train_x[list(np.where(np.asarray(channel_map) == 1)[0]), :, :]

    k_folds = 10
    model = train_pca_rda_kde_model(train_x, train_y, k_folds=k_folds)

    # Define task and operate
    task_list = [('I_LOVE_COOKIES', 'I_LOVE_'),
                 ('THIS_IS_A_DEMO', 'THIS_IS_A_')]

    task = CopyPhraseWrapper(model, fs=dim_x * 2, k=1, alp=alphabet(),
                             task_list=task_list)

    print(task)
예제 #2
0
    def __init__(self, win, daq, parameters, file_save, classifier, lmodel,
                 fake):

        self.window = win
        self.frame_rate = self.window.getActualFrameRate()
        self.parameters = parameters
        self.daq = daq
        self.static_clock = core.StaticPeriod(screenHz=self.frame_rate)
        self.experiment_clock = core.Clock()
        self.buffer_val = parameters['task_buffer_len']
        self.alp = alphabet(parameters)
        self.rsvp = _init_copy_phrase_display(self.parameters, self.window,
                                              self.daq, self.static_clock,
                                              self.experiment_clock)
        self.file_save = file_save

        trigger_save_location = f"{self.file_save}/{parameters['triggers_file_name']}"
        self.trigger_file = open(trigger_save_location, 'w')
        self.session_save_location = f"{self.file_save}/{parameters['session_file_name']}"

        self.wait_screen_message = parameters['wait_screen_message']
        self.wait_screen_message_color = parameters[
            'wait_screen_message_color']

        self.num_sti = parameters['num_sti']
        self.len_sti = parameters['len_sti']
        self.timing = [
            parameters['time_target'], parameters['time_cross'],
            parameters['time_flash']
        ]

        self.color = [
            parameters['target_letter_color'], parameters['fixation_color'],
            parameters['stimuli_color']
        ]

        self.task_info_color = parameters['task_color']

        self.stimuli_height = parameters['sti_height']

        self.is_txt_sti = parameters['is_txt_sti']
        self.eeg_buffer = parameters['eeg_buffer_len']
        self.copy_phrase = parameters['text_task']
        self.spelled_letters_count = int(parameters['spelled_letters_count'])
        if self.spelled_letters_count > len(self.copy_phrase):
            logging.debug("Already spelled letters exceeds phrase length.")
            self.spelled_letters_count = 0

        self.max_seq_length = parameters['max_seq_len']
        self.max_seconds = parameters['max_minutes'] * 60  # convert to seconds
        self.fake = fake
        self.lmodel = lmodel
        self.classifier = classifier
        self.down_sample_rate = parameters['down_sampling_rate']
예제 #3
0
    def test_alphabet_text(self):
        parameters_used = 'bcipy/parameters/parameters.json'
        parameters = load_json_parameters(parameters_used, value_cast=True)

        parameters['is_txt_sti'] = True

        alp = alphabet(parameters)

        self.assertEqual(alp, [
            'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M',
            'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z',
            '<', '_'
        ])
예제 #4
0
    def test_alphabet_images(self):
        parameters_used = 'bcipy/parameters/parameters.json'
        parameters = load_json_parameters(parameters_used, value_cast=True)

        parameters['is_txt_sti'] = False
        parameters['path_to_presentation_images'] = ('bcipy/static/images/'
                                                     'rsvp_images/')

        alp = alphabet(parameters)

        self.assertNotEqual(alp, [
            'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M',
            'N', 'O', 'P', 'R', 'S', 'T', 'U', 'V', 'Y', 'Z', '<', '_'
        ])
예제 #5
0
    def __init__(self, win, daq, parameters, file_save, fake):
        super(RSVPCopyPhraseCalibrationTask, self).__init__()
        self.window = win
        self.frame_rate = self.window.getActualFrameRate()
        self.parameters = parameters
        self.daq = daq
        self.static_clock = core.StaticPeriod(screenHz=self.frame_rate)
        self.experiment_clock = core.Clock()
        self.buffer_val = parameters['task_buffer_len']
        self.alp = alphabet(parameters)
        self.rsvp = _init_copy_phrase_display_task(self.parameters,
                                                   self.window, self.daq,
                                                   self.static_clock,
                                                   self.experiment_clock)
        self.file_save = file_save
        trigger_save_location = f"{self.file_save}/{parameters['triggers_file_name']}"
        self.session_save_location = f"{self.file_save}/{parameters['session_file_name']}"
        self.trigger_file = open(trigger_save_location, 'w')

        self.wait_screen_message = parameters['wait_screen_message']
        self.wait_screen_message_color = parameters[
            'wait_screen_message_color']

        self.num_sti = parameters['num_sti']
        self.len_sti = parameters['len_sti']
        self.timing = [
            parameters['time_target'], parameters['time_cross'],
            parameters['time_flash']
        ]

        self.color = [
            parameters['target_letter_color'], parameters['fixation_color'],
            parameters['stimuli_color']
        ]

        self.task_info_color = parameters['task_color']

        self.stimuli_height = parameters['sti_height']

        self.is_txt_sti = parameters['is_txt_sti']
        self.eeg_buffer = parameters['eeg_buffer_len']
        self.copy_phrase = parameters['text_task']

        self.max_seq_length = parameters['max_seq_len']
        self.fake = fake

        self.enable_breaks = parameters['enable_breaks']
예제 #6
0
    def __init__(self, win, daq, parameters, file_save, signal_model,
                 language_model, fake, is_word, auc_filename):
        super(RSVPIconToIconTask, self).__init__()
        self.window = win
        self.frame_rate = self.window.getActualFrameRate()
        self.parameters = parameters
        self.daq = daq
        self.static_clock = core.StaticPeriod(screenHz=self.frame_rate)
        self.experiment_clock = core.Clock()
        self.buffer_val = parameters['task_buffer_len']
        self.alp = alphabet(parameters)
        self.rsvp = _init_icon_to_icon_display_task(self.parameters,
                                                    self.window, self.daq,
                                                    self.static_clock,
                                                    self.experiment_clock,
                                                    is_word)
        self.file_save = file_save
        self.is_word = is_word

        trigger_save_location = f"{self.file_save}/{parameters['triggers_file_name']}"
        self.trigger_file = open(trigger_save_location, 'w+')
        self.session_save_location = f"{self.file_save}/{parameters['session_file_name']}"

        self.wait_screen_message = parameters['wait_screen_message']
        self.wait_screen_message_color = parameters[
            'wait_screen_message_color']

        self.num_sti = parameters['num_sti']
        self.len_sti = parameters['len_sti']
        self.timing = [
            parameters['time_target'], parameters['time_cross'],
            parameters['time_flash']
        ]

        self.color = [
            parameters['target_letter_color'], parameters['fixation_color'],
            parameters['stimuli_color']
        ]

        self.task_info_color = parameters['task_color']

        self.stimuli_height = parameters['sti_height']

        self.eeg_buffer = parameters['eeg_buffer_len']

        self.max_seconds = parameters['max_minutes'] * 60  # convert to seconds
        self.max_seq_length = parameters['max_seq_len']
        self.fake = fake
        self.language_model = language_model
        self.signal_model = signal_model
        self.auc_filename = auc_filename

        self.image_path = parameters['path_to_presentation_images']
        self.task_height = parameters['height_task']

        self.is_txt_sti = False

        self.min_num_seq = parameters['min_seq_len']
        self.word_matching_text_size = parameters['word_matching_text_size']
        self.collection_window_len = parameters[
            'collection_window_after_trial_length']
        self.data_save_path = parameters['data_save_loc']
예제 #7
0
 def __init__(self, path2eeg):
     self.abc = alphabet()
     self.samples = eegs(path2eeg)
예제 #8
0
import os
import docker
import requests
import time
import re
import logging
import unittest
from errors import ConnectionErr, StatusCodeError, DockerDownError
from bcipy.helpers.bci_task_related import alphabet
from subprocess import Popen, PIPE
import platform

ALPHABET = alphabet()


class LangModel:
    def __init__(self,
                 localpath2fst,
                 host="127.0.0.1",
                 port="5000",
                 logfile="log"):
        """
        Initiate the langModel class. Primarly initializing
        is aimed at establishing the tcp/ip connection
        between the host (local machine) and its server
        (the docker machine)
        Establishing the connection and running the server
        are done in a single operartion
        Input:
          localpath2fst (str) - the local path to the fst file
          host (str) - host machine ip address
예제 #9
0
    def __init__(self,
                 window,
                 clock,
                 experiment_clock,
                 color_task='white',
                 font_task='Times',
                 pos_task=(-.75, .75),
                 task_height=0.1,
                 grid_rows=6,
                 grid_columns=6,
                 time_flash=.25,
                 text_task='1/100',
                 color_text=['white'],
                 font_text='Times',
                 height_text=0.25,
                 font_sti='Times',
                 pos_sti=(0, .0),
                 sti_height=0.25,
                 is_txt_sti=True,
                 alp=None):

        self.win = window
        self.logger = logging

        # TASK TEXT
        self.font_task_text = font_task
        self.task_height = task_height
        self.pos_task_text = pos_task
        self.text_task = text_task
        self.color_task = color_task

        # STIM / GRID
        self.is_txt_sti = is_txt_sti
        self.stimuli = []
        self.rows = grid_rows
        self.font = font_sti
        self.columns = grid_columns
        self.sti_height = sti_height

        self.stim_number = grid_rows + grid_columns

        self.max_height_grid = -1 + sti_height
        self.max_width_grid = 1 - sti_height
        self.uniform_grid_values_row = sorted(
            np.linspace(start=self.max_height_grid,
                        stop=self.max_width_grid,
                        num=self.rows))

        self.uniform_grid_values_col = sorted(np.linspace(
            start=self.max_height_grid,
            stop=self.max_width_grid - .25,
            num=self.columns),
                                              reverse=True)

        if not alp:
            self.alp = alphabet()
        else:
            self.alp = alp

        self.flash = time_flash
        # Clocks
        self.trialClock = clock
        self.expClock = experiment_clock

        # Length of the stimuli (number of stimuli on screen)
        self.len_sti = len(self.stimuli)