Integral-retrospective-correction or IRC is an experimental modification of the Loop's Retrospective Correction.
Integral Retrospective Correction (IRC) Status (Nov. 2019):
- IRC is not a standard Loop feature and is not considered for inclusion in the standard Loop at this time.
- IRC is considered highly experimental and is not recommended for new Loop users or users who are having issues with Loop settings.
- The IRC algorithm was developed and implemented during 2018. At this time, the IRC algorithm and the IRC code are stable, and there are no known bugs.
- Until further notice, I am planning to keep the IRC branch closely up to date with Loop dev branch for my own personal use. Since the Loop dev branch is updated very often, the IRC branch may be behind Loop dev at times.
- If you wish to try IRC, you may do so on your own following the standard Loop installation directions. Please do not distribute IRC to other Loop users in any form.
- Feel free to contact me (@ Dragan Maksimovic on Loop Zulip) about any algorithm questions or feedback you may have about IRC, but please note that I am unable to provide any installation support or any other technical support.
- In the IRC branch, the IRC feature is disabled by default, and standard RC is enabled. To enable IRC, tap on the glucose chart, scroll down to the Algorithm Settings and turn the slider switch on.
-
Known risk factors compared to standard Loop: with IRC turned on, in response to persistent discrepancies between observed and predicted glucose motion, Loop may increase insulin corrections, which may increase risks of hypoglycemia. In general, IRC may also lead to increased oscillations ("roller-coaster") in glucose responses. Both of these risk factors are increased if the user's setting value for Insulin Sensitivity (ISF) is too low. Increasing ISF setting value tends to mitigate these risks but it is impossible to offer any guarantees for anything around your own T1D.
-
Compared to standard Loop, IRC is more likely to improve glucose control in the following situations:
- Glucose staying above (or below) the correction range due to too low (or too high) basal rate settings
- Glucose spikes (or dips) on tail ends of meals where carbs entered are underestimated or overestimated
- Glucose spikes due to unannounced protein+fat effects
- Glucose spikes due to any unannounced meals
The current implementation of the IRC code is in IntegralRetrospectiveCorrection.swift and the algorithm is described below.
******************** .IRC Algorithm Description ********************************************
Integral retrospective correction (integral RC) is an experimental modification of the Loop's retrospective correction algorithm. Loop with integral RC, which is based on the current dev branch of Loop, has no customization other than the IRC code. Just as the standard RC, the motivation behind integral RC is to make Loop less dependent on how well carb entries, ISF, CR, or programmed basal rates represent reality, and to improve responses in the presence of any unmodeled factors.
If you are interested in trying out the experimental integral RC Loop branch, some points to note:
- I believe the algorithm and the code are safe and suitable for testing purposes, but since Loop with integral RC is even more highly experimental than standard Loop please do not even consider trying unless you are a Loop user who is willing and able to carefully observe operation and provide feedback. There are measures takes so that IRC should not make anything worse, but there is no way to guarantee that. Too low ISF setting value may lead to increased risks of hypoglycemia or oscillatory glucose responses.
- Please do not expect any immediate or very substantial improvements. The algorithm changes described here are relatively modest tweaks to existing Loop algorithms.
- Please read through the rest of this post (which is rather long, sorry), and feel free to ask any questions.
Integral retrospective correction: algorithm description
Operation of the standard Loop retrospective correction is illustrated below, where time = 0 represents present time.
A modeling error called discrepancy
is calculated as the difference between the actual BG and the BG predicted based on insulin and carbs models over the past 30 minutes. In the example shown, discrepancy = 15 mg/dL
. The discrepancy
is then used to modify the BG forecast over a correction interval of 60 min. The net effect of standard RC is that the eventual predicted BG is adjusted up (or down) by a retrospective correction equal to the current discrepancy (subject to momentum effects, but that’s a different topic).
In the integral RC, the correction magnitude and the correction time interval depend not only on the current discrepancy but also on past discrepancy values, so that the correction becomes more aggressive if discrepancy persists over consecutive Loop cycles. This results is more aggressive dosing in response to any persistent modeling errors due to over/under-estimated carbs, parameters (ISF, CR, or basal rates) being away from reality, exercise, … whatever.
Simulation examples
In the first example, the actual basal needs increase by 40% (to 0.7 U/h) over a period of about 10 hours. Standard Loop high temps, which keeps BG from ramping up, but BG hovers away from the target. Integral RC kicks in more aggressive high temp corrections, which brings BG closer to the target.
In the second simulation example, the actual basal needs fall by 40% (to 0.3 U/h) over a period of around 10 hours. Standard Loop responds by low temping, but BG still drops below suspend threshold, which triggers some on/off oscillations around the suspend threshold. Integral RC results in a smaller BG drop and keeps BG closer to the target throughout.
The third example is a case of unannounced 25 g carbs with absorption time of about 3 hours. Compared to the standard Loop, integral RC reduces the magnitude and the duration of the spike.
Integral RC math
Integral RC math is relatively simple. Overall retrospective correction is computed as a sum of two components, proportional and integral:
overallDiscrepancy = proportionalGain * discrepancy + integralDiscrepancy
where integralDiscrepancy
is computed as:
integralDiscrepancy = integralForget * integralDiscrepancy + integralGain * discrepancy
proportionalGain
, integralForget
and integralGain
are constant parameters of the integral RC filter. In the standard RC, proportionalGain = 1
, and integralGain = 0
. In simple control theory terms, standard RC can be viewed as a proportional (P) controller trying to reduce modeling error (discrepancy
). Integral RC adds an integral (I) action to this control loop. In addition to the above basic math, safety provisions (integration resets and limits) are included to minimize chances of over-correction.