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 = scalem([],'variance')*loglc2([],0.01); |
---|
12 | %u = scalem([],'variance')*knnc; |
---|
13 | u = 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 | % *************** |
---|
20 | wtrain = xtrain*u; |
---|
21 | % test on cells: |
---|
22 | acc_CC = 1-xtest*wtrain*testd; |
---|
23 | c_CC = confmat(xtest*wtrain); |
---|
24 | % test on image level: |
---|
25 | [labout,truelab] = majorityimagevote(xtest,wtrain); |
---|
26 | %[labout,truelab] = combinecells(xtest,wtrain); |
---|
27 | acc_CI = mean(all(truelab==labout,2)); |
---|
28 | c_CI = confmat(truelab,labout); |
---|
29 | if size(c_CI,2)<size(c_CI,1), c_CI = [c_CI zeros(6,1)]; end |
---|
30 | |
---|
31 | % ********************* |
---|
32 | % crossval over images: |
---|
33 | % ********************* |
---|
34 | imlab = getident(a,'image'); |
---|
35 | [nlab,baglab] = renumlab(imlab); |
---|
36 | nrfolds = length(baglab); % leave one image out |
---|
37 | |
---|
38 | truelab = []; |
---|
39 | ll = getlabels(wtrain); |
---|
40 | c = size(ll,1); |
---|
41 | n = zeros(nrfolds,2); |
---|
42 | c_IC = zeros(c,c); |
---|
43 | c_II = zeros(c,c); |
---|
44 | Iall = (1:size(nlab,1))'; |
---|
45 | for 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; |
---|
67 | end |
---|
68 | acc_IC = sum(diag(c_IC))/sum(c_IC(:)); |
---|
69 | acc_II = sum(diag(c_II))/sum(c_II(:)); |
---|
70 | |
---|
71 | dd_message(4,'\n'); |
---|
72 | |
---|
73 | save 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: |
---|
76 | showconfmat(c_CC,ll); |
---|
77 | fprintf('Train:Cell Test:cell %3.1f%% correct\n',100*acc_CC); |
---|
78 | showconfmat(c_CI,ll); |
---|
79 | fprintf('Train:Cell Test:image %3.1f%% correct\n',100*acc_CI); |
---|
80 | fprintf('*************************************************************\n'); |
---|
81 | for i=1:28 |
---|
82 | fprintf('Image %2d:%s %3d %3.1f%%\n',i,truelab(i,:),n(i,1),100*n(i,2)); |
---|
83 | end |
---|
84 | showconfmat(c_IC,ll); |
---|
85 | fprintf('Train:Image Test:cell %3.1f%% correct\n',100*acc_IC); |
---|
86 | showconfmat(c_II,ll); |
---|
87 | fprintf('Train:Image Test:image %3.1f%% correct\n',100*acc_II); |
---|
88 | |
---|