source: hep2cells/dosimpleofficial.m @ 97

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

Changes....

File size: 2.4 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:
11%u =  scalem([],'variance')*loglc2([],0.01);
12%u = scalem([],'variance')*knnc;
13u = scalem([],'variance')*liknonc;
14%u = scalem([],'variance')*libsvc([],[],0.01);
15%u = scalem([],'variance')*libsvc([],proxm([],'r',12),1);
16
17% ***************
18% train on cells:
19% ***************
20wtrain = xtrain*u;
21% test on cells:
22acc_CC = 1-xtest*wtrain*testd;
23c_CC = confmat(xtest*wtrain);
24% test on image level:
25[labout,truelab] = majorityimagevote(xtest,wtrain);
26%[labout,truelab] = combinecells(xtest,wtrain);
27acc_CI = mean(all(truelab==labout,2));
28c_CI = confmat(truelab,labout);
29if size(c_CI,2)<size(c_CI,1), c_CI = [c_CI zeros(6,1)]; end
30
31% *********************
32% crossval over images:
33% *********************
34imlab = getident(a,'image');
35[nlab,baglab] = renumlab(imlab);
36nrfolds = length(baglab); % leave one image out
37
38truelab = [];
39ll = getlabels(wtrain);
40c = size(ll,1);
41n = zeros(nrfolds,2);
42c_IC = zeros(c,c);
43c_II = zeros(c,c);
44Iall = (1:size(nlab,1))';
45for i=1:nrfolds
46   dd_message(4,'*');
47   Jtst = find(nlab==i);
48   Jtrn = Iall; Jtrn(Jtst)=[];
49   x = a(Jtrn,:);
50   z = a(Jtst,:);
51
52   % train classifier:
53   w = x*u;
54   % test on cells
55   labout = z*w*labeld;
56   Icorr = all(getlab(z)==labout,2);
57   n(i,1) = sum(Icorr);
58   n(i,2) = mean(Icorr);
59   c_IC = c_IC + confmat(z*w);
60
61   % test on images
62   [labout,truelab(i,:)] = majorityimagevote(z,w);
63   %[labout,truelab(i,:)] = combinecells(z,w);
64   i1 = strmatch(char(truelab(i,:)),ll);
65   i2 = strmatch(labout,ll);
66   c_II(i1,i2) = c_II(i1,i2) + 1;
67end
68acc_IC = sum(diag(c_IC))/sum(c_IC(:));
69acc_II = sum(diag(c_II))/sum(c_II(:));
70
71dd_message(4,'\n');
72
73save results_liknon ll c_CC acc_CC c_CI acc_CI truelab n c_IC acc_IC c_II acc_II
74
75% show all:
76showconfmat(c_CC,ll);
77fprintf('Train:Cell   Test:cell       %3.1f%% correct\n',100*acc_CC);
78showconfmat(c_CI,ll);
79fprintf('Train:Cell   Test:image      %3.1f%% correct\n',100*acc_CI);
80fprintf('*************************************************************\n');
81for i=1:28
82   fprintf('Image %2d:%s  %3d   %3.1f%%\n',i,truelab(i,:),n(i,1),100*n(i,2));
83end
84showconfmat(c_IC,ll);
85fprintf('Train:Image   Test:cell      %3.1f%% correct\n',100*acc_IC);
86showconfmat(c_II,ll);
87fprintf('Train:Image   Test:image     %3.1f%% correct\n',100*acc_II);
88
Note: See TracBrowser for help on using the repository browser.