An Insulin Model. James K. Peterson. June 14, Department of Biological Sciences and Department of Mathematical Sciences Clemson University

Similar documents
Mathematical Modeling of Diabetes

Project for Math. 224 DETECTION OF DIABETES

Chapter 3: Linear & Non-Linear Interaction Models

Endocrine System. Regulating Blood Sugar. Thursday, December 14, 17

Human Biochemistry. Hormones

The Chemostat: Stability at Steady States. Chapter 5: Linear & Non-Linear Interaction Models. So, in dimensional form, α 1 > 1 corresponds to

Additional Case Study: Glands and Hormones

Hormones and Homeostasis

Overview. Physiology 1. The Gastrointestinal Tract. Guyton section XI

Chapter 20 Endocrine System

LESSON 2.4 WORKBOOK. Part two: Glucose homeostasis in the blood Un-Storing energy

EB Education Revision Guide. How to work with Homeostasis: Part 2 Blood Glucose Regulation

9.3 Stress Response and Blood Sugar

Chapter 41. Lecture 14. Animal Hormones. Dr. Chris Faulkes

Module 2 Endocrine System

Biology 30. Morinville Community High School. Unit 2: Endocrine System. Name:

Cell Processes: Osmosis


Homeostatic Regulation

Session 3 - The Type 2 Diabetes Cycle Transcript

Respiration Cellular Respiration Understand the relationship between glucose breakdown and ATP when you burn glucose with the help of oxygen, it

Unit 4 Homeostasis. The term homeostasis refers to the body s attempt. Your body systems must to maintain a stable internal environment -

5.0 HORMONAL CONTROL OF CARBOHYDRATE METABOLISM

Endocrine System. Chemical Control

Chapter 4 Reading Guide

Chapter 26. Hormones and the Endocrine System. Lecture by Edward J. Zalisko

Endocrine System Notes

Chemical Regulation. Chapter 26. Testosterone and Male Aggression: Is There a Link? THE NATURE OF CHEMICAL REGULATION

Moh Tarek. Razi Kittaneh. Jaqen H ghar

Ch. 39 Endocrine System

What systems are involved in homeostatic regulation (give an example)?

Concentration of drug [A]

Endocrine System. Chapter 20. Endocrine Glands and Hormones. The Endocrine System. Endocrine glands

Glucoregulation 1 of 27 Boardworks Ltd 2012

Hypoglycemia. When recognized early, hypoglycemia can be treated successfully.

Control of Glucose Metabolism

Testosterone and other male hormones seem to be related to aggressive behavior in some species

Hormonal regulation of. Physiology Department Medical School, University of Sumatera Utara

Endocrine System. Endocrine vs. Exocrine. Bio 250 Human Anatomy & Physiology

number Done by Corrected by Doctor

Stanford Youth Diabetes Coaches Program Instructor Guide Class #1: What is Diabetes? What is a Diabetes Coach? Sample

Energy stores in different organs for a 155 lb male, in Calories

Chapter 20. Endocrine System Chemical signals coordinate body functions Chemical signals coordinate body functions. !

ENERGY FROM INGESTED NUTREINTS MAY BE USED IMMEDIATELY OR STORED

I How the human body is put together and organized

Endocrine System Hormones (Ch. 45)

Slim & Save Re-feed Programme

Endocrine System Hormones. AP Biology

Introduction Causes Of Out Of Control Hunger...3. Dehydration...3. Hyperthyroidism...4. Your Hormones Are off...4. You Skip Meals...

UNIVERSITY OF PNG SCHOOL OF MEDICINE AND HEALTH SCIENCES DIVISION OF BASIC MEDICAL SCIENCES DISCIPLINE OF BIOCHEMISTRY AND MOLECULAR BIOLOGY

6. The diagram below represents an interaction between parts of an organism.

Ch45: Endocrine System

Campbell's Biology: Concepts and Connections, 7e (Reece et al.) Chapter 26 Hormones and the Endocrine System Multiple-Choice Questions

Carbohydrates. Three Types of Carbs Fiber. Does not impact the blood sugar. Cleaners Controllers May be eaten on a Ketogenic diet

3 The Endocrine System

Exercise Physiology: Theory and Application to Fitness and Performance By Scott Powers & Edward Howley

What is the endocrine system?

Computer Science 101 Project 2: Predator Prey Model

Carbohydrate Metabolism

Pancreas. Endocrine pancreas - Islets of Langerhans A or alpha cells glucagon B or beta cells insulin Delta cells somatostatin

1. In this process substances move from the nephron to the circulatory system. A. filtration B. reabsorption C. secretion D.

3. The function of that hormone. In other words, what change does that hormone facilitate.

UNDERSTANDING THE DIGESTIVE SYSTEM

HORMONES AND CELL SIGNALLING

Plant organ systems, regulation and human endocrine systems: 1. Which of the following conditions would NOT cause the stomata to close?

MODELING GLUCOSE-INSULIN METABOLIC SYSTEM AND INSULIN SECRETORY ULTRADIAN OSCILLATIONS WITH EXPLICIT TIME DELAYS. Yang Kuang

Lecture 2: Glycogen metabolism (Chapter 15)

The Endocrine System. By Carl Antiado, Marco Habana, Cameron Loewen, and Nikki Ooka

Standard B-3: The student will demonstrate an understanding of the flow of energy within and between living systems.

MBios 478: Systems Biology and Bayesian Networks, 27 [Dr. Wyrick] Slide #1. Lecture 27: Systems Biology and Bayesian Networks

Thyroid Gland. Chapter 18 Part 2. Thyroid gland. Thyroid Gland. Thyroid Gland. Parathyroid Gland. Adrenal Gland. Pancreas

Control of Blood Sugar Levels

Endocrine System. True or False

Physiology 12. Overview. The Gastrointestinal Tract. Germann Ch 19

Type 1 Diabetes 2/23/2015. Endocrine System Hormones. Living with Type 1 Diabetes

Equine Metabolic Syndrome and Obesity

18. PANCREATIC FUNCTION AND METABOLISM. Pancreatic secretions ISLETS OF LANGERHANS. Insulin

Name Group. 8. Growth 9. Insulin 10. Iodine 11. Manufactures 12. Nervous system 13. Neuron 14. Neurotransmitter

CoreModels Glucose-Insulin Model A CORE LEARNING GOALS ACTIVITY FOR SCIENCE AND MATHEMATICS

Homeostasis. Endocrine System Nervous System

Hormones. Regulation. Endocrine System. What Do Endocrine Glands Release (Secrete)? Endocrine System

The Cell Membrane and Homeostasis What is the cell membrane? A quick review A. Cell Membrane and Cell Transport. Unit 2: Cells and Cell Transport

Endocrine System. Chapter 9

The Endocrine System 2

CHAPTER 50 Endocrine Systems. Copyright The McGraw-Hill Companies, Inc. Permission required for reproduction or display.

Unit 1 Matter & Energy for Life

Diabetes and Related Emergencies. *** CME Version *** Aaron J. Katz, AEMT-P, CIC

5. Maintaining the internal environment. Homeostasis

Target cells only respond to specific signals Different target cells have different kinds of receptors in their membranes or cytoplasm

Copyright Strength Works International Publishing. All rights are reserved.

UNDERSTANDING THE DIGESTIVE SYSTEM

Unit 2: Cellular Chemistry, Structure, and Physiology Module 2: Cellular Chemistry

CIE Biology A-level Topic 14: Homeostasis

NOTES: ENDOCRINE SYSTEM (CH 9)

NOTES 11.5: ENDOCRINE SYSTEM. Pages

Rev. date Kaiser Foundation Health Plan of Washington

The Endocrine System

Endocrine System. The Endocrine Glands

BODY CONTROL SYSTEMS

CHY2026: General Biochemistry UNIT 7& 8: CARBOHYDRATE METABOLISM

Transcription:

An Insulin Model James K. Peterson Department of Biological Sciences and Department of Mathematical Sciences Clemson University June 14, 2017

Outline 1 The Background for the Diabetes Model 2 The Diabetes Detection Model 3 Fitting the Data 4 Gradient Descent Implementation 5 Adding Line Search

Abstract This lecture discusses a model of diabetes detection.

The Background for the Diabetes Model We are now going to discuss a very nice model of diabetes detection which was presented in the classic text on applied mathematical modeling by Braun, Differential Equations and Their Applications.

The Background for the Diabetes Model We are now going to discuss a very nice model of diabetes detection which was presented in the classic text on applied mathematical modeling by Braun, Differential Equations and Their Applications. In diabetes there is too much sugar in the blood and the urine. This is a metabolic disease and if a person has it, they are not able to use up all the sugars, starches and various carbohydrates because they don t have enough insulin.

The Background for the Diabetes Model We are now going to discuss a very nice model of diabetes detection which was presented in the classic text on applied mathematical modeling by Braun, Differential Equations and Their Applications. In diabetes there is too much sugar in the blood and the urine. This is a metabolic disease and if a person has it, they are not able to use up all the sugars, starches and various carbohydrates because they don t have enough insulin. Diabetes can be diagnosed by a glucose tolerance test (GTT). If you are given this test, you do an overnight fast and then you are given a large dose of sugar in a form that appears in the bloodstream. This sugar is called glucose. Measurements are made over about five hours or so of the concentration of glucose in the blood. These measurements are then used in the diagnosis of diabetes. It has always been difficult to interpret these results as a means of diagnosing whether a person has diabetes or not. Hence, different physicians interpreting the same data can come up with a different diagnosis, which is a pretty unacceptable state of affairs!

The Background for the Diabetes Model We are now going to discuss a criterion developed in the 1960 s by doctors at the Mayo Clinic and the University of Minnesota that was fairly reliable. It showcases a lot of our modeling in this course and will give you another example of how we use our tools. We start with a simple model of the blood glucose regulatory system.

The Background for the Diabetes Model We are now going to discuss a criterion developed in the 1960 s by doctors at the Mayo Clinic and the University of Minnesota that was fairly reliable. It showcases a lot of our modeling in this course and will give you another example of how we use our tools. We start with a simple model of the blood glucose regulatory system. Glucose plays an important role in vertebrate metabolism because it is a source of energy. For each person, there is an optimal blood glucose concentration and large deviations from this leads to severe problems including death.

The Background for the Diabetes Model We are now going to discuss a criterion developed in the 1960 s by doctors at the Mayo Clinic and the University of Minnesota that was fairly reliable. It showcases a lot of our modeling in this course and will give you another example of how we use our tools. We start with a simple model of the blood glucose regulatory system. Glucose plays an important role in vertebrate metabolism because it is a source of energy. For each person, there is an optimal blood glucose concentration and large deviations from this leads to severe problems including death. Blood glucose levels are autoregulated via standard forward and backward interactions like we see in many biological systems. An example is the signal that is used to activate the creation of a protein which we discussed earlier.

The Background for the Diabetes Model The signaling molecules are typically either bound to another molecule in the cell or are free. The equilibrium concentration of free signal is due to the fact that the rate at which signaling molecules bind equals the rate at which they split apart from their binding substrate. When an external message comes into the cell called a trigger, it induces a change in this careful balance which temporarily upgrades or degrades the equilibrium signal concentration. This then influence the protein concentration rate.

The Background for the Diabetes Model The signaling molecules are typically either bound to another molecule in the cell or are free. The equilibrium concentration of free signal is due to the fact that the rate at which signaling molecules bind equals the rate at which they split apart from their binding substrate. When an external message comes into the cell called a trigger, it induces a change in this careful balance which temporarily upgrades or degrades the equilibrium signal concentration. This then influence the protein concentration rate. Blood glucose concentrations work like this too, although the details differ. The blood glucose concentration is influenced by a variety of signaling molecules just like the protein creation rates can be.

The Background for the Diabetes Model The signaling molecules are typically either bound to another molecule in the cell or are free. The equilibrium concentration of free signal is due to the fact that the rate at which signaling molecules bind equals the rate at which they split apart from their binding substrate. When an external message comes into the cell called a trigger, it induces a change in this careful balance which temporarily upgrades or degrades the equilibrium signal concentration. This then influence the protein concentration rate. Blood glucose concentrations work like this too, although the details differ. The blood glucose concentration is influenced by a variety of signaling molecules just like the protein creation rates can be. The hormone that decreases blood glucose concentration is insulin.

The Background for the Diabetes Model Insulin is a hormone secreted by the β cells of the pancreas. After we eat carbohydrates, our gastrointestinal tract sends a signal to the pancreas to secrete insulin. Also, the glucose in our blood directly stimulates the β cells to secrete insulin. We think insulin helps cells pull in the glucose needed for metabolic activity by attaching itself to membrane walls that are normally impenetrable.

The Background for the Diabetes Model Insulin is a hormone secreted by the β cells of the pancreas. After we eat carbohydrates, our gastrointestinal tract sends a signal to the pancreas to secrete insulin. Also, the glucose in our blood directly stimulates the β cells to secrete insulin. We think insulin helps cells pull in the glucose needed for metabolic activity by attaching itself to membrane walls that are normally impenetrable. This attachment increases the ability of glucose to pass through to the inside of the cell where it can be used as fuel. So, if there is not enough enough insulin, cells don t have enough energy for their needs.

The Background for the Diabetes Model Insulin is a hormone secreted by the β cells of the pancreas. After we eat carbohydrates, our gastrointestinal tract sends a signal to the pancreas to secrete insulin. Also, the glucose in our blood directly stimulates the β cells to secrete insulin. We think insulin helps cells pull in the glucose needed for metabolic activity by attaching itself to membrane walls that are normally impenetrable. This attachment increases the ability of glucose to pass through to the inside of the cell where it can be used as fuel. So, if there is not enough enough insulin, cells don t have enough energy for their needs. The other hormones we will focus on all tend to change blood glucose concentrations also.

The Background for the Diabetes Model Glucagon is a hormone secreted by the α cells of the pancreas. Excess glucose is stored in the liver in the form of Glycogen. There is the usual equilibrium amount of storage caused by the rate of glycogen formation being equal to the rate of the reverse reaction that moves glycogen back to glucose. Hence the glycogen serves as a reservoir for glucose and when the body needs glucose, the rate balance is tipped towards conversion back to glucose to release needed glucose to the cells. The hormone glucagon increases the rate of the reaction that converts glycogen back to glucose and so serves an important regulatory function. Hypoglycemia (low blood sugar) and fasting tend to increase the secretion of the hormone glucagon. On the other hand, if the blood glucose levels increase, this tends to suppress glucagon secretion; i.e. we have another back and forth regulatory tool.

The Background for the Diabetes Model Epinephrine also called adrenalin is a hormone secreted by the adrenal medulla. It is part of an emergency mechanism to quickly increase the blood glucose concentration in times of extremely low blood sugar levels. Hence, epinephrine also increases the rate at which glycogen converts to glucose. It also directly inhibits how much glucose is able to be pulled into muscle tissue because muscles use a lot of energy and this energy is needed elsewhere more urgently. It also acts on the pancreas directly to inhibit insulin production which keeps glucose in the blood. There is also another way to increase glucose by converting lactate into glucose in the liver. Epinephrine increases this rate also so the liver can pump this extra glucose back into the blood stream.

The Background for the Diabetes Model Glucocorticoids are hormones like cortisol which are secreted by the adrenal cortex which influence how carbohydrates are metabolized which is turn increase glucose if the the metabolic rate goes up.

The Background for the Diabetes Model Glucocorticoids are hormones like cortisol which are secreted by the adrenal cortex which influence how carbohydrates are metabolized which is turn increase glucose if the the metabolic rate goes up. Thyroxin is a hormone secreted by the thyroid gland and it helps the liver form glucose from sources which are not carbohydrates such as glycerol, lactate and amino acids. So another way to up glucose!

The Background for the Diabetes Model Glucocorticoids are hormones like cortisol which are secreted by the adrenal cortex which influence how carbohydrates are metabolized which is turn increase glucose if the the metabolic rate goes up. Thyroxin is a hormone secreted by the thyroid gland and it helps the liver form glucose from sources which are not carbohydrates such as glycerol, lactate and amino acids. So another way to up glucose! Somatotrophin is called the growth hormone and it is secreted by the anterior pituitary gland. This hormone directly affect blood glucose levels (i.e. an increase in Somatotrophin increases blood glucose levels and vice versa) but it also inhibits the effect of insulin on muscle and fat cell s permeability which diminishes insulin s ability to help those cells pull glucose out of the blood stream. These actions can therefore increase blood glucose levels.

The Background for the Diabetes Model Now net hormone concentration is the sum of insulin plus the others. Let H denote this net hormone concentration.

The Background for the Diabetes Model Now net hormone concentration is the sum of insulin plus the others. Let H denote this net hormone concentration. At normal conditions, call this concentration H 0. There have been studies performed that show that under close to normal conditions, the interaction of the one hormone insulin with blood glucose completely dominates the net hormonal activity. That is normal blood sugar levels primarily depend on insulin-glucose interactions.

The Background for the Diabetes Model Now net hormone concentration is the sum of insulin plus the others. Let H denote this net hormone concentration. At normal conditions, call this concentration H 0. There have been studies performed that show that under close to normal conditions, the interaction of the one hormone insulin with blood glucose completely dominates the net hormonal activity. That is normal blood sugar levels primarily depend on insulin-glucose interactions. So if insulin increases from normal levels, it increases net hormonal concentration to H 0 + H and decreases glucose blood concentration.

The Background for the Diabetes Model On the other hand, if other hormones such as cortisol increased from base levels, this will make blood glucose levels go up.

The Background for the Diabetes Model On the other hand, if other hormones such as cortisol increased from base levels, this will make blood glucose levels go up. Since insulin dominates all activity at normal conditions, we can think of this increase in cortisol as a decrease in insulin with a resulting drop in blood glucose levels. A decrease in insulin from normal levels corresponds to a drop in net hormone concentration to H 0 H.

The Background for the Diabetes Model On the other hand, if other hormones such as cortisol increased from base levels, this will make blood glucose levels go up. Since insulin dominates all activity at normal conditions, we can think of this increase in cortisol as a decrease in insulin with a resulting drop in blood glucose levels. A decrease in insulin from normal levels corresponds to a drop in net hormone concentration to H 0 H. Now let G denote blood glucose level. Hence, in our model an increase in H means a drop in G and a decrease in H means an increase in G! Note our lumping of all the hormone activity into a single net activity is very much like how we modeled food fish and predator fish in the predator prey model.

The Background for the Diabetes Model The idea of our model for diagnosing diabetes from the GTT is to find a simple dynamical model of this complicated blood glucose regulatory system in which the values of two parameters would give a nice criterion for distinguishing normal individuals from those with mild diabetes or those who are pre diabetic. Here is what we will do. We describe the model as G (t) = F 1 (G, H) + J(t) H (t) = F 2 (G, H) where the function J is the external rate at which blood glucose concentration is being increased.

The Background for the Diabetes Model The idea of our model for diagnosing diabetes from the GTT is to find a simple dynamical model of this complicated blood glucose regulatory system in which the values of two parameters would give a nice criterion for distinguishing normal individuals from those with mild diabetes or those who are pre diabetic. Here is what we will do. We describe the model as G (t) = F 1 (G, H) + J(t) H (t) = F 2 (G, H) where the function J is the external rate at which blood glucose concentration is being increased. There are two nonlinear interaction functions F 1 and F 2 because we know G and H have complicated interactions.

The Background for the Diabetes Model Let s assume G and H have achieved optimal values G 0 and H 0 by the time the fasting patient has arrived at the hospital.

The Background for the Diabetes Model Let s assume G and H have achieved optimal values G 0 and H 0 by the time the fasting patient has arrived at the hospital. Hence, we don t expect to have any contribution to G (0) and H (0); i.e. F 1 (G 0, H 0 ) = 0 and F 2 (G 0, H 0 ) = 0.

The Background for the Diabetes Model Let s assume G and H have achieved optimal values G 0 and H 0 by the time the fasting patient has arrived at the hospital. Hence, we don t expect to have any contribution to G (0) and H (0); i.e. F 1 (G 0, H 0 ) = 0 and F 2 (G 0, H 0 ) = 0. We are interested in the deviation of G and H from their optimal values G 0 and H 0, so let g = G G 0 and h = H H 0. We can then write G = G 0 + g and H = H 0 + h.

The Background for the Diabetes Model The model can then be rewritten as (G 0 + g) (t) = F 1 (G 0 + g, H 0 + h) + J(t) (H 0 + h) (t) = F 2 (G 0 + g, H 0 + h)

The Background for the Diabetes Model The model can then be rewritten as (G 0 + g) (t) = F 1 (G 0 + g, H 0 + h) + J(t) (H 0 + h) (t) = F 2 (G 0 + g, H 0 + h) or g (t) = F 1 (G 0 + g, H 0 + h) + J(t) h (t) = F 2 (G 0 + g, H 0 + h)

The Background for the Diabetes Model We can expand our functions using tangent plane approximations: F 1 (G 0 + g, H 0 + h) = F 1 (G 0, H 0 ) + F 1 g (G 0, H 0 ) g + F 1 h (G 0, H 0 ) h + E F1 F 2 (G 0 + g, H 0 + h) = F 2 (G 0, H 0 ) + F 2 g (G 0, H 0 ) g + F 2 h (G 0, H 0 ) h + E F2

The Background for the Diabetes Model We can expand our functions using tangent plane approximations: F 1 (G 0 + g, H 0 + h) = F 1 (G 0, H 0 ) + F 1 g (G 0, H 0 ) g + F 1 h (G 0, H 0 ) h + E F1 F 2 (G 0 + g, H 0 + h) = F 2 (G 0, H 0 ) + F 2 g (G 0, H 0 ) g + F 2 h (G 0, H 0 ) h + E F2 but the terms F 1 (G 0, H 0 ) = 0 and F 1 (G 0, H 0 ) = 0, so we can simplify to F 1 (G 0 + g, H 0 + h) = F 1 g (G 0, H 0 ) g + F 1 h (G 0, H 0 ) h + E F1 F 2 (G 0 + g, H 0 + h) = F 2 g (G 0, H 0 ) g + F 2 h (G 0, H 0 ) h + E F2

The Background for the Diabetes Model It seems reasonable to assume that since we are so close to ordinary operating conditions, the errors E F1 and E F2 will be negligible. Thus our model approximation is g (t) = F 1 g (G 0, H 0 ) g + F 1 h (G 0, H 0 ) h + J(t) h (t) = F 2 g (G 0, H 0 ) g + F 2 h (G 0, H 0 ) h

The Background for the Diabetes Model It seems reasonable to assume that since we are so close to ordinary operating conditions, the errors E F1 and E F2 will be negligible. Thus our model approximation is g (t) = F 1 g (G 0, H 0 ) g + F 1 h (G 0, H 0 ) h + J(t) h (t) = F 2 g (G 0, H 0 ) g + F 2 h (G 0, H 0 ) h Next, we can reason out the algebraic signs of the four partial derivatives.

The Diabetes Detection Model Our model approximation is g (t) = F 1 g (G 0, H 0 ) g + F 1 h (G 0, H 0 ) h h (t) = F 2 g (G 0, H 0 ) g + F 2 h (G 0, H 0 ) h

The Diabetes Detection Model Our model approximation is g (t) = F 1 g (G 0, H 0 ) g + F 1 h (G 0, H 0 ) h h (t) = F 2 g (G 0, H 0 ) g + F 2 h (G 0, H 0 ) h Next, we can reason out the algebraic signs are F 1 g (G 0, H 0 ) = F 1 h (G 0, H 0 ) = F 2 g (G 0, H 0 ) = + F 2 h (G 0, H 0 ) = The arguments for these algebraic signs come from our understanding of the physiological processes that are going on here.

The Diabetes Detection Model Let s look at a small positive deviation g from the optimal value G 0 while letting the net hormone concentration be fixed at H 0. Then our model approximation is g (t) = F 1 g (G 0, H 0 ) g since we do not have an external input here. At a state where we have an increase in blood sugar levels over optimal, i.e. g > 0, the other hormones such as cortisol and glucagon will try to regulate the blood sugar level down by increasing their concentrations and for example storing more sugar into glycogen.

The Diabetes Detection Model Let s look at a small positive deviation g from the optimal value G 0 while letting the net hormone concentration be fixed at H 0. Then our model approximation is g (t) = F 1 g (G 0, H 0 ) g since we do not have an external input here. At a state where we have an increase in blood sugar levels over optimal, i.e. g > 0, the other hormones such as cortisol and glucagon will try to regulate the blood sugar level down by increasing their concentrations and for example storing more sugar into glycogen. Hence, the term F1 g (G 0, H 0 ) should be negative as here g is negative as g should be decreasing.

The Diabetes Detection Model Let s look at a small positive deviation g from the optimal value G 0 while letting the net hormone concentration be fixed at H 0. Then our model approximation is g (t) = F 1 g (G 0, H 0 ) g since we do not have an external input here. At a state where we have an increase in blood sugar levels over optimal, i.e. g > 0, the other hormones such as cortisol and glucagon will try to regulate the blood sugar level down by increasing their concentrations and for example storing more sugar into glycogen. Hence, the term F1 g (G 0, H 0 ) should be negative as here g is negative as g should be decreasing. So we model this as F1 g (G 0, H 0 ) = m 1 for some positive number m 1.

The Diabetes Detection Model Now consider a positive change in h from the optimal level while keeping at the optimal level G 0. Then the model is g (t) = F 1 h (G 0, H 0 ) h

The Diabetes Detection Model Now consider a positive change in h from the optimal level while keeping at the optimal level G 0. Then the model is g (t) = F 1 h (G 0, H 0 ) h and since h > 0, this means the net hormone concentration is up which we interpret as insulin above normal. This means blood sugar levels go down which implies g is negative again.

The Diabetes Detection Model Now consider a positive change in h from the optimal level while keeping at the optimal level G 0. Then the model is g (t) = F 1 h (G 0, H 0 ) h and since h > 0, this means the net hormone concentration is up which we interpret as insulin above normal. This means blood sugar levels go down which implies g is negative again. Thus, F1 h (G 0, H 0 ) must be negative which means we model it as F 1 h (G 0, H 0 ) = m 2 for some positive m 2.

The Diabetes Detection Model If we have a small positive deviation g from the optimal value G 0 while letting the net hormone concentration be fixed at H 0, we have h (t) = F 2 g (G 0, H 0 ) g.

The Diabetes Detection Model If we have a small positive deviation g from the optimal value G 0 while letting the net hormone concentration be fixed at H 0, we have h (t) = F 2 g (G 0, H 0 ) g. Again, since g is positive, this means we are above normal blood sugar levels which implies mechanisms are activated to bring the level down. Hence h > 0 as we have increasing net hormone levels.

The Diabetes Detection Model If we have a small positive deviation g from the optimal value G 0 while letting the net hormone concentration be fixed at H 0, we have h (t) = F 2 g (G 0, H 0 ) g. Again, since g is positive, this means we are above normal blood sugar levels which implies mechanisms are activated to bring the level down. Hence h > 0 as we have increasing net hormone levels. Thus, we must have F2 g (G 0, H 0 ) = m 3 for some positive m 3.

The Diabetes Detection Model Finally, if we have a positive deviation h from optimal while blood sugar levels are optimal, the model is h (t) = F 2 h (G 0, H 0 ) h.

The Diabetes Detection Model Finally, if we have a positive deviation h from optimal while blood sugar levels are optimal, the model is h (t) = F 2 h (G 0, H 0 ) h. Since h is positive, we have the concentrations of the hormones that pull glucose out of the blood stream are above optimal. This means that too much sugar is being removed as so the regulatory mechanisms will act to stop this action implying h < 0.

The Diabetes Detection Model Finally, if we have a positive deviation h from optimal while blood sugar levels are optimal, the model is h (t) = F 2 h (G 0, H 0 ) h. Since h is positive, we have the concentrations of the hormones that pull glucose out of the blood stream are above optimal. This means that too much sugar is being removed as so the regulatory mechanisms will act to stop this action implying h < 0. This tells us F2 g (G 0, H 0 ) = m 4 for some positive constant m 4.

The Diabetes Detection Model Hence, the four partial derivatives at the optimal points can be defined by four positive numbers m 1, m 2, m 3 and m 4 as follows: F 1 g (G 0, H 0 ) = m 1 F 1 h (G 0, H 0 ) = m 2 F 2 g (G 0, H 0 ) = +m 3 F 2 h (G 0, H 0 ) = m 4

The Diabetes Detection Model Hence, the four partial derivatives at the optimal points can be defined by four positive numbers m 1, m 2, m 3 and m 4 as follows: F 1 g (G 0, H 0 ) = m 1 F 1 h (G 0, H 0 ) = m 2 F 2 g (G 0, H 0 ) = +m 3 F 2 h (G 0, H 0 ) = m 4 Our model dynamics are thus approximated by g (t) = m 1 g m 2 h + J(t) h (t) = m 3 g m 4 h

The Diabetes Detection Model Hence, the four partial derivatives at the optimal points can be defined by four positive numbers m 1, m 2, m 3 and m 4 as follows: F 1 g (G 0, H 0 ) = m 1 F 1 h (G 0, H 0 ) = m 2 F 2 g (G 0, H 0 ) = +m 3 F 2 h (G 0, H 0 ) = m 4 Our model dynamics are thus approximated by This implies g (t) = m 1 g m 2 h + J(t) h (t) = m 3 g m 4 h g (t) = m 1 g m 2 h + J (t)

The Diabetes Detection Model Now plug in the formula for h to get g (t) = m 1 g m 2 (m 3 g m 4 h) + J (t) = m 1 g m 2 m 3 g + m 2 m 4 h + J (t).

The Diabetes Detection Model Now plug in the formula for h to get g (t) = m 1 g m 2 (m 3 g m 4 h) + J (t) = m 1 g m 2 m 3 g + m 2 m 4 h + J (t). But we can use the g equation to solve for h. This gives m 2 h = g (t) m 1 g + J(t)

The Diabetes Detection Model Now plug in the formula for h to get g (t) = m 1 g m 2 (m 3 g m 4 h) + J (t) = m 1 g m 2 m 3 g + m 2 m 4 h + J (t). But we can use the g equation to solve for h. This gives m 2 h = g (t) m 1 g + J(t) which leads to g (t) = m 1 g m 2 m 3 g + m 4 ( g (t) m 1 g + J(t)) + J (t) = (m 1 + m 4 ) g (m 1 m 4 + m 2 m 3 )g + m 4 J(t) + J (t).

The Diabetes Detection Model Now plug in the formula for h to get g (t) = m 1 g m 2 (m 3 g m 4 h) + J (t) = m 1 g m 2 m 3 g + m 2 m 4 h + J (t). But we can use the g equation to solve for h. This gives m 2 h = g (t) m 1 g + J(t) which leads to g (t) = m 1 g m 2 m 3 g + m 4 ( g (t) m 1 g + J(t)) + J (t) = (m 1 + m 4 ) g (m 1 m 4 + m 2 m 3 )g + m 4 J(t) + J (t). So our final model is g (t) + (m 1 + m 4 ) g + (m 1 m 4 + m 2 m 3 )g = m 4 J(t) + J (t).

The Diabetes Detection Model Let α = (m 1 + m 4 )/2 and ω 2 = m 1 m 4 + m 2 m 3 and we can rewrite as where S(t) = m 4 J(t) + J (t). g (t) + 2α g + ω 2 g = S(t).

The Diabetes Detection Model Let α = (m 1 + m 4 )/2 and ω 2 = m 1 m 4 + m 2 m 3 and we can rewrite as where S(t) = m 4 J(t) + J (t). g (t) + 2α g + ω 2 g = S(t). Now the right hand side here is zero except for the very short time interval when the glucose load is being ingested. Hence, we can simply search for the solution to the homogeneous model g (t) + 2α g + ω 2 g = 0.

The Diabetes Detection Model Let α = (m 1 + m 4 )/2 and ω 2 = m 1 m 4 + m 2 m 3 and we can rewrite as where S(t) = m 4 J(t) + J (t). g (t) + 2α g + ω 2 g = S(t). Now the right hand side here is zero except for the very short time interval when the glucose load is being ingested. Hence, we can simply search for the solution to the homogeneous model g (t) + 2α g + ω 2 g = 0. The roots of the characteristic equation here are r = 2α ± 4α 2 4ω 2 2 = α ± α 2 ω 2.

The Diabetes Detection Model The most interesting case is if we have complex roots. In that case, α 2 ω 2 < 0. Let Ω 2 = α 2 ω 2. Then, the general phase shifted solution has the form g = Re αt cos(ωt δ) which implies G = G 0 + Re αt cos(ωt δ).

The Diabetes Detection Model The most interesting case is if we have complex roots. In that case, α 2 ω 2 < 0. Let Ω 2 = α 2 ω 2. Then, the general phase shifted solution has the form g = Re αt cos(ωt δ) which implies G = G 0 + Re αt cos(ωt δ). Hence, our model has five unknowns to find: G 0, R, α, Ω and δ, The easiest way to do this is to measure G 0, the patient s initial blood glucose concentration, when the patient arrives. Then measure the blood glucose concentration N more times giving the data pairs (t 1, G 1 ), (t 2, G 2 ) and so on out to (t N, G N ).

The Diabetes Detection Model The most interesting case is if we have complex roots. In that case, α 2 ω 2 < 0. Let Ω 2 = α 2 ω 2. Then, the general phase shifted solution has the form g = Re αt cos(ωt δ) which implies G = G 0 + Re αt cos(ωt δ). Hence, our model has five unknowns to find: G 0, R, α, Ω and δ, The easiest way to do this is to measure G 0, the patient s initial blood glucose concentration, when the patient arrives. Then measure the blood glucose concentration N more times giving the data pairs (t 1, G 1 ), (t 2, G 2 ) and so on out to (t N, G N ). Then form the least squares error function E = N ( Gi G 0 Re αt i cos(ωt i δ) ) 2 i=1

Fitting the Data Here is some typical glucose versus time data. Time Glucose Level 0 95 1 180 2 155 3 140 We will now try to find the parameter values which minimize the nonlinear least squares problem we have here. This appears to be a simple problem, but you will see all numerical optimization problems are actually fairly difficult. Our problem is to find the free parameters G o, R, α, Ω and δ which minimize E(G 0, R, α, Ω, δ) = N ( Gi G 0 Re αt i cos(ωt i δ) ) 2 i=1 For convenience, let X = [G 0, R, α, Ω, δ] and f i (X ) = G i G 0 Re αt i cos(ωt i δ); then we can rewrite the error function as E(X ) = N i=1 f i 2 (X ). Gradient descent requires the gradient of this error function. This is just a messy calculation;

Fitting the Data E G o = 2 N i=1 E N R = 2 i=1 N E α = 2 i=1 E N Ω = 2 E δ = 2 i=1 N i=1 f i (X ) f i G o f i (X ) f i R f i (X ) f i α f i (X ) f i Ω f i (X ) f i δ

Fitting the Data where the f i partials are given by f i G o = 1 f i R = e αt i cos(ωt i δ) f i α = t i Re αt i cos(ωt i δ), f i Ω = t i Re αt i sin(ωt i δ) f i δ = Re αt i sin(ωt i δ) Now gradient descent works like this: from a given point X 0, we find the gradient of E, E(X 0 ). We know that E decreases in the direction of the negative gradient so caculating E(X 0 λ E(X 0 )) for some positive number λ has the potential to decrease E. But how big or small should λ be? Choosing λ is a difficult problem in general.

Fitting the Data Now any vector D for which the value of E goes down is called a descent vector. Now suppose we are at the point X 0 and we want to know how much of the descent vector D to use. Note, if we use the amount ξ of the descent vector at X 0, we compute the new error value E(X 0 ξd(x 0 )). Let g(ξ) = E(X 0 ξd(x 0 )). We see g(0) = E(X 0 ) and given a first choice of ξ = λ, we have g(λ) = E(X 0 λd(x 0 )). Next, let Y = X 0 ξ D(X 0 ). Then, using the chain rule, we can calculate the derivative of g at 0. First, we have g (ξ) = < (E), D(X 0 ) > and using the normalized gradient of E as the descent vector, we find g (0) = (E).

Fitting the Data Now let s approximate g using a quadratic model. Since we are trying for a minimum, in general we try to take a step in the direction of the negative gradient which makes the error function go down. Then, we have g(0) = E(X 0 ) is less than g(λ) = E(X 0 λd(x 0 )) and the directional derivative gives g (0) = (E) < 0. Hence, if we approximate g by a simple quadratic model, g(ξ) = A + Bξ + Cξ 2, this model will have a unique minimizer and we can use the value of ξ where the minimum occurs as our next choice of descent step. This technique is called a Line Search Method and it is quite useful. To summarize, we fit our g model and find g(0) = E(X 0 ) g (0) = (E) g(λ) = A + Bλ + Cλ 2 = C = E(X 0 λd(x 0 )) E(X 0 ) + (E) λ λ 2 The minimum of this quadratic occurs at λ = B 2C and this will give us our next descent direction X 0 λ D(X 0 ).

Gradient Descent Implementation Let s get started on how to find the optimal parameters numerically. Along the way, we will show you how hard this is. We start with a minimal implementation. We have already discussed some root finding codes in so we have seen code kind of similar. But this will be a little different and it is good to have you see a bit about it. What is complicated here is that we have lots of functions that depend on the data we are trying to fit. So the number of functions depends on the size of the data set which makes it harder to set up.

Gradient Descent Implementation 1 f u n c t i o n [ E r r o r, G0, R, alpha, Omega, d e l t a, normgrad, update ] = DiabetesGradOne ( I n i t i a l, lambda, m a x i t e r, data ) % I n i t i a l g u e s s f o r G0, R, alpha, Omega, d e l t a % data = c o l l e c t i o n o f ( time, g l u c o s e ) p a i r s % maxiter = max number of i t s ; lambda = how much of descent to use % s e t u p l e a s t s q u a r e s e r r o r f u n c t i o n 6 N = l e n g t h ( d a t a ) ; E = 0. 0 ; Time = d a t a ( :, 1 ) ; G = data ( :, 2 ) ; % I n i t i a l = [ i n i t i a l G, i n i t i a l R, i n i t i a l alpha, i n i t i a l Omega, i n i t i a l d e l t a ] g = I n i t i a l ( 1 ) ; r = I n i t i a l ( 2 ) ; a = I n i t i a l ( 3 ) ; o = I n i t i a l ( 4 ) ; d = I n i t i a l ( 5 ) ; 11 f = @( t, e q u i l G, r, a, o, d ) e q u i l G + r exp( a ˆ2 t ). ( c o s ( o t d ) ) ; E = D i a b e t e s E r r o r ( f, g, r, a, o, d, Time, G) f o r i = 1 : m a x i t e r E = D i a b e t e s E r r o r ( f, g, r, a, o, d, Time, G) ; % c a l c u l a t e e r r o r i f ( i == 1) 16 E r r o r ( 1 ) = E ; end E r r o r = [ E r r o r ; E ] ; [ grade, normgrad ] = E r r o r G r a d i e n t ( Time, G, g, r, a, o, d ) ; % f i n d g r a d o f E i f ( normgrad >1)% f i n d d e s c e n t d i r e c t i o n D 21 Descent = grade / normgrad ; e l s e Descent = grade ; end Del = [ g ; r ; a ; o ; d] lambda Descent ; 26 g = Del ( 1 ) ; r = Del ( 2 ) ; a = Del ( 3 ) ; o = Del ( 4 ) ; d = Del ( 5 ) ; end G0 = g ; R = r ; a l p h a = a ; Omega = o ; d e l t a = d ; E = D i a b e t e s E r r o r ( f, g, r, a, o, d, Time, G) update = [ G0 ; R ; a l p h a ; Omega ; d e l t a ] ; 31 end

Gradient Descent Implementation Note inside this function, we call another function to calculate the gradient of the norm. This is given below. The inputs are these: f u n c t i o n [ grade, normgrad ] = E r r o r G r a d i e n t ( Time, G, g, r, a, o, d ) % Time i s the time data ; % G i s the glucose data 4 % g = c u r r e n t e q u i l G ; % r = c u r r e n t R % a = c u r r e n t a l p h a ; % o = c u r r e n t Omega ; % d = c u r r e n t d e l t a

Gradient Descent Implementation f u n c t i o n [ grade, normgrad ] = E r r o r G r a d i e n t ( Time, G, g, r, a, o, d ) 2 f e r r o r = @( t, G, g, r, a, o, d ) G g r exp( a ˆ2 t ). ( c o s ( o t d ) ) ; g e r r o r = @( t, r, a, o, d ) r exp( a ˆ2 t ). ( c o s ( o t d ) ) ; h e r r o r = @( t, r, a, o, d ) r exp( a ˆ2 t ). ( s i n ( o t d ) ) ; N = l e n g t h ( Time ) ; sum = 0 ; 7 f o r k =1:N sum = sum + f e r r o r ( Time ( k ),G( k ), g, r, a, o, d ) ; end pepequilg = 2 sum ; sum = 0 ; 12 f o r k =1:N sum = sum + f e r r o r ( Time ( k ),G( k ), g, r, a, o, d ) g e r r o r ( Time ( k ), r, a, o, d ) / r ; end pepr = 2 sum ; sum = 0 ; 17 f o r k =1:N sum = sum + f e r r o r ( Time ( k ),G( k ), g, r, a, o, d ) Time ( k ) 2 a Time ( k ) g e r r o r ( Time ( k ), r, a, o, d ) ; end pepa = 2 sum ; sum = 0 ; 22 f o r k =1:N sum = sum + f e r r o r ( Time ( k ),G( k ), g, r, a, o, d ) Time ( k ) h e r r o r ( Time ( k ), r, a, o, d ) ; end pepo = 2 sum ; sum = 0 ; 27 f o r k =1:N sum = sum + f e r r o r ( Time ( k ),G( k ), g, r, a, o, d ) h e r r o r ( Time ( k ), r, a, o, d ) ; end pepd = 2 sum ; grade = [ pepequilg ; pepr ; pepa ; pepo ; pepd ] ; normgrad = norm ( grade ) ; 32 end

Gradient Descent Implementation We also need code for the error calculations which is given here. f u n c t i o n E = D i a b e t e s E r r o r ( f, g, r, a, o, d, Time, G) % 3 % T = Time % G = G l o c u o s e v a l u e s % f = n o n l i n e a r i n s u l i n model % g, a, r, o, d = p a r a m e t e r s i n d i a b e t e s n o n l i n e a r model % N = s i z e o f d ata 8 N = l e n g t h (G) ; E = 0. 0 ; % c a l c u l a t e e r r o r f u n c t i o n f o r i = 1 :N E = E +( G( i ) f ( Time ( i ), g, r, a, o, d ) ) ˆ 2 ; 13 end

Gradient Descent Implementation After 100, 000 iterations we still do not have a good fit. Note we start with a small constant λ = 5.0e 4 here. Try it yourself. If you let this value be larger, the optimization spins out of control. Also, we have not said how we chose our initial values. Let s look at some run time results using this code. Data = [ 0, 9 5 ; 1, 1 8 0 ; 2, 1 5 5 ; 3, 1 4 0 ] ; Time = Data ( :, 1 ) ; G = Data ( :, 2 ) ; f = @( t, e q u i l G, r, a, o, d ) e q u i l G + r exp( a ˆ2 t ). ( c o s ( o t d ) ) ; time = l i n s p a c e ( 0, 3, 4 1 ) ; R I n i t i a l = 5 3. 6 4 ; G O I n i t i a l = 95 + R I n i t i a l ; A I n i t i a l = s q r t ( l o g ( 1 7 / 5 ) ) ; O I n i t i a l = p i ; d I n i t i a l = p i ; I n i t i a l = [ G O I n i t i a l ; R I n i t i a l ; A I n i t i a l ; O I n i t i a l ; d I n i t i a l ] ; [ E r r o r, G0, R, a lpha, Omega, d e l t a, normgrad, update ] = D i a b e t e s G r a d ( I n i t i a l, 5. 0 e 4,20000, Data, 0 ) ; I n i t i a l E = 4 6 3. 9 4 E = 3 7 6. 4 0 o c t a v e :16> [ E r r o r, G0, R, alpha, Omega, d e l t a, normgrad, update ] = D i a b e t e s G r a d ( I n i t i a l, 5. 0 e 4,40000, Data, 0 ) ; I n i t i a l E = 4 6 3. 9 4 E = 3 7 7. 7 7 o c t a v e :145> [ E r r o r, G0, R, alpha, Omega, d e l t a, normgrad, update ] = D i a b e t e s G r a d ( I n i t i a l, 5. 0 e 4,100000, Data, 0 ) ; I n i t i a l E = 4 6 3. 9 4 E = 3 7 7. 7 7

Gradient Descent Implementation We actually looked at the data on a sheet of paper and did some rough calculations to try for some decent values. We will leave that to you to figure out. If the initial values are poorly chosen, gradient descent optimization is a great way to generate really bad values! So be warned. You will have to exercise due diligence to find a sweet starting spot. We can see how we did by looking the resulting curve fit

Adding Line Search Now let s add line search and see if it gets better. We will also try scaling the data so all the variables in question are roughly the same size. For us, a good choice is to scale the G 0 and the R value by 50, although we could try other choices. We have already discussed line search for our problem, but here it is again in a quick nutshell. If we are minimizing a function of M variables, say f (X ), then if we are at the point X 0, we can look at the slice of this function if we move out from the base point X 0 is the direction of the negative gradient, (f (X 0 ) = (f 0 ). Define a function of the single variable ξ as g(ξ) = f (X 0 + ξ (f 0 )). Then, we can try to approximate g as a quadratic, g(ξ) = A + Bξ + Cξ 2. Of course, the actual function might not be approximated nicely by such a quadratic, but it is worth a shot! Once we fit the parameters A, B and C, we see this quadratic model is minimized at λ = B 2C. The code now adds the line search code which is contained in the block

Adding Line Search f u n c t i o n [ l a m b d a s t a r, D eloptimal ] = L i n e S e a r c h ( Del, EStart, E F u l l S t e p, Base, Descent, normgrad, lambda ) % % Del i s the update due to the step lambda % E s t a r t i s E a t t h e base v a l u e 5 % EFullStep i s E at the given lambda value % Base i s t h e c u r r e n t p a r a m e t e r v e c t o r % Descent i s t h e c u r r e n t d e s c e n t v e c t o r % normgrad o f g r a d o f E a t t h e base v a l u e % lambda i s t h e c u r r e n t s t e p 10 % % we have enough i n f o r m a t i o n to do a l i n e s e a r c h h e r e A = EStart ; BCheck = normgrad ; C = ( EFullStep A BCheck lambda ) /( lambda ˆ2) ; 15 lambdastar = BCheck /(2 C) ; i f (C<0 lambdastar < 0) % we a r e g o i n g to a maximum on t h e l i n e s e a r c h ; r e j e c t DelOptimal = Del ; e l s e 20 % we have a minimum on the l i n e search DelOptimal= Base lambdastar Descent ; end end

Adding Line Search f u n c t i o n [ E r r o r, G0, R, alpha, Omega, d e l t a, normgrad, update ] = D i a b e t e s G r a d ( I n i t i a l, lambda, m a x i t e r, data, d o l i n e s e a r c h ) 2 % % I n i t i a l g u e s s f o r G0, R, alpha, Omega, d e l t a % data = c o l l e c t i o n o f ( time, g l u c o s e ) p a i r s % t o l = s t o p t o l e r a n c e % m a x i t e r = maximum number o f i t e r a t i o n s to use 7 % lambda = how much o f t h e d e s c e n t v e c t o r to use % % s e t u p l e a s t s q u a r e s e r r o r f u n c t i o n N = l e n g t h ( d a t a ) ; E = 0. 0 ; 12 Time = data ( :, 1 ) ; G = data ( :, 2 ) ; % I n i t i a l = [ i n i t i a l G, i n i t i a l R, i n i t i a l alpha, i n i t i a l Omega, i n i t i a l d e l t a ] g = I n i t i a l ( 1 ) ; r = I n i t i a l ( 2 ) ; 17 a = I n i t i a l ( 3 ) ; o = I n i t i a l ( 4 ) ; d = I n i t i a l ( 5 ) ; f = @( t, e q u i l G, r, a, o, d ) e q u i l G + r exp( a ˆ2 t ). ( c o s ( o t d ) ) ; I n i t i a l E = D i a b e t e s E r r o r ( f, g, r, a, o, d, Time, G) 22 % c a l c u l a t e e r r o r The rest of the code is on the next slide.

Adding Line Search f o r i = 1 : m a x i t e r E = D i a b e t e s E r r o r ( f, g, r, a, o, d, Time, G) ; 3 i f ( i == 1) E r r o r ( 1 ) = E ; end E r r o r = [ E r r o r ; E ] ; [ grade, normgrad ] = E r r o r G r a d i e n t ( Time, G, g, r, a, o, d ) ; % C a l c u l a t e E r r o r g r a d i e n t 8 % f i n d d e s c e n t d i r e c t i o n i f ( normgrad >1) Descent = grade / normgrad ; e l s e Descent = grade ; 13 end Base = [ g ; r ; a ; o ; d ] ; Del = Base lambda Descent ; newg = Del ( 1 ) ; newr = Del ( 2 ) ; newa = Del ( 3 ) ; newo = Del ( 4 ) ; newd = Del ( 5 ) ; E S t a r t = E ; 18 E F u l l S t e p = D i a b e t e s E r r o r ( f, newg, newr, newa, newo, newd, Time, G) ; i f ( d o l i n e s e a r c h ==1) [ l a m b d a s t a r, D e l O p t i m a l ] = L i n e S e a r c h ( Del, EStart, E F u l l S t e p, Base, Descent, normgrad, lambda ) ; g = DelOptimal ( 1 ) ; r = DelOptimal ( 2 ) ; a = DelOptimal ( 3 ) ; o = DelOptimal ( 4 ) ; d = DelOptimal ( 5 ) ; EOptimalStep = D i a b e t e s E r r o r ( f, g, r, a, o, d, Time, G) ; 23 e l s e g = Del ( 1 ) ; r = Del ( 2 ) ; a = Del ( 3 ) ; o = Del ( 4 ) ; d = Del ( 5 ) ; end end G0 = g ; R = r ; a l p h a = a ; Omega = o ; d e l t a = d ; 28 E = D i a b e t e s E r r o r ( f, g, r, a, o, d, Time, G) update = [ G0 ; R ; a l p h a ; Omega ; d e l t a ] ; end

Adding Line Search We can see how this is working by letting some of the temporary calculations print. Here are two iterations of line search printing out the A, B and C and the relevant energy values. Our initial values don t matter much here as we are just checking out the line search algorithm. Data = [ 0, 9 5 ; 1, 1 8 0 ; 2, 1 5 5 ; 3, 1 4 0 ] ; Time = Data ( :, 1 ) ; G = Data ( :, 2 ) ; f = @( t, e q u i l G, r, a, o, d ) e q u i l G + r exp( a ˆ2 t ). ( c o s ( o t d ) ) ; time = l i n s p a c e ( 0, 3, 4 1 ) ; R I n i t i a l = 85 17/21; G O I n i t i a l = 95 + R I n i t i a l ; A I n i t i a l = s q r t ( l o g ( 1 7 / 4 ) ) ; O I n i t i a l = p i ; d I n i t i a l = p i ; I n i t i a l = [ G O I n i t i a l ; R I n i t i a l ; A I n i t i a l ; O I n i t i a l ; d I n i t i a l ] ; [ E r r o r, G0, R, a lpha, Omega, d e l t a, normgrad, update ] = D i a b e t e s G r a d ( I n i t i a l, 5. 0 e 4,2, Data, 1 ) ; I n i t i a l E = 6 3 5. 3 8 E F u l l S t e p = 6 3 5. 3 1 A = 6 3 5. 3 8 BCheck = 595.35 C = 9. 1002 e+05 lambdastar = 3. 2711 e 04 E F u l l S t e p = 6 3 5. 2 7 A = 6 3 5. 3 3 BCheck = 592.34 C = 9. 0725 e+05 lambdastar = 3. 2645 e 04 E = 6 3 5. 2 9

Adding Line Search Now let s remove those prints and let it run for awhile. We are using the original data here to try to find the fit. o c t a v e :90> [ E r r o r, G0, R, alpha, Omega, d e l t a, normgrad, update ] = D i a b e t e s G r a d ( I n i t i a l, 5. 0 e 4,20000, Data, 1 ) ; I n i t i a l E = 6 3 5. 3 8 E = 3 8 9. 0 7 o c t a v e :93> [ E r r o r, G0, R, alpha, Omega, d e l t a, normgrad, update ] = D i a b e t e s G r a d ( I n i t i a l, 5. 0 e 4,30000, Data, 1 ) ; I n i t i a l E = 6 3 5. 3 8 E = 0.067171 We have success! The line search got the job done in 30, 000 iterations while the attempt using just gradient descent without line search failed. but remember, we do additional processing at each step.

Adding Line Search We show the resulting curve fit here

Adding Line Search The five parameter values that make this error a minimum have been found using line search. Numerous experiments have shown if T 0 = 2π/Ω then whent 0 < 4 hours, the patient is normal and if T 0 is much larger than that, the patient has mild diabetes. Finally, the optimal values of the parameters are update = 154.37240 % G0 62.73116 % R 0. 5 7 0 7 6 % a l p h a 3.77081 % Omega 3.47707 % d e l t a The critical value of 2π/Ω = 1.6663 here which is less than 4 so this patient is normal!

Adding Line Search The five parameter values that make this error a minimum have been found using line search. Numerous experiments have shown if T 0 = 2π/Ω then whent 0 < 4 hours, the patient is normal and if T 0 is much larger than that, the patient has mild diabetes. Finally, the optimal values of the parameters are update = 154.37240 % G0 62.73116 % R 0. 5 7 0 7 6 % a l p h a 3.77081 % Omega 3.47707 % d e l t a The critical value of 2π/Ω = 1.6663 here which is less than 4 so this patient is normal!

Adding Line Search The five parameter values that make this error a minimum have been found using line search. Numerous experiments have shown if T 0 = 2π/Ω then whent 0 < 4 hours, the patient is normal and if T 0 is much larger than that, the patient has mild diabetes. Note how much of our material from this course was involved in building this model! Finally, the optimal values of the parameters are update = 154.37240 % G0 62.73116 % R 0. 5 7 0 7 6 % a l p h a 3.77081 % Omega 3.47707 % d e l t a The critical value of 2π/Ω = 1.6663 here which is less than 4 so this patient is normal!