-
Notifications
You must be signed in to change notification settings - Fork 0
/
oneofc_inv.m
54 lines (49 loc) · 1.05 KB
/
oneofc_inv.m
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
function label = oneofc_inv(Y, class_name)
% Usage: label = oneofc_inv(Y, class_name)
%
% Covert 1-of-c coding to an one-dim output vector. For each row,
% we pick up the index (idx) of the column having the largest entry in
% this row, and pick the the class_name(idx) as the output.
%
% Inputs:
% Y - (n x c) matrix
% class_name - (n x 1) vector
%
% Outputs:
% label - (n x 1) vector
%
% Example:
% Y =
% 1 0 0 0
% 0 1 0 0
% 0 0 1 0
% 0 1 0 0
% 0 0 0 1
% class_name =
%
% 3 2 1 4
%
% oneofc_inv(Y, class_name)
%
% ans =
%
% 3 2 1 2 4
%
% See also,
% oneofc.m
%
% Kai Yu, Siemens AG
[N,M] = size(Y);
error( nargchk(1, 2, nargin));
if nargin < 2
class_name = [];
end
if isempty(class_name)
class_name = [1:M];
end
% idx = Y*[1:M]';
[dummy, idx] = max(Y, [], 2);
lable = zeros(N,1);
label = class_name(idx);
label = label';