From 547b2277a14a7333d10e5e4bd79dd6002ea9a9de Mon Sep 17 00:00:00 2001 From: Yihui Cai Date: Tue, 25 Jul 2023 12:39:41 +0800 Subject: [PATCH] Fix Risk Index calculation and add data sanitization --- simglucose/analysis/report.py | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/simglucose/analysis/report.py b/simglucose/analysis/report.py index 968057a6..244ccfcb 100644 --- a/simglucose/analysis/report.py +++ b/simglucose/analysis/report.py @@ -93,10 +93,13 @@ def percent_stats(BG, ax=None): def risk_index_trace(df_BG, visualize=False): - chunk_BG = [df_BG.iloc[i:i + 60, :] for i in range(0, len(df_BG), 60)] + chunk_BG = [df_BG.iloc[i:i + 20, :] for i in range(0, len(df_BG), 20)] + + if len(chunk_BG[-1]) != 20: # Remove the last chunk which is not full + chunk_BG.pop() fBG = [ - np.mean(1.509 * (np.log(BG[BG > 0])**1.084 - 5.381)) for BG in chunk_BG + 1.509 * (np.log(BG[BG > 0]).mean() ** 1.084 - 5.381) for BG in chunk_BG ] fBG_df = pd.concat(fBG, axis=1).transpose()