% Train on individual cells, % evaluate on individual cells clear all; addpath ~/matlab/ideas/hep2cells; load cellssimple_rotinv.mat xtrain = a; xtest = b; a = [a;b]; % get imageIDs from test: testimlab = getident(xtest,'image'); % the classifier: u = loglc2; u = scalem([],'variance')*liknonc; % *************** % train on cells: % *************** wtrain = xtrain*u; % test on cells: acc_CC = 1-xtest*wtrain*testd; c_CC = confmat(xtest*wtrain); % test on image level: [labout,truelab] = majorityimagevote(xtest,wtrain); acc_CI = mean(all(truelab==labout,2)); c_CI = confmat(truelab,labout); % ********************* % crossval over images: % ********************* imlab = getident(a,'image'); [nlab,baglab] = renumlab(imlab); nrfolds = length(baglab); % leave one image out truelab = []; ll = getlabels(wtrain); c = size(ll,1); n = zeros(nrfolds,2); c_IC = zeros(c,c); c_II = zeros(c,c); Iall = (1:size(nlab,1))'; for i=1:nrfolds dd_message(4,'*'); Jtst = find(nlab==i); Jtrn = Iall; Jtrn(Jtst)=[]; x = a(Jtrn,:); z = a(Jtst,:); % train classifier: w = x*u; % test on cells labout = z*w*labeld; Icorr = all(getlab(z)==labout,2); n(i,1) = sum(Icorr); n(i,2) = mean(Icorr); c_IC = c_IC + confmat(z*w); % test on images [labout,truelab(i,:)] = majorityimagevote(z,w); i1 = strmatch(char(truelab(i,:)),ll); i2 = strmatch(labout,ll); c_II(i1,i2) = c_II(i1,i2) + 1; end acc_IC = sum(diag(c_IC))/sum(c_IC(:)); acc_II = sum(diag(c_II))/sum(c_II(:)); dd_message(4,'\n'); % show all: showconfmat(c_CC,ll); fprintf('Train:Cell Test:cell %3.1f%% correct\n',100*acc_CC); showconfmat(c_CI,ll); fprintf('Train:Cell Test:image %3.1f%% correct\n',100*acc_CI); fprintf('*************************************************************\n'); for i=1:28 fprintf('Image %2d:%s %3d %3.1f%%\n',i,truelab(i,:),n(i,1),100*n(i,2)); end showconfmat(c_IC,ll); fprintf('Train:Image Test:cell %3.1f%% correct\n',100*acc_IC); showconfmat(c_II,ll); fprintf('Train:Image Test:image %3.1f%% correct\n',100*acc_II);