-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathbartmipc.m
More file actions
executable file
·96 lines (61 loc) · 2.5 KB
/
Copy pathbartmipc.m
File metadata and controls
executable file
·96 lines (61 loc) · 2.5 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
%BARTMIPC Dissimilarity-based MIL with clusters as prototypes
%
% W = BARTMIPC(A,K,BAGDIST,W_U)
%
% INPUT
% A MIL-dataset
% K Number of clusters (default = 5)
% BAGDIST Bag distance 'maxmin', 'meanmin' (default) or 'minmin'
% W_U Supervised learner to be used in the dissimilarity space
%
% OUTPUT
% W MIL-classifier using distance to a prototype
%
% DESCRIPTION
% Clusters training bags into clusters (using Hausdorff type distance), selects cluster centres as
% prototypes, and uses another Hausdroff type distance to these centres as
% the dissimilarity representation
%Implementation from Multi-instance clustering with application to
%multi-instance prediction by Min-Ling Zhang and Zhi-Hua Zhou (Applied
%Intelligence (2009) 31:47-68)
%function w = bartmipc(a,k,bagdist,w_u)
function W = bartmipc(varargin)
argin= shiftargin(varargin,'char');
argin = setdefaults(argin,[],5,'meanmin',scalem([],'variance')*libsvc);
if mapping_task(argin,'definition')
[A,k,bagdist,w_u] = deal(argin{:});
W = define_mapping(argin,'untrained','bartmip');
W = setbatch(W,0); %NEVER use batches!!
elseif mapping_task(argin,'training')
[A,k,bagdist,w_u] = deal(argin{:});
if ~hasmilbags(A)
error('This mapping requires a MIL set with bags.');
end
[bags labs bagid] = getbags(A);
%Distance matrix between bags
D = A*milproxm(A,bagdist,{'d',1});
[clustlab, centerix] = kcentres(D,k,1);
%Train the classifier only on distances to cluster centres
w_t = D(:, centerix)*w_u;
%Reduce the MIL dataset so it only contains the bags which are cluster
%centres
centerbagid = bagid(centerix',:);
instix = ismember(A.ident.milbag, centerbagid,'rows');
B = genmil(A(instix,:), A.labels(instix,:), A.ident.milbag(instix,:));
%Store things
W.w_t = w_t;
W.centerbags = B;
W = prmapping(mfilename,'trained',W);
W = setname(W,'bartmip-%s',getname(w_u));
W = setbatch(W,0);
elseif mapping_task(argin,'trained execution')
[A,k,bagdist,w_u] = deal(argin{:});
% we have to apply the mapping:
W = getdata(k);
B = W.centerbags;
w_t = W.w_t;
%Calculate the dissimilarity representation to the prototypes
D = A*milproxm(B, bagdist,{'d',1});
%And apply the trained classifier on this representation
W = D*w_t;
end