%% Classification based on constructed brain networks % Select network parameter L1 and L2 through CV, based on % 1) t-test with p=0.01 for selecting features % 2) linear SVM with default C=1 for classification % Written by Lishan Qiao @UNC, 11/09/2016 %% clear close all load brainNetSet_PCNYUBASE.mat; %Brain network sets based on different net parameters. root=cd; addpath(genpath([root '/DATA'])); addpath(genpath([root '/FUN'])); nROI=size(brainNetSet{1,1},1); %ROI size nSubj=length(lab); %# of subject [nL nZ]=size(brainNetSet); % # of candidate parameter Lambda1 and Lambda2 p_value=0.01; %p-value of t-test for feature selection kfoldout=nSubj; % LOO CV for outer loop kfoldin=nSubj-1; % inner LOO CV % kfoldout=10; % LOO CV for outer loop % kfoldin=9; % inner LOO CV c_out = cvpartition(nSubj,'k',kfoldout); % for outer CV accnum=0; tp=0; tn=0; Test_res = zeros(1,kfoldout); % for final test results for fdout=1:c_out.NumTestSets %% CV Vali_res=zeros(nL,nZ); % for results on validation set (split from training set) for iL=1:nL % corresponds to regularized parameter lambda 2 in our model for iZ=1:nZ % lambda 1 (L1-norm regularized parameter in our model) data=zeros(nROI^2,nSubj); for i=1:nSubj originalNet = brainNetSet{iL,iZ}(:,:,i);%第nZ个稀疏度下第第i个人的信? originalNet=originalNet-diag(diag(originalNet)); % remove the non-informative diagal elements originalNet=(originalNet+originalNet')/2; % symmetrization originalNet=triu(originalNet); data(:,i)=reshape(originalNet,nROI^2,1); end idx=find(sum(abs(data'))>1e-12); % for removing the trivial zero-rows data=data(idx,:); Train_dat = data(:,training(c_out,fdout)); Train_lab = lab(training(c_out,fdout)); Test_dat = data(:,test(c_out,fdout)); Test_lab = lab(test(c_out,fdout)); c_in = cvpartition(length(Train_lab),'k',kfoldin); % leave one out for validation (i.e., parameter slection) acc=0; % for save current validation result for fdin=1:c_in.NumTestSets % partion the training samples into a training subset and a % validation subset for selecing optimal regularized network parameters. InTrain_dat = Train_dat(:,training(c_in,fdin)); InTrain_lab = Train_lab(training(c_in,fdin)); Vali_dat = Train_dat(:,test(c_in,fdin)); Vali_lab = Train_lab(test(c_in,fdin)); POSITIVE_data = InTrain_dat(:,InTrain_lab==1); NEGATIVE_data = InTrain_dat(:,InTrain_lab==-1); % t-test for feature selection [tad,p_tmp] = ttest2(double(POSITIVE_data'), double(NEGATIVE_data')); [ordered_p,indp]=sort(p_tmp); index = indp(ordered_p1e-12); data=data(idx,:); Train_dat = data(:,training(c_out,fdout)); Train_lab = lab(training(c_out,fdout)); Test_dat = data(:,test(c_out,fdout)); Test_lab = lab(test(c_out,fdout)); POSITIVE_data = Train_dat(:,Train_lab==1); NEGATIVE_data = Train_dat(:,Train_lab==-1); % t-test for feature selection [tad,p_tmp] = ttest2(double(POSITIVE_data'), double(NEGATIVE_data')); [ordered_p,indp]=sort(p_tmp); index = indp(ordered_p