model predictive control with invariant sets in artificial pancreas for

87
Institutionen för systemteknik Department of Electrical Engineering Examensarbete Model Predictive Control with Invariant Sets in Artificial Pancreas for Type 1 Diabetes Mellitus Examensarbete utfört i Elektroteknik vid Tekniska högskolan vid Linköpings universitet av Andreas Svensson LiTH-ISY-EX--13/4699--SE Linköping 2013 Department of Electrical Engineering Linköpings tekniska högskola Linköpings universitet Linköpings universitet SE-581 83 Linköping, Sweden 581 83 Linköping

Upload: lyliem

Post on 21-Jan-2017

219 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: Model Predictive Control with Invariant Sets in Artificial Pancreas for

Institutionen för systemteknikDepartment of Electrical Engineering

Examensarbete

Model Predictive Control with Invariant Sets inArtificial Pancreas for Type 1 Diabetes Mellitus

Examensarbete utfört i Elektroteknikvid Tekniska högskolan vid Linköpings universitet

av

Andreas Svensson

LiTH-ISY-EX--13/4699--SE

Linköping 2013

Department of Electrical Engineering Linköpings tekniska högskolaLinköpings universitet Linköpings universitetSE-581 83 Linköping, Sweden 581 83 Linköping

Page 2: Model Predictive Control with Invariant Sets in Artificial Pancreas for
Page 3: Model Predictive Control with Invariant Sets in Artificial Pancreas for

Model Predictive Control with Invariant Sets inArtificial Pancreas for Type 1 Diabetes Mellitus

Examensarbete utfört i Elektroteknikvid Tekniska högskolan vid Linköpings universitet

av

Andreas Svensson

LiTH-ISY-EX--13/4699--SE

Handledare: Ravi GondhalekarDepartment of Chemical Engineering, University of Californa Santa Barbara

Isak Nielsenisy, Linköpings universitet

Examinator: Daniel Axehillisy, Linköpings universitet

Linköping, 20 juni 2013

Page 4: Model Predictive Control with Invariant Sets in Artificial Pancreas for
Page 5: Model Predictive Control with Invariant Sets in Artificial Pancreas for

Avdelning, InstitutionDivision, Department

Avdelningen för reglerteknikDepartment of Electrical EngineeringSE-581 83 Linköping

DatumDate

2013-06-20

SpråkLanguage

� Svenska/Swedish

� Engelska/English

RapporttypReport category

� Licentiatavhandling

� Examensarbete

� C-uppsats

� D-uppsats

� Övrig rapport

URL för elektronisk version

http://www.ep.liu.se

ISBN

ISRN

LiTH-ISY-EX--13/4699--SE

Serietitel och serienummerTitle of series, numbering

ISSN

TitelTitle

Modellbaserad prediktionsreglering med invarianta mängder av artificiella pankreas för di-abetes typ 1

Model Predictive Control with Invariant Sets in Artificial Pancreas for Type 1 Diabetes Mel-litus

FörfattareAuthor

Andreas Svensson

SammanfattningAbstract

This thesis deals with Model Predictive Control (mpc) for artificial pancreas for Type 1 Dia-betes Mellitus (t1dm) patients. A control strategy exploiting invariant sets in mpc for bloodglucose level control is developed, to the authors knowledge for the first time. The workincludes various types of invariant sets relevant for the artificial pancreas problem, and dif-ferent ways to incorporate them into the mpc strategy. The work is an extension to the zonempc controller for artificial pancreas developed at University of California Santa Barbaraand Sansum Diabetes Research Institute (Grosman et al. [2010]; van Heusden et al. [2012]).

The evaluation of the proposed control strategy is done in silico in the fda (U.S. Food andDrug Administration) approved metabolic simulator (Kovatchev et al. [2009]). The trialsshow some promising results in terms of more rapid meal responses and decreased vari-ability between the subjects than the zone mpc. An attempt to robust control employinginvariant sets proved to be less promising in the evaluations. The results indicate that thedirect application of known robust control techniques is not appropriate, and that more ap-propriate robust control techniques must be searched for, or developed, more specific to theartificial pancreas control.

Altogether, this thesis pinpoints a possible future direction of artificial pancreas control de-sign, with mpc based on invariant sets.

NyckelordKeywords MPC, Invariant sets, Artificial Pancreas, Type 1 Diabetes Mellitus

Page 6: Model Predictive Control with Invariant Sets in Artificial Pancreas for
Page 7: Model Predictive Control with Invariant Sets in Artificial Pancreas for

Sammanfattning

Det här examensarbetet handlar om modellbaserad prediktionsreglering (mpc)av artificiella pankreas för typ 1 diabetes mellitus (t1dm) patienter. I arbetetutvecklas, till författarens kännedom för första gången, en mpc-strategi med in-varianta mängder för reglering av blodsockernivå. I arbetet ingår olika typer avinvarianta mängder för artificiella pankreas, och olika sätt att införliva dem impc. Arbetet är en utvidgning av den zon-mpc för artificiella pankreas som ut-vecklats vid University of Californa Santa Barbara och Sansum Diabetes ResearchInstitute (Grosman et al. [2010], van Heusden et al. [2012]).

Utvärderingen av den föreslagna reglerstrategin görs in silico i en metabolisk si-mulator (Kovatchev et al. [2009]) godkänd av U.S. Food and Drug Administration.Försöken visar lovande resultat i form av snabb respons på måltider och minskadvariation mellan individer jämfört med nämnda zon-mpc. Ett försök till robustreglering med invarianta mängder visade sig dock vara mindre lovande i utvär-deringarna. Resultaten antyder att en rättfram tillämpning av kända metoder förrobust reglering inte är ändamålsenlig för den här applikationen, och att metodermer relevanta för artificiella pankreas behöver hittas eller utvecklas.

Sammantaget lyfter det här examensarbetet fram en möjlig framtida inriktningför reglering av artificiella pankreas med mpc baserad på invarianta mängder.

iii

Page 8: Model Predictive Control with Invariant Sets in Artificial Pancreas for
Page 9: Model Predictive Control with Invariant Sets in Artificial Pancreas for

Abstract

This thesis deals with Model Predictive Control (mpc) for artificial pancreas forType 1 Diabetes Mellitus (t1dm) patients. A control strategy exploiting invariantsets in mpc for blood glucose level control is developed, to the authors knowl-edge for the first time. The work includes various types of invariant sets relevantfor the artificial pancreas problem, and different ways to incorporate them intothe mpc strategy. The work is an extension to the zone mpc controller for arti-ficial pancreas developed at University of California Santa Barbara and SansumDiabetes Research Institute (Grosman et al. [2010]; van Heusden et al. [2012]).

The evaluation of the proposed control strategy is done in silico in the fda (U.S.Food and Drug Administration) approved metabolic simulator (Kovatchev et al.[2009]). The trials show some promising results in terms of more rapid meal re-sponses and decreased variability between the subjects than the zone mpc. Anattempt to robust control employing invariant sets proved to be less promising inthe evaluations. The results indicate that the direct application of known robustcontrol techniques is not appropriate, and that more appropriate robust controltechniques must be searched for, or developed, more specific to the artificial pan-creas control.

Altogether, this thesis pinpoints a possible future direction of artificial pancreascontrol design, with mpc based on invariant sets.

v

Page 10: Model Predictive Control with Invariant Sets in Artificial Pancreas for
Page 11: Model Predictive Control with Invariant Sets in Artificial Pancreas for

Acknowledgments

First of all, I would like to thank Dr. Ravi Gondhalekar for being a truly excellentsupervisor to me. I really appreciate all discussions we have had, your patience,advice and all challenges you have encouraged me to tackle!

I would also like to thank Prof. Francis J. Doyle III and Dr. Eyal Dassau for takingme up in the group and letting me work on the artificial pancreas project, and allmy fellow Doyle group members for the atmosphere in the lab that made me feelat home. I am also grateful to the people at Sansum for giving me a glimpse ofthe very interesting world of real (i.e., not simulated) patients and trials.

Dr. Daniel Axehill deserves a big thank for initially letting me in touch with Raviand the Doyle group, and for your advice and proofreading of this thesis togetherwith Isak Nielsen.

I would also like to thank Sanna. Although your contributions to this thesis arerather limited, your contributions to my life during this period have been themore important. Finally, I am also very grateful to my family for their supportduring all my years of studies.

Santa Barbara, May 2013Andreas Svensson

vii

Page 12: Model Predictive Control with Invariant Sets in Artificial Pancreas for
Page 13: Model Predictive Control with Invariant Sets in Artificial Pancreas for

Contents

Notation xi

1 Introduction 11.1 Problem formulation . . . . . . . . . . . . . . . . . . . . . . . . . . 1

1.1.1 Background . . . . . . . . . . . . . . . . . . . . . . . . . . . 11.1.2 Objective . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 21.1.3 Methods . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 21.1.4 Limitations . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2

1.2 Outline of the thesis . . . . . . . . . . . . . . . . . . . . . . . . . . . 3

2 Control theory 52.1 Dynamical systems . . . . . . . . . . . . . . . . . . . . . . . . . . . 6

2.1.1 Discrete time state space form . . . . . . . . . . . . . . . . . 62.1.2 Discrete time transfer function . . . . . . . . . . . . . . . . 72.1.3 State estimation . . . . . . . . . . . . . . . . . . . . . . . . . 9

2.2 Model Predictive Control . . . . . . . . . . . . . . . . . . . . . . . . 92.2.1 The standard MPC formulation . . . . . . . . . . . . . . . . 102.2.2 Zone MPC . . . . . . . . . . . . . . . . . . . . . . . . . . . . 12

2.3 Invariant sets . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 122.3.1 Positively invariant sets . . . . . . . . . . . . . . . . . . . . . 132.3.2 Controlled invariant sets . . . . . . . . . . . . . . . . . . . . 152.3.3 Robust controlled invariant sets . . . . . . . . . . . . . . . . 162.3.4 Periodic controlled invariant sets . . . . . . . . . . . . . . . 162.3.5 Maximum invariant sets . . . . . . . . . . . . . . . . . . . . 17

2.4 Mini example of invariant set in MPC control . . . . . . . . . . . . 17

3 Diabetes and the artificial pancreas 233.1 Diabetes . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 233.2 Insulin treatment . . . . . . . . . . . . . . . . . . . . . . . . . . . . 243.3 Continuous Glucose Monitoring . . . . . . . . . . . . . . . . . . . . 243.4 Metabolic system simulator . . . . . . . . . . . . . . . . . . . . . . 253.5 System identification for an insulin-glucose model . . . . . . . . . 253.6 Artificial pancreas . . . . . . . . . . . . . . . . . . . . . . . . . . . . 26

ix

Page 14: Model Predictive Control with Invariant Sets in Artificial Pancreas for

x CONTENTS

3.6.1 Meals . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 263.6.2 Safety systems and hypoglycemia treatments . . . . . . . . 283.6.3 Insulin on board constraints . . . . . . . . . . . . . . . . . . 283.6.4 Night time zone . . . . . . . . . . . . . . . . . . . . . . . . . 28

4 MPC with invariant set constraints for an artificial pancreas 314.1 Invariant sets for the insulin-glucose model . . . . . . . . . . . . . 314.2 Robust invariant set for the insulin-glucose model . . . . . . . . . 32

4.2.1 Measurement errors in the state space . . . . . . . . . . . . 324.2.2 Robustification against measurement errors . . . . . . . . . 334.2.3 Meals . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 344.2.4 Plant-model mismatch . . . . . . . . . . . . . . . . . . . . . 35

4.3 Implementation of set constraints in MPC . . . . . . . . . . . . . . 354.4 In silico trials . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 37

4.4.1 Test protocol . . . . . . . . . . . . . . . . . . . . . . . . . . . 374.4.2 Different controller setups in the trials . . . . . . . . . . . . 374.4.3 Subjects in the trial . . . . . . . . . . . . . . . . . . . . . . . 384.4.4 In silico results . . . . . . . . . . . . . . . . . . . . . . . . . 384.4.5 Evaluation of alternative controllers . . . . . . . . . . . . . 42

5 Concluding comments 475.1 Comments and conclusions . . . . . . . . . . . . . . . . . . . . . . 47

5.1.1 In silico results . . . . . . . . . . . . . . . . . . . . . . . . . 475.1.2 Invariant set approach . . . . . . . . . . . . . . . . . . . . . 47

5.2 Further work . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 48

A Invariant set mathematics 51A.1 Controlled invariant set . . . . . . . . . . . . . . . . . . . . . . . . . 51

B Implementation 53B.1 Software . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 53B.2 Matlab code . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 53

B.2.1 Code for invariant set computations . . . . . . . . . . . . . 54B.2.2 Code for Example 2.10 . . . . . . . . . . . . . . . . . . . . . 56

C Experimental invariant set illustration 63

Bibliography 65

Index 69

Page 15: Model Predictive Control with Invariant Sets in Artificial Pancreas for

Notation

General

Symbol Explanation

R Set of real numbers∀ For all

Abbreviations

Symbol Explanation

arx Auto-Regressive model with eXogenous inputcgm Continuous Glucose Monitoringcvga Control-Variability Grid Analysiscsii Continuous Subcutaneous Insulin Infusionmpc Model Predictive Controltdi Total Daily Insulint1dm Type 1 Diabetes Mellituszmpc zone-mpc

xi

Page 16: Model Predictive Control with Invariant Sets in Artificial Pancreas for
Page 17: Model Predictive Control with Invariant Sets in Artificial Pancreas for

1Introduction

Artificial Pancreas for Type 1 Diabetes Mellitus (t1dm) is an evolving field, withnumerous projects going on around the world. This thesis deals with invariantsets for robust model predictive control (mpc) for an artificial pancreas.

The work behind this thesis is done in the group1 of Prof. Francis J. Doyle III atthe University of California Santa Barbara (ucsb), in collaboration with SansumDiabetes Research Institute2, where the development of artificial pancreas hasbeen a topic for several years (Grosman et al. [2010]; van Heusden et al. [2012]).

1.1 Problem formulation

In this section, an overview of this thesis in terms of background, objective, meth-ods, and limitations is given.

1.1.1 Background

Type 1 Diabetes Mellitus (t1dm) is an autoimmune chronic metabolic disease,characterized by the loss of endogenous secretion of insulin from the pancreaticbeta-cells. The insulin is crucial in the control of the blood glucose level in thehuman body. Without treatment, the consequences of the heighten blood glucoselevel are life-threatening. About 348 million people worldwide had some kindof Diabetes in 2008 (Danaei et al. [2011]), of which approximately 10% (Eiseleinet al. [2004]) can be assumed being t1dm.

1www.thedoylegroup.org2www.sansum.org

1

Page 18: Model Predictive Control with Invariant Sets in Artificial Pancreas for

2 1 Introduction

The traditional treatment of t1dm involves, since the discovery of the insulinin the 1920s, manually injected insulin (Skyler [2012]), to compensate for theabsence of insulin-production in the beta-cells. In the last decades, the use ofinsulin pumps has evolved as an alternative to manual injections (Skyler [2012]).

A fully automatic system that delivers insulin via a pump based on continuousmeasurement of the blood glucose level is called an artificial pancreas. A well-functioning artificial pancreas could improve the quality of life, and lengthen thelife-expectancy, of people with t1dm. Besides the practical assistance with thedelivery itself, an artificial pancreas could possibly decrease a possible mentalstress over blood glucose control for a t1dm patient3.

1.1.2 Objective

The objective for this thesis work is to investigate possible ways to utilize the statespace information in the predictions in thempc for artificial pancreas done in theucsb/Sansum group4. This is an attempt to improve the control and handle someof the uncertainties in the artificial pancreas control problem in a mathematicallyrigorous way.

1.1.3 Methods

The methods used is mpc, extended with various invariant set methods from theliterature (Blanchini [1999]; Blanchini and Ukovich [1993]; Dórea and Hennet[1999]; Gondhalekar et al. [2013], see Section 2.3 and 2.4). These methods are im-plemented in the zone-mpc (zmpc) controller for artificial pancreas developed bythe ucsb/ Sansum group, and evaluated in silico5 in the UVa/Padova simulator(Kovatchev et al. [2009], see Section 3.4).

1.1.4 Limitations

There are several limitations for this works of which the most important mightbe:

• The controller evaluation is only done in silico

• The tuning of the various control parameters is not addressed systemati-cally, but the focus is rather on qualitative aspects of the control behaviorthan on parameter optimization

• Only the zmpc controller is modified, and no tuning or changing of thestate estimator, safety systems or other components in the ucsb/Sansumgroup system is addressed

• All work is done on the current insulin-glucose model (van Heusden et al.[2012], see Section 3.5), and no attempts on improving or finding new mod-els are done.

3See Greenberg [2013] for an anecdotal example.4In the current version, only the predicted outputs are used in the control design.5i.e., in simulations

Page 19: Model Predictive Control with Invariant Sets in Artificial Pancreas for

1.2 Outline of the thesis 3

1.2 Outline of the thesis

The outline of the thesis is as follows

• This is Chapter 1

• Chapter 2 gives a brief introduction to control theory and automatic control

• A brief introduction to t1dm is given in Chapter 3, together with a sum-mary of related recent work on artificial pancreas

• Chapter 4 presents and discusses design choices in the controller design,and presents the in silico trial results

• Chapter 5 gives some comments on the results and suggests directions forfuture work

• Some mathematical details on the invariant sets are given in Appendix A

• Appendix B provides some details on the implementations of various com-putations, including Matlab code examples

• Appendix C presents an experimental way for illustration of invariant setsfor a special class of systems, relevant for the current application.

Page 20: Model Predictive Control with Invariant Sets in Artificial Pancreas for
Page 21: Model Predictive Control with Invariant Sets in Artificial Pancreas for

2Control theory

Figure 2.1: The notion of a ‘system’

The core idea of automatic control is to engineer signals such that a system be-haves in a desired way. Some central parts of control theory relevant for thisthesis will be presented in this chapter; first the idea and mathematical modelingof a system is briefly presented, followed by a short introduction to the controltechnique Model Predictive Control (mpc). In the second last section of this chap-ter, an introduction to invariant sets is found, and an example on how to combinethe mpc and the invariant sets methods for improved control is given in the lastsection.

A few references to recommended literature on automatic control are Glad andLjung [2006] (in Swedish), Åström and Murray [2010] and Glad and Ljung [2000].For more details on the mathematical modeling and analysis of dynamical sys-tems, Rugh [1996] is recommended.

5

Page 22: Model Predictive Control with Invariant Sets in Artificial Pancreas for

6 2 Control theory

2.1 Dynamical systems

The term ‘system’ is used to describe situations as shown in Figure 2.1. Thereare signals which, e.g., can be electronic, medical or chemical, which are namedinput signals. There are also signals, of possibly different sort than the inputsignals, which are named output signals. Causal relations between the input andoutput signals are assumed, where the output signals are depending on the inputsignals. The terminology can be used even if there is only a limited knowledge ofthese relations available.

If an input signal is used to control the system, it can also be named controlsignal. If an input signal, on the other hand, is beyond control, it can be nameddisturbance signal. When a system is subject to control, it is also sometimescalled a plant .

The notion of dynamical systems is to stress a (possible) dependence between thecurrent output and the previous1 inputs (in contrast to a static system, where thecurrent output depends only on the current, and not the previous, inputs).

2.1.1 Discrete time state space form

If the relation between the output at time t and the input at2 time t, t − 1, . . . canbe described by a mathematical model with the structure of (2.1), the system iscalled a linear discrete time system.

x(t + 1) =A(t)x(t) + B(t)u(t) (2.1a)

y(t) =C(t)x(t) + D(t)u(t) (2.1b)

Here, the input is denoted u(t) and the output y(t). The input, the output, thevariable x(t) are scalars or vectors. The (possibly time-varying) parameters A(t),B(t), C(t) and D(t) are matrices of appropriate dimension (possibly scalar).

The structure of (2.1) is called state space form, which is related to the statevariable x(t). The values of x(t) might, but do not have to, have physical interpre-tations for the system described by the model (such as speed, acceleration, etc.).A crucial point with the state space form is that the state variables x(t) containall information about the current state of the system, i.e., as long as the currentstate is known, the input and output histories are of no further use in telling thecurrent situation in the system3.

Consider, e.g., a car. Given only the current position, it is hard to make any claimsabout the position of the car in the near future. However, given the positionand the velocity, the possibilities of making accurate claims about the position of

1An even more ambitious notion would be causal dynamical systems to stress the dependence oncurrent and previous, but not future, inputs. This will however be implicitly assumed in the sequel.

2For the sake of a simple and intuitive notation, a sample-period of 1 is assumed.3This has big similarities with the markov property of stochastic processes, see, e.g., Yates and

Goodman [1999].

Page 23: Model Predictive Control with Invariant Sets in Artificial Pancreas for

2.1 Dynamical systems 7

the car in the near future increases drastically. The velocity and position can bethought of as state variables for this case.

The linear state space form in (2.1) can be generalized to cover also systems withnonlinear dynamics. To obtain a more general form of the equations, the (linear)matrix multiplications and additions on the right hand sides in (2.1) are simplyreplaced by the more general function symbols f and g.

x(t + 1) =f (x(t), u(t)) (2.2a)

y(t) =g(x(t), u(t)) (2.2b)

Of course, the matrix multiplications and additions in (2.1) can be considered asa special case of (2.2).

2.1.2 Discrete time transfer function

If there is only one4 input and one output to the system, the input–output relationexpressed on the form (2.1) can also be expressed on the following form (see, e.g.,Rugh [1996]) eliminating the state variables:

y(t) + a1y(t − 1) + . . . + any(t − n) = b0u(t) + b1u(t − 1) + . . . + bmu(t −m) (2.3)

(where the constants a1, . . . , an and b0, . . . , bm might be time-varying).

From (2.3) it is clear that the output y(t) is calculated using information of thecurrent and old input signals u(t), u(t − 1), . . . . This is to compare with the statespace form (2.1), where the current input signal u(t) and the current states x(t)are sufficient for calculating the output y(t).

In the case of time-invariant constants a1, . . . , an, b0, . . . , bm, the z-transform canbe used (see, e.g., Rugh [1996]) to rewrite (2.3) into an equivalent, but slightlymore compact, form. Via the step

Y (z) + a1z−1Y (z) + . . . + anz

−nY (z) =

b0U (z) + b1 · z−1U (z) + . . . + bmy−m(z) (2.4a)

(where Y (z) is the z-transform of y(t), and similar for U (z)) the equation

Y (z) =b0 + b1z

−1 + . . . + bmz−m

1 + a1z−1 + . . . + anz−nU (z). (2.4b)

can be obtained.

The form (2.4b) is usually referred to as the transfer function from the input U (z)to the output Y (z).

The values of z for which the denominator of (2.4b) equals 0 is denoted as thepoles of the system. For the same system described on the state space form, all

4There exists a corresponding theory also for systems with multiple inputs and outputs, see forinstance Rugh [1996].

Page 24: Model Predictive Control with Invariant Sets in Artificial Pancreas for

8 2 Control theory

poles are found also as eigenvalues to the matrix5 A. The values of z for whichthe numerator becomes zero are denoted the zeros of the system.

The theory of state space forms (2.1) and transfer functions (2.4b) is extensiveand is only very briefly summarized in this section. It is however enough for thescope of this thesis to note that there exists a detailed theory on the relationshipand conversion between the forms, and refer to, e.g., Rugh [1996] for more detailson the topic.

2.1 Example: Transfer functionThe relationship between subcutaneous injected insulin and the blood glucose

level in the human body can be viewed as a system with one input signal (the in-jected insulin) and one output signal (the blood glucose level). This relationshiphas been identified and approximated as (van Heusden et al. [2012]):

Y (z) =−0.01

(z − 0.98)(z − 0.965)2U (z) (2.5)

where U (z) is the z-transform of the injected insulin and Y (z) is the z-transformof the blood glucose level6. In the previous text the sample-period has been setto 1 for the sake of simplicity. For this model, the sample-period is 5 minutes. Amore thorough walkthrough of the model can be found in Section 3.5.

2.2 Example: State space descriptionThe input–output relation described by the transfer function (2.5) in Example

2.1 can be described on a state space form:

x1(t + T )x2(t + T )x3(t + T )

=

2.91 −2.823 0.9131 0 00 1 0

x1(t)x2(t)x3(t)

+

−0.0100

u(t) (2.6a)

y(t) =(

0 0 1) x1(t)

x2(t)x3(t)

(2.6b)

where T is the sample-period 5 minutes. This particular state space description(there exists infinitely many different state space descriptions equivalent to (2.6))is sometimes referred to as controllable canonical form (Glad and Ljung [2000]).

5It is possible to construct a state space description of a given transfer function with not onlythe poles as the eigenvalues of A, but also other eigenvalues in addition, a so called non-minimalrealization. Once again, the reader are referred to the standard literature, e.g., Rugh [1996], for moreinformation on these topics.

6This model is a linearization around a specific operating point, andU (z) and Y (z) are not absolutevalues, but deviations from this point.

Page 25: Model Predictive Control with Invariant Sets in Artificial Pancreas for

2.2 Model Predictive Control 9

2.1.3 State estimation

For some applications it is not possible to measure all states of the system, butonly, e.g., some of them is included in the output. There are, however, situationswhen knowledge of the states is needed (e.g., in mpc, see Section 2.2). There arehowever, in absence of access to the current states, numerous ways to estimatethe current states, given only the output, input and the state space model.

One such technique is the Luenberger observer. The structure of the Luenbergerobserver is presented in (2.7), where the estimated states are denoted x̂:

x̂(t + 1) =Ax̂(t) + Bu(t) + K[y(t) − Cx̂(t)] (2.7)

where the constant vector K is obtained by solving a discrete algebraic Riccatiequation, see Glad and Ljung [2000].

2.2 Model Predictive Control

This section will give an overview of the main idea of Model Predictive Control(mpc). mpc is a technique for designing automatic control algorithms, based onfuture predictions from a model of the controlled system. This section will onlygive a brief overview of mpc. A good introduction (in Swedish) can be foundin Enqvist et al. [2010], and a more thorough treatment can be found in, e.g,Maciejowski [2002].

mpc is only one out of several techniques for designing feedback controllers. Theoverall structure of feedback control is illustrated in Figure 2.2. In particular ismpc a state feedback controller, as illustrated in Figure 2.3, where the controllerin Figure 2.2 is split into a state estimator (see Subsection 2.1.3) and a controller,e.g., mpc.

Page 26: Model Predictive Control with Invariant Sets in Artificial Pancreas for

10 2 Control theory

Figure 2.2: The basic structure of a feedback system: Information from theoutput signals are used for shaping the input signals.

Figure 2.3: The structure for a state feedback controller as, e.g., mpc. Thecontroller in Figure 2.2 is here split into two parts; the state estimator andthe controller.

2.2.1 The standard MPC formulation

The main idea is to formulate the control problem as an optimization problemover nc future samples. The optimization problem contains an objective func-tion, a prediction model and possibly constraints on, e.g., the input, the states orthe output. A rather general formulation of the optimization problem (with, forsimplicity, only input constraints) is given in (2.8):

minu(t),u(t+1),...,u(t+nc−1)

F (x(t), u(t), . . . , u(t + nc − 1)) (2.8)

subject to umin ≤ u(i) ≤ umax, i = t, t + 1, . . . , t + nc − 1

where the objective function F contains the system model (2.2) for predictionsas a function of the optimization variables u(t), u(t + 1), . . . , u(t + nc) and the cur-rent state x(t). The optimization (2.8) is performed, and u(t) is in each sampleexecuted as control signal.

An example for nc = 2 and a linear system model is given in Example 2.3.

2.3 Example: Model Predictive ControlAssume the system subject to control is described by a state space model of

the form (2.1), and the current state is known to the controller. The ultimateobjective is to drive the system states to the origin, using a good trade-off betweenthe ‘energy’ in the input signal (i.e., the square of the inputs) and the sum of thesquares of the state deviations from the origin.

Page 27: Model Predictive Control with Invariant Sets in Artificial Pancreas for

2.2 Model Predictive Control 11

The prediction horizon is chosen to 2. Since

x(t + 1) = Ax(t) + Bu(t) (2.9a)

it can be noted that

x(t + 2) = Ax(t + 1) + Bu(t + 1) = A(Ax(t) + Bu(t)) + Bu(t + 1) (2.9b)

= A2x(t) + ABu(t)) + Bu(t + 1) (2.9c)

Hence the following optimization problem can be formulated

minu(t),u(t+1)

∑i=t+1,t+2

xT (i)Qx(i) +∑i=t,t+1

uT (i)Ru(i) = (2.10a)

minu(t),u(t+1)

uT (t)Ru(t) + uT (t + 1)Ru(t + 1) + (Ax(t) + Bu(t))TQ(Ax(t) + Bu(t))+

(A2x(t) + ABu(t) + Bu(t + 1))TQ(A2x(t) + ABu(t) + Bu(t + 1)) = (2.10b)

= minu(t),u(t+1)

(u(t) u(t + 1)

) (( BT (AB)T

0 BT

)Q

(B 0AB B

)+

(R 00 R

)) (u(t)

u(t + 1)

)+

2((

0 BT

0 0

)Q

(AA2

)x(t)

)T (u(t)

u(t + 1)

)+

xT (t)(I AT

)Q

(IA

)x(t) (2.10c)

where Q and R are the relative weights between the cost of deviations from 0 inthe input and deviations from the origin in the states. The choice of Q and R is atuning of the ‘aggressiveness’ of the controller.

Noting that the last term is independent of the optimization variable (and hencenot affecting the minimizing argument for the problem) and defining a compactmatrix notation, the problem can be formulated as

minu(t),u(t+1)

12U T (BTmpcQBmpc + R)U + (BTmpcQAmpcx(t))TU (2.10d)

where

U =(

u(t)u(t + 1)

), Ampc =

(AA2

), Bmpc =

(B 0AB B

).

The problem in (2.10d) is a convex quadratic programming problem and can besubject to various constraints, such as bounds on the input or the states. Theseproblems are a well studied class of problems, see, e.g., Boyd and Vandenberghe[2004].

Page 28: Model Predictive Control with Invariant Sets in Artificial Pancreas for

12 2 Control theory

The optimizing argument of (2.10d) will give the optimal solution for the statedcontrol problem, fulfilling possible constraints. The solution u(t) is then used asthe input to the system (u(t + 1), . . . are simply ignored). The entire optimizationproblem is thereafter solved all over again in the next sample.

2.2.2 Zone MPC

If the mpc control objective is not defined as a specific value for the states, butas an interval for the output, the controller is called a zone mpc (zmpc). Insteadof penalizing deviations from a set-point, e.g., x(t) = 0 as in Example 2.3, onlydeviations outside a zone [ymin, ymax] are penalized. This optimization problemcan be formulated in a similar way, using so called slack variables, see, e.g., Boydand Vandenberghe [2004].

Another possible extension is to allow the penalization of deviations from thezone or set-point to be asymmetric, e.g., to relate a higher cost to deviations ina positive than a negative direction. The costs associated to deviations from aset-point and a zone respectively are exemplified in Figure 2.4.

Figure 2.4: Quadratic output costs for a set-point controller (left), and azone controller with asymmetric costs (right). The horizontal axis illustratesdeviations from the set-point and the zone respectively.

2.3 Invariant sets

This section will give a brief overview of invariant sets for discrete time systems.For all cases t is assumed to be an integer, and since the focus will be on positivelyinvariant sets of different kinds, t will in most cases be restricted to non-negativeintegers. The definitions 2.4, 2.7, 2.8 and 2.9 are intended to be equivalent to,but somewhat less technically stated than the definitions in Blanchini and Miani[2007] and Blanchini and Ukovich [1993] respectively.

A more detailed introduction to invariant sets is given in the book Blanchini andMiani [2007] (covering also the continuous time case) and the articles Blanchini[1999] and Dórea and Hennet [1999].

Page 29: Model Predictive Control with Invariant Sets in Artificial Pancreas for

2.3 Invariant sets 13

2.3.1 Positively invariant sets

For an autonomous system (i.e., has no inputs) described by x(t + 1) = f (x(t)),where x ∈ X ⊂ R

n, a positively invariant set is defined as follows:

2.4 Definition (Positively invariant set). A set S ⊆ X is positively invariant(w.r.t. the given system) if x(0) ∈ S implies that x(t) ∈ S for all7 t = 1, 2, . . .

This definition of a positively invariant set is illustrated with the following exam-ple:

2.5 Example: Positively invariant set for a pendulumConsider a pendulum, with some damping and with small deviations from its

downward position. The dynamics of a pendulum can be described with equa-tions on state space form, where the two states can be chosen as x1 position andx2 velocity, as sketched in Figure 2.5.

Figure 2.5: A pendulum. The dynamics in the pendulum can be caught inthe two states x1, the position, and x2, the velocity, as illustrated.

Starting at an initial position to the right of the downward position and with aninitial velocity to the right, the pendulum will eventually come to a point wherethe velocity is zero and its distance to the downward position is at its maximum.Thereafter, the velocity will start to increase and be directed to the left, and thedistance to the downward position will decrease. Eventually the pendulum willpass its downward position, with a maximum speed toward the left, and there-after reach the left point with maximum distance, and continue back and forth

7For the definition of an invariant (not only positively invariant) set, the implication has to holdfor any integer t, not only t > 0

Page 30: Model Predictive Control with Invariant Sets in Artificial Pancreas for

14 2 Control theory

in the same way. Since there is a damping (e.g., friction) in the system, the max-imum distance to the downward position, as well as the maximum speed, willdecrease for each iteration. This is plotted in Figure 2.6, using x1 and x2 as theaxes8.

Figure 2.6: The time evolution of the pendulum states for a certain set of ini-tial conditions. The evolution is indicated by the arrows. The horizontal axisis the position of the pendulum (i.e., its distance to the downward position,taken with a negative sign if the pendulum is to the left of the downwardposition), and the vertical axis is the velocity of the weight, with the corre-sponding sign convention as for the distances.

Figure 2.6 reveals that the pendulum’s state, once entering a circle9 of a certainradius, it will never leave the circle in the future. Hence, a circle around theorigin is an invariant set for this system. An example of such a circle is sketchedin Figure 2.7.

8Such a plot is usually referred to as a phase plane.9In fact, an ellipsoid would be more correct. In these plots, however, the axes are scaled in a way

such that the ellipsoid becomes a circle.

Page 31: Model Predictive Control with Invariant Sets in Artificial Pancreas for

2.3 Invariant sets 15

Figure 2.7: A positively invariant set (the circle defined via the black dashedline) for a pendulum. The grey lines (all depicting time evolution of thependulum states for different initial conditions) all enter the set, but neverleave it.

2.3.2 Controlled invariant sets

For automatic control purposes, systems without inputs are by obvious reasons oflimited interest. Therefore, systems with control inputs are considered, and con-trolled invariant10 sets are defined for systems on the form x(t + 1) = f (x(t), u(t)),where x ∈ X ⊂ R

n and u ∈ U ⊂ Rm:

2.6 Definition (Controlled invariant set). A set S ⊆ X is a controlled invariantset if there for all x(0) ∈ S exists u(t) ∈ U such that x(t) ∈ S,∀t = 1, 2, . . .

In words, this definition says that there exists an (admissible) input signal u(t)such that if applied to the system, once the states x(t) are within the set, they willremain within the set for all future.

The algorithm for computations of the (maximum) controlled invariant set is aninversed reachability analysis, and is presented in Appendix A, and an implemen-tation of the algorithm in Matlab is given in Section B.2 in Appendix B.

However, in computations of an invariant set, numerical problems may occur andgive incorrect results, e.g., indicating points belonging to the set, although they

10The term ‘positively’ is here implicit.

Page 32: Model Predictive Control with Invariant Sets in Artificial Pancreas for

16 2 Control theory

do not. One remedy to avoid such numerical problems is to introduce contractivesets. For some cases, this also improves the convergence properties for the com-putations of the sets (Blanchini [1991]). A contractive controlled invariant set forthe system x(t + 1) = f (x(t), u(t)), where x ∈ X ⊂ R

n and u ∈ U ⊂ Rm, is defined

as follows:

2.7 Definition (Controlled contractive set). A set S ⊆ X is a contractive con-trolled invariant set (w.r.t. the given system and a given λ, 0 < λ < 1) if thereexists a u(t) ∈ U such that x(t) ∈ S implies that x(t + 1) ∈ λS,∀t = 0, 1, . . . .

The core idea is still the same as for invariant sets, but instead of requiring acontrol signal such that the states remain within the set, the existence of a controlsignal such that the states belong to a slightly shrunken version of the set in thetarget step. Another way to interpret it is as a margin is added in each time step.

2.3.3 Robust controlled invariant sets

So far, full knowledge of the system and all input signals has implicitly beenassumed for the definitions to be useful. The next extension of the idea is tointroduce robust controlled invariant sets. Consider a system with two inputs,of which one, u(t), is controlled as before, and the other d(t) is an unknowndisturbance, known to belong to a bounded set D: x(t + 1) = f (x(t), u(t), d(t)),where x ∈ X ⊂ R

n, u ∈ U ⊂ Rm and d ∈ D ⊂ R

q, (or, for the linear case x(t + 1) =Ax(t) + Bu(t) + Ed(t)). The definition of the robust controlled invariant set forthis system reads:

2.8 Definition (Robust controlled invariant sets). A set S ⊆ X is a robust con-trolled invariant set (w.r.t. the given system) if there for every x(t) ∈ S existsu(t) ∈ U such that x(t + 1) ∈ S, for all d(t) ∈ D and all t = 0, 1, . . . .

One way to interpret the robust set is as a game, where you do not know whatyour opponent (the disturbance) is doing. You want to define the region whereyou can ‘feel safe’ and can counteract your opponents turns even if he is doingthe (from your point of view) worst possible turns.

The extension of robust controlled invariant sets to robust contractive controlledinvariant sets should be straight forward.

2.3.4 Periodic controlled invariant sets

So far, only different kinds of invariant sets for time invariant systems have beenconsidered. The last theoretical extension of the invariant set idea is an exten-sion to cover periodic systems. A periodic controlled invariant set for a systemwith periodicity T described as x(t + 1) = f (t, x(t), u(t)), where x(t) ∈ Xt modT ⊂Rnt modT , u(t) ∈ Ut modT ⊂ R

mt modT and f is periodic such that f (t, x(t), u(t)) =f (t + T , x(t), u(t)), is defined as follows:

Page 33: Model Predictive Control with Invariant Sets in Artificial Pancreas for

2.4 Mini example of invariant set in MPC control 17

2.9 Definition (Periodic controlled invariant sets). A finite sequence of setsSk ⊆ Xk , k ∈ 1, 2, . . . , T is called a periodic controlled invariant (w.r.t. the givensystem) if for all x(t) ∈ St modT there exists an u(t) ∈ Ut modT such thatx(t + 1) ∈ St+1 mod T , ∀t = 0, 1, . . .

A more thorough treatment of periodic sets can be found in Blanchini and Ukovich[1993]. Gondhalekar and Jones [2011] and Gondhalekar et al. [2013] both dealswith periodic robust invariant sets, and the former also offers an extension to pe-riodic time-varying state space dimensions, used in an example for asynchronouscontrol.

2.3.5 Maximum invariant sets

In many cases can several different sets, all fulfilling the definition of an invariantset, be found. In, e.g., the Pendulum example 2.5 are all circles around the originpositively invariant sets. Throughout this thesis, however, will only the largestpossible set (i.e., the maximum set, the union of all possible sets) be considered.

2.4 Mini example of invariant set in MPC control

To illustrate how to use invariant sets in mpc, an example is given in this section.The entire Matlab code for the example is provided in Appendix B, Section B.2.

2.10 Example: Robust periodic invariant set inmpc controlConsider the dynamical system

x(t + 1) =(

1.67 −0.711 0

)x(t) +

(10

)u(t) +

(1 00 1

)d(t) (2.11a)

y(t) =(

17.3 −199). (2.11b)

The input u(t) is bounded by [−0.5, 0.5], and the bounds on the output y(t) areperiodic with a periodicity of 24 samples. The disturbances d(t) are unknown,but known to be bounded with periodic bounds. The states are known to thecontroller, and there are no mismatch between the model and the real system.

The periodic output bounds are described in Figure 2.8. The disturbance d(t) isa two dimensional signal, only known to be bounded by Di , which is the unitsquare with a side of 0.02, except at sample i = 7, 12, 20 and i = 16, 22, where itis bounded by a square in the positive quadrant with one corner in the origin anda side of 0.25 and 0.1 respectively (see the green sets in Figure 2.9).

The robust periodic contractive set Xi , i = 1, . . . , 24 with11 λ = 0.99 is computedfor this problem. 30 iterations are required, and the set is shown in Figure 2.9.

The control of the system (2.11) is formulated as an mpc problem. The mpcproblem is formulated with prediction horizon nc = 1 and a quadratic input cost

11The contraction factor, see Definition 2.7.

Page 34: Model Predictive Control with Invariant Sets in Artificial Pancreas for

18 2 Control theory

Figure 2.8: Output bounds for system (2.11) in Example 2.10

R for input signals deviating from 0. The input constraints are used as constraintsto the optimization.

The invariant set Xi , i = 1, . . . , 24 is incorporated into thempc problem as follows,in order to maintain the output boundaries: Xi is, for each i, shrunk by the dis-turbance bound for the previous sample12, X̃i+1 = {x ∈ R2|x + d ∈ Xi+1 ∀d ∈ Di}.The set X̃i are thereafter used as a constraint for the corresponding predictedstates.

Altogether, the optimization problem solved in each step looks like this:

arg minu(t)

u2(t) (2.12)

subject to umin < u(t) < umaxx(t + 1) ∈ X̃t+1 modT

This can be compared to the standard mpc formulation (2.8), with nc = 1 andF (x(t), u(t)) = u2(t), and the constraint x(t + 1) ∈ X is the extension from stan-dard mpc to mpc with invariant set.

Using this mpc control strategy, with (robust periodic contractive) invariant set,the results shown in Figure 2.10 are obtained for a simulation. Note that nooutput bounds are violated, and the mpc problem solved in each step uses a pre-diction horizon of only 1. Also note that there are possibilities for various tuningof the controller; the invariant set constraints guarantee the output bounds, butdo not imply any optimality of the control. The objective function (2.12) can stillbe subject to tuning with, e.g., respect to input and output values.

As a comparison, the results of an mpc controller not using the invariant set butonly the output boundaries as control objective are shown in Figure 2.11. Thisis the standard mpc as described in Subsection 2.2.1, but with a zone as controlobjective, as described in Subsection 2.2.2. This controller has no knowledge of

12Also named the pontryagin difference, X̃i+1 = Xi+1 Di

Page 35: Model Predictive Control with Invariant Sets in Artificial Pancreas for

2.4 Mini example of invariant set in MPC control 19

Figure 2.9: Robust periodic contractive set for the system in Example 2.10.Some characteristics in the set shapes is interesting to note: the sizes of theset at sample 7, 12 and 20 are related to the relatively big disturbance boundsat these samples; to guarantee existence of an admissible control signal con-trolling the system such that it belongs to the set in the consecutive sample,even with the worst case of the unknown disturbances, the states have to bein this rather small set for these samples. The small size of the set in sample10 is, in a similar way, related to the tightening of the output bounds in theconsecutive sample.

the disturbances, and uses the prediction13 horizon 3. Clearly the output trajec-tory violates the output boundaries several times. The tuning of the controller(i.e., the prediction horizon and the input/output costs) is by no means optimal,but gives still an idea of the advantages of robust mpc with invariant set for thisexample.

The system (2.11) used in this example has some similarities with the insulin-glucose model briefly presented in Example 2.1; their input-output behavior havesimilarities, if the sampling time of (2.11) is interpreted as 60 minutes. Also,some of the input, output and disturbances have similarities with the artificialpancreas control problem (e.g., typical meal times and the samples when distur-bances occur), although they are not identical. However, as will be apparent inthe sequel, the assumptions of perfect knowledge of the system (i.e., the modelis correct) and the current states (i.e., no measurement errors and an ‘ideal’ stateestimation) are far away from the reality in the artificial pancreas problem. The

13Since the system in fact is a non-minimum phase system, see, e.g., Glad and Ljung [2000], ashorter prediction horizon will make the system unstable.

Page 36: Model Predictive Control with Invariant Sets in Artificial Pancreas for

20 2 Control theory

Figure 2.10: Result for a simulation of the system in Example 2.10, con-trolled by an mpc controller using the robust periodic invariant set as con-straint and a prediction horizon of 1. (Note that the height of the disturbancebars has no direct interpretation, since the disturbances are two dimensional,but gives only an idea of the relative sizes of the disturbances.)

entire Matlab code for this example is found in Section B.2. A detailed treatmentof robust periodic invariant sets for mpc and an application example to buildingclimate control can be found in Gondhalekar et al. [2013]

Page 37: Model Predictive Control with Invariant Sets in Artificial Pancreas for

2.4 Mini example of invariant set in MPC control 21

Figure 2.11: Result for a simulation of the system Example 2.10 using astandard mpc controller without knowledge of the disturbances.

Page 38: Model Predictive Control with Invariant Sets in Artificial Pancreas for
Page 39: Model Predictive Control with Invariant Sets in Artificial Pancreas for

3Diabetes and the artificial pancreas

This chapter serves two purposes. First, to give an introduction to Type 1 Dia-betes Mellitus (t1dm), and second, to give an overview over some relevant workon the artificial pancreas problem. For a more detailed treatment of diabetes andt1dm is referred to the literature, e.g., Skyler [2012]. For a popular science in-troduction to diabetes in Swedish, e.g., Hellerström [2002] and Ajanki [1999] isrecommended.

3.1 Diabetes

The blood glucose level in the human body is affected by various organs andprocesses in the human body. The blood glucose is an energy source for the cells,and the uptake of blood glucose by the metabolic system is partly controlled bythe insulin. Insulin is produced in the beta-cells in the pancreas, and the releaseof insulin from the beta-cells is controlled by an intrinsic system in the body,together with, e.g., the liver.

Type 1 Diabetes Mellitus (t1dm) is an autoimmune chronic metabolic diseasecharacterized by the loss of endogenous secretion of insulin from the pancreaticbeta-cells. A lack of insulin causes high blood glucose levels, known as hyper-glycemia1. This can be dangerous and cause severe and life-threatening compli-cations to the patient if maintained for a long period of time.

A low blood glucose value is known as hypoglycemia2. Hypoglycemia may causesevere and life-threatening complications even if maintained only for a short pe-riod of time.

1Hyperglycemia is typically defined as a blood glucose level over approximately 180 mg/dL2Hypoglycemia is typically defined as a blood glucose level below approximately 70 mg/dL.

23

Page 40: Model Predictive Control with Invariant Sets in Artificial Pancreas for

24 3 Diabetes and the artificial pancreas

The unit used for blood glucose level in this thesis is milligram per deciliter,mg/dL. The unit mmol/l is also a common unit for blood glucose values, and1 mmol/l is approximately 18 mg/dL.

3.2 Insulin treatment

Insulin is a peptide hormone, and for a patient suffering from t1dm, there isa need for exogenous insulin. The infusion of insulin has to be done carefully,since an over-delivery of insulin can cause hypoglycemia. Since the discoveryof insulin in the 1920s, the traditional way to deliver insulin has been throughmanual injections based on manual blood glucose readings through finger sticks.

Continuous subcutaneous insulin infusion (csii) pumps have been developedand have been available for patient use since the 1980s (Skyler [2012]). csii is,however, only a tool for facilitated delivery of exogenous insulin, and does notnecessarily imply improved blood glucose level control. A typical use of csii to-day is in open-loop control with, e.g., pre-programmed insulin delivery profiles.

From a control perspective, the effect of the insulin makes the problem asymmet-ric, since insulin basically drives the blood glucose value down. However, a mealor a snack typically raises the blood glucose value, which in some sense can beused as a control input, see Subsection 3.6.2. One remedy to this asymmetricproblem is to use even another peptide hormone, glucagon, with the oppositeeffect to the insulin, i.e., driving the blood glucose value up. Such bi-hormonal ar-tificial pancreas systems have been designed, see for example Russell et al. [2012].This solution is however not used by the ucsb/Sansum group, and will hence nei-ther be used in this thesis work.

3.3 Continuous Glucose Monitoring

Recently, subcutaneous continuous glucose monitoring (cgm) techniques havebeen developed, and have during the last decade become available for patient use(Skyler [2012]). Such devices can give almost continuously (e.g., every 5 minutes)measurements of the subcutaneous glucose.

The relevant quantity to control for a t1dm patient is however not the cgm read-ings, but the intravenous blood glucose level. The cgm measurements do notalways coincide with the intravenous blood glucose level, for physiological rea-sons (the blood glucose and the subcutaneous glucose values can be different(Steil et al. [2003])) as well as technical reasons (errors and uncertainties in themeasurement method and equipment). From a control perspective the cgmmea-surements are hence affected by a noise, which is not neglectable (Zisser et al.[2009]; Huyett et al. [2013]). Currently there does not exist any, known to theauthor, control-relevant description of this noise.

The information itself, obtained from the cgm, does of course not improve thecontrol of the blood glucose level. However, in a system with both cgm and csii,

Page 41: Model Predictive Control with Invariant Sets in Artificial Pancreas for

3.4 Metabolic system simulator 25

the blood glucose level control can possibly be improved, as will be discussed inSection 3.6.

3.4 Metabolic system simulator

A simulation environment of the metabolic system for evaluation of artificial pan-creas has been developed at University of Virginia and University of Padova (Ko-vatchev et al. [2009]). The simulator is approved by the U.S. Food and DrugAdministration (fda) for verification of control algorithms for artificial pancreasbefore doing clinical trials on t1dm subjects. This simulation environment is inthe sequel shortly referred to as the UVa/Padova simulator.

The simulator contains a set of different virtual patients with varying parameters,such as weight, age, gender etc, see Subsection 4.4.3. There is also a noise modelsimulating cgmmeasurement errors for closed loop control simulations.

3.5 System identification for an insulin-glucosemodel

To obtain a model of the insulin-glucose relation suitable for (linear)mpc, systemidentification has been done in the UVa/Padova simulator (see Subsection 3.4).The obtained model is a (linear, time-invariant) third order transfer function (anarxmodel) describing the dynamics of the insulin-glucose relation, as deviationsfrom an input of basal3 rate and an output of 110 mg/dL (van Heusden et al.[2012]):

Y (z) = −5F · 1800tdi

(1 − p1)(1 − p2)2 1(z − p1)(z − p2)2U (z) (3.1)

where

• p1 = 0.98

• p2 = 0.965

• F is a safety constant tuned by a physician, with a typical value of 1.5

• tdi is the total daily insulin, also prescribed by a physician, with a typicalvalue between 25 and 70

• U is the input signal, i.e., injected insulin, in Insulin Units per hour (U/h).

• Y is the output signal, i.e., the blood glucose level, in mg/dL.

The sampling time of the model is 5 minutes. Altogether, a typical value of thenumerator could be −0.01, which is used for computations in this thesis whennothing else is mentioned.

3A value prescribed by a physician, related to the tdi value.

Page 42: Model Predictive Control with Invariant Sets in Artificial Pancreas for

26 3 Diabetes and the artificial pancreas

The transfer function is a linearization around the patients basal rate (tuned by aphysician, which typically is of the size 1 U/h) and a blood glucose value of 110mg/dL.

There is no possibility to give ‘negative’ insulin. But since the model is describedas deviations from a working point, a suspension of the pump (which is the small-est possible input) corresponds to minus the basal rate as the value of u(t), i.e.,typically −1 U/h. There is also an upper limit of the pump of the size 100 U/h.Altogether, the input is approximately bounded as u(t) ∈ [−1, 100].

There is, based on experience from in silico trials, a non-neglectable plant-modelmismatch between this model and the virtual subjects in the simulator.

3.6 Artificial pancreas

Figure 3.1: The structure of an artificial pancreas

A lot of work has been carried out by different research groups at different placesto design closed loop systems for automatic delivery of insulin, i.e., artificial pan-creas. An overview of the basic structure of an artificial pancreas is given in Fig-ure 3.1. An artificial pancreas has been developed in the group at ucsb/Sansum(van Heusden et al. [2012]; Harvey et al. [2010]). Especially the zmpc tech-nique has shown some promising results (Dassau et al. [2013]; Grosman et al.[2010]). In the zmpc control algorithm developed in the ucsb/Sansum group,the model (3.1) presented in Subsection 3.5 has been used. An overview of theucsb/Sansum group system is given in Figure 3.2.

3.6.1 Meals

One of the most important and characteristic disturbances (from a control per-spective) are the meals. Different approaches can be used to deal with meals:

Announced meals

With announced meals, the controller is assumed to have knowledge of the timeand the size of the meals the patient is having. The controller can hence ‘counter-act’ the meal in advance and give a dose of insulin before or at the time the mealis eaten, a so called meal-bolus4. The size and the distribution over time of the

4The idea with the term is to emphasize the similarities with the insulin secretion from normal-functioning beta cells, which can be divided into bolus and basal parts, see Skyler [2012].

Page 43: Model Predictive Control with Invariant Sets in Artificial Pancreas for

3.6 Artificial pancreas 27

Figure 3.2: An overview of the ucsb/Sansum group artificial pancreas sys-tem.

bolus is subject to current research.

Announced meal can be designed either as real time inputs from the patient, orforcing the patient to follow a meal schedule known by the controller on fore-hand. Depending on context, only the former may be called announced meal,but they are equivalent from a control algorithm perspective, since the informa-tion on the meal is available to the controller before its effects are seen in thesystem output.

From a control point of view, this can be considered as a feed-forward controldesign.

Unannounced meals

With unannounced meals, the controller has no information of the meals a pa-tient is having. This is the case considered in this thesis, although extensions tothe announced case could be possible.

Page 44: Model Predictive Control with Invariant Sets in Artificial Pancreas for

28 3 Diabetes and the artificial pancreas

Meal detection

When having unannounced meals, ideas from the announced meal strategy canstill be used as inspiration for the design of the controller. The idea is to detect ameal, basically by a rising cgm value, and give a bolus to treat the meal, as if itwas announced. Work on meal detection can be found in Dassau et al. [2008].

By intuition, it is in general possible to achieve a better control performance hav-ing information of the meal, as opposed not to have the information. It is, how-ever, also possible to discuss what the best is from a patient perspective. A com-parison between announced and unannounced meal for zmpc control is found inGrosman et al. [2010].

3.6.2 Safety systems and hypoglycemia treatments

Since the control problem is asymmetric not only in the input (see Section 3.2) butalso since hypoglycemias are more critical than hyperglycemias, safety systemshave been developed to react on low cgm readings and, e.g., to give a warningand request the patient to eat some carbohydrates (Dassau et al. [2010]).

3.6.3 Insulin on board constraints

To prevent too much insulin to be delivered during a certain time window, theconcept of insulin on board constraints has been developed. The problem withover-delivery of insulin can be relevant with, e.g., a plant-model mismatch, mea-surement errors and an aggressively tuned controller. It can especially be prob-lematic in combination with announced meals where big boluses are given inaddition to the action suggested by the control algorithm. The constraints are inprinciple an integral constraint on the input signal. A detailed description andevaluation of the insulin on board constraints can be found in Ellingsen et al.[2009].

3.6.4 Night time zone

A severe hypoglycemic event during the night could be even more dangerousthan during the day, since the possibilities to action from the patient or anotherperson from the household (to, e.g., give carbohydrates to the patient to eat) aremore limited during night than day-time. Hence, the concept of a night-timezone is introduced, with a different control objective and tighter constraints onthe control signal.

A typical value for the night time control objective zone is 110 − 170 mg/dL(instead of the day time control objective of 80 − 140 mg/dL), as shown in Fig-ure 3.3. The night time control objective has been tuned to reduce the risk ofhypoglycemia, based on experiences from the clinical trials in the ucsb/Sanumgroup. The control signals can be limited to typically never exceed, e.g., 1.6 timesthe basal rate (i.e., u(t) ≤ −0.6 · umin, since u(t) is described as deviations from thebasal rate and the basal rate is −umin) during night time zone.

Page 45: Model Predictive Control with Invariant Sets in Artificial Pancreas for

3.6 Artificial pancreas 29

Figure 3.3: Example of an overnight zone (00:00 - 05:00) with an heightenedcontrol objective zone (110-170 mg/dL), for decreased risk of hypoglycemicevents during night time.

Page 46: Model Predictive Control with Invariant Sets in Artificial Pancreas for
Page 47: Model Predictive Control with Invariant Sets in Artificial Pancreas for

4MPC with invariant set constraints for

an artificial pancreas

In this chapter, the contribution to artificial pancreas control by this thesis, ispresented. Various design choices and results are presented and discussed.

4.1 Invariant sets for the insulin-glucose model

The controlled invariant set as defined in Definition 2.6 for the insulin-glucosemodel (3.1) was computed with the Matlab code presented in Section B.2. The setis shown in Figure 4.1a. (An alternative idea to plot the invariant set for the pur-pose of better intuitive understanding of its meaning is presented in AppendixC.)

The computations of the invariant set converges for the particular numerical val-ues used (tdi, input and output limits, etc) after 57 iterations (which correspondsto approximately 10 minutes on an Intel Core i5 2.5 GHz CPU with the implemen-tation in Appendix B). The number of iterations, which also affects the computa-tion time, is highly sensitive to different numerical values.

The contractive controlled invariant set as defined in Definition 2.7 for λ = 0.99and the insulin-glucose model (3.1) computed with Matlab is shown in Figure 4.1b.The computations converges after 63 iterations (approximately 20 minutes on thesame CPU).

A periodic controlled invariant set for a 24 hour period (i.e., 288 samples with 5minutes sampling time) for periodic output constraints, can also be computed ina reasonable time.

As noted in Subsection 2.1.1, a state space model is not a unique representation ofan input-output relation, but there exists infinitely many state space descriptions

31

Page 48: Model Predictive Control with Invariant Sets in Artificial Pancreas for

32 4 MPC with invariant set constraints for an artificial pancreas

(a) Controlled invariant set (b) Contractive controlled invariantset

Figure 4.1: Controlled invariant and contractive controlled invariant set forthe insulin-glucose model (3.1). The sets are very similar, but the contractivecontrolled invariant set is a subset of the nominal controlled invariant set,and hence slightly smaller.

for one input-output relation. However, all (minimal) state space descriptionsof the same input-output relation are related through (invertible) linear transfor-mations (Rugh [1996]). Hence the corresponding invariant sets for the differentstate space descriptions are related through (invertible) linear transformations aswell. The structure of the invariant set (number of vertices, etc) can thereforebe expected to be independent of the choice of state space description, althoughthe numerical properties of the computations probably can be affected. The influ-ence of different state space descriptions have not been analyzed thoroughly, andthe state space description presented in Example 2.1 and used in the controllerstructure developed by the ucsb/Sansum group was used throughout this thesis.

4.2 Robust invariant set for the insulin-glucose model

In addition to the nominal and periodic controlled invariant sets presented inSection 4.1, different robust invariant sets have been considered.

4.2.1 Measurement errors in the state space

Since the invariant set is a feature in the state space, the measurement errors(naturally entering in the ‘output space’) have to be converted to a ‘state spacefeature’ to be able to include in the invariant set framework. The state estimator(estimating the current states from the current and the previous output and in-put signals, explained in Subsection 2.1.3) is relevant for this conversion. At thetime when writing this thesis, the artificial pancreas of the UCSB/Sansum groupused a Luenberger observer as state estimator. Simulated measurement errors

Page 49: Model Predictive Control with Invariant Sets in Artificial Pancreas for

4.2 Robust invariant set for the insulin-glucose model 33

were propagated through the state estimator into the state space using a genericmethod with Monte Carlo simulations. Since no extensive model for the measure-ment errors was present (Section 3.3), the errors were assumed to be white noisewith a realistic variance.

Figure 4.2: The propagated measurement errors, from three different angles.

According to the simulations, the errors converge to a two-dimensional plane(in the three-dimensional state space), as shown in Figure 4.2. The existence andproperties of this plane could not be supported by any theory found by the authorin the literature. The existence of the plane was however utilized for fitting atwo-dimensional rectangle in this plane to the simulated errors. The 90% of thesimulated errors that minimized the circumference of the rectangle were chosento define the bounds for the rectangle, as shown in Figure 4.3. This rectanglewas considered as the measurement error bound in the robustification methoddescribed in Subsection 4.2.2.

Because of the unknown properties of the errors and the disturbances, the statis-tical approach with Monte Carlo simulations was considered to be sufficient forthis purpose, although an analytical method would be more rigorous.

4.2.2 Robustification against measurement errors

The measurement errors propagate, as described in Subsection 4.2.1, through thestate observer to the state space. Since the state estimator is a linear system, thepropagated measurement errors can be described as an additive error in the statespace.

The measurement errors do however not affect the system dynamics behavior, asthe disturbances do in the disturbed system description in connection to Defini-tion 2.8. A robustification according to Definition 2.8 is therefore not relevant forthis problem.

Instead, the robustification method chosen for this problem is to interpret thedisturbance bounds as a desired robustness margin against the bounds of thestates, and compute the invariant set for these tighter bounds. The only boundson the states are imposed by the constraints ymax ≥ y = Cx and ymin ≤ y = Cx,which for the case without night-time zones reduces to −30 ≤ x3 ≤ 30. However,since x3(t + T ) = x2(t), and x2(t + T ) = x1(t) for this state space description (see

Page 50: Model Predictive Control with Invariant Sets in Artificial Pancreas for

34 4 MPC with invariant set constraints for an artificial pancreas

Figure 4.3: The propagated measurement errors, with 90% of the simula-tions in the two-dimensional box.

Example 2.2), the bounds [−30, 30] will apply to those states as well. The robus-tification is hence to subtract the disturbance bound (Figure 4.3) from the box[−30, 30] × [−30, 30] × [−30, 30], and compute the invariant set with these new,tighter bounds on the states1.

4.2.3 Meals

The design of a controller that is robust against meals is an interesting challenge.Without any prior knowledge of the meals, and with the present cgm errors,it appears from experience of in silico trials almost impossible to maintain theblood glucose zone when the patient is having a big meal.

The lack of a model describing the relationship between a meal and the bloodglucose value relevant for control is a bottleneck for further investigation of thistheme. However, with a relevant model, robustification according to Definition2.8 against a smaller meal could probably be interesting to investigate.

1A comparable, although not equivalent, approach would be to simply shrink the control objectivezone by the 90% bound of the measurement errors.

Page 51: Model Predictive Control with Invariant Sets in Artificial Pancreas for

4.3 Implementation of set constraints in MPC 35

4.2.4 Plant-model mismatch

With a description for the plant-model mismatch, an invariant set approach ro-bust against plant-model mismatches could be a very interesting concept to in-vestigate. Due to the absence of such a description, this theme is however notlooked into further.

4.3 Implementation of set constraints in MPC

The invariant set is used as constraints for the predicted states in the mpc op-timization, basically as illustrated in Example 2.10, and in particular in (2.12).This is to be compared with the zmpc used, where only the predicted output(and not the predicted states) were directly considered in the optimization.

However, to enforce constraints on the predicted states (as done in (2.12)) is inpractice not a good idea, due to the risk of formulating an infeasible2 problem, if,e.g., the system has been subject to a major disturbance, and cannot be broughtback to the invariant set in one sample. This is highly relevant for the artificialpancreas problem, since the experience suggests that it is hard not to exceed theoutput 140 mg/dL after a big meal.

Hence, the implementation of the constraints must be able to handle deviationsfrom the invariant set. Therefore, the constraints are implemented as soft con-straints, which means that deviations from the set are allowed, but penalized inthe optimization objective function. As opposed to this, a normal constraint im-plementation will be named hard constraint for clarity. The soft constraint willcause no issues with infeasible solutions due to the invariant set, since there areno (hard) constraints related to the invariant set to violate. There are, however,various ways to parametrize the penalization of the soft constraints:

Assume the invariant set is described as Ax ≤ b. The implementation of this as ahard constraint into the mpc optimization problem (2.8) would then be

minu(t),u(t+1),...,u(t+nc−1)

F (x(t), u(t), . . . , u(t + nc − 1)) (4.1)

subject to Ax(t + 1) ≤ b, . . . ,Ax(t + nc) ≤ b

However, implementing the set Ax ≤ b as a soft constraint can either be made as

minu(t),u(t+1),...,u(t+nc−1)

F (x(t), u(t), . . . , u(t + nc − 1)) + G(εt+1, . . . , εt+nc+1) (4.2)

subject to Ax(t + 1) ≤ b + εt+1, . . . ,Ax(t + nc) ≤ b + εt+ncεt+1, . . . , εt+nc ≥ 0

2This is of course relevant for all constraints, not only constraints related to invariant sets.

Page 52: Model Predictive Control with Invariant Sets in Artificial Pancreas for

36 4 MPC with invariant set constraints for an artificial pancreas

Figure 4.4: An asymmetricly located rectangle described by Ax ≤ b, com-pared to Ax ≤ b + ε for an ε > 0, and Ax ≤ θb with θ (= 2) > 1. Note thedifferent scalings of the rectangle, and compare to the discussed ε- (4.2) andθ-implementation (4.3) of invariant set constraints.

or as

minu(t),u(t+1),...,u(t+nc−1)

F (x(t), u(t), . . . , u(t + nc − 1)) + G(θt+1, . . . , θt+nc+1) (4.3)

subject to Ax(t + 1) ≤ bθt+1, . . . ,Ax(t + nc) ≤ bθt+ncθt+1, . . . , θt+nc ≥ 1

where G( · ) is a strict convex function, e.g., a quadratic function. If ε > 0 or θ > 1(and not equal to 0 or 1 respectively), it indicates deviations from the invariantset in the predicted states. θ and ε can either be scalar or a matrix or vector withone scalar variable for each inequality in A.

The difference between (4.2) and (4.3) may be subtle, but produces significantlydifferent results for this application and is worth a further discussion.

The ε-implementation of the invariant set, (4.2), gives the deviation from theinvariant set in absolute terms. It is, however, dependent on the scaling of therows of the matrix A. If the rows of A are normalized to the length of 1 (whichthey are with the implementation used for computations of A), ε will be in theunits of mg/dL, because of the structure of the state space model.

The θ-implementation of the invariant set, (4.3), gives the deviation from theinvariant set in relative terms, which makes θ unitless and not dependent onthe scaling of A. Studying the invariant set in Figure 4.1a, it is clear that someconstraints are much closer to the origin than others, which will highly affect thepenalization using the θ-implementation and give different ‘weight’ to differentinequalities in A.

The qualitative difference between the ε- and θ-implementation is illustrated inFigure 4.4.

Page 53: Model Predictive Control with Invariant Sets in Artificial Pancreas for

4.4 In silico trials 37

4.4 In silico trials

The mpc algorithm with invariant set for artificial pancreas has been evaluatedin in silico trials. The trials have been done in version 3 of the UVa/Padova sim-ulator (Kovatchev et al. [2009]), see Section 3.4). The trials have been performedas a benchmark against a zmpc controller form the ucsb/Sansum group. Thissection contains information on the trials, as well as the results.

4.4.1 Test protocol

The trial started at 14.00, and the closed loop control of the subjects started 2hours thereafter. Meals were given according to Table 4.1 and the trials endedafter 52 hours.

Meal Dinner Breakfast Lunch Snack Dinner Breakfast LunchTime 18.30 7.00 13.00 16.00 18.30 7.00 13.00Size 50 g 40 g 50 g 10 g 50 g 40 g 50 g

Table 4.1: Meal schedule in the simulations. The sizes of the meals is thecarbohydrates, e.g., the lunch contains 50 g carbohydrates.

To ensure comparability between the results for different controllers, cgm errorswere generated using the same random seed.

4.4.2 Different controller setups in the trials

Two different controllers were used in the trials. In addition to them, severalother controllers have been tested and evaluated in shorter trials, see Section4.4.5.

1. zmpc: The benchmark controller, tuned with experience from theucsb/Sansumgroup: Asymmetric input costs, control objective 80-140 mg/dL, night timezone (see Subsection 3.6.4) between 00:00 and 05:00 with control objective110-170 mg/dL and an upper bound of control action limited to 1.6 basalrate in the night time zone.

2. MPC with invariant set: The proposed controller;mpc with nominal invari-ant set as soft constraints with scalar θ-implementation (see Section 4.3).The set used for all controllers was a set computed for a tdi value of 33and a basal rate of 1. The input costs were asymmetric and tuned itera-tively. The controller also had a night time zone with an upper bound ofthe control action limited to 1.6 basal rate.

For all controllers the safety systems (Section 3.6.2) and insulin on board con-straints (Section 3.6.3) were inactive, as an attempt to evaluate the efficacy of thecontrol algorithm itself without including the complexities of any safety layers.No information on the meal was present to the controllers, i.e., unannouncedmeals.

Page 54: Model Predictive Control with Invariant Sets in Artificial Pancreas for

38 4 MPC with invariant set constraints for an artificial pancreas

# 1 2 3 4 5 6 7 8 9 10Age 32 22 42 24 47 23 47 56 24 31

Weight (kg) 80 80 71 67 67 73 46 98 68 81tdi (U) 42 43 52 35 40 72 43 52 34 47

Basal (U/h) 1.2 1.3 1.5 1.0 0.9 1.9 1.2 1.1 0.9 1.2

Table 4.2: Some parameters for the virtual subjects in the trial

4.4.3 Subjects in the trial

The simulator contains a set of 10 virtual subjects. Each subject is associatedwith individual different physiological parameters. A few of these parametersare presented in Table 4.2, to get an idea of the variety between the subjects inthe trial.

4.4.4 In silico results

The results from the in silico trial are presented in this section. The results arepresented in a few different ways

• Tables with ratios of time spent in different blood glucose intervals

• Population plots showing the blood glucose mean, standard deviation andmin/max values over all subjects, for each time instance

• Control Variable Grid Analysis (cvga) plots, showing the 90% confidencebounds on the highest and lowest blood glucose value for each subject dur-ing the trials

• Entire blood glucose trajectory and control action for 3 different subjects.

Tables

The in silico results are presented for Controller 1 (the zmpc controller) in Ta-ble 4.3a, and for Controller 2 (the mpc controller with invariant sets) in Ta-ble 4.3b. Each row adds up to 100, except for rounding effects, and shows thedistribution of all blood glucose values for all subjects during the closed loopcontrol in the trials.

Population plots

The population plots in Figure 4.5a and 4.5b shows the mean, standard deviationand min/max envelope for the blood glucose values in the trials.

Page 55: Model Predictive Control with Invariant Sets in Artificial Pancreas for

4.4 In silico trials 39

below within aboveAll day 80-140 mg/dL 0.37 41.62 58.00All day 70-180 mg/dL 0.04 74.81 25.15

22:30-07:00 80-140 mg/dL 0.63 58.40 40.9822:30-07:00 70-180 mg/dL 0.00 98.12 1.88

00:00-05:00 110-220 mg/dL 4.82 95.18 0.00

(a) Controller 1, the benchmark zmpc controller

below within aboveAll day 80-140 mg/dL 0.25 42.27 57.48All day 70-180 mg/dL 0.00 74.66 25.34

22:30-07:00 80-140 mg/dL 0.77 69.38 29.8422:30-07:00 70-180 mg/dL 0.00 99.81 0.19

00:00-05:00 110-220 mg/dL 2.74 97.26 0.00

(b) Controller 2, the proposed invariant set controller.

Table 4.3: Time in range-statistics for the in silico trials. All values are per-centages.

CVGA plots

The Control Variable Grid Analysis plot (cvga , Magni et al. [2008]) is a plotdeveloped for being a compact way to illustrate trial results. In short, the cvgaplot is showing the 95% confidence bound for the highest and lowest blood glu-cose value for each subject as y- and x-coordinate respectively, and the space isdivided into different zones (represented by different colors) to facilitate evalu-ation. For instance is a subject in the A-zone intended to be preferred over theB-zone. The cvga plots for the trials are found in Figure 4.6a and 4.6b. Notehowever the nonlinear scaling of the y-axis.

General comments

In general, the two different controllers performs similarly, but not identically. Itis apparent from the population and cvga plots that the proposed Controller 2results in a smaller variation between the subjects, i.e., the min-max envelope inthe population plot is smaller and the points in the cvga are more clustered.

It is also interesting to note the more steady and less ‘oscillatory’ control, es-pecially during the night, for Controller 2 (the proposed controller) comparedto Controller 1 (the zmpc controller). Subjects controlled by Controller 2 startstheir new day, in general, with a less oscillating blood glucose curve, compared toController 1. In this comparison, it is however important to remember the differ-ent tuning with an overnight zone with a higher objective zone (110-170 mg/dL)for the blood glucose values in Controller 1 than for Controller 2.

Page 56: Model Predictive Control with Invariant Sets in Artificial Pancreas for

40 4 MPC with invariant set constraints for an artificial pancreas

(a) Controller 1, the benchmark zmpc controller

(b) Controller 2, the proposed invariant set controller

Figure 4.5: Population plots. The solid blue line is the mean, the red dash-dotted line is 1 standard deviation, and the black dash-dotted line is themin-max envelope, of all subjects.

Page 57: Model Predictive Control with Invariant Sets in Artificial Pancreas for

4.4 In silico trials 41

(a) Controller 1, the zmpc controller

(b) Controller 2, the invariant set controller

Figure 4.6: cvga plots. Each subject is represented by a small black dot, andthe mean of all points is represented by a bigger blue dot.

Page 58: Model Predictive Control with Invariant Sets in Artificial Pancreas for

42 4 MPC with invariant set constraints for an artificial pancreas

Some interesting subjects

Out of the 10 virtual subjects in the simulator, the results for subject 1, 7 and 9have been chosen to be presented in detail, since they appear to represent charac-teristics typical for the trial.

The blood glucose trajectory for the two different controllers as well as the cgmreading and the controller action for subject 1 are shown in Figure 4.7. Notethe more steady overnight control, the somewhat higher top value of the peaks,slightly more damped oscillations after meals and the more aggressive controlaction for Controller 2 (mpc with invariant set) than for Controller 1 (zmpc).

Subject 7, Figure 4.8, is the subject in the trials where the difference between thecontrollers is largest. The most striking difference is probably the less ‘oscilla-tory’ behavior in the blood glucose curves for Controller 2, and the higher lows.This behavior seems to be achieved thanks to the more aggressive control actionin Controller 2 (than 1) which gives more insulin during the rising slopes andsuspends the pump earlier on downward slopes.

The results of subject 9, Figure 4.9, are similar to subject 1. Here, however, allpeaks are of the same height, but the differences in the lows are larger betweenthe controllers. The blood glucose trajectory for Controller 2 is hardly never lessthan 110 mg/dL, although Controller 1 goes below 100 mg/dL several times.

4.4.5 Evaluation of alternative controllers

Other controllers have also been tested in silico, but are only briefly presentedhere, since their performance has not been found as promising as Controller 2 inthe in silico trials.

• mpcwith an invariant set for a tdi value close to the actual tdi value3 ofthe subject. Only very small differences in performance were found, com-pared to Controller 2, not giving a qualitatively different behavior. How-ever, the tdi value is inverse proportional to the model gain (see (3.1)).Since the effect of the input is scaled by the model gain, and the lowerbound on the input is the basal rate, the relevant value for the invariantset shape is in fact not the tdi value nor the basal rate, but the fractionBasal/tdi (assuming that the exact value of the upper bound on the inputis of less importance). Looking at Table 4.2, it becomes clear that the rangeof values for the fraction Basal/tdi is smaller than the range of tdi andbasal rates respectively, i.e., there is a correlation between basal rates andtdi values. Hence it is justified to use only one invariant set for all con-trollers, as done in the in silico trials.

• mpc controller using an invariant set robust against cgm errors accord-ing to Subsection 4.2.3. However, a robustification against realistic mea-surement errors yields a controller with a very small invariant set (cf. shrink-ing the objective zone with the upper bound on measurement errors). With

3In the in silico trials, a set for a tdi value of 33 was used for the control of all subjects.

Page 59: Model Predictive Control with Invariant Sets in Artificial Pancreas for

4.4 In silico trials 43

Glu

cose

[mg/

dL]

Blood glucose level

00:00 00:00

50

100

150

200

250

300

00:00 00:00

0

0.1

0.2

0.3

0.4

0.5Invariant Set control action. TDI (18:00−18:00) = 31.95 [U] , Basal = 1.20 [U/h]

Insu

lin [U

]

Time of day

00:00 00:00

0

0.1

0.2

0.3

0.4

0.5zMPC control action. TDI (18:00−18:00) = 32.75 [U] , Basal = 1.20 [U/h]

Insu

lin [U

]

Time of day

70−180mg/dL

80−140mg/dL Meal BG

(Invariant Set)CGM(Invariant Set)

BG(zMPC)

CGM(zMPC)

Figure 4.7: Blood glucose trajectory for subject 1. The blood glucose curvefor controller 2 (the mpc controller with invariant set) is the solid blue line,and the controller action is the upper graph. The blood glucose for Con-troller 1 (the zmpc controller) is the dashed black line, and the lower graphwith control action.

Page 60: Model Predictive Control with Invariant Sets in Artificial Pancreas for

44 4 MPC with invariant set constraints for an artificial pancreas

Glu

cose

[mg/

dL]

Blood glucose level

18:00 00:00 06:00 12:00 18:00 00:00 06:00 12:00 18:00

50

100

150

200

250

300

18:00 00:00 06:00 12:00 18:00 00:00 06:00 12:00 18:00

0

0.1

0.2

0.3

0.4

0.5Invariant Set control action. TDI (18:00−18:00) = 35.60 [U] , Basal = 1.25 [U/h]

Insu

lin [U

]

Time of day

18:00 00:00 06:00 12:00 18:00 00:00 06:00 12:00 18:00

0

0.1

0.2

0.3

0.4

0.5zMPC control action. TDI (18:00−18:00) = 36.00 [U] , Basal = 1.25 [U/h]

Insu

lin [U

]

Time of day

70−180mg/dL

80−140mg/dL Meal BG

(Invariant Set)CGM(Invariant Set)

BG(zMPC)

CGM(zMPC)

Figure 4.8: Blood glucose trajectory for subject 7

Page 61: Model Predictive Control with Invariant Sets in Artificial Pancreas for

4.4 In silico trials 45

Glu

cose

[mg/

dL]

Blood glucose level

18:00 00:00 06:00 12:00 18:00 00:00 06:00 12:00 18:00

50

100

150

200

250

300

18:00 00:00 06:00 12:00 18:00 00:00 06:00 12:00 18:00

0

0.1

0.2

0.3

0.4

0.5Invariant Set control action. TDI (18:00−18:00) = 26.30 [U] , Basal = 0.95 [U/h]

Insu

lin [U

]

Time of day

18:00 00:00 06:00 12:00 18:00 00:00 06:00 12:00 18:00

0

0.1

0.2

0.3

0.4

0.5zMPC control action. TDI (18:00−18:00) = 26.80 [U] , Basal = 0.95 [U/h]

Insu

lin [U

]

Time of day

70−180mg/dL

80−140mg/dL Meal BG

(Invariant Set)CGM(Invariant Set)

BG(zMPC)

CGM(zMPC)

Figure 4.9: Blood glucose trajectory for subject 9

Page 62: Model Predictive Control with Invariant Sets in Artificial Pancreas for

46 4 MPC with invariant set constraints for an artificial pancreas

a very small target set, the controller becomes similar to a set-point con-troller, and the advantages of the zmpc idea (Grosman et al. [2010]) be-comes less present, and the controller performs poorer than any of the con-troller in the in silico trials.

• mpc controller with invariant set robust against meals or plant-modelmismatch. In the absence of a meal model or an uncertainty bound onthe model (3.1), no meaningful way to robustify against meals or plant-model mismatch was found, as described in Subsection 4.2.3 and 4.2.4 re-spectively.

• mpc controller with invariant set using ε-implementation (see Section4.3) for penalization of deviations from the invariant set. The result forsuch a controller are more similar to Controller 1, the zmpc controller, thanController 2. This could however be an interesting controller if Controller2 is found to be, e.g., too aggressive.

• mpc controller using invariant set with one θ/ε variable per constraint(and not one per prediction step, see Section 4.3). This increases the size ofthe optimization problem drastically, and was not realistic to solve in theframework the implementation was done, using the built-in optimizationsolvers in Matlab.

• mpc controller using contractive invariant set. Due to the very big sim-ilarities between the controlled invariant and the controlled contractive(λ = 0.99) invariant sets (see Figure 4.1), is the perfomance of a mpc con-troller using a contractive set almost identical to a controller using the in-variant set controller.

• mpc controller with periodic invariant set using overnight zones with ahigher control objective (e.g., 110-170 mg/dL) during night time. Such acontroller is possible to implement, but since Controller 2 did not showany problems at all with hypoglycemia during overnight, this controllerwas decided not to be a part of the in silico trials.

Page 63: Model Predictive Control with Invariant Sets in Artificial Pancreas for

5Concluding comments

This chapter gives some comments on the presented work and results. There arealso some suggestions on directions for further work.

5.1 Comments and conclusions

First, the in silico results will be commented in this section, and the approachwith invariant set in general will be discussed thereafter.

5.1.1 In silico results

The in silico results looks overall promising and interesting, as seen in Figure 4.5.However, the most interesting evaluation would be a clinical trial, and too com-prehensive conclusions should not be drawn from the in silico results.

5.1.2 Invariant set approach

Since the same model has been used for prediction in the invariant set mpc con-troller as in the zmpc controller, and somewhat ‘better’ results have been ob-tained, it is clear that there exists information in the predicted states that is notfully utilized with the zmpc approach. The concept of invariance is obviouslyone way to exploit this information, however not proven to be the optimal one. Itis not really clear whether the improved results actually are due to the conceptof invariance, or if it is of a more coincidental occurrence. There could possiblyexists another underlying structure or concept that is more powerful to utilize forthe purpose of improved mpc for artificial pancreas control, than the invariantset.

47

Page 64: Model Predictive Control with Invariant Sets in Artificial Pancreas for

48 5 Concluding comments

The invariant set approach is relatively ‘model-intensive’, and the results wouldprobably improve with even better models. Even though the arx model (3.1)used for the insulin-glucose relation indeed is relevant to the problem, it does notcatch the entire characteristics of the dynamics. Also the shortage of satisfyingmodels for, e.g., meals, cgm errors and plant-model mismatch is apparent.

Although the results for the invariant set control are promising, the tuning andthe understanding of the control algorithm is more advanced than for the zmpcsolution. E.g., the computation of a new invariant set might be necessary in aretuning of an mpc with invariant set, which requires a higher workload thanonly changing some parameters during a re-tuning of the zmpc.

5.2 Further work

In this section, some interesting ways to extend and further investigate the pre-sented work are suggested.

• The tuning of Controller 2 in the in silico trials is by no means done system-atically, and a systematic tuning of the parameters (i.e., control objectivezones, input/output costs, ε- or θ- implementation, prediction and controlhorizon, different kinds of invariant sets (nominal, contractive, robust, pe-riodic), etc.) could probably result in an even better control.

• The absence of a model describing meals has been a bottleneck for all at-tempts to develop a controller robust to meals. If, e.g., the insulin-glucosemodel (3.1) was extended with a second input (describing meals), a robus-tification against a possible meal at, e.g., the time 13.00 and 18.00 couldbe an interesting concept to investigate. Such an extension of the modelwould, however, in the best case not affect the dimensions of the model(3.1), since the computations of invariant sets with the presented methodswould probably be a new bottleneck for a 4- (or even higher) dimensionalmodel.

• Given knowledge on the mismatch between the model (3.1) and the truesystem, a controller using invariant sets robust against such plant-modelmismatches could be an interesting subject. A parametrization of the mis-match could possibly be a way to better personalization of the control toeach subject, as intended by the safety factor F in (3.1) (van Heusden et al.[2012]).

• The attempt to develop a controller robust to cgm errors has so far notbeen successful, see Section 4.4.5. However, with better models of the errordynamics and with more sophisticated theory utilizing not only the errorbounds, but also the error dynamics, such an attempt could be interesting.

Page 65: Model Predictive Control with Invariant Sets in Artificial Pancreas for

5.2 Further work 49

• To determine whether the obtained results are due to the concept of invari-ance or not, as discussed in Section 5.1, it could be interesting to develop anmpc strategy (without invariant set) penalizing not only the absolute valuesof the cgm readings, but also the rate of change, and see if similar resultsare possible to obtain with such an approach.

Page 66: Model Predictive Control with Invariant Sets in Artificial Pancreas for
Page 67: Model Predictive Control with Invariant Sets in Artificial Pancreas for

AInvariant set mathematics

In this chapter, a description of the mathematical algorithm for computations ofinvariant sets using convex polyhedral sets, is provided. For computations of therobust and periodic case is referred to Blanchini [1999] respectively Blanchiniand Ukovich [1993].

A.1 Controlled invariant set

A controlled invariant set (Definition 2.6) for the system x(t + 1) = Fx(t) + Gu(t),y = Hx(t), x ∈ Rn and u ∈ U (where U is a convex polyhedral set) can be com-puted via a reversed reachability analysis algorithm. The algorithm is describedin detail in the following:

1. Define1 A1 and b1 such that the set X1 = {x ∈ Rn|A1x ≤ b1} describes the

given state constraints2. E.g., output constraints on the form y ∈ [ymin, ymax]

can be transformed to state constraints as[H−H

]x ≤

[ymax−ymin

].

2. Define the lifted state space X̄i as the set of input signals u ∈ U and statesx ∈ X such that the states in the following time step will be in Xi−1, i.e.,

X̄i = {x ∈ Rn+m|[Ai−1F Ai−1G

0 Au

] [xu

]≤

[bibu

]}.

1Although the convention of using the index 0 for this appears to be the most common in theliterature, index 1 is here used to conform with the Matlab code.

2Which here is implicitly assumed to be a convex polyhedral set.

51

Page 68: Model Predictive Control with Invariant Sets in Artificial Pancreas for

52 A Invariant set mathematics

3. Since the invariant set concept only cares about existence of control signals,and not the control law itself, the ‘input dimensions’ of the set X̄ is pro-jected onto the subspace Rn where the states lives, i.e., ¯̄

Xi = Projection(X̄i , n)

4. Xi is finally obtained by intersection between ¯̄Xi and Xi−1, i.e., Xi =

{x ∈ Rn|[ ¯̄AiAi−1

]x ≤

[ ¯̄bibi−1

]}, where ¯̄Ai and ¯̄bi is describing the set ¯̄

Xi .

5. If Xi is the empty set, the invariant set does not exist, and the procedurecan be aborted.

6. If Xi = Xi−1, a fixed-point is reached and Xi is the invariant set.

7. Otherwise, return to Step 2.

Page 69: Model Predictive Control with Invariant Sets in Artificial Pancreas for

BImplementation

This appendix contains some details on the implementation for various tasks inthis thesis.

B.1 Software

The software used for the computations of the invariant sets are listed in Ta-ble B.1.

Name Organization/ Authors Version URLMatlab The MathWorks, Inc. R2011b www.mathworks.com/matlabmpt3 Kvasnica et al. [2004] 3.0 www.tbxmanager.comGurobi Gurobi Optimization, Inc. 5.1.0 www.gurobi.com

Table B.1: Software used for computations

Version 3 of the UVa/Padova simulator (Magni et al. [2008]) was used for the insilico trials (see Section 4.4) . The controller code used for the trials was based onthe code described in Grosman et al. [2010].

B.2 Matlab code

The Matlab code for some computational tasks are provided in this section. Firstthe code for computing the invariant set for the insulin-glucose model (3.1) on thestate space form (2.6) is found. Second the code for Example 2.10 is presented.

53

Page 70: Model Predictive Control with Invariant Sets in Artificial Pancreas for

54 B Implementation

B.2.1 Code for invariant set computations

The Matlab code in this subsection is divided into two parts. The first part definesthe insulin-glucose model (3.1) on state space form (2.6), and calls the secondpart, the function InvariantSetDiscreteLTISystem.m. This code requiresthe toolbox mpt3, see Section B.1. The comments about step numbers in thesecond part refer to the mathematical algorithm presented in Section A.1.

main.m

K = -0.01;a1 = -0.965*2-0.98;a2 = 2*0.98*0.965+0.965^2;a3 = -0.98*0.965^2;

sys.F = [-a1 -a2 -a3; 1 0 0; 0 1 0];sys.G = [K; 0; 0];sys.H = [0 0 1];sys.T = 5*60;

% Input constraintssys.umin = -10;sys.umax = 100;

% State constraintssys.xBoundaries = Polyhedron('A',[eye(3);-eye(3)],'b',30*[1 1 1 1 1 1]);

% Output constraintssys.ymin = -Inf;sys.ymax = Inf;

max_it = 100;lambda = 1;

time = cputime;[InvSet, N] = InvariantSetDiscreteLTI(sys,lambda,max_it);display(['Total time elapsed ', num2str(cputime-time)])

InvariantSetDiscreteLTISystem.m

function [ InvSet, N ] = InvariantSetDiscreteLTI( sys, lambda, max_it )%INVARIANTSETDISCRETELTI Calculates the invariant (or contractive) set for%the system sys% Calculate the invariant or contractive set for the discrete LTI system% sys.%% sys - Description of discrete LTI system, with dynamics% x(t+1) = F*x(t) + G*u(t), y(t) = H*x(t).% The struct sys must be on the following form:% sys.F% sys.G% sys.H% sys.umin% sys.umax

Page 71: Model Predictive Control with Invariant Sets in Artificial Pancreas for

B.2 Matlab code 55

% sys.xBoundaries MPT Polyhedron object% sys.ymin% sys.ymax% sys.T Sampling time%% lambda - contraction paramterer when calculating contractive sets.% lambda = 1 gives an invariant set.%% max_it - number of iterations before the calculation is stopped% (if no convergence before)%% Andreas Svensson, 2013

F = sys.F;G = sys.G;

% Define dimensions for the problemdim = size(F,1);

%Preallocate structsX = cell([1,max_it]);X_ = cell([1,max_it]);X__ = cell([1,max_it]);A = cell([1,max_it]);b = cell([1,max_it]);

A{1} = [sys.xBoundaries.A; sys.H; -sys.H];b{1} = [sys.xBoundaries.b; sys.ymax; -sys.ymin];X{1} = Polyhedron('A',A{1},'b',b{1}); %STEP 1

X{1}.plot;title('Iteration number 1')

UcA = [eye(size(G,2)); -eye(size(G,2))];Ucb = [sys.umax; -sys.umin];

i = 2;exit = 0;while (i > max_it) + exit == 0

%Exit conditions: Either fix point, or too many iterationstic[¬,n] = size(A{i-1});X_{i} = Polyhedron('A', [A{i-1}*F A{i-1}*G; zeros(2,n), UcA],...

'b',[lambda*b{i-1};lambda*Ucb]);%STEP 2, augmentation of the state space and the input space

X__{i} = X_{i}.projection(1:dim); %STEP 3, ProjectionX{i} = X{i-1}.intersect(X__{i}); %STEP 4, Intersection

A{i} = X{i}.A;b{i} = X{i}.b;

X{i}.plot;title(['Iteration number ', num2str(i)])pause(0.05)

exit = X{i-1}==X{i}; %STEP 6 Check if fix point is reachedT = toc;

Page 72: Model Predictive Control with Invariant Sets in Artificial Pancreas for

56 B Implementation

display(['Iteration number ', num2str(i), ': ', num2str(T)])i = i+1;

end

N = i-1;

InvSet = X{1};for i = 2:N

InvSet = InvSet.intersect(X{i});end

if exittitle([num2str(i-1), ', Invariant set found! :-)'])display('Invariant set found! :-)')

elsetitle([num2str(i-1), ', Terminated early. :-('])display('Terminated early. :-(')

end

end

B.2.2 Code for Example 2.10

This Matlab computes the robust periodic contractive set described in Exam-ple 2.10, and performs a simulated mpc control using this. The code automat-ically produces Figure 2.10 and a simplified version of Figure 2.9. The code is,however, relatively general in its notation, and should be straight forward to mod-ify for related problems. This code requires mpt3 and Gurobi, see Section B.1,

cleartime = cputime;

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% Define system struct 'sys' %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

% System dynamics on the form%% x(t+1) = sys.F*x(t) + sys.G*u(t) + sys.E*d(t),% y(t) = sys.H*x(t)%% where y(t) is the system output, u(t) is the control input% and d(t) are the disturbances.

sys.F = [1.67 -0.71; 1 0];sys.G = [1; 0];sys.E = -1*eye(2);sys.H = [17.3 -199];

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% Define problem struct 'prob' %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

% The struct prob defines the entire problem. Each feature (except prob.P)

Page 73: Model Predictive Control with Invariant Sets in Artificial Pancreas for

B.2 Matlab code 57

% is an array with prob.P cells, one for each corresponding time step

%%% Define periodicity of period Pprob.P = 24;

%%% Define state bounds on the form Ax*x < bx, for each time step% Upper and lower bound on y; lby < y < uby

uby = [10 10 10 10 10 10 30 30 30 30 5 30 ...30 30 30 30 30 30 30 0 30 30 30 30];

lby = [10 10 10 10 10 10 10 30 30 30 5 30 ...30 30 30 30 30 30 0 30 30 30 30 30];

% Distribute uby and lby to corresponding time step, using y = H*x% together with the ultimate bounds on x [-1e5, 1e5]*[-1e5, 1e5]prob.Ax = cell(prob.P,1);[prob.Ax{1:prob.P}] = deal([sys.H; -sys.H; eye(2); -eye(2)]);

prob.bx = cell(prob.P,1);for i = 1:prob.P

prob.bx{i} = [uby(i); lby(i); 1e5*[1; 1; 1; 1]];end

%%% Define input bounds for each step on the form Au*u < buprob.Au = cell(prob.P,1);[prob.Au{1:prob.P}] = deal([1; -1]);

prob.bu = cell(prob.P,1);[prob.bu{1:prob.P}] = deal([0.5; 0.5]);

%%% Define disturbance bounds for each step on the form Ad*d < bd

prob.Ad = cell(prob.P,1);[prob.Ad{1:prob.P}] = deal([eye(2); -eye(2)]);

prob.bd = cell(prob.P,1);[prob.bd{1:prob.P}] = deal(0.01*[1; 1; 1; 1]);prob.bd{7} = deal(0.25*[1; 1; 0; 0]);prob.bd{12} = deal(0.25*[1; 1; 0; 0]);prob.bd{16} = deal(0.1*[1; 1; 0; 0]);prob.bd{20} = deal(0.25*[1; 1; 0; 0]);prob.bd{22} = deal(0.1*[1; 1; 0; 0]);

%%% Define contraction factorprob.lambda = 0.99;

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% Define simulation parameters %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

%%% Number of simulated periodssim.n = 3;

%%%%%%%%%%%%%%%%%%%%%%% End of input %%%%%%%%%%%%%%%%%%%%%%%

% Add some state space model information in struct sys

Page 74: Model Predictive Control with Invariant Sets in Artificial Pancreas for

58 B Implementation

sys.n = size(sys.F,2);sys.un = size(sys.G,2);sys.dn = size(sys.E,2);

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% Calculate invariant set %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

% Initializefor h = prob.P:-1:1S{h,1} = Polyhedron('A',prob.Ax{h},'b',prob.bx{h});end

set_found = false; % Initializationis_empty = false; % Initializationmax_it = 300; % Maximum number of iterations before ending prematurely

k = -prob.P-1; %Initialize step counter

while -k < max_it + prob.P && ¬set_found && ¬is_emptytic

lcurrent = floor( ( - k - 1) / prob.P ) + 1; % Index of periodic roundhcurrent = k + lcurrent * prob.P + 1; % Index within periodic round

ktarget = k + 1; % Target stepltarget = floor( ( - ktarget - 1 ) / prob.P ) + 1; % Target indexhtarget = ktarget + ltarget * prob.P + 1; % Target index

Atarget = S{htarget,ltarget}.A; % Get the set matrices for the targetbtarget = S{htarget,ltarget}.b; % step

Ap = S{hcurrent,lcurrent-1}.A; % Get the set matrices for the step inbp = S{hcurrent,lcurrent-1}.b; % the previous periodic round

[m,n] = size(Atarget);[mp,np] = size(Ap);

% Calculate the erosion for robustification against disturbanceserosion = zeros(m,1);for j = 1:m

prob.A = sparse(prob.Ad{hcurrent});prob.lb = -Inf*ones(sys.dn,1);prob.rhs = prob.bd{hcurrent};prob.sense = '<';prob.obj = -Atarget(j,:)*sys.E;params.outputflag = 0;y = gurobi(prob,params);erosion(j) = -y.objval;

end

% Define the augmented set S_S_ = Polyhedron('A',...

[Atarget*sys.F Atarget*sys.G; ...zeros(2*sys.un,sys.n), prob.Au{hcurrent}],...'b', [prob.lambda*btarget-erosion;prob.lambda*prob.bu{hcurrent}]);

Page 75: Model Predictive Control with Invariant Sets in Artificial Pancreas for

B.2 Matlab code 59

% Project S_ on the dimensions belonging to the state spaceSp = S_.projection(1:sys.n);

if Sp.isEmptySetis_empty = true;

end

% Intersect current step with corresponding step from previous roundS{hcurrent,lcurrent} = Polyhedron('A',[Ap; Sp.A],'b',[bp; Sp.b]);

% Define set for control constraintsC{htarget,ltarget} = Polyhedron('A',S{htarget,ltarget}.A,...

'b',S{htarget,ltarget}.b-erosion);

figure(1)S{hcurrent,lcurrent}.plottitle([num2str(hcurrent),', ',num2str(lcurrent),...

' (', num2str(k+prob.P),')'])pause(0.05)

if S{hcurrent,lcurrent}.isEmptySetis_empty = true;

elseif lcurrent > 2 && S{hcurrent,lcurrent-1} == S{hcurrent,lcurrent}set_found = true;

end

T = toc;display([num2str(hcurrent),', ',num2str(lcurrent),...

' (', num2str(k+prob.P),') ', num2str(T), ' s.'])

k = k-1;endk = k+1;

if set_founddisplay('Invariant set found!')

elseif is_emptydisplay('Empty set; no periodically invariant set exists!')clf

elsedisplay('Terminated early')

end

display(['Total time elapsed ', num2str(cputime-time)])

if ¬set_found % End scriptreturn

end

%%%%%%%%%%%%%%%%%%%%%%%%%%%%% Plot invariant set %%%%%%%%%%%%%%%%%%%%%%%%%%%%%

% Size of subplot plotp = ceil(sqrt(prob.P));q = p - (p*(p-1)≥prob.P);

Page 76: Model Predictive Control with Invariant Sets in Artificial Pancreas for

60 B Implementation

figure(2), clf

for n = k:1:k+prob.P-1lp = floor((-n-1)/prob.P)+1;hp = n + lp*prob.P + 1;subplot(p,q,prob.P+k-n)dim = S{hp,lp}.Dim;if dim == 2

% Plot set (MPT plot function is not supported in subplots)hull = convhull(S{hp,lp}.minVRep.V(:,1),S{hp,lp}.minVRep.V(:,2));fill(S{hp,lp}.minVRep.V(hull,1),S{hp,lp}.minVRep.V(hull,2),'r');

elseif dim == 3% Plot set (MPT plot function is not supported in subplots)M = S{hp,lp}.minVRep.V;hull = convhull(M(:,1),M(:,2),M(:,3));trisurf(hull,M(:,1),M(:,2),M(:,3),'Facecolor','r')

endtitle([num2str(hp),', ',num2str(lp), ' (', num2str(n+prob.P),')'])

end

InvSet = cell(1,prob.P);

for j = 1:prob.Psubplot(p,q,j)if isempty(S{j,end})

InvSet{j} = S{j,end-1};else

InvSet{j} = S{j,end};enddim = InvSet{j}.Dim;if dim == 2

% Plot set (MPT plot function is not supported in subplots)hull = ...

convhull(InvSet{j}.minVRep.V(:,1),InvSet{j}.minVRep.V(:,2));fill(InvSet{j}.minVRep.V(hull,1),InvSet{j}.minVRep.V(hull,2),'r');

elseif dim == 3% Plot set (MPT plot function is not supported in subplots)M = InvSet{j}.minVRep.V;hull = convhull(M(:,1),M(:,2),M(:,3));trisurf(hull,M(:,1),M(:,2),M(:,3),'Facecolor','r')

endtitle(num2str(j),'FontWeight','bold')

end

% Extract the set aimed for control constraintsSetConstr = cell(1,prob.P);

for j = 1:prob.Pif isempty(C{j,end})

SetConstr{j} = C{j,end-1};else

SetConstr{j} = C{j,end};end

end

%%%%%%%%%%%%%%%%%%%%%% Simulations %%%%%%%%%%%%%%%%%%%%%%

Page 77: Model Predictive Control with Invariant Sets in Artificial Pancreas for

B.2 Matlab code 61

N = sim.n*prob.P;

% Set random seedrng(1,'v5uniform')

% Preallocationsx = zeros(sys.n,N+1); y = zeros(1,N); u = zeros(1,N); d = zeros(2,N);

% Initializatiopnsx(:,1) = [0,0];t = 1:N;

for i = tj = mod(i,prob.P); jplus1 = j+1; j = j + (j==0)*10; % Define index

% Generate disturbances according to description% (assuming given on a form with Ad = [eye(2); -eye(2)])b = prob.bd{j};d(:,i) = (b(1:2)+b(3:4)).*(rand(2,1)-0.5) + (b(1:2)-b(3:4))/2;

% Calculate outputy(1,i) = sys.H*x(:,i);

% MPC problem with prediction horizon 1 and no outputpr.obj = 0; pr.Q = sparse(1);pr.A = sparse([SetConstr{jplus1}.A*sys.G; prob.Au{j}]);pr.sense = '<';pr.rhs = [SetConstr{jplus1}.b-SetConstr{jplus1}.A*(sys.F*x(:,i));...

prob.bu{j}];pr.lb = -Inf; pr.ub = Inf;params.outputflag = 0;s = gurobi(pr,params);

% Simulate systemu(i) = s.x;x(:,i+1) = sys.F*x(:,i) + sys.G*s.x + sys.E*d(:,i);

end

% Plottingfigure(3)

subplot(2,1,1)limh = plot(t,repmat(uby,1,sim.n),'Color',0.8*[1 1 1],'LineWidth',2);hold on;plot(t,-repmat(lby,1,sim.n),'Color',0.8*[1 1 1],'LineWidth',2);yh = plot(t,y,'k');disth = stem(t,150*(d(1,:)+d(2,:))-100,'k-','fill','marker','.');baseline_handle = get(disth,'BaseLine');set(baseline_handle,'BaseValue',-100)hold off; axis([t(1) t(end) -100 100])legend([yh disth limh],'Output','Disturbances','Output boundaries')title('Output trajectory and disturbances'); xlabel('Time')

subplot(2,1,2)stem(t,u,'k','fill'); axis([t(1) t(end) -0.4 0.4])title('Control input'); xlabel('Time')

Page 78: Model Predictive Control with Invariant Sets in Artificial Pancreas for
Page 79: Model Predictive Control with Invariant Sets in Artificial Pancreas for

CExperimental invariant set illustration

It is, at least for the author, not easy to get an intuitive feeling for the mean-ing of the shape of an invariant set of dimension N when it is displayed as aN -dimensional figure, as in, e.g., the 2-dimensional set in Figure 2.10 or the 3-dimensional ser in Figure 4.1a. The plotting of an invariant set of dimension Nis also limited, by obvious reason, to N ≤ 3

However, the states of the chosen state space description of the model, presentedin Example 2.1, are possible to interpret as future outputs, i.e., x3(t) = y(t),x2(t) = y(t + T ) and x1(t) = y(t + 2T ), according to the model structure. Thisidea of interpreting the states as consecutive outputs is utilized in Figure C.1.The plotting shows, for one given x3 value at a time (with tick marker x3), theprojection of the x1 - x2 plane onto the x2 axis (with tick marker x2), and finally,for every x2 value, the projection on the x1 axis of the intersection of the given x2and x3 values (with tick marker1 x1).

1Since this is plotted for a lot of different x2 values at the same x1 tick on the axis, the associationbetween the x1 and x2 values are lost. This plot hence only gives an idea of the, in some sense, extremebounds on the invariant set. Since the set is convex, however, the extreme values of x2 are associatedwith the extreme values of x1, which guarantees that the plot is not misleading in that sense.

Figure C.1: Experimental illustration of the invariant set

63

Page 80: Model Predictive Control with Invariant Sets in Artificial Pancreas for

64 C Experimental invariant set illustration

Three consecutive output values at the times t, t + T and t + 2T from the modelare possible to interpret as the state of the model at time t. Although the practicaluse of this might be limited, it can still provide an intuitive idea of how steep theoutput curves can go2, according to the invariant set.

This way of plotting an invariant set does, indeed, not give full information ofthe invariant set, since only a sample of it is plotted.

2However, for the states at time t + T to still be within the set, if they were at time t, the controlaction taken at time t had to be appropriate.

Page 81: Model Predictive Control with Invariant Sets in Artificial Pancreas for

Bibliography

T Ajanki. Historien om diabetes och insulinets upptäckt. Svenska diabetesförb.,Sundbyberg, 1999. Cited on page 23.

F Blanchini. Ultimate boundedness control for uncertain discrete-time systemsvia set-induced Lyapunov functions. In Decision and Control, 1991., Proceed-ings of the 30th IEEE Conference on, pages 1755–1760. IEEE, 1991. Cited onpage 16.

F Blanchini. Set invariance in control. Automatica, 35(11):1747–1767, 1999.Cited on pages 2, 12, and 51.

F Blanchini and S Miani. Set-theoretic methods in control. Birkhäuser Boston,2007. Cited on page 12.

F Blanchini and W Ukovich. Linear programming approach to the control ofdiscrete-time periodic systems with uncertain inputs. Journal of optimizationtheory and applications, 78(3):523–539, 1993. Cited on pages 2, 12, 17, and 51.

S Boyd and L Vandenberghe. Convex optimization. Cambridge university press,2004. Cited on pages 11 and 12.

G Danaei, MM Finucane, Y Lu, G M Singh, M J Cowan, C J Paciorek, J K Lin,F Farzadfar, YH Khang, GA Stevens, et al. National, regional, and globaltrends in fasting plasma glucose and diabetes prevalence since 1980: system-atic analysis of health examination surveys and epidemiological studies with370 country-years and 2· 7 million participants. The Lancet, 378(9785):31–40,2011. Cited on page 1.

E Dassau, B W Bequette, B A Buckingham, and F J Doyle III. Detection of ameal using continuous glucose monitoring implications for an artificial β-cell.Diabetes Care, 31(2):295–300, 2008. Cited on page 28.

E Dassau, F Cameron, H Lee, B W Bequette, H Zisser, L Jovanovič, H P Chase,D M Wilson, B A Buckingham, and F J Doyle III. Real-time hypoglycemiaprediction suite using continuous glucose monitoring. Diabetes Care, 33(6):1249–1254, 2010. Cited on page 28.

65

Page 82: Model Predictive Control with Invariant Sets in Artificial Pancreas for

66 Bibliography

E Dassau, H Zisser, R A Harvey, M W Percival, B Grosman, W Bevier, E Atlas,S Miller, R Nimri, L Jovanovič, et al. Clinical evaluation of a personalizedartificial pancreas. Diabetes care, 36:801–809, 2013. Cited on page 26.

C E T Dórea and J C Hennet. (A, B)-invariant polyhedral sets of linear discrete-time systems. Journal of optimization theory and applications, 103(3):521–542,1999. Cited on pages 2 and 12.

L Eiselein, H J Schwartz, and J C Rutledge. The challenge of type 1 diabetesmellitus. ILAR Journal, 45(3):231–236, 2004. Cited on page 1.

C Ellingsen, E Dassau, H Zisser, B Grosman, M W Percival, L Jovanovič, and F JDoyle III. Safety constraints in an artificial pancreatic β cell: An implemen-tation of model predictive control with insulin on board. Journal of diabetesscience and technology (Online), 3(3):536, 2009. Cited on page 28.

M Enqvist, T Glad, S Gunnarsson, P Lindskog, L Ljung, J Löfberg, T McKelvey,A Stenman, and J E Strömberg. Industriell reglerteknik kurskompendium. Di-vision of Automatic Control, Department of Electrical Engineering, LinköpingUniversity, Sweden, 2010. Cited on page 9.

T Glad and L Ljung. Control theory. CRC Press, 2000. Cited on pages 5, 8, 9,and 19.

T Glad and L Ljung. Reglerteknik : grundläggande teori. Studentlitteratur, Lund,4., [omarb.] uppl. edition, 2006. Cited on page 5.

R Gondhalekar and C N Jones. MPC of constrained discrete-time linear periodicsystems-a framework for asynchronous control: Strong feasibility, stability andoptimality via periodic invariance. Automatica, 47(2):326–333, 2011. Cited onpage 17.

R Gondhalekar, F Oldewurtel, and C N Jones. Least-restrictive robust periodicmodel predictive control applied to room temperature regulation. Automatica,2013. doi: 10.1016/j.automatica.2013.05.009. Cited on pages 2, 17, and 20.

R Greenberg. Turning diabetes over to the bionic pancreas. Huffington Post,04 2013. URL http://www.huffingtonpost.com/riva-greenberg/diabetes-clinical-trial_b_3110140.html. Cited on page 2.

B Grosman, E Dassau, H Zisser, L Jovanovič, and F J Doyle III. Zone modelpredictive control: A strategy to minimize hyper- and hypoglycemic events.Journal of diabetes science and technology (Online), 4(4):961–975, 2010. Citedon pages iii, v, 1, 26, 28, 46, and 53.

R A Harvey, Y Wang, B Grosman, M W Percival, W Bevier, DA Finan, H Zisser,DE Seborg, L Jovanovic, F J Doyle III, et al. Quest for the artificial pancreas:combining technology with treatment. Engineering in Medicine and BiologyMagazine, IEEE, 29(2):53–62, 2010. Cited on page 26.

C Hellerström. Diabetes : forskningen, framstegen, framtiden. Vetenskapsrådet,Stockholm, 2002. Cited on page 23.

Page 83: Model Predictive Control with Invariant Sets in Artificial Pancreas for

Bibliography 67

L M Huyett, R A Harvey, W Bevier, H Zisser, L Jovanovic, E Dassau, and F JDoyle III. Closed-loop control and quality of continuous glucose monitor databased on prospective closed-loop clinical trial, March 2013. Presented at the6th International Conference on Advanced Technologies and Treatments forDiabetes. Cited on page 24.

B P Kovatchev, M Breton, C Dalla Man, and C Cobelli. In silico preclinical trials:a proof of concept in closed-loop control of type 1 diabetes. Journal of diabetesscience and technology, 3:44–55, January 2009. Cited on pages iii, v, 2, 25,and 37.

M Kvasnica, P Grieder, M Baotić, and M Morari. Multi-parametric toolbox (MPT).Hybrid Systems: Computation and Control, pages 121–124, 2004. Cited onpage 53.

J M Maciejowski. Predictive control with constraints. Pearson education, 2002.Cited on page 9.

L Magni, D M Raimondo, C Dalla Man, M Breton, S Patek, G De Nicolao, C Co-belli, and B P Kovatchev. Evaluating the efficacy of closed-loop glucose reg-ulation via control-variability grid analysis. Journal of diabetes science andtechnology (Online), 2(4):630, 2008. Cited on pages 39 and 53.

K J Åström and R M Murray. Feedback Systems: An Introduction for Scientistsand Engineers. Princeton University Press, 2010. URL http://www.cds.caltech.edu/~murray/amwiki/index.php/Main_Page. Cited on page5.

W J Rugh. Linear system theory. Prentice-Hall, Inc., 1996. Cited on pages 5, 7, 8,and 32.

S J Russell, F H El-Khatib, DM Nathan, K L Magyar, J Jiang, and E R Damiano.Blood glucose control in type 1 diabetes with a bihormonal bionic endocrinepancreas. Diabetes care, 35(11):2148–2155, 2012. Cited on page 24.

J Skyler, editor. Atlas of diabetes. Springer Verlag, 5th edition, 2012. Cited onpages 2, 23, 24, and 26.

G M Steil, K Rebrin, J Mastrototaro, B Bernaba, and M F Saad. Determination ofplasma glucose during rapid glucose excursions with a subcutaneous glucosesensor. Diabetes technology & therapeutics, 5(1):27–31, 2003. Cited on page24.

K van Heusden, E Dassau, H C Zisser, D E Seborg, and F J Doyle III. Control-relevant models for glucose control using a priori patient characteristics.Biomedical Engineering, IEEE Transactions on, 59(7):1839–1849, 2012. Citedon pages iii, v, 1, 2, 8, 25, 26, and 48.

R D Yates and D J Goodman. Probability and stochastic processes. John Wiley &Sons, 2nd edition, 1999. Cited on page 6.

Page 84: Model Predictive Control with Invariant Sets in Artificial Pancreas for

68 Bibliography

H C Zisser, T S Bailey, S Schwartz, R E Ratner, and J Wise. Accuracy of the seven®continuous glucose monitoring system: Comparison with frequently sampledvenous glucose measurements. Journal of diabetes science and technology (On-line), 3(5):1146, 2009. Cited on page 24.

Page 85: Model Predictive Control with Invariant Sets in Artificial Pancreas for

Index

artificial pancreas, 2, 26arx, 25

abbreviation, xiasymmetric costs, 12

basal rate, 25bolus, 26

cgm, 24abbreviation, xierrors, see measurement errors

computations, 53–61control signals, 6csii, 24

abbreviation, xicvga, 39

abbreviation, xi

disturbance signals, 6

ε-implementation, 35–36, 46

fda, see U.S. Food and Drug Adminis-tration

feedback control, 9

glucagon, 24Gurobi, 53

hard constraint, 35hyperglycemia, 23hypoglycemia, 23, 28

implementation, 53in silico, 2, 37–46

input signals, 6insulin on board, 28, 37insulin-glucose model, 25invariant sets, 12–17

computation, 51–52, 54–56constraints, 35–36contractive, 16controlled, 15glucose-insulin model, 31glucose-insulin model, robust, 32–

34, 46maximum, 17periodic controlled, 17positively, 13robust controlled, 16

limitations, 2Luenberger observer, 9

Matlab, 53Matlab code, 53–61meals

announced, 26detection, 28robustification, 34, 48unannounced, 27

measurement errors, 24, 32–34, 48model mismatch, 48mpc, 9–12

abbreviation, xiexample, 17–21zone, see zmpc

mpt3, 53

69

Page 86: Model Predictive Control with Invariant Sets in Artificial Pancreas for

70 Index

night time zone, 28, 37

objective, 2output signals, 6

pendulum, 13phase plan, 14plant, 6plant-model mismatch, 26, 35poles, 7

results, 37–46

safety system, 37safety systems, 28simulations, 25, 37–46simulator, 25, 53soft constraint, 35state estimation, 9state space form, 6

t1dm, 1, 23–25abbreviation, xi

tdi, 25abbreviation, xi

θ-implementation, 36–37transfer function, 7

U.S. Food and Drug Administration, 25ucsb/Sansum group, 1UVa/Padova simulator, see simulator

z-transform, 7zeros, 8zmpc, 12

abbreviation, xi

Page 87: Model Predictive Control with Invariant Sets in Artificial Pancreas for

Upphovsrätt

Detta dokument hålls tillgängligt på Internet — eller dess framtida ersättare —under 25 år från publiceringsdatum under förutsättning att inga extraordinäraomständigheter uppstår.

Tillgång till dokumentet innebär tillstånd för var och en att läsa, ladda ner,skriva ut enstaka kopior för enskilt bruk och att använda det oförändrat för icke-kommersiell forskning och för undervisning. Överföring av upphovsrätten viden senare tidpunkt kan inte upphäva detta tillstånd. All annan användning avdokumentet kräver upphovsmannens medgivande. För att garantera äktheten,säkerheten och tillgängligheten finns det lösningar av teknisk och administrativart.

Upphovsmannens ideella rätt innefattar rätt att bli nämnd som upphovsmani den omfattning som god sed kräver vid användning av dokumentet på ovanbeskrivna sätt samt skydd mot att dokumentet ändras eller presenteras i sådanform eller i sådant sammanhang som är kränkande för upphovsmannens litteräraeller konstnärliga anseende eller egenart.

För ytterligare information om Linköping University Electronic Press se förla-gets hemsida http://www.ep.liu.se/

Copyright

The publishers will keep this document online on the Internet — or its possi-ble replacement — for a period of 25 years from the date of publication barringexceptional circumstances.

The online availability of the document implies a permanent permission foranyone to read, to download, to print out single copies for his/her own use andto use it unchanged for any non-commercial research and educational purpose.Subsequent transfers of copyright cannot revoke this permission. All other usesof the document are conditional on the consent of the copyright owner. Thepublisher has taken technical and administrative measures to assure authenticity,security and accessibility.

According to intellectual property law the author has the right to be men-tioned when his/her work is accessed as described above and to be protectedagainst infringement.

For additional information about the Linköping University Electronic Pressand its procedures for publication and for assurance of document integrity, pleaserefer to its www home page: http://www.ep.liu.se/

© Andreas Svensson