Skip to content

Commit

Permalink
minor log clean
Browse files Browse the repository at this point in the history
  • Loading branch information
sreekaroo committed Feb 5, 2024
1 parent 95c16fd commit 0671627
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 7 deletions.
18 changes: 16 additions & 2 deletions bcipy/simulator/helpers/log_utils.py
Original file line number Diff line number Diff line change
@@ -1,15 +1,17 @@
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]
formatted = [f"{a} : {l}" for a, l in zip(alp, rounded)]
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
Expand All @@ -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)
4 changes: 2 additions & 2 deletions bcipy/simulator/helpers/state_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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:
Expand Down
8 changes: 5 additions & 3 deletions bcipy/simulator/sim.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down Expand Up @@ -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()
Expand Down

0 comments on commit 0671627

Please sign in to comment.