From be6b2925f38106227a9747ca54732b85a775ace7 Mon Sep 17 00:00:00 2001 From: lawhead Date: Fri, 22 Dec 2023 13:30:46 -0800 Subject: [PATCH 1/2] Fixes an issue with logging samples that was caused by the provided type being a DataFrame rather than a List[Series] --- bcipy/simulator/helpers/log_utils.py | 11 ++++------- bcipy/simulator/helpers/sampler.py | 5 +++-- 2 files changed, 7 insertions(+), 9 deletions(-) diff --git a/bcipy/simulator/helpers/log_utils.py b/bcipy/simulator/helpers/log_utils.py index 8e91d5110..19cf8c2bc 100644 --- a/bcipy/simulator/helpers/log_utils.py +++ b/bcipy/simulator/helpers/log_utils.py @@ -9,10 +9,7 @@ def format_alp_likelihoods(likelihoods, alp): return formatted -def format_sample_rows(sample_rows: List[pd.Series]): - formatted_rows = [] - for row in sample_rows: - new_row = row.drop(columns=['eeg'], axis=1, inplace=False) - formatted_rows.append(new_row.to_string(index=False, header=True)) - - return ", ".join(formatted_rows) +def format_sample_rows(sample_rows: List[pd.Series]) -> str: + """Returns a tabular representation of the sample rows.""" + return pd.DataFrame(sample_rows).drop(columns=['eeg']).to_string( + index=False, header=True) diff --git a/bcipy/simulator/helpers/sampler.py b/bcipy/simulator/helpers/sampler.py index 3111d2370..44fe029c3 100644 --- a/bcipy/simulator/helpers/sampler.py +++ b/bcipy/simulator/helpers/sampler.py @@ -53,11 +53,12 @@ def sample(self, state: SimState) -> np.ndarray: if not len(filtered_data): raise TaskConfigurationException(message="No eeg sample found with provided data and query") - row = filtered_data.sample(1) + row = filtered_data.sample(1).iloc[0] sample_rows.append(row) log.debug(f"EEG Samples: \n {format_sample_rows(sample_rows)}") - eeg_responses = [r['eeg'].to_numpy()[0] for r in sample_rows] + + eeg_responses = [r['eeg'] for r in sample_rows] sample = self.model_input_reshaper(eeg_responses) return sample From 77ab10725b9e9075502f017b08982152b5a33c7b Mon Sep 17 00:00:00 2001 From: lawhead Date: Mon, 5 Feb 2024 13:55:57 -0800 Subject: [PATCH 2/2] Fixed merge error --- bcipy/simulator/helpers/log_utils.py | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/bcipy/simulator/helpers/log_utils.py b/bcipy/simulator/helpers/log_utils.py index 81181783c..e1877116d 100644 --- a/bcipy/simulator/helpers/log_utils.py +++ b/bcipy/simulator/helpers/log_utils.py @@ -3,6 +3,11 @@ import pandas as pd +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): rounded = [round(lik, 3) for lik in likelihoods] formatted = [(a, l) for a, l in zip(alp, rounded)]