These are chat archives for nightscout/intend-to-bolus

24th
Jan 2015
Dana Lewis
@danamlewis
Jan 24 2015 00:51
+1 @waaronw! Can't wait to see that (control of meter data)
Ben West
@bewest
Jan 24 2015 00:52
:+1: I'm hopeful we can even bless old devices with ability to send meter data to pump
so annoying for vendors to get to choose weird parts of formulary, hear all the time from people having trouble getting both dexcom and medtronic
diabeticgonewild
@diabeticgonewild
Jan 24 2015 01:22

So, while I am programming the mathematical models for the AP project in C++, a (nonlinear) model predictive control, which is basically a complex algorithm that adaptively solves for the proper insulin dose, needs to be present. Although there is an "open-source" option (see: http://www.nonlinearmpc.com/ ), MATLAB is known to engineers (and engineering students) as the industry standard, and is used in all sorts of environments, including refineries.

The good news is that both options can be used, individually (not in tandem). MATLAB runs C++ code, so I will still continue to program in C++. However, choosing to use C++ absolutely requires numerical methods to solve for solutions, instead of symbolic math (approximations--somewhat disadvantageous--but less processor intensive), which is less convenient, but I don't think it will be much harder to implement.

A MATLAB license for a single user, with my intents of use, costs ~$2000 (super-ouch!), but I know this is the way to go, even though implementing all of this is going to be super expensive. But, it is for my health, and I have a complicated medical situation and MATLAB is trusted in risky environments all the time.

diabeticgonewild
@diabeticgonewild
Jan 24 2015 01:27
Without going into all sorts of complex information, this throws out the possibility of any AP stuff going on without a 3G/4G/LTE/whatever network. However, in restricted environments, such as on airplanes, I believe "tablets" are allowed, and a maxed out tech spec Microsoft Surface PRO might be able to handle the task.
With MATLAB installed on it, that is.
Or I guess with that C++ nonlinear MPC library, but I guess I am slow tonight to realize that.
Chris Oattes
@cjo20
Jan 24 2015 01:47
if you need an i7-class machine to run it, it's going to start to get quite expensive
diabeticgonewild
@diabeticgonewild
Jan 24 2015 01:52
yeah, that's why I am doing it in the cloud. An i5 likely could handle it but it depends on the processor used and memory allocation and stuff like that.
Chris Oattes
@cjo20
Jan 24 2015 01:56
my gut feeling is that it shouldn't take that much computation to work this out
diabeticgonewild
@diabeticgonewild
Jan 24 2015 01:58

Also, something not expected...I was intending on running MATLAB in the cloud on the Amazon EC2 platform, which is pretty solid. However, I knew that in order to use the Model Predictive Control Toolbox, that I would have to get a MATLAB Distributed Computing Server license, among other things. I was anticipating that to be no big deal. I literally just found out that even for my intended use that it would cost thousands upon thousands of dollars for use.

I have a student license for MATLAB with access to a bunch of toolboxes (I really only need the Model Predictive Control Toolbox, technically), so I guess I will be hosting my server in the cloud from my house, for personal use. Obviously I have to have constant uptime, but I am pretty much always at home so I am not too worried. FWIW, MATLAB is $200 for strictly "personal" use.

Chris Oattes
@cjo20
Jan 24 2015 01:58
or, rather, if you're trying to get it so accurate that it requires a 4 core 3.3GHz to compute quickly enough, then your solution will probably be below the noise floor of diabetic control
diabeticgonewild
@diabeticgonewild
Jan 24 2015 01:58
My old AP project takes like 30 seconds to solve on a 2010 i7 processor. Also, when you use numerical methods, the solution has to be solved for iteratively, so it is very computation intensive.
Chris Oattes
@cjo20
Jan 24 2015 01:59
matlab really isn't fast though
diabeticgonewild
@diabeticgonewild
Jan 24 2015 01:59
That is in MATLAB, on a Mid-2010 i7 2.66 GHz processor, 4 GB ram.
Chris Oattes
@cjo20
Jan 24 2015 02:00
I know. Matlab really isn't fast.
diabeticgonewild
@diabeticgonewild
Jan 24 2015 02:00
Well, numerical methods is worse, and that's the only way if anyone wants it to be open-source.
Well, of course, MATLAB is an IDE.
Chris Oattes
@cjo20
Jan 24 2015 02:01
I'm not sure that there isn't enough noise in blood sugar data (even if CGMs were perfect) that the output wouldn't be any more useful than a simpler model
diabeticgonewild
@diabeticgonewild
Jan 24 2015 02:01
But numerical methods is much more computation intensive. The only other option (which is not an option if it's going to be open-source) is solving symboliclly, which provides an approximate solution.
Ross Naylor
@rnpenguin
Jan 24 2015 02:02
simple is the way to go
diabeticgonewild
@diabeticgonewild
Jan 24 2015 02:02
Hey, I am using the models from Cambridge. I think they know what they are doing. Roman Hovorka's work is used in critical care units too, so I trust their models.
Chris Oattes
@cjo20
Jan 24 2015 02:03
and unless you're dragging a lab around with you, any BG results you plug in to the algorithm will have, what, 10% error at best?
the minimum standard is 20% IIRC
diabeticgonewild
@diabeticgonewild
Jan 24 2015 02:03
It's not as complex as you think it is. And if you want simpler, I have the old models programmed in MATLAB from a 2008 model from Hovorka on a sliding mode controller (SMCs are no longer used).
Ross Naylor
@rnpenguin
Jan 24 2015 02:04
hovorka model can be simplified down with quite ease and does not require much processing power
diabeticgonewild
@diabeticgonewild
Jan 24 2015 02:04
Using deconvolution methods the sensor error can be brought down to roughly 8.8% in clinical settings.
@rnpenguin , modifying them puts the potential of getting more fluke values, unless of course you are an applied mathematician simplifying the models.
Chris Oattes
@cjo20
Jan 24 2015 02:08
All I'm saying is that it seems like it might be a bit of a waste when none of the input to the system is as accurate as the data the models are based on
diabeticgonewild
@diabeticgonewild
Jan 24 2015 02:10
The problem with the AP was that the sensor error could not be modeled, up until this past year--mid 2014, and a Gaussian normal distribution with zero mean and unit covariance was used to model the error, which obviously is wrong, as blood glucose values are skewed in the upwards direction, even in completely healthy individuals.
*used in the past
Scott Leibrand
@scottleibrand
Jan 24 2015 02:36
You're overcomplicating this. Inputs have at most 2 significant digits of accuracy. Output precision is limited to 2 significant digits. You get input data every 5 minutes. You could calculate the solutions to that precision with pen and paper faster than you need to.
diabeticgonewild
@diabeticgonewild
Jan 24 2015 02:38
Not really, the numerical methods have to converge on a solution.
It is an iterative process.
Scott Leibrand
@scottleibrand
Jan 24 2015 02:43
Then the numerical methods you're using are unnecessarily complicated. I do this with simple arithmetic and a bit of algebra. There was a tiny bit of calculus involved in deriving the quadratic IOB formulas, but that only had to be done once.
diabeticgonewild
@diabeticgonewild
Jan 24 2015 02:45
Yeah, that's what you are using. I am using
something else. And I have programmed these models, in a general sense, in the past. I know what I have to do.
Scott Leibrand
@scottleibrand
Jan 24 2015 03:59
fair enough
Toby Canning
@TC2013
Jan 24 2015 05:04
Wow, we don't use math at all at our house. We just make wild ass guesses--no need for any of that complicated stuff!
And we eat lots of cinnamon too...
diabeticgonewild
@diabeticgonewild
Jan 24 2015 05:06
yeah, well I gotta do what I gotta do. I will finish.
Haha
Dana Lewis
@danamlewis
Jan 24 2015 06:10
@tc2013 as you should ;) (the cinnamon, that is!)
Ben West
@bewest
Jan 24 2015 06:11
:+1: re cinnamon
Sulka Haro
@sulkaharo
Jan 24 2015 10:11
Lots of people say cinnamon helps. Is the reason known? We started supplementing zinc and have now settled at around 30% less insulin needed on daily basis. Almost all the postprandial rapid glucagon raises have disappeared from meals consisting of low carbs / slow GI.
Ben West
@bewest
Jan 24 2015 10:31
cinnamon tastes much better than zinc
Sulka Haro
@sulkaharo
Jan 24 2015 10:31
Hey big request to @jasoncalabrese @bewest and @scottleibrand - there seems to be multiple efforts to clear the cgm-remote-monitor codebase up so it's easier to manage multiple devs, done by people with no commit right to the main repo. It's currently pretty frustrating to maintain pull requests to be mergeable - I'd love to help develop the software but with unclear process for how pull requests are managed and needing to do manual merges to keep up to date is a bit too much. What I'd like you guys to do is make a clear call on how the code cleanup will happen / what tech will be used and who'll drive that.
@bewest I found chewable zinc pills! But yes, cinnamon is awesome tasting. :)
Jason Calabrese
@jasoncalabrese
Jan 24 2015 18:35
@sulkaharo request heard, it's pretty clear that if more people are going to be involved we need to make things more modular and get some tests in place for the client. Also I'd like to move towards making lots of the iob-cob features enableable the mainline so the diff between mainline and iob-cob isn't so big.
With that new dexcom receiver with share coming out soon I think lots (most?) of the less technical crowd will leave Nightscout for Share, and since the FDA said we're not in compliance maybe we should be more aggressive in pushing the limits in the mainline anyway.
Sulka Haro
@sulkaharo
Jan 24 2015 18:40
👍
Ben probably has some insight on whether the class II assignment paves way for some level of official sanctioning
Ben West
@bewest
Jan 24 2015 19:19
@sulkaharo I'm preparing some docs, basically "dev" is our main branch that is actively being worked on
I work with a lot of other branches to help keep it clean
Chris Oattes
@cjo20
Jan 24 2015 23:12
@jasoncalabrese @scottleibrand The results of that 'else' change are really odd O.o
Jason Calabrese
@jasoncalabrese
Jan 24 2015 23:18
I was surprised to see that
Chris Oattes
@cjo20
Jan 24 2015 23:23
it shouldn't ever get to that path anyway, because of if(treatment.created_at < time) { on line 1326
Chris Oattes
@cjo20
Jan 24 2015 23:52
@jasoncalabrese sorry, I can't run the code myself, but could you try putting document.write(minAgo) just after the variable is defined and see what it spits out?
ah, nevermind