def _demo_fusion(): len_alp = 4 evidence_names = ['LM', 'ERP', 'FRP'] num_series = 4 num_inquiries = 10 conjugator = EvidenceFusion(evidence_names, len_dist=len_alp) print('Random Series!') for idx_ep in range(num_series): prior = np.abs(np.random.randn(len_alp)) prior = prior / np.sum(prior) conjugator.update_and_fuse({'LM': prior}) for idx in range(num_inquiries): # Generate random inquiries evidence_erp = 10 * np.abs(np.random.randn(len_alp)) evidence_frp = 10 * np.abs(np.random.randn(len_alp)) conjugator.update_and_fuse( {'ERP': evidence_erp, 'FRP': evidence_frp}) print('Series: {}'.format(idx_ep)) print(conjugator.evidence_history['ERP']) print(conjugator.evidence_history['FRP']) print(conjugator.evidence_history['LM']) print('Posterior:{}'.format(conjugator.likelihood)) # Reset the conjugator before starting a new series for clear history conjugator.reset_history()
def _demo_decision_maker(): alp = ['T', 'H', 'I', 'S', 'I', 'S', 'D', 'E', 'M', 'O'] len_alp = len(alp) evidence_names = ['LM', 'ERP', 'FRP'] num_series = 10 conjugator = EvidenceFusion(evidence_names, len_dist=len_alp) decision_maker = DecisionMaker( min_num_inq=1, max_num_inq=10, state='', alphabet=alp) for idx_series in range(num_series): while True: # Generate random inquiries evidence_erp = np.abs(np.random.randn(len_alp)) evidence_erp[idx_series] += 1 evidence_frp = np.abs(np.random.randn(len_alp)) evidence_frp[idx_series] += 3 p = conjugator.update_and_fuse( {'ERP': evidence_erp, 'FRP': evidence_frp}) d, arg = decision_maker.decide(p) if d: break # Reset the conjugator before starting a new series for clear history conjugator.reset_history() print('State:{}'.format(decision_maker.state)) print('Displayed State: {}'.format(decision_maker.displayed_state))
def __init__(self, min_num_seq, max_num_seq, signal_model=None, fs=300, k=2, alp=None, evidence_names=['LM', 'ERP'], task_list=[('I_LOVE_COOKIES', 'I_LOVE_')], lmodel=None, is_txt_stim=True, device_name='LSL', device_channels=None, stimuli_timing=[1, .2], decision_threshold=0.8, backspace_prob=0.05, backspace_always_shown=False, filter_high=45, filter_low=2, filter_order=2, notch_filter_frequency=60): self.conjugator = EvidenceFusion(evidence_names, len_dist=len(alp)) seq_constants = [] if backspace_always_shown and BACKSPACE_CHAR in alp: seq_constants.append(BACKSPACE_CHAR) self.decision_maker = DecisionMaker( min_num_seq, max_num_seq, decision_threshold=decision_threshold, state=task_list[0][1], alphabet=alp, is_txt_stim=is_txt_stim, stimuli_timing=stimuli_timing, seq_constants=seq_constants) self.alp = alp # non-letter target labels include the fixation cross and calibration. self.nonletters = ['+', 'PLUS', 'calibration_trigger'] self.valid_targets = set(self.alp) self.signal_model = signal_model self.sampling_rate = fs self.downsample_rate = k self.filter_high = filter_high self.filter_low = filter_low self.filter_order = filter_order self.notch_filter_frequency = notch_filter_frequency self.mode = 'copy_phrase' self.task_list = task_list self.lmodel = lmodel self.channel_map = analysis_channels(device_channels, device_name) self.backspace_prob = backspace_prob
def setUp(self): """Set up decision maker object for testing """ self.decision_maker = DecisionMaker( 1, 3, state='', alphabet=list(string.ascii_uppercase) + ['<'] + [SPACE_CHAR], is_txt_stim=True, stimuli_timing=[1, .2], seq_constants=None) self.evidence_fusion = EvidenceFusion(list_name_evidence=['A', 'B'], len_dist=2)
def setUp(self): """Set up decision maker object for testing """ alphabet = list(string.ascii_uppercase) + ['<'] + [SPACE_CHAR] stopping_criteria = CriteriaEvaluator( continue_criteria=[MinIterationsCriteria(min_num_inq=1)], commit_criteria=[ MaxIterationsCriteria(max_num_inq=10), ProbThresholdCriteria(threshold=0.8) ]) stimuli_agent = NBestStimuliAgent(alphabet=alphabet, len_query=10) self.decision_maker = DecisionMaker( stimuli_agent=stimuli_agent, stopping_evaluator=stopping_criteria, state='', alphabet=alphabet, is_txt_stim=True, stimuli_timing=[1, .2], inq_constants=None) self.evidence_fusion = EvidenceFusion(list_name_evidence=['A', 'B'], len_dist=2)
def __init__(self, min_num_inq, max_num_inq, signal_model=None, fs=300, k=2, alp=None, evidence_names=['LM', 'ERP'], task_list=[('I_LOVE_COOKIES', 'I_LOVE_')], lmodel=None, is_txt_stim=True, device_name='LSL', device_channels=None, stimuli_timing=[1, .2], decision_threshold=0.8, backspace_prob=0.05, backspace_always_shown=False, filter_high=45, filter_low=2, filter_order=2, notch_filter_frequency=60): self.conjugator = EvidenceFusion(evidence_names, len_dist=len(alp)) inq_constants = [] if backspace_always_shown and BACKSPACE_CHAR in alp: inq_constants.append(BACKSPACE_CHAR) # Stimuli Selection Module stopping_criteria = CriteriaEvaluator( continue_criteria=[MinIterationsCriteria(min_num_inq)], commit_criteria=[ MaxIterationsCriteria(max_num_inq), ProbThresholdCriteria(decision_threshold) ]) # TODO: Parametrize len_query in the future releases! stimuli_agent = NBestStimuliAgent(alphabet=alp, len_query=10) self.decision_maker = DecisionMaker( stimuli_agent=stimuli_agent, stopping_evaluator=stopping_criteria, state=task_list[0][1], alphabet=alp, is_txt_stim=is_txt_stim, stimuli_timing=stimuli_timing, inq_constants=inq_constants) self.alp = alp # non-letter target labels include the fixation cross and calibration. self.nonletters = ['+', 'PLUS', 'calibration_trigger'] self.valid_targets = set(self.alp) self.signal_model = signal_model self.sampling_rate = fs self.downsample_rate = k self.filter_high = filter_high self.filter_low = filter_low self.filter_order = filter_order self.notch_filter_frequency = notch_filter_frequency self.mode = 'copy_phrase' self.task_list = task_list self.lmodel = lmodel self.channel_map = analysis_channels(device_channels, device_name) self.backspace_prob = backspace_prob