Mercurial > hg > mauch-mirex-2010
annotate _FullBNT/KPMtools/unaryEncoding.m @ 9:4ea6619cb3f5 tip
removed log files
author | matthiasm |
---|---|
date | Fri, 11 Apr 2014 15:55:11 +0100 |
parents | b5b38998ef3b |
children |
rev | line source |
---|---|
matthiasm@8 | 1 function U = unaryEncoding(data, K) |
matthiasm@8 | 2 % unaryEncoding Encode data(s) as a 1-of-K column vector |
matthiasm@8 | 3 % function U = unaryEncoding(data, K) |
matthiasm@8 | 4 % |
matthiasm@8 | 5 % eg. |
matthiasm@8 | 6 % If data = [3 2 2] and K=3, |
matthiasm@8 | 7 % then U = [0 0 0 |
matthiasm@8 | 8 % 0 1 1 |
matthiasm@8 | 9 % 1 0 0] |
matthiasm@8 | 10 |
matthiasm@8 | 11 if nargin < 2, K = max(data); end |
matthiasm@8 | 12 N = length(data); |
matthiasm@8 | 13 U = zeros(K,N); |
matthiasm@8 | 14 ndx = subv2ind([K N], [data(:)'; 1:N]'); |
matthiasm@8 | 15 U(ndx) = 1; |
matthiasm@8 | 16 U = reshape(U, [K N]); |