Home > demo2 > demo21.m

demo21

PURPOSE ^

SYNOPSIS ^

This is a script file.

DESCRIPTION ^

CROSS-REFERENCE INFORMATION ^

This function calls: This function is called by:

SOURCE CODE ^

0001 addpath ../dal/
0002 
0003 S=importdata('journal.pbio.0030002.sd001.xls');
0004 
0005 Ytmp=cell2mat(foreach(@isequal,S.textdata.Sheet1(2:end,1),[],'good'));
0006 
0007 Gene=S.textdata.Sheet1(1,7:end-6);
0008 
0009 id_sbj=S.data.Sheet1(:,1);  [tmp,I]=unique(id_sbj); code=id_sbj(sort(I));
0010 
0011 Ttmp=S.textdata.Sheet1(2:end,3);
0012 Xtmp=S.data.Sheet1(:,6:end-6); 
0013 
0014 % Clean up the data
0015 ix = [153, 211];
0016 Xtmp(ix,:)=[]; id_sbj(ix)=[]; Ytmp(ix)=[]; Ttmp(ix)=[];
0017 
0018 Xtmp(isnan(Xtmp))=0;
0019 
0020 
0021 % Collect subjects into cells
0022 Y=zeros(1,length(code));
0023 X=cell(1,length(code));
0024 T=cell(1,length(code));
0025 L=zeros(1,length(code));
0026 for ii=1:length(code)
0027   I=find(id_sbj==code(ii));
0028   Y(ii)=mean(Ytmp(I));
0029   X{ii}=Xtmp(I,:);
0030   T{ii}=Ttmp(I);
0031   L(ii)=length(I);
0032   if ~isequal(T{ii}{1},'t0')
0033     display(I);
0034     display(T{ii});
0035     warning('Index seems to be wrong!');
0036   end
0037 end
0038 
0039 %% Perform cross-validation
0040 xTrials = [100 4];
0041 lambda=exp(linspace(log(10),log(0.001),20));
0042 [Am, As,divTr,divTe,output,memo]=xvalidation(X,Y,'dallrgl',lambda,xTrials,'preproc','meandiffs');
0043 
0044 %% Plot accuracy
0045 figure, h=errorbar(log(lambda), Am, As);
0046 set(gca,'fontsize',16);
0047 set(h,'linewidth',2);
0048 grid on;
0049 logticks('x');
0050 set(gca,'position',[0.13, 0.2 0.775, 0.75])
0051 xlabel('Regularization constant');
0052 ylabel('Accuracy');
0053 format_ticks(gca,get(gca,'xticklabel'))
0054 xlim(log([0.0009 11]))
0055 
0056 
0057 hold on;
0058 plot(xlim,0.8705*ones(1,2),'--','color',[0 .5 0],'linewidth',2);
0059 
0060 legend('DALGL','Borgwardt et al.')
0061 
0062 
0063 %% Plot feature weights at lambda=0.5456
0064 ds=zeros(prod(xTrials), length(Gene));
0065 for kk=1:prod(xTrials)
0066   [ii,jj]=ind2sub(xTrials,kk);
0067   ds(kk,:)=sqrt(sum(memo(ii,jj,7).C.w.^2));
0068 end
0069 figure, plot(mean(ds),'linewidth',2);
0070 set(gca,'fontsize',12)                 
0071 set(gca,'position',[0.05 0.2 0.9 0.7]) 
0072 set(gca,'xtick',1:length(Gene))                   
0073 format_ticks(gca,Gene,[],[],[],45);
0074 grid on;
0075 title('Feature weights')
0076 set(gcf,'paperpositionmode','auto')   
0077 set(gcf,'position',[-595, 402, 1591, 263]);

Generated on Sat 22-Aug-2009 22:15:36 by m2html © 2003