1 | % Train on individual cells, |
---|
2 | % evaluate on individual cells |
---|
3 | clear all; addpath ~/matlab/ideas/hep2cells; |
---|
4 | load cellssimple_rotinv.mat |
---|
5 | xtrain = a; xtest = b; a = [a;b]; |
---|
6 | |
---|
7 | % get imageIDs from test: |
---|
8 | testimlab = getident(xtest,'image'); |
---|
9 | |
---|
10 | % the classifier: |
---|
11 | u = loglc2; |
---|
12 | u = scalem([],'variance')*liknonc; |
---|
13 | |
---|
14 | % *************** |
---|
15 | % train on cells: |
---|
16 | % *************** |
---|
17 | wtrain = xtrain*u; |
---|
18 | % test on cells: |
---|
19 | acc_CC = 1-xtest*wtrain*testd; |
---|
20 | c_CC = confmat(xtest*wtrain); |
---|
21 | % test on image level: |
---|
22 | [labout,truelab] = majorityimagevote(xtest,wtrain); |
---|
23 | acc_CI = mean(all(truelab==labout,2)); |
---|
24 | c_CI = confmat(truelab,labout); |
---|
25 | |
---|
26 | % ********************* |
---|
27 | % crossval over images: |
---|
28 | % ********************* |
---|
29 | imlab = getident(a,'image'); |
---|
30 | [nlab,baglab] = renumlab(imlab); |
---|
31 | nrfolds = length(baglab); % leave one image out |
---|
32 | |
---|
33 | truelab = []; |
---|
34 | ll = getlabels(wtrain); |
---|
35 | c = size(ll,1); |
---|
36 | n = zeros(nrfolds,2); |
---|
37 | c_IC = zeros(c,c); |
---|
38 | c_II = zeros(c,c); |
---|
39 | Iall = (1:size(nlab,1))'; |
---|
40 | for 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; |
---|
61 | end |
---|
62 | acc_IC = sum(diag(c_IC))/sum(c_IC(:)); |
---|
63 | acc_II = sum(diag(c_II))/sum(c_II(:)); |
---|
64 | |
---|
65 | dd_message(4,'\n'); |
---|
66 | |
---|
67 | % show all: |
---|
68 | showconfmat(c_CC,ll); |
---|
69 | fprintf('Train:Cell Test:cell %3.1f%% correct\n',100*acc_CC); |
---|
70 | showconfmat(c_CI,ll); |
---|
71 | fprintf('Train:Cell Test:image %3.1f%% correct\n',100*acc_CI); |
---|
72 | fprintf('*************************************************************\n'); |
---|
73 | for i=1:28 |
---|
74 | fprintf('Image %2d:%s %3d %3.1f%%\n',i,truelab(i,:),n(i,1),100*n(i,2)); |
---|
75 | end |
---|
76 | showconfmat(c_IC,ll); |
---|
77 | fprintf('Train:Image Test:cell %3.1f%% correct\n',100*acc_IC); |
---|
78 | showconfmat(c_II,ll); |
---|
79 | fprintf('Train:Image Test:image %3.1f%% correct\n',100*acc_II); |
---|
80 | |
---|