-
Notifications
You must be signed in to change notification settings - Fork 1.1k
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
Problems with LinearTrapezoidInsulin.java [Incorrect Boundary Conditions] #1200
Comments
GM jamorham/gruoner. I was looking at the java code and I believe we can directly use the uncorrected time which simplifies the code (uncorrected time is what I used in my derivation directly and accounted for "onset" explicitly.. I believe "time" is a local variable and so should not affect other modules. please confirm. I am attaching the zipped file that has the updated equations. LinearTrapezoidInsulinUpdated.zip Thanks |
@peeyes-dev
did i missed something? the fourth one is a matter of personal preferences. As iActivity between injection (time zero) and onset is zero, there is no effect on BG-prediction when assigning 1.0 to IOB. The only effect (currently) is on the GUI as time "when injection becomes activate" is visible (marked as the solid green line suddenly rises). We can change this behaviour when community wants to (or when we get other effects, maybe something related to accumulation of repeated / regularly injections of the same profile which has be seen in clinical studies with very long acting basal insulin profiles) major root cause of our identified issues one to three is that the algorithm calculating IOB and iactivity has been completely changed. the "old" algorithm needed a really stepwise schema to calculate iActivity - the new one has a formula to calculate it and thus doesn't need it. So the "old" one has a one step decay (5 minutes) before "time" and that's a (lets say) timeshift. As a result treatments.ioBForGraph_new starts exactly one timeslice before "time" of the "old" one and the new algorithm has to compensate that. So we "see" a timeshift (of currently 5 min) between the output of the "old" and the "new" one. Coming back to our issues 1 and 2: So just u'r second issue seems to be really important as when we want to define onset's not only a multiply of stepsize (timeslice) we have to change calculation (and maybe algorithm too). BUT at first lets close u'r other three issues....... (and let me think about an equation when we want such onset's) |
Thank you for the feedback and explaining the underlying reasons for the quirkiness that I was observing. You are absolutely correct with 1 and 2. If the “peak” and “duration” time can be timeshifted to account for “onset” in insulin-profiles.txt to address 1 and 2. Basically, if all times have the same datum (onset), the equations become consistent but because the stepwise schema, it may still have the issue, but may be less pronounced. It was NOT clear to me to whether the timeshift has already been accounted for in the insulin-profiles.txt and that is part of my confusion. If times are already timeshifted for onset, and if a comment can be added to insulin-profiles.txt to help With regards to 3, again it is only for consistency, as the value is so close to zero, it is NOT going to impact anything. I was using it as a check for my derivation, to ensure it is indeed zero at the end of “duration”. The java code actually sets the value to zero beyond “duration”. The 4-th item until “onset”, activity is zero and hence, the IOB can be fixed at 1.0 and it is a boundary condition that we use in the derivation. Again it is not going to impact any calculations. May be just the insulin depletion curve will start immediately from the treatment instead of from the onset time. Let me know if you need any help. On a site note, I am in the process of deriving the equations for NPH which someone pointed out has two peaks, although I am very interested in Tresiba functionality. Thanks. |
regarding u'r fourth issue: as said, it is a matter of personal preference. For me an information when injection takes action is more important than a "correct" line (correct in meaning: whats the semantics of "insulin-on-board" - when its injected it is "on board"). Btw. the time of injection is also shown as the injection/treatment icon..... i don't know how to define a comment in a JSON file, so i will write a comment in InsulinManager. Just to store upcomings of our discussion. i also experienced with profiles having 2 peaks (@stephencmorton also experienced with curves of 4 order) but currently such precisions aren't needed as we can't calculate influence of different carbs, sporting activities and illnesses. "Prediction errors" are mostly caused by not existing (or totally undifferentiated) influencers of BG value not by imprecise insulin profile curves. I'm afraid even the missing consideration of the accumulation effect has more impact on BG-prediction errors than this "curve of fourth order". Btw. i have no f..cking glue how to model these accumulation or concentration effects described in clinical studies on Toujeo (https://www.monitor-versorgungsforschung.de/news/nachhaltigere-blutzuckerkontrolle-unter-toujeo-im-vergleich-zu-lantus) and Tresiba #1153 |
@stephencmorton do you also have an interest in this issue? |
Oh, I meant to look at it but then I forgot. There wasn't an online diff, I had to download the file to diff it manually and that's when I forgot. I'll try to have a look tonight. |
@jamorham, Yes, @peeyes-dev is absolutely right, and his updated calculations look correct. |
@stephencmorton |
As a meta-comment, although I've been a big fan of this feature in general, it is not really clear who would ever use it for long-acting insulin. Rapid acting insulins, absolutely, yes it makes sense. But for long-acting... Longer-acting insulins are usually used, at least in part, as basal insulins. Generally you do not record basal insulin and your basal-IOB and account for basal in your I:C ratio. So you generally do not want them in your IOB curves and messing with your xDrip+ data. For me, my son uses NPH as a basal+delayed-bolus. He can take NPH at breakfast time and it boluses for lunch, avoiding the need to have an insulin pen at school. But some of that NPH is basal too. So the only way to make it useful for me was to make a sort of custom NPH curve in the json file that subtracted some of that basal and I compiled it just for me. And I do not use that normally, it was just for the Christmas holidays when schedules and eating were very variable and it was very hard to keep track of COB and IOB. During school, everything is like clockwork. All that to say I'd curious if there are any normal real valid use-cases for this feature and long-acting insulins. |
Thanks for your insight. You are correct @stephencmorton about this feature, in its current form, will not be as useful for long term insulin as it is for rapid/short acting insulins. Even now, I am only using Toujeo option to just log my Tresiba dose, and not for anything else. I was just plotting to test my equations and see the impact on all types in my excel file and to check whether transitions are continuous and provided as supporting evidence to help As you might have noted, in my write-up, I did observe that correction had more impact on Humalog than long-acting insulin and that disparity is a function of both large onset value and short life. |
…e out issue NightscoutFoundation#1200. Please note Android Studio issues a warning that "public LinearTrapezoidInsulin" could be become "private LinearTrapezoidInsulin". Please do the needful
…e out issue NightscoutFoundation#1200. Did a non-functional correction to if construct for Activity. Please note Android Studio issues a warning that "public LinearTrapezoidInsulin" in (Line 16) could be become "private LinearTrapezoidInsulin". Please do the needful
Linear Trapezoid Equations to Close out #1200
@peeyes-dev |
See my response to your comments on #1252. I do not spot any error, please do check the script against implemented equations in the pull request. wxMaxima does not provide a good view of the multiplication symbol. Here is the notepad version that pasted into wxMaxima. onset:10; |
for the heck of it, i set onset to zero, as you indicated, and still my equations holds good and sum from last line is spot on 1.0. |
What is the status of this issue please? |
Closing due to inactivity |
Hi jamorham/gruoner
I found few problems with the LinearTrapezoidInsulin.java equations because the value of “onset” has not been properly accounted for in applying the boundary conditions during integration.
Having said that, the impact of the error is a strong function of the numerical value of the “onset” and the life of the insulin. Larger value of onset and shorter insulin life seems to have strong impact. Also, as implemented, the IOB value at transition points do not match, you can actually see with Toujeo, you can see a kink (see excel file).
Its effect on affect rapid/short acting insulins like Fiasp is very small but more pronounced for long acting insulin, in particular, Toujeo which has a life of 180 minutes it is very noticeable (see the attached excel file). Even for Humalog, you can see the difference, which has an onset of 10 minutes, it is noticeable because of its life is only 180 minutes.
Also, I believe, IOB should be set to 1.0 for time between the dosage time and onset, current implementation is setting to zero.
As “onset” is subtracted from "time", I believe we need compare the corrected value of t1, t2 and t3, i.e. after subtracting “onset” to match the actual profile [assuming t1, t2 and t3 are uncorrected].
I used the following criteria to ensure that my derivations are correct and consistent.
(a) At each of the transition points, the IOB should remain the same (current implementation it does not).
(b) At the end of t3, IOB should become zero (current implementation it does not).
You may want to evaluate whether defining intermediate variables for the corrected values “t1 – onset”, “t2 – onset”, and “t3 – onset” is beneficial computationally.
Unfortunately, I am new to GitHub community (and to java) and have not mastered the committing process and hence am providing a text file with the modified equations, as I can NOT attach a java file here. I am also attaching an excel file that compares predictions from new equations and current xDrip+ implementation.
If you want me to upload the derivations, I am more than happy to provide scanned copies of my derivations.
Thanks
LinearTrapezoidInsulin PS.txt
insulin-profiles-xDrip-compare.xlsx
The text was updated successfully, but these errors were encountered: