Predicting Mortality of ICU Patients: The PhysioNet/Computing in Cardiology Challenge 2012 1.0.0
(7,830 bytes)
function [risk,prediction]=physionet2012(time,param,value)
I=1;
i=1;
[ALL_CATEGORIES,time_series_names,descriptors]=get_param_names();
num_params=length(ALL_CATEGORIES);
num_ts_params=length(time_series_names);
num_descriptors=length(descriptors);
MEAN_DATA_24=zeros(I,num_ts_params) + NaN;
MEAN_DATA_48=zeros(I,num_ts_params) + NaN;
DESCRIPTORS=zeros(I,num_descriptors) + NaN;
[times,values,names]=extract_param_series(time,param,value);
[ts_times,ts_values,ts_names]=get_param_subset(time_series_names,times,values,names);
[des_times,des_values,des_names]=get_param_subset(descriptors,times,values,names);
DESCRIPTORS(i,:)=cell2mat(des_values(:))';
means24=calculate_mean(ts_times,ts_values,ts_names,time_series_names,[0 24*60]);
means48=calculate_mean(ts_times,ts_values,ts_names,time_series_names,[24*60 48*60]);
MEAN_DATA_24(i,:)=means24;
MEAN_DATA_48(i,:)=means48;
[cont_times,cont_values,cont_names,d,dd,md_max,cont_values2,vari]=resample_params(time_series_names,ts_times,ts_values,ts_names,des_values,des_names);
MD_DATA_D(i,1:length(d))=d';
MD_DATA_DD(i,1:length(d))=dd';
MD_VARI(i,:)=vari';
MD_DATA(i)=md_max;
DYN_DATA(:,:,i)=cont_values;
R=~isnan(MEAN_DATA_24);
%SAPS_SCORES(i)=saps_score(time,param,value,1,[0 24]);
%SAPS_SCORES_48(i)=saps_score(time,param,value,1,[24 48]);
[risk1,prediction1]=lin_reg_classify(time_series_names,MD_DATA_D,MD_DATA_DD,MD_DATA,DESCRIPTORS,des_names,R,MD_VARI,MEAN_DATA_24,MEAN_DATA_48);
[risk2,prediction2]=lin_reg_classify2(time_series_names,MD_DATA_D,MD_DATA_DD,MD_DATA,DESCRIPTORS,des_names,R,MD_VARI,MEAN_DATA_24,MEAN_DATA_48);
%[risk3,prediction3]=lda_classify(DYN_DATA);
prediction=prediction1> 0.39 | prediction2> 0.35;
risk=mean([risk1 risk2 ]);
% [PHAT,TH]=PCA_classify(MEAN_DATA_24,MEAN_DATA_48,DESCRIPTORS,time_series_names,des_names);
% if isnan(PHAT(:,2))
% X_trunc_saps=[SAPS_SCORES-SAPS_SCORES_48 SAPS_SCORES ];
% PHAT_saps = mnrval(B_saps,X_trunc_saps);
% end
% if isnan(PHAT(2))
% % [risk,prediction]=physionet2012_SAPS(time,param,value);
% risk=0.5;
% prediction=risk>TH;
% elseif PHAT(2)<0.01
% risk=0.01;
% prediction=risk>TH;
% elseif PHAT(2)>0.99
% risk=0.99;
% prediction=risk>TH;
% else
% risk=PHAT(2);
% prediction=risk>TH;
% end
function [risk,prediction]=lin_reg_classify(time_series_names,MD_DATA_D,MD_DATA_DD,MD_DATA,DESCRIPTORS,des_names,R,MD_VARI,MEAN_DATA_24,MEAN_DATA_48);
X=[MEAN_DATA_24 MEAN_DATA_48 ];
%X=[X1];
%X=[X];
AGE_a=DESCRIPTORS(:,strcmp(des_names,'Age'));
Gender_a=DESCRIPTORS(:,strcmp(des_names,'Gender'));
ICUTYPE_a=[DESCRIPTORS(:,strcmp(des_names,'ICUType'))];
ICUTYPE_t=ICUTYPE_a;
ICUTYPE_a(ICUTYPE_t==1)=2;
ICUTYPE_a(ICUTYPE_t==2)=4;
ICUTYPE_a(ICUTYPE_t==3)=1;
ICUTYPE_a(ICUTYPE_t==4)=3;
X=[AGE_a ICUTYPE_a X];
if Gender_a==0
%if des{:,strcmp(des_names,'Gender')}==0
%X_new_rec=zeros(size(X));
% savefile='gender0.mat';
savefile='gender0_60.mat';
% savefile='gender0_60_ppca';
% load(savefile,'N2','PHAT_all','best_th','A','S','Mu','V', 'CV', 'HP', 'LC','N','pc1','mu','sigma','B');
load(savefile,'N2','best_th','A','Mu','V', 'CV','N','mu','sigma');
%save('gender0_60_karsittu.mat','N2','best_th','A','Mu','V', 'CV','N','mu','sigma')
% S_new=calc_S_new_data(X',A,V,Mu,N,CV);
% X_new_rec =( repmat(Mu,1,size(S,2)) + (A*S))';
S_new=calc_S_new_data(X',A,V,Mu,N,CV);
X_new_rec =( repmat(Mu,1,1) + A*S_new)';
sigma0 = sigma;
sigma0(sigma0==0) = 1;
z = bsxfun(@minus,X_new_rec', mu');
z = bsxfun(@rdivide, z, sigma0');
z(isnan(z))=0;
% x_in=(pinv(pc1)*z)';
% X(Gender_a==0,:)=x_in(Gender_a==0,:);
z=z';
X(Gender_a==0,:)=z(Gender_a==0,:);
elseif Gender_a==1 || Gender_a==-1
% savefile='gender1.mat';
savefile='gender1_60.mat';
% savefile='gender1_60_ppca';
%load(savefile,'N2','PHAT_all','best_th','A','S','Mu','V', 'CV', 'HP', 'LC','N','pc1','mu','sigma','B');
load(savefile,'N2','best_th','A','Mu','V', 'CV','N','mu','sigma');
%save('gender1_60_karsittu.mat','N2','best_th','A','Mu','V', 'CV','N','mu','sigma')
% S_new=calc_S_new_data(X(Gender_a==1,:),A,V,Mu,N,CV);
% X_new_rec =( repmat(Mu,1,size(S,2)) + A*S)';
S_new=calc_S_new_data(X',A,V,Mu,N,CV);
X_new_rec =( repmat(Mu,1,1) + A*S_new)';
sigma0 = sigma;
sigma0(sigma0==0) = 1;
z = bsxfun(@minus,X_new_rec', mu');
z = bsxfun(@rdivide, z, sigma0');
% x_in=(pinv(pc1)*z)';
% X(Gender_a==1,:)=x_in(Gender_a==1,:);
z=z';
z(isnan(z))=0;
X(Gender_a==1,:)=z(Gender_a==1,:);
X(Gender_a==-1,:)=z(Gender_a==-1,:);
end
%X=[ MD_DATA_D MD_DATA_DD MD_DATA double(R) zscore(MD_VARI) X];
X=[Gender_a double(R) MD_VARI X];
load('w1.mat','w1')
[ResTrain,labelsEstimTrain,probsTrain,P] = predict_LRoma(w1,X,1);
%[ResTrain,labelsEstimTrain,probsTrain,P2] = predict_LRoma(w2,X,1);
PHAT = P';
PHAT2 = P';
class_th=0.32;
% IHD_=IHD;
% max_score1=0;
% max_score2=100000;
% best_th=0;
% best_th2=0;
% for class_th=.1:.01:0.5
DATA(:,1)=str2double('0000');
DATA(:,2)=PHAT2(:,1);
DATA(:,3)=PHAT(:,1)> class_th;
DATA(DATA(:,2)<0.01,2)=0.01;
DATA(DATA(:,2)>0.99,2)=0.99;
risk=DATA(:,2);
prediction=DATA(:,3);
end
function [risk,prediction]=lin_reg_classify2(time_series_names,MD_DATA_D,MD_DATA_DD,MD_DATA,DESCRIPTORS,des_names,R,MD_VARI,MEAN_DATA_24,MEAN_DATA_48);
AGE_a=DESCRIPTORS(:,strcmp(des_names,'Age'));
Gender_a=DESCRIPTORS(:,strcmp(des_names,'Gender'));
ICUTYPE_a=[DESCRIPTORS(:,strcmp(des_names,'ICUType'))];
ICUTYPE_t=ICUTYPE_a;
ICUTYPE_a(ICUTYPE_t==1)=2;
ICUTYPE_a(ICUTYPE_t==2)=4;
ICUTYPE_a(ICUTYPE_t==3)=1;
ICUTYPE_a(ICUTYPE_t==4)=3;
X=[Gender_a (AGE_a) (ICUTYPE_a) double(R) MD_DATA_D,MD_DATA_DD,MD_DATA,MD_VARI];
load('w2.mat','w2')
[ResTrain,labelsEstimTrain,probsTrain,P] = predict_LRoma(w2,X,1);
%[ResTrain,labelsEstimTrain,probsTrain,P2] = predict_LRoma(w2,X,1);
PHAT = P';
PHAT2 = P';
class_th=0.32;
% IHD_=IHD;
% max_score1=0;
% max_score2=100000;
% best_th=0;
% best_th2=0;
% for class_th=.1:.01:0.5
DATA(:,1)=str2double('0000');
DATA(:,2)=PHAT2(:,1);
DATA(:,3)=PHAT(:,1)> class_th;
DATA(DATA(:,2)<0.01,2)=0.01;
DATA(DATA(:,2)>0.99,2)=0.99;
risk=DATA(:,2);
prediction=DATA(:,3);
end
function [risk,prediction]=lda_classify(DYN_DATA)
matrixData=DYN_DATA;
load('weightsLDA.mat','weightsLDA')
featureVectors = featureExtractionLDA2(matrixData,weightsLDA);
X=featureVectors;
load('w3.mat','w3')
[ResTrain,labelsEstimTrain,probsTrain,P] = predict_LRoma(w3,X,1);
%[ResTrain,labelsEstimTrain,probsTrain,P2] = predict_LRoma(w2,X,1);
PHAT = P';
PHAT2 = P';
class_th=0.32;
% IHD_=IHD;
% max_score1=0;
% max_score2=100000;
% best_th=0;
% best_th2=0;
% for class_th=.1:.01:0.5
DATA(:,1)=str2double('0000');
DATA(:,2)=PHAT2(:,1);
DATA(:,3)=PHAT(:,1)> class_th;
DATA(DATA(:,2)<0.01,2)=0.01;
DATA(DATA(:,2)>0.99,2)=0.99;
risk=DATA(:,2);
prediction=DATA(:,3);
end
end