detection of diabetes with matlab
TRANSCRIPT
1
Simulation in Biomedicine
Detection of Diabetes
Kévin MEFFRAY
Biomedical Engineering Master
Hochschule Furtwangen University
Villingen-Schwenningen, Germany
Rahman MIZANUR
Biomedical Engineering Master
Hochschule Furtwangen University
Villingen-Schwenningen, Germany
2
Table of Contents
Table of Contents..................................................................................................................... 2
Executive summary................................................................................................................. 3
Task.......................................................................................................................................................... 3
Method .................................................................................................................................................... 3
Results ..................................................................................................................................................... 5
Matlab code .............................................................................................................................. 7
Function “main” .................................................................................................................................... 7
Function “err” ........................................................................................................................................ 8
Function “gluc”...................................................................................................................................... 8
Function “errorfm” ............................................................................................................................... 8
Presentation.............................................................................................................................. 9
3
Executive summary/Abstract
Task
Statement of the task
Thus, )sincos()( 21 tctcetgt
ωωα
+=− and )sincos()( 210 tctceGtG
tωω
α
++=− .
Research has shown that lab results of 24/ω > 4 indicate a mild case of diabetes. For example, suppose
that we ha given the GTT to four patients we suspect of having a mild case of diabetes. The results for
each patient are shown in the following table. Which patients, if any, have a mild case of diabetes?
Patient 1 Patient 2 Patient 3 Patient 4
G0 80.00 90.00 100.00 110.00
t = 1 85.32 91.77 103.35 114.64
t = 2 82.54 85.69 98.26 105.89
t = 3 78.25 92.39 96.59 108.14
t = 4 76.61 91.13 99.47 113.76
Analysis of the task
Regarding the references added to the statement, g(t) and G(t) are respectively the excess glucose
concentration and the total glucose concentration of the patient. It’s also explained that 24/ω is a time
constant in hours named resonant period. Akkerman et al. claim that a resonant period over 4 hours is
a sign of diabetes.
The data are the results of a glucose tolerance test applied on 4 patients. Each patient received an
injection of glucose and then their glucose concentration has been measured every hour during 4
hours.
The task is to identify the parameters which set our model to fit the experimental data. When the
parameters are identified, the resonant period is calculated and compare to 4 hours. If the resonant
period is higher than 4 hours, the program should point out a case of diabetes.
Method
g(t) and G(t) being non-linear, the problem is to fit a non-linear equation. This has been already
done in class through the Levenberg-Marquardt algorithm. The same algorithm has been used in our
task.
Implementation
The Levenberg-Marquardt algorithm is implemented in a function given in class named
“SMarquardt”.
4
This implementation is described so:
[X,info,perf] = SMarquardt(fun,par,x0,opts)
where:
- fun is the function which needs to be minimized through the least-square fitting. In this
implementation, the function needed to be minimized is the function giving the difference
between the experimental data and the data calculated by the model at the same point. This
function is implemented in the Matlab function “err”.
- par is a vector of eventual parameters involved in the function to minimized. In this
implementation, this vector contains the experimental data for one patient.
- x0 is the initial vector of the implementation. It contains normal values of the unknown
parameter.
- otps is a vector of options. The values of this vector used in this implementation are the same
than the one used in class.
- X is the matrix of the approximation of the unknown parameter for each iteration of the
algorithm. The first column of the vector will be x0 and the last column is the final estimation
of the unknown parameter.
- info is a matrix containing different informations about the process of the algorithm. The only
value of this vector used in this implementation is info(5) which is the number of iteration
done by the algorithm.
- perf is a matrix containing different informations about the performances of the algorithm.
The only informations used in this implementation are the values of the first line of this vector
which are the results of half of the square residual sum. In the results, the first value of this
line is compared to the last value of this line to get an idea about the efficiency of the
algorithm.
The next step was to implement the “err” function. As it has been already explain, the SMarquardt
function already minimize the square residual sum of the function. So the task of the “err” function is
to evaluate the values of the estimated glucose concentration through the function “gluc” and to
calculate the difference with the experimental data.
The last step was the implementation of the function “gluc” which evaluate the value of the model
at a time t depending of the different parameters c1, c2, α, and ω. The equation of the excess glucose
concentration has been chosen in the implementation of this function to reduce the number of
parameters and avoid mistakes mixing the G0 of the different patients.
The general implementation of the detection is divided in 4 step.
The first step is to insert the data.
The second step is to transform the matrix of total glucose concentration in a matrix of excess glucose
concentration allowing avoiding the parameter G0.
The third step is the processing of the Levenberg-Marquardt algorithm.
5
The final step is a shaping of the results in order present the results. In this step is included the if-loop
identifying if the patient has diabetes or not. In order to get a good graphic shape of the model, a new
time matrix has been define and the values of the model have been calculated for this time matrix.
Problems
The major problem in this implementation is that the Levenberg-Marquardt algorithm is very
sensitive to the initial vector and no normal values of the parameters were available in the references.
The solution to this problem was to use the fitting algorithm implemented in the function fminsearch
in Matlab which is less sensible to the initial vector. Regarding the fact that the fminsearch algorithm
doesn’t include the evaluation of the square residual sum, this calculation has to be included in the
“errorfm” function. This algorithm led to results for each patient which were averaged to create an
initial vector for the Levenberg-Marquardt algorithm.
Results
*************** Patient 1 *******************
Fitting results after 25 iterations
Square sum of residuals for initial guess / last iterate : 54.726224 /
0.257647
Parameters: alpha=0.173469, omega=1.221912, C1=0.102495,
C2=6.484800
The time constant is 5.142092 so the patient has a mild case of
diabetes.
*************** Patient 2 *******************
Fitting results after 35 iterations
Square sum of residuals for initial guess / last iterate : 56.862800 /
0.637985
Parameters: alpha=-0.184088, omega=2.279678, C1=0.208101,
C2=2.612618
The time constant is 2.756173 so the patient doesnt have diabetes
0 0.5 1 1.5 2 2.5 3 3.5 485
86
87
88
89
90
91
92
93
94
95
time [hour]
glu
cose level [m
g/d
L]
measured data
model result
0 0.5 1 1.5 2 2.5 3 3.5 476
77
78
79
80
81
82
83
84
85
86
time [hour]
glu
cose level [m
g/d
L]
measured data
model result
6
*************** Patient 3 *******************
Fitting results after 37 iterations
Square sum of residuals for initial guess / last iterate : 10.040399 /
2.640664
Parameters: alpha=-0.043125, omega=1.518054, C1=0.711780,
C2=3.037021
The time constant is 4.138973 so the patient has a mild case of
diabetes
*************** Patient 4 *******************
Fitting results after 23 iterations
Square sum of residuals for initial guess / last iterate : 13.622471 /
0.556820
Parameters: alpha=0.099449, omega=1.968686, C1=0.164680,
C2=5.966058
The time constant is 3.191563 so the patient doesnt have diabetes
0 0.5 1 1.5 2 2.5 3 3.5 4104
106
108
110
112
114
116
time [hour]
glu
cose level [m
g/d
L]
measured data
model result
0 0.5 1 1.5 2 2.5 3 3.5 496
97
98
99
100
101
102
103
104
time [hour]
glu
cose level [m
g/d
L]
measured data
model result
7
Matlab code/Abstract
Function “main”
clear all clc
%% Data
global t
data = [ 80 90 100 110 85.32 91.77 103.35 114.64 82.54 85.69 98.26 105.89 78.25 92.39 96.59 108.14 76.61 91.13 99.47 113.76]; %Column : Patients %Lines : G0-G4 : total glucose concentration at t=0-4 t=0:1:4;
%% Test
for p=1:1:length(data) g(p,:)=data(p,:)-data(1,:); end
global t gd
Tr = 0:0.1:4;
for k=1:1:length(g(1,:)) Gc = 0; gd=g(:,k); % par(k,:)=fminsearch('errorfm',[0.5 0.5 1 1]); [par,info,perf]=SMarquardt('err',gd,[0.01 1.7 0.3 4.5],[1e-3 1e-4 1e-8
200 1e-8]);
fprintf('*************** Patient %d *******************\n',k); fprintf('Fitting results after %d iterations\n', info(5)); fprintf('Square sum of residuals for initial guess / last iterate : %f
/ %f\n',2*perf(1,1),2*perf(1,end)); fprintf('Parameters: alpha=%f, omega=%f, C1=%f,
C2=%f\n',par(1,end),par(2,end),par(3,end),par(4,end)); if (2*pi()/par(2,end))>4 fprintf('The time constant is %f so the patient has a mild case of
diabetes\n\n',2*pi()/par(2,end)); else fprintf('The time constant is %f so the patient doesnt have
diabetes\n\n',2*pi()/par(2,end)); end
Gc = gluc(Tr,par(:,end))+data(1,k);
figure
8
plot(t,data(:,k),'x','LineWidth',1.5,'MarkerSize',10); hold on plot(Tr,Gc,'r','LineWidth',1.5); xlabel('time [hour]'); ylabel('glucose level [mg/dL]'); legend('measured data','model result');
end
Function “err”
function err=err(param,gd)
global t
gc=gluc(t,param);
err=(gd-gc);
end
Function “gluc”
function g=gluc(t,param)
alpha=param(1); omega=param(2); c1=param(3); c2=param(4);
for k=1:1:length(t) g(k,1)=exp(-alpha*t(k))*((c1*cos(omega*t(k)))+(c2*sin(omega*t(k)))); end
end
Function “errorfm”
function err=errorfm(param)
global t gd
gc=gluc(t,param);
err=sum((gd-gc).^2);
end
9
Presentation/Abstract
Biomedical Engineering Master, Furtwangen University, Villingen-Schwenningen, Germany
Simulation in Biomedicine
K. Meffray, R. Mizanur
Detection of Diabetes
Detection of Diabetes
Introduction
Methods
Results
Materiel
Testing for diabetes
=> Fitting a non-linear equation
)sincos()(21
tctcetgt
ωωα
+=−
)sincos()( 210 tctceGtGt
ωωα
++=−
• Glucose Tolerance Test (GTT)
• Model is a differential equation
• Characteristic solutions of the equation
- Total glucose concentration :
- Excess glucose concentration :
• Criteria for diabetes : 2π/ω > 4
Questions
•
=> Levenberg-Marquardt algorithm
•
10
Detection of Diabetes
Patient data
113.7699.4791.1376.61t = 4
108.1496.5992.3978.25t = 3
105.8998.2685.6982.54t = 2
114.64103.3591.7785.32t = 1
110.00100.0090.0080.00G0
Patient 4Patient 3Patient 2Patient 1
• GTT of 4 patient taken at 1 hour intervals during 4 hours
Introduction
Materiel
Methods
•
Results
•
Questions
Detection of Diabetes
Implementation of the Levenberg-Maquart Algorithm
• Implementation of the function “err”
function g=gluc(t,param)
alpha=param(1);
omega=param(2);
c1=param(3);
c2=param(4);
for k=1:1:length(t)
g(k,1)=exp(-alpha*t(k))*((c1*cos(omega*t(k)))+(c2*sin(omega*t(k))));
end
end
• Implementation of the function “gluc”
function err=err(param,gd)
global t
gc=gluc(t,param);
err=(gd-gc);
end
• The function “SMarquardt”
[X,info,perf] = SMarquardt(fun,par,x0,opts)
)sincos()( 21 tctcetgt
ωωα
+=−
Introduction
Materiel
Methods
•
Results
•
Questions
11
Detection of Diabetes
Implementation of the Levenberg-Maquart Algorithm
• Implementation of the parameters identificationclear allclc
%% Data
global t
data = [ 80 90 100 11085.32 91.77 103.35 114.64 82.54 85.69 98.26 105.8978.25 92.39 96.59 108.1476.61 91.13 99.47 113.76];
t=0:1:4;
%% Test
for p=1:1:length(data)g(p,:)=data(p,:)-data(1,:);
end
global t gd
Tr = 0:0.1:4;
for k=1:1:length(g(1,:))Gc = 0;gd=g(:,k);
% X0=fminsearch('errorfm',[0.5 0.5 1 1]);[par,info,perf]=SMarquardt('err',gd,[0.01 1.7 0.3 4.5],[1e-3 1e-4 1e-8 200 1e-8]);
fprintf('*************** Patient %d *******************\n',k);fprintf('Fitting results after %d iterations\n', info(5)); fprintf('Square sum of residuals for initial guess / last iterate : %f / %f\n',2*perf(1,1),2*perf(1,end)); fprintf('Parameters: alpha=%f, omega=%f, C1=%f, C2=%f\n',par(1,end),par(2,end),par(3,end),par(4,end)); if (2*pi()/par(2,end))>4
fprintf('The time constant is %f so the patient has a mild case of diabetes\n\n',2*pi()/par(2,end));else
fprintf('The time constant is %f so the patient doesnt have diabetes\n\n',2*pi()/par(2,end));end
Gc = gluc(Tr,par(:,end))+data(1,k);
figureplot(t,data(:,k),'x','LineWidth',1.5,'MarkerSize',10); hold onplot(Tr,Gc,'r','LineWidth',1.5); xlabel('time [hour]'); ylabel('glucose level [mg/dL]'); legend('measured data','model result');
end
Introduction
Materiel
Methods
•
Results
•
Questions
0 0.5 1 1.5 2 2.5 3 3.5 476
77
78
79
80
81
82
83
84
85
86
time [hour]
glu
cose level [m
g/d
L]
measured data
model result
0 0.5 1 1.5 2 2.5 3 3.5 485
86
87
88
89
90
91
92
93
94
95
time [hour]
glu
cos
e le
vel
[mg
/dL
]
measured data
model result
Detection of Diabetes
Results
*************** Patient 1 *******************
Fitting results after 25 iterations
Square sum of residuals for initial guess / last iterate :
54.726224 / 0.257647
Parameters: alpha=0.173469, omega=1.221912,
C1=0.102495, C2=6.484800
The time constant is 5.142092 so the patient has a mild
case of diabetes.
*************** Patient 2 *******************
Fitting results after 35 iterations
Square sum of residuals for initial guess / last iterate :
56.862800 / 0.637985
Parameters: alpha=-0.184088, omega=2.279678,
C1=0.208101, C2=2.612618
The time constant is 2.756173 so the patient doesnt have
diabetes
Introduction
Materiel
Methods
•
Results
•
Questions
12
0 0.5 1 1.5 2 2.5 3 3.5 496
97
98
99
100
101
102
103
104
time [hour]
glu
cose level [m
g/d
L]
measured data
model result
0 0.5 1 1.5 2 2.5 3 3.5 4104
106
108
110
112
114
116
time [hour]
glu
cose level [m
g/d
L]
measured data
model result
Detection of Diabetes
Results
*************** Patient 3 *******************
Fitting results after 37 iterations
Square sum of residuals for initial guess / last iterate :
10.040399 / 2.640664
Parameters: alpha=-0.043125, omega=1.518054,
C1=0.711780, C2=3.037021
The time constant is 4.138973 so the patient has a mild
case of diabetes
*************** Patient 4 *******************
Fitting results after 23 iterations
Square sum of residuals for initial guess / last iterate :
13.622471 / 0.556820
Parameters: alpha=0.099449, omega=1.968686,
C1=0.164680, C2=5.966058
The time constant is 3.191563 so the patient doesnt have
diabetes
Introduction
Materiel
Methods
•
Results
•
Questions
Biomedical Engineering Master, Furtwangen University, Villingen-Schwenningen, Germany
Simulation in Biomedicine
K. Meffray, R. Mizanur
Detection of DiabetesQuestions ?