#simPancreas updates May 2015

My account of the events that have led to this latest version of the project

Two Months have gone by since the last major update to simPancreas. The actual state for simPancreas has been very challenging for the time invested on it and the testing requirements in order to make sure of its capabilities and limitations.

During this release, I went through LOTS of different hypotheses that I developed / tested / discarded in order to select the ones I felt most comfortable with.

No. There is no public repository for my code yet. I still treat them as releases for myself. Before I am completely convinced I should test something “hands-free” I do lots of manual testing. I treat simPancreas decisions as recommendations and adjust until I know the controller will always make safe decisions. Once I get to that point, I have a release and I start behaving as a test subject.

Here is my account of the events that have led to this latest version:

What did not work!

After starting to test with how the Fuzzy Logic controller behaved with meals and noticing that it worked much better if I maintained a steady amount of carbohydrates intake during the day, I decided it was not the best option at this time for the project. I did not like observing the controller react to small amounts of carbs as if they were larger amounts. ( this lead to idea A )

Since I’ve been logging all of the data generated from the insulin boluses and their effects on BG, I decided to start trying to predict blood glucose levels. I began by analyzing past blood glucose data for last hours and decided a polynomial would be the best model ( to my mathematical possibilities ).

I started by determining the degree of the polynomial from the past readings and then trying to predict where it would get. I tried everything from a linear, quadratic, cubic, quartic, quintic, sextic, septic and their combinations in order to determine the best prediction frankenstein curve.


I even tried to generate Hermite Polynomials, but things got ugly. I ended up with 400 – 2000 mg/dl predictions but I learned from this something very interesting! ( this led to idea B ).

After spending a couple of weeks with predictions and Fuzzy Logic combinations, I got frustrated and decided to stop testing and developing simPancreas. I decided to rest and dedicate to other stuff to help clear my mind and then get back with a fresh positive attitude 🙂 ( this led to idea C ).

What did work

I came back after thinking about how it was not working and how I could make it work and started with a couple of ideas.

Idea A
Do not allow simPancreas to act on its own for meals. Yes it hurt like nothing to accept I was not going to achieve this YET ( I am now working on a model that will! ) but I had to eliminate variables in order to have something I could better understand and control. This version was going to have manual boluses and then adjust for any over / under dosing.

Idea B
Our blood glucose cannot jump from 150 to 20,000 mg/dl in five minutes. I may have accidentally ended up proving this fact throughout my years with T1D and a couple of meals where I forgot to bolus myself. So my question was:

If BG cannot jump from 150 to 20,000 mg/dl what is the acceptable maximum level it can / should jump?

I began testing and observing my data and ended up determining that in my personal case, my BG cannot jump in higher than 15mg/dl increments within 5 minutes. It does now and then, but I have learned with time that when I get those types of jumps from my CGM data, something is not ok.

Idea C
Why do I get from 150 mg/dl to 100 mg/dl sometimes with 1U of insulin and other times I don’t? I totally understand this happening on different times of the day. But this had me thinking…

What if our insulin sensitivities curve is super dynamic throughout the day(s)?

I found out it is… at least for me. I validated this by reading this paper.

A Shiny New Controller

With these ideas I was able to generate a controller that takes into account three elements:

BG prediction. It considers the maximum amount of BG change that is normal for me between CGM readings and gives me a prediction for the next 20 – 30 minutes based on speed & acceleration with a variation of about 5 mg/dl which I think is still a LOT.

The Acceleration Curve ( I wrote about that curve on this post ) is still very important if I want to successfully be ahead of the BG curve.

Insulin On Board (IOB). I could have inserted this variable from the beginning of simPancreas, but I did not and I have no idea why. The main tool I used here to determine IOB was glucoDyn from ( We are working hard with on a daily basis, please check it out and give us feedback! )

Varying insulin sensitivities. Remember I told you I log everything. I am able to determine insulin sensitivity throughout the day with different BG levels. This has helped me determine the most adequate insulin treatment for the next 3 hours.

Treatment simulation

If sensitivities vary depending on the time of day / day of week / blood glucose levels how can you determine the best treatment?

No wonder why we have awful curves sometimes. We are always considering an average sensitivity factor!

I decided to build a simulation that would test for the next three hours the most adequate amount of insulin to give, according to varying sensitivities. The trick is that as the bolus size increases, IOB curve changes and BG decrements begin to variate and sensitivities change.

This is an actual Vine on the simulation on simPancreas.

Results ( In Progress )

The first test I did was to discard “good” days in my treatment. You know, those days where BG behaves perfectly and you have no idea why but it looks and feels great. I just did not want that to be confused with simPancreas acting on my BG levels.

I have tested for a couple of days now and although I still have postprandial spikes they are within very good limits.

Each day, at the end I sat down and worked on updates to the different part of the controller.

I added green rows as days I used simPancreas and red rows as days I DID NOT.

All data in mg/dl.

Next steps

I am working on the next release which will include Carbs on Board, still deciding on the way I will input them. Once I achieve that, I will have less guesses estimations to make in order to improve control!

Screen Shot 2015-05-23 at 09.47.39

Don’t forget to check out:
Open and transparent effort to make safe and effective basic Artificial Pancreas System (APS) technology widely available to more quickly improve and save as many lives as possible and reduce the burden of Type 1 Diabetes. This is where I get the bases for IOB & COB on simPancreas.
Not for profit, generating open sourced tools to educate patients through autonomous data visualization around T1D.
The Nightscout Foundation is proud to actively advocate and support open source technology in pursuit of improved options to manage Type 1 Diabetes (T1D)