Join GitHub today
GitHub is home to over 28 million developers working together to host and review code, manage projects, and build software together.Sign up
Exponential curves #568
Implements #544 - needs testing help, do not merge until confirmed to work.
NOTE: consider testing this extremely experimental! This code branch implements the new exponential curve model for insulin activity. This is a fairly big change compared to the old bilinear model, so if you do participate in the testing of this feature, assume you will need to monitor your BG closely and might need to adjust your profile to fit.
The code now supports three new configuration variables in preferences.json:
In order to use the rapid-acting or ultra-rapid curves, your pump must be set to 5 hour DIA, or longer. 6 hours is recommended as the starting point.
The underlying mathematical model is developed by @dm61.
Below are the activity and IOB graphs at various DIA and peak values
Both Fiasp and Novorapid curves are modeled after 5 hour DIA (compared to 3 hour default DIA for the old model). Due to the curve shape, the insulin activity contribution at the 5 hour mark is extremely low but should model the actual insulin tail more effectively than the old model, so it'd be extremely beneficial to get testing help from users who currently have their DIA set to a lower value (3 or 4 hours), who would set their DIA to 5 hours with the new curve model and report back if OpenAPS correctly keeps the basal rates in balance.
For Fiasp users, please start testing with DIA = 6, curve = "ultra-rapid" and do not set insulinPeakTime. If it looks like Fiasp is peaking for you faster or slower than OpenAPS expects (similar to your DIA being shorter or longer in the old parlance), please adjust insulinPeakTime by a small amount (such as 5 minutes) from the default of 55.
Note on Fiasp
Multiple users have reported cab take up to a month for the body to fully to adapt to Fiasp. If your body needs to adapt, you're likely to see the first few days post adopting Fiasp to work well and then hit a sudden resistance period, where your total daily dose will increase substantially and you might need to adjust every setting in your profile (ISF, carb ratios, basals). Cause for this is unknown but this is expected on some individuals and this doesn't indicate the loop is behaving unexpectedly.
This has nothing to do with this PR per se, but I have noticed a recent performance regression that I noticed when I started using the exponential curves.
I had gone a while between loop updates prior to implementing the exponential curves so this isn't necessarily the cause, but
oref0-meal has gone from returning almost instantaneously to requiring well over a minute to execute in my loop. I don't know whether it's because the IOB formula is now significantly more resource-intensive to calculate (non-integral powers are computationally expensive) or because
oref0-meal is operating on significantly more data with the merged pump history or both, but it is leading to a non-trivial amount of extra load on my Edison and I can no longer loop through the night if I forget to plug in at night. SMB boluses are also coming in minutes later now, which should lead to more control instability. It's small, but small things add up.
It's a little tough seeing what changed in the tests through Github's interface. Did you just add a couple tests?
This appears to address the concerns that I had, aside from verifying that the peak-scaled and normalized IOB and activity formulas correspond with eachother. Intuitively they look like they should, but I haven't yet done the math.
Given @sulkaharo 's investigations into the maths of the existing bilinear curves, is it worth leaving out the bilinear option and simply releasing 0.6.0 with the updated "rapid" and "ultra-rapid" curves? We know that these scale safely and produce good results, and it will remove the broken maths for bilinear in the process.
I'm running exponential curves branch on a rig with node 0.10.29, updated to the latest versions of the code. Preferences are:
And the loop is running correctly. See logs:
Aug 13, 2017
does this change include a finer control over DIA (e.g., 4.5 hours vs 4 or 5)? or do you think i will no longer want that after using the new curves? right now 4 has trouble giving lows overnight and 5 doesn't quite get us down to target overnight, i'm hoping a longer autotune on 5 will fix that but not sure...
To my eye a peak of 90 and dia of about 8h approximates R well enough, but there a lot of other assumptions being made in the system about insulin activity that make it a bigger task than it immediately appears to use "R." I suspect there aren't many (any?) users using OpenAPS with regular insulin.
I ran the
Do people use 0.6.0 with this