IOB-COB math

303 views
Skip to first unread message

Bert Berla

unread,
Mar 20, 2015, 2:32:59 PM3/20/15
to opena...@googlegroups.com
Hi all,

I set up my IOB-COB website and started playing around.

My profile is:

"carbratio": 16,
"carbs_hr": 30,
"dia": 3,
"sens": 80

I noticed that I can input a zero temp basal as a negative bolus, so I tried it. I put in -0.4, which should raise my BG 0.4 * 80 = 32 mg/dL, but the purple line on my site went up >50 mg/dL over the following 3 hrs. When I input a 0.4 unit bolus to offset, the line went back to flat, and when I updated my sens to 40 in my profile, the change was half as much. So everything seems to be working, but there's something I'm not understanding about the math.

I know I can find this out for myself if I knew where to look on github, but I don't know where to look on github. Can someone explain the mismatch I'm seeing and/or (even better) show me where to look on github to better understand the calculations?

Also, the IOB-COB site SAYS I need raw data, but I'm currently uploading through share so I don't have any. The values are set to on in my azure site, so I don't know if perhaps that's causing wonkiness or if that's not actually a requirement.

Scott Leibrand

unread,
Mar 20, 2015, 3:25:50 PM3/20/15
to opena...@googlegroups.com
That sounds like a bug I fixed last month: https://github.com/scottleibrand/cgm-remote-monitor/commit/1b77a1078f379e1f3524b9495b0d3733523dc07b

Does your branch of iob-cob have that commit?

-Scott

--
You received this message because you are subscribed to the Google Groups "OpenAPS Dev" group.
To unsubscribe from this group and stop receiving emails from it, send an email to openaps-dev...@googlegroups.com.
To post to this group, send email to opena...@googlegroups.com.
Visit this group at http://groups.google.com/group/openaps-dev.
To view this discussion on the web visit https://groups.google.com/d/msgid/openaps-dev/06ebd689-0cff-4276-b3c6-451adab71bc3%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Bert Berla

unread,
Mar 21, 2015, 1:54:11 PM3/21/15
to opena...@googlegroups.com
So, it looks like there are a number of differences in our IOB-COB math. I'll spend some time reading both files and see what else are the differences, and try to understand it better overall.

Id love to build a simulator to play around with and try to get the predictions to look more like the curves my intuition tells me to expect. I might just do it in Excel or something, though.

Another question - when I turn on the look back in Nightscout, from what point in time are those blue dot predictions generated?

Bert Berla

unread,
Mar 23, 2015, 3:20:53 PM3/23/15
to opena...@googlegroups.com
Is there a version of cgm-remote-monitor that contains the math currently being used in #DIYPS or #openAPS? Some things I can't seem to find but that seem important are extended boluses and temp basals, for example. Perhaps I'm just looking in the wrong places. These seem important to me for testing during the 'open loop' phase, but perhaps they aren't so important during closed-loop operation.

Bert

Scott Leibrand

unread,
Mar 23, 2015, 6:19:14 PM3/23/15
to opena...@googlegroups.com
So the math in my personal fork of wip/iob-cob has code to take temp basals from the pump and display them as microboluses, the same way DIYPS does.  Neither DIYPS nor Nightscout currently supports extended boluses, but since they're functionally identical to high temp basals, it would be fairly easy to add them.  (We just don't use extended boluses ourselves, in favor of lots of DIYPS-recommended 0.5U boluses for meals.)

Also, if you're trying to replicate the OpenAPS math, that is actually far simpler than the math in Nightscout.  Nightscout wip/iob-cob includes both an every-5-minute breakdown of IOB/COB decay, as well as an extra liverCarb overlay that models a delay in carb absorption when insulin activity is high, to better predict the effect of liver carb uptake.  OpenAPS, OTOH (and the closedloop portion of DIYPS) simply do the bolus calculator math to determine how BG will "eventually" turn out, without concern for the intermediate predictions of how it'll get there.

I also just had another request to write up the actual math that OpenAPS will use, perhaps as a flowchart or a set of manual steps that can be implemented with pen and paper (or coded into whatever language you want).  So if I end up doing that, I might have something more for you soon...

-Scott

--
You received this message because you are subscribed to the Google Groups "OpenAPS Dev" group.
To unsubscribe from this group and stop receiving emails from it, send an email to openaps-dev...@googlegroups.com.
To post to this group, send email to opena...@googlegroups.com.
Visit this group at http://groups.google.com/group/openaps-dev.

Brandon Berne

unread,
Sep 3, 2015, 4:22:41 PM9/3/15
to OpenAPS Dev
Mr. Leibrand a question regarding iob-cob decay as I've no hardware just enjoying trying to crunch numbers atm.

Initial values and assumptions:
1u per 5g consumed
1u will drop 25mg/dl
5g will raise 25mg/dl or simply 1g:5mg/dl

So consuming 26g of carbs with initial BG value of 121, I expect 130 mg/dl rise to a value of 251 at the end of the test. Rise began 30 minutes after carbs taken.
Peaks 90 minutes after consumed
Initial carb intake 7:01 am. Uptick began at 7:27am going from 110mg/dl to 117 mg/dl


26 initial carbs-(60 minutes measured – 30 for initial rise divided by 2 mg/dl rise / min averaged equals out to 11 carbs / hour
 However if 26-(90-30)/2=-4 (no ketones in urine haha)

Thanks for everything!


Was I to measure entire time I was rising or just initial uptick? I was a bit confused at that point. Using Miss Leibrand (And congratulations on the wedding and the closed loop that's impressive!)

Scott Leibrand

unread,
Sep 3, 2015, 5:23:44 PM9/3/15
to opena...@googlegroups.com
On Thu, Sep 3, 2015 at 1:22 PM, Brandon Berne <brando...@gmail.com> wrote:
Mr. Leibrand a question regarding iob-cob decay as I've no hardware just enjoying trying to crunch numbers atm.

Initial values and assumptions:
1u per 5g consumed
1u will drop 25mg/dl
5g will raise 25mg/dl or simply 1g:5mg/dl

So consuming 26g of carbs with initial BG value of 121, I expect 130 mg/dl rise to a value of 251 at the end of the test. Rise began 30 minutes after carbs taken.
Peaks 90 minutes after consumed
Initial carb intake 7:01 am. Uptick began at 7:27am going from 110mg/dl to 117 mg/dl

Wait, you only rose 7 points from 26 carbs?  Or is that a typo?
 


26 initial carbs-(60 minutes measured – 30 for initial rise divided by 2 mg/dl rise / min averaged equals out to 11 carbs / hour
 However if 26-(90-30)/2=-4 (no ketones in urine haha)


If your carbs took 1 hour to absorb after the initial 25 minute delay, then that should be 26 carbs/hour, right?
 


Thanks for everything!


Was I to measure entire time I was rising or just initial uptick? I was a bit confused at that point. Using Miss Leibrand (And congratulations on the wedding and the closed loop that's impressive!)


Thanks!  It's still Ms. Lewis, though: we didn't want to have to re-key everything on new unique identifiers. ;-)

-Scott
 

On Monday, March 23, 2015 at 6:19:14 PM UTC-4, Scott Leibrand wrote:
So the math in my personal fork of wip/iob-cob has code to take temp basals from the pump and display them as microboluses, the same way DIYPS does.  Neither DIYPS nor Nightscout currently supports extended boluses, but since they're functionally identical to high temp basals, it would be fairly easy to add them.  (We just don't use extended boluses ourselves, in favor of lots of DIYPS-recommended 0.5U boluses for meals.)

Also, if you're trying to replicate the OpenAPS math, that is actually far simpler than the math in Nightscout.  Nightscout wip/iob-cob includes both an every-5-minute breakdown of IOB/COB decay, as well as an extra liverCarb overlay that models a delay in carb absorption when insulin activity is high, to better predict the effect of liver carb uptake.  OpenAPS, OTOH (and the closedloop portion of DIYPS) simply do the bolus calculator math to determine how BG will "eventually" turn out, without concern for the intermediate predictions of how it'll get there.

I also just had another request to write up the actual math that OpenAPS will use, perhaps as a flowchart or a set of manual steps that can be implemented with pen and paper (or coded into whatever language you want).  So if I end up doing that, I might have something more for you soon...

-Scott

On Mon, Mar 23, 2015 at 12:20 PM, Bert Berla <bert....@gmail.com> wrote:
Is there a version of cgm-remote-monitor that contains the math currently being used in #DIYPS or #openAPS? Some things I can't seem to find but that seem important are extended boluses and temp basals, for example. Perhaps I'm just looking in the wrong places. These seem important to me for testing during the 'open loop' phase, but perhaps they aren't so important during closed-loop operation.

Bert

On Saturday, March 21, 2015 at 12:54:11 PM UTC-5, Bert Berla wrote:
So, it looks like there are a number of differences in our IOB-COB math. I'll spend some time reading both files and see what else are the differences, and try to understand it better overall.

Id love to build a simulator to play around with and try to get the predictions to look more like the curves my intuition tells me to expect. I might just do it in Excel or something, though.

Another question - when I turn on the look back in Nightscout, from what point in time are those blue dot predictions generated?

--
You received this message because you are subscribed to the Google Groups "OpenAPS Dev" group.
To unsubscribe from this group and stop receiving emails from it, send an email to openaps-dev...@googlegroups.com.
To post to this group, send email to opena...@googlegroups.com.
Visit this group at http://groups.google.com/group/openaps-dev.
To view this discussion on the web visit https://groups.google.com/d/msgid/openaps-dev/b2ba6ecb-60e7-4011-bed6-5a0a3d73cc88%40googlegroups.com.

For more options, visit https://groups.google.com/d/optout.

--
You received this message because you are subscribed to the Google Groups "OpenAPS Dev" group.
To unsubscribe from this group and stop receiving emails from it, send an email to openaps-dev...@googlegroups.com.
To post to this group, send email to opena...@googlegroups.com.
Visit this group at http://groups.google.com/group/openaps-dev.

Brandon B.

unread,
Sep 4, 2015, 8:20:08 AM9/4/15
to OpenAPS Dev
Wait, you only rose 7 points from 26 carbs?  Or is that a typo?
 Answer: Yes Miss Lewis indeed a typo! Pardon. There's the spreadsheet I kept.
The math I'm fairly sure is off as the concept was/is still fairly new to me. It took 30 minutes to begin to rise. Peaked at 90 minutes at 222 You're more than welcome to throw my data in for to help get a general idea of an algorithm. I believe I'm mis understanding the math behind it, perhaps I shouldn't have done the bolus and seen how I absorbed the carbs over time?

Thanks again for the response Miss Lewis! Any improvements made to your system yet?
Time CGM Read Meter Carbs
7:01 AM 121 121 26g Carbs
7:07 AM 115
7:12 AM 114
7:17 AM 111
7:22 AM 110
7:27 AM 110
7:32 AM 117
7:37 AM 126
7:42 AM 139
7:47 AM 149
7:52 AM 155
7:57 AM 165
8:02 AM 176
8:07 AM 182
8:12 AM 185
8:17 AM 184
8:22 AM 185
8:27 AM 185
8:32 AM 206 222
8:37 AM 208
8:42 AM 207
8:47 AM 209 210
8:52 AM 195 193
8:56 AM 196
9:02 AM 196 201
9:07 AM 195
9:12 AM 194 217
9:17 AM 203
9:22 AM 200
9:27 AM 201
9:32 AM 201
9:37 AM 200
9:41 AM 198
9:47 AM 197 206
9:51 AM Bolus: 4u Humulog
10:16 AM 200 209
10:31 AM 201 210
11:06 AM 192 210
11:37 AM 188 175
12:22 PM 166 174
Rise/Min 2.00    
Guess @ absorption: =26-(60-30)/2
   







   


Jeff freedman

unread,
Dec 15, 2016, 7:46:16 PM12/15/16
to OpenAPS Dev
I know I am jumping on a dead thread - but I could use some help.  I don't understand why the predictive line in the IOB-COB branch is no longer there.  I have my T1D on a G5, and I have version 9.0 of nightscout running through Share.  


I would like to see the purple line.  The Bolus Wizard does the predictions if I bring it up, but I would still like to see the predictive line as a visual guide, and to help review the sensitivity.  

Any help is appreciated

Dana Lewis

unread,
Dec 15, 2016, 8:55:05 PM12/15/16
to opena...@googlegroups.com
The iob-cob branch was killed a long time ago when it was majorly out of sync with the main Nightscout branches. Now the purple line you see in some people's is from DIY closed loop forecasting (either from OpenAPS, Loop, AndroidAPS, etc.), so you'd have to do some heavy lifting to manually do the calculations for providing the inputs it expects for forecasting the purple line in the modern NS infrastructure. If you're interested in making that happen, you might ping Jason in Nightscout/public on gitter to see if he has any ideas for the most efficient way to achieve that.
To unsubscribe from this group and stop receiving emails from it, send an email to openaps-dev+unsubscribe@googlegroups.com.

To post to this group, send email to opena...@googlegroups.com.
Visit this group at https://groups.google.com/group/openaps-dev.
To view this discussion on the web visit https://groups.google.com/d/msgid/openaps-dev/c1ae2b84-04f0-49b6-ad9c-f8dd828eeb90%40googlegroups.com.

For more options, visit https://groups.google.com/d/optout.


--
Dana Lewis | http://OpenAPS.org | http://DIYPS.org | @DanaMLewis | http://www.linkedin.com/in/danalewis
"Doing something for someone else is more important than anything you would do for yourself."

Sulka Haro

unread,
Dec 16, 2016, 1:59:08 PM12/16/16
to OpenAPS Dev

Adding a plugin that implemented COB modeling should’t be too difficult, so if someone wants to work on this, that’d be great.

Another big reason the branch was dropped was the COB model was deemed quite challenging to make work well - carb absorption is extremely different even for the same person depending on the glycemic index of the meal and the potential feature list to make the system generic enough to allow data entry that’d allow accurate modeling started ballooning hugely.

OpenAPS now uses an algorithm that models the absorption by looking at the effects of IOB after meals to estimate if there’s carbs left anymore, which automagically works for everyone; if we figure out how to visualize _this_ in Nightscout, that’d be amazing.

sulka

Scott Leibrand

unread,
Dec 16, 2016, 2:51:14 PM12/16/16
to opena...@googlegroups.com
Yeah, I think Sulka has it right.  We moved away from basing predictions on the our linear carb decay function (as that can be highly inaccurate for some people) and instead re-implemented the purple line predictions based on the OpenAPS Advanced Meal Assist algorithm's adaptive carb absorption estimates.

While it might be possible to resurrect the old wip/iob-cob branch, there were a lot of things with that which didn't quite mesh with the rest of Nightscout, so I'm not sure that's practical any longer.  

I wonder if the fastest way to get this working in your case (not using a Medtronic pump) might be to set up an instance of oref0 (running on a VM or something) that just pulls BG and treatment data from Nightscout and uploads the AMA predictions...

-Scott

--
You received this message because you are subscribed to the Google Groups "OpenAPS Dev" group.
To unsubscribe from this group and stop receiving emails from it, send an email to openaps-dev+unsubscribe@googlegroups.com.
To post to this group, send email to opena...@googlegroups.com.
Visit this group at https://groups.google.com/group/openaps-dev.

Tim Omer

unread,
Dec 17, 2016, 3:07:42 AM12/17/16
to OpenAPS Dev
Hey all,

Just to add my feedback, I use the old COB calc from nightscout in HAPP to see future COB. I agree it's not that accurate, but I find it very helpful to get an idea of COB.

Interested to take a look at oref0 forecasting when time allows.

Reply all
Reply to author
Forward
0 new messages