From 06716279f82a6765103403948be1781c448760a2 Mon Sep 17 00:00:00 2001 From: sreekaroo Date: Sun, 4 Feb 2024 20:55:25 -0500 Subject: [PATCH] minor log clean --- bcipy/simulator/helpers/log_utils.py | 18 ++++++++++++++++-- bcipy/simulator/helpers/state_manager.py | 4 ++-- bcipy/simulator/sim.py | 8 +++++--- 3 files changed, 23 insertions(+), 7 deletions(-) diff --git a/bcipy/simulator/helpers/log_utils.py b/bcipy/simulator/helpers/log_utils.py index 881b38d45..0e43c2fbb 100644 --- a/bcipy/simulator/helpers/log_utils.py +++ b/bcipy/simulator/helpers/log_utils.py @@ -1,7 +1,9 @@ -from typing import List +from typing import List, Dict import pandas as pd +from bcipy.simulator.helpers.types import SimEvidence + def fmt_stim_likelihoods(likelihoods, alp): rounded = [round(lik, 3) for lik in likelihoods] @@ -9,7 +11,7 @@ def fmt_stim_likelihoods(likelihoods, alp): return formatted -def fmt_fused_likelihoods_for_hist(likelihoods, alp): +def fmt_likelihoods_for_hist(likelihoods, alp): rounded = [round(lik, 3) for lik in likelihoods] formatted = [(a, l) for a, l in zip(alp, rounded)] return formatted @@ -22,3 +24,15 @@ def format_sample_rows(sample_rows: List[pd.DataFrame]): formatted_rows.append(new_row.to_string(index=False, header=True)) return ", ".join(formatted_rows) + + +def fmt_reshaped_evidence(evidences: Dict[str, SimEvidence]): + """ Formats evidences to log shapes pf ndarrays """ + + evidence_shape_strs = [] + + for evidence_name, evidence in evidences.items(): + evidence_shape = evidence.evidence.shape if evidence is not None else None + evidence_shape_strs.append(f"{evidence.evidence_type} => {evidence_shape}") + + return ", ".join(evidence_shape_strs) diff --git a/bcipy/simulator/helpers/state_manager.py b/bcipy/simulator/helpers/state_manager.py index 622784862..3ccd63cda 100644 --- a/bcipy/simulator/helpers/state_manager.py +++ b/bcipy/simulator/helpers/state_manager.py @@ -13,7 +13,7 @@ from bcipy.helpers.symbols import alphabet, BACKSPACE_CHAR from bcipy.simulator.helpers.decision import SimDecisionCriteria, MaxIterationsSim, ProbThresholdSim from bcipy.simulator.helpers.evidence_fuser import MultiplyFuser, EvidenceFuser -from bcipy.simulator.helpers.log_utils import fmt_fused_likelihoods_for_hist +from bcipy.simulator.helpers.log_utils import fmt_likelihoods_for_hist from bcipy.simulator.helpers.rsvp_utils import next_target_letter from bcipy.simulator.helpers.types import InquiryResult, SimEvidence @@ -115,7 +115,7 @@ def update(self, evidence) -> InquiryResult: log.debug( f"Fused Likelihoods | current typed - {self.state.current_sentence} | stimuli {self.state.display_alphabet} \n " - f"{histogram(fmt_fused_likelihoods_for_hist(new_inquiry_result.fused_likelihood, alphabet()))}") + f"{histogram(fmt_likelihoods_for_hist(new_inquiry_result.fused_likelihood, alphabet()))}") new_state['series_results'][self.state.series_n].append(new_inquiry_result) if is_decidable: diff --git a/bcipy/simulator/sim.py b/bcipy/simulator/sim.py index 8170f2035..d10c8d77f 100644 --- a/bcipy/simulator/sim.py +++ b/bcipy/simulator/sim.py @@ -6,6 +6,7 @@ import numpy as np from bcipy.helpers import load, stimuli, symbols +from bcipy.helpers.language_model import histogram from bcipy.helpers.parameters import Parameters from bcipy.helpers.symbols import alphabet from bcipy.simulator.helpers.data_engine import DataEngine @@ -14,7 +15,8 @@ from bcipy.simulator.helpers.sampler import Sampler from bcipy.simulator.helpers.state_manager import StateManager, SimState from bcipy.simulator.helpers.types import InquiryResult, SimEvidence -from bcipy.simulator.helpers.log_utils import fmt_stim_likelihoods +from bcipy.simulator.helpers.log_utils import fmt_stim_likelihoods, fmt_reshaped_evidence, \ + fmt_likelihoods_for_hist from bcipy.simulator.helpers.model_handler import ModelHandler from bcipy.simulator.simulator_base import Simulator from bcipy.task.data import EvidenceType @@ -82,8 +84,8 @@ def run(self): f"EEG Evidence for stimuli {curr_state.display_alphabet} " + f"\n {fmt_stim_likelihoods(evidence['sm'].evidence, self.symbol_set)}") - reshaped_evidence = self.__reshape_evidences(evidence) - log.debug(f"reshaped evidence {reshaped_evidence}") + reshaped_evidence: Dict[str, SimEvidence] = self.__reshape_evidences(evidence) + log.debug(f"Evidence Shapes {fmt_reshaped_evidence(reshaped_evidence)}") inq_record: InquiryResult = self.state_manager.update(reshaped_evidence) updated_state = self.state_manager.get_state()