Skip to content
Snippets Groups Projects
Commit e61a696b authored by herrTilda's avatar herrTilda
Browse files

Adding ensamble model and blood pressure model

parent 0927d9f0
No related branches found
No related tags found
No related merge requests found
Showing
with 2078 additions and 0 deletions
DBP_1,,DBP_2,,BDP_3,,DBP_4,
X,Y,X,Y,X,Y,X,Y
30,71.79750117868932,30,75.84512022630835,30.08250825082509,80.66674524595315,29.999999999999986,83.46416784535596
35.115511551155116,73.35730001571584,35.11551155115512,77.52396668238255,35.115511551155116,81.2144428728587,35.03300330033003,84.54757975797583
40.066006600660074,74.26194405154801,40.06600660066007,79.44051548011944,40.066006600660074,83.72622976583372,39.98349834983499,88.42841426999841
45.016501650165026,75.16658808738018,45.01650165016502,80.28563570642778,45.01650165016502,84.8094452302373,45.01650165016502,88.976111896904
49.96699669966996,74.28551783749803,50.049504950495056,80.05952380952382,49.966996699669956,84.88075593273614,50.049504950495056,90.65476190476191
54.91749174917491,74.53539996856829,55.000000000000014,79.65464403583215,54.917491749174914,84.0592094923778,54.91749174917491,90.90444758761592
59.95049504950493,74.07119283356909,59.95049504950498,78.47595473833098,59.86798679867989,83.71385352820997,59.95049504950495,89.01166902404529
64.81848184818485,72.83278327832784,64.81848184818486,78.07087851642304,64.90099009900992,81.16631305987744,64.9009900990099,85.92821782178217
69.93399339933994,71.77353449630678,69.93399339933994,76.35686782964008,69.7689768976898,79.4517130284457,69.85148514851487,83.14238566713814
74.88448844884489,69.58294043690084,74.80198019801983,74.22560113154174,74.71947194719475,78.1539761118969,74.80198019801979,82.67798208392267
79.9174917491749,69.11873330190163,79.83498349834981,71.79710828225681,79.83498349834984,72.57091780606629,79.83498349834984,82.15425113939966
MAP_1,,MAP_2,,MAP_3,,MAP_4,
X,Y,X,Y,X,Y,X,Y
30.172562553925797,84.98561978717285,30.417026171987345,89.77063560540695,30.613555747291723,95.62721694947749,30.74537436487393,99.55541175342728
35.24877768190969,86.2568306010929,35.50762151279839,91.47037676157608,35.56753906624485,95.75591985428053,35.65142364106988,100.75568018406672
40.313009299204296,87.17093279647204,40.52391908733581,93.45604448279168,40.71325855622663,99.0983606557377,40.92177164222031,105.31205061834913
45.38682772505033,88.37072188668395,45.60492761959543,94.87009874412809,45.80864730131339,100.94094525932314,46.00278017447991,106.72610487968552
50.40072859744991,87.78496788419136,50.57089444923784,95.35591026747196,50.79378774805866,101.99813057233246,51.07420189818809,110.35447224618922
55.304381171508,88.91381459112262,55.53686127888025,95.84172179081582,55.759754577701074,102.48394209567633,56.071325855622646,111.76876617773941
60.3518358738376,89.32796472054454,60.57233247052055,95.89876330169686,60.814399386444265,103.11235739622278,61.09481353657367,111.46869907007954
65.37053015051288,88.88505416546832,65.53829930016293,96.38457482504073,65.82590355670598,102.45518167002203,66.07516057904324,109.88304093567248
70.22864538395167,88.65688812194422,70.56897708752756,96.29877288850541,70.76071325855622,102.0125107851596,70.90930879110344,108.9406576550666
75.23056274566197,87.71402550091075,75.46064615089635,94.57051097689578,75.68353944971717,101.21273128175629,76.08858211101524,110.78300258843828
80.1893394688908,87.9855718531301,80.36909212923021,93.34220113124339,80.58000191736171,97.12731281756302,80.99702808934904,109.5546927427859
PP_1,,PP_2,,PP_3,,PP_4,
X,Y,X,Y,X,Y,X,Y
30.063833667700166,39.87336616207672,30.226457535412507,42.23581980667518,30.224937686181548,44.690376314669564,30.433157030822542,48.41613471943578
35.150769043710866,39.47273390479663,35.24499969603015,42.29023040914339,35.28147607757313,43.380874217277665,35.46689768374978,48.92498024196004
40.15715241048089,39.16359657122008,40.260502158185915,42.253754027600436,40.38512979512437,45.98012037205912,40.63894461669403,51.069183536993116
45.280564168034545,39.85360812207428,45.42342999574443,44.12529637060001,45.57237522037816,48.57875858714816,45.74259833424526,53.66842969177458
50.332543011733236,40.90777554866554,50.511885220986116,46.270107605325556,50.77785883640344,51.722718706304356,51.005836221046934,58.53924250714333
55.45443492005593,44.0523436075141,55.61857863699922,48.960240744118174,55.84655602164267,55.77676454495715,56.07453340628611,62.59328834579609
60.56112833606906,46.742476746306764,60.75566903763148,52.55924372302269,61.07027782843943,59.46604656818044,61.340810991549645,67.55498814517598
65.65262325977267,48.97817496504346,65.87452124749227,55.61292479786006,66.21952702291938,63.42859748312966,66.32287677062439,71.51875493950999
70.94777798042435,52.303301112529624,71.0891239589033,59.02954586904978,71.38397470970882,67.84558331813483,71.72746063590495,78.11581251139884
75.78545808255822,54.449936166332215,76.11830506413767,61.90206091555716,76.40099702109555,70.35455042859746,76.88430907653964,84.80558088637605
80.99398139704542,57.68478326949963,81.22499848015076,64.59219405434979,81.55632561249928,74.49887531156907,81.85117636330477,83.31491276065412
PWV_w,,PWV_m,
X,Y,X,Y
18.477508650519027,5.333333333333336,18.477508650519027,5.681159420289859
25.259515570934255,5.507246376811601,25.017301038062286,5.855072463768124
34.94809688581315,6.2028985507246475,34.94809688581315,6.492753623188406
44.878892733564015,6.608695652173921,44.878892733564015,7.072463768115945
55.05190311418686,7.1304347826087024,54.80968858131489,7.7681159420289845
65.2249134948097,8.869565217391305,64.98269896193771,9.565217391304351
75.15570934256056,11.014492753623188,74.91349480968859,9.971014492753625
82.90657439446368,11.130434782608702,82.90657439446368,13.333333333333332
To reproduce results, run the two main scripts:
*main_SimulateAndPlot_fitToData_age_drugs to plot fit to data during training,
to plot the prediciton of medication at t=45, and optionally re-run the parameter estimation to age data.
*main_CrossValidation_ageData to plot the results from the cross validation, and optionally re-run it.
To run the scripts, the following toolboxes are needed in matlab 2021a:
IQM toolbox: https://iqmtools.intiquan.com/ (results ran with version 2.2)
Global Optimization Toolbox
Optimization Toolbox
Parallel Computing Toolbox
Statistics and Machine Learning Toolbox
\ No newline at end of file
SBP_1,,SBP_2,,SBP_3,,SBP_4,
X,Y,X,Y,X,Y,X,Y
30.00000000000003,111.4727722772277,30.08250825082507,117.86074440777409,29.91749174917493,125.22368903557015,29.917491749174943,131.61257792445903
35.03300330033002,112.66685001833511,35.03300330033004,119.61129446277954,35.03300330033002,124.05573890722391,34.95049504950494,133.36221122112192
40.06600660066009,113.16648331499809,39.983498349834974,121.50073340667399,39.983498349834974,129.83406674000727,39.983498349834974,139.55628896222942
45.09900990099008,114.2216721672167,44.93399339933998,124.08461679501278,44.93399339933994,133.3901723505683,44.85148514851487,142.55775577557745
49.96699669966998,114.58425009167578,49.88448844884489,126.25183351668494,49.88448844884489,136.3907224055738,49.801980198019805,149.16941694169398
54.83498349834986,117.72460579391267,54.75247524752477,128.41996699669963,54.83498349834983,139.66905023835707,54.752475247524785,153.5588558855884
59.867986798679866,120.16868353502008,59.785478547854794,131.00293362669592,59.78547854785478,142.94737807114038,59.78547854785478,156.55848918225138
64.98349834983497,121.36184451778504,64.8184818481848,133.58590025669224,64.8184818481848,144.69701136780336,64.73597359735973,157.47570590392357
69.85148514851484,123.52997799779968,69.85148514851483,135.33553355335522,69.6864686468647,147.42070040337356,69.68646864686465,161.17070040337347
74.71947194719472,124.1703337000366,74.63696369636965,135.83791712504572,74.63696369636965,148.47680601393452,74.55445544554455,167.64438943894368
79.75247524752474,126.19774477447737,79.66996699669967,136.89310597726424,79.66996699669967,146.8931059772643,79.5049504950495,165.36716171617147
********** MODEL NAME
BP_age
********** MODEL NOTES
t0 = 30 years
********** MODEL STATES
d/dt(SBP) = ((k1_SBP + k2_SBP*age) * SBP_vs_IC) - drugS % ~ linear with time
d/dt(DBP) = ((k1_DBP - k2_DBP*age) * DBP_vs_IC) - drugD % ~exponential with time
SBP(0) = IC_SBP
DBP(0) = IC_DBP
********** MODEL PARAMETERS
k1_SBP = 0.4081
k2_SBP = 0
k1_DBP = 0.9262
k2_DBP = 0.0183
bSBP = 99.8670
bDBP = 55.9788
IC_SBP = 120
IC_DBP = 70
t_drug = 1
effect_drugS = 20
effect_drugD = 5
drug_on = 0 %set to 1 at time of treatment
********** MODEL VARIABLES
age = time
PP = SBP-DBP
MAP = DBP + (PP/3)
SBP_vs_IC = (IC_SBP-bSBP)/(117.86-bSBP)
DBP_vs_IC = (IC_DBP-bDBP)/(75.8451-bDBP)
drugS = (effect_drugS/t_drug)*drug_on
drugD = (effect_drugD/t_drug)*drug_on
********** MODEL REACTIONS
********** MODEL FUNCTIONS
********** MODEL EVENTS
********** MODEL MATLAB FUNCTIONS
function [cost] = costFunc_age(params,model,ic,data)
sim = model(data.time,ic,params);
cost_SBP = sum( ((data.SBP - sim.statevalues(:,1)).^2)./(data.sd_SBP.^2) );
cost_DBP = sum( ((data.DBP - sim.statevalues(:,2)).^2)./(data.sd_DBP.^2) );
% cost_SBP = sum((data.SBP - sim.statevalues(:,1)).^2);
% cost_DBP = sum((data.DBP - sim.statevalues(:,2)).^2);
%
cost = cost_SBP + cost_DBP;
end
\ No newline at end of file
function [cost] = costFunc_age_all(firstparams,model,data)
drugparams = [2,20,5,0];%need to have values but are not used in the age simulation
ic_PWV = 5; %need to a value but is not used in the age simulation
cost = 0;
dataToCostFunction.sd_SBP = data.sd_SBP;
dataToCostFunction.sd_DBP = data.sd_DBP;
for i = 1:4
ic = [data.SBP(1,i),data.DBP(1,i)];
params = [firstparams, ic,drugparams];
dataToCostFunction.SBP = data.SBP(:,i);
dataToCostFunction.DBP = data.DBP(:,i);
dataToCostFunction.time = data.time;
cost = cost + costFunc_age(params,model,[ic,ic_PWV],dataToCostFunction);
end
end
\ No newline at end of file
function [cost] = costFunc_age_crossvalidation(firstparams,model,data,trainingRange)
ic_PWV = 5;
cost = 0;
for t = 1:length(trainingRange)
ind = trainingRange(t);
ic = [data.SBP(1,ind),data.DBP(1,ind)];
drugparams = [1,20,8,0];
params = [firstparams, ic,drugparams];
indata.SBP = data.SBP(:,ind);
indata.DBP = data.DBP(:,ind);
indata.time = data.time;
indata.sd_SBP = data.sd_SBP;
indata.sd_DBP = data.sd_DBP;
cost = cost + costFunc_age(params,model,[ic,ic_PWV],indata);
end
end
\ No newline at end of file
function [cost,sim] = costFunc_treatment(params,drugparams,tmedication,model,ic,data,inddrug,doPlot)
tstart = 30;%tmedication-1;
tend = 85;%data.time(end)+tmedication+1;
resolution = 0.001;
sim = sim_treatment(model,tstart,tmedication,tend,params,ic,drugparams,resolution);
% dataind = ismember(sim.time,data.time+tmedication);
dataind = ismember(round(sim.time,4),round(data.time+tmedication,4));
cost_SBP = sum( ((data.SBP(:,inddrug) - sim.statevalues(dataind,1)).^2)./(data.sd_SBP(:,inddrug).^2) );
cost_DBP = sum( ((data.DBP(:,inddrug) - sim.statevalues(dataind,2)).^2)./(data.sd_DBP(:,inddrug).^2) );
% cost_SBP = sum((data.SBP - sim.statevalues(:,1)).^2);
% cost_DBP = sum((data.DBP - sim.statevalues(:,2)).^2);
%
cost = cost_SBP + cost_DBP;
if doPlot
figure('Name','cost_treatment')
hold on
title(sprintf('Blood pressure response to treatment at t=%0.1f, cost: %0.2f',tmedication,cost))
inds = find(dataind);
plotind = max(1,inds(1)-1000):min(length(sim.time),inds(end)+1000);
plot(sim.time(plotind),sim.statevalues(plotind,1),'b--')
plot(sim.time(plotind),sim.statevalues(plotind,2),'b--')
plot(sim.time(dataind),sim.statevalues(dataind,1),'r*')
plot(sim.time(dataind),sim.statevalues(dataind,2),'r*')
errorbar(data.time+tmedication,data.DBP(:,inddrug),data.sd_DBP(:,inddrug),'ko')
errorbar(data.time+tmedication,data.SBP(:,inddrug),data.sd_SBP(:,inddrug),'ko')
end
end
File added
File added
blood-pressure-model/crossValidation_220223-2253/crossValidation_age.png

107 KiB

Source diff could not be displayed: it is too large. Options to address this: view the blob.
File added
File added
File added
File added
File added
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment