-
Notifications
You must be signed in to change notification settings - Fork 114
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Risk Index probably incorrect #63
Comments
Thanks for raising this issue. The simple add-up comes from the original UVa/Padova Simulator, but I agree that your proposed weighted average makes more sense, and it will bring the final risk index into the same scale of LBGI and HBGI. If you are interested, feel free to submit a PR to the repo, otherwise, I will do that. FYI, there is a related risk index computation error reported here #62, which is due to the numpy version compatibility, and there is already a PR to fix this computation error. |
This is a follow up to my previous solution. It still suffers from a problem: the risk values are not capped to [0, 100] as they should be. This stems from the assumption in the paper that the bg values should be within [20, 600] mg/dL. Outside of that range we cannot depend on natural log to behave. Here is the updated implementation - this should directly replace the contents of import numpy as np
def risk_index(BG, horizon):
# BG is in mg/dL
BG_to_compute = BG[-horizon:]
risks =[risk(r) for r in BG_to_compute]
LBGI = np.mean([r[0] for r in risks])
HBGI = np.mean([r[1] for r in risks])
RI = np.mean([r[2] for r in risks])
return (LBGI, HBGI, RI)
def risk(BG):
MIN_BG = 20.0
MAX_BG = 600.0
if BG <= MIN_BG:
return (100.0, 0.0, 100.0)
if BG >= MAX_BG:
return (0.0, 100.0, 100.0)
U = 1.509 * (np.log(BG)**1.084 - 5.381)
ri = 10 * U**2
rl, rh = 0.0, 0.0
if U <= 0:
rl = ri
if U >= 0:
rh = ri
return (rl, rh, ri) |
Opened a PR with the proposed changes. Closed the old PR. |
UPDATE: See my update in a post below - this also has a problem.
This here is simply adding two means:
simglucose/simglucose/analysis/risk.py
Line 16 in c51e7f2
However, adding up two means (or taking the mean) of sub-sequences that are different in length does not equal the mean of the whole sequence:
Instead we have to weigh the each individual mean by the length of sequence it represents. Like this:
While risk index is not explicitly defined in any paper I can find (neither here nor here) - only the low and high risk indicies are defined:
it is not unreasonable to assume that it should be defined such that risk function applied to the whole trajectory would result in the same mean as the combination of low and high risk indicies, e.g.:
The nice thing about weighing the LBGI and HBGI is that the final risk then is still bounded between 0 and 100.
The text was updated successfully, but these errors were encountered: