source: hep2cells/dosimpleofficial.m @ 44

Last change on this file since 44 was 44, checked in by dtax, 12 years ago

To it nicer

File size: 2.0 KB
Line 
1% Train on individual cells,
2% evaluate on individual cells
3clear all; addpath ~/matlab/ideas/hep2cells;
4load cellssimple_rotinv.mat
5xtrain = a; xtest = b; a = [a;b];
6
7% get imageIDs from test:
8testimlab = getident(xtest,'image');
9
10% the classifier:
11u =  loglc2;
12u = scalem([],'variance')*liknonc;
13
14% ***************
15% train on cells:
16% ***************
17wtrain = xtrain*u;
18% test on cells:
19acc_CC = 1-xtest*wtrain*testd;
20c_CC = confmat(xtest*wtrain);
21% test on image level:
22[labout,truelab] = majorityimagevote(xtest,wtrain);
23acc_CI = mean(all(truelab==labout,2));
24c_CI = confmat(truelab,labout);
25
26% *********************
27% crossval over images:
28% *********************
29imlab = getident(a,'image');
30[nlab,baglab] = renumlab(imlab);
31nrfolds = length(baglab); % leave one image out
32
33truelab = [];
34ll = getlabels(wtrain);
35c = size(ll,1);
36n = zeros(nrfolds,2);
37c_IC = zeros(c,c);
38c_II = zeros(c,c);
39Iall = (1:size(nlab,1))';
40for i=1:nrfolds
41   dd_message(4,'*');
42   Jtst = find(nlab==i);
43   Jtrn = Iall; Jtrn(Jtst)=[];
44   x = a(Jtrn,:);
45   z = a(Jtst,:);
46
47   % train classifier:
48   w = x*u;
49   % test on cells
50   labout = z*w*labeld;
51   Icorr = all(getlab(z)==labout,2);
52   n(i,1) = sum(Icorr);
53   n(i,2) = mean(Icorr);
54   c_IC = c_IC + confmat(z*w);
55
56   % test on images
57   [labout,truelab(i,:)] = majorityimagevote(z,w);
58   i1 = strmatch(char(truelab(i,:)),ll);
59   i2 = strmatch(labout,ll);
60   c_II(i1,i2) = c_II(i1,i2) + 1;
61end
62acc_IC = sum(diag(c_IC))/sum(c_IC(:));
63acc_II = sum(diag(c_II))/sum(c_II(:));
64
65dd_message(4,'\n');
66
67% show all:
68showconfmat(c_CC,ll);
69fprintf('Train:Cell   Test:cell       %3.1f%% correct\n',100*acc_CC);
70showconfmat(c_CI,ll);
71fprintf('Train:Cell   Test:image      %3.1f%% correct\n',100*acc_CI);
72fprintf('*************************************************************\n');
73for i=1:28
74   fprintf('Image %2d:%s  %3d   %3.1f%%\n',i,truelab(i,:),n(i,1),100*n(i,2));
75end
76showconfmat(c_IC,ll);
77fprintf('Train:Image   Test:cell      %3.1f%% correct\n',100*acc_IC);
78showconfmat(c_II,ll);
79fprintf('Train:Image   Test:image     %3.1f%% correct\n',100*acc_II);
80
Note: See TracBrowser for help on using the repository browser.