-
Notifications
You must be signed in to change notification settings - Fork 0
/
cosmo_randomize_targets.m
40 lines (36 loc) · 1.01 KB
/
cosmo_randomize_targets.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
function randomized_targets=cosmo_randmize_targets(targets, chunks)
% provides randomized target labels
%
% randomized_targets=cosmo_randmize_targets(count, targets, chunks)
%
% Inputs
% targets: Px1 target (class) labels
% chunks: Px1 chunk indices
%
% Returns
% randomized_targets P x 1 with randomized targets
% Each chunk in each row is randomized seperately
%
% NNO Aug 2013
if isstruct(targets)
if isfield(targets,'sa') && isfield(targets.sa,'targets')
if isfield(targets.sa,'chunks') && nargin<3
chunks=targets.sa.chunks;
end
targets=targets.sa.targets;
else
error('illegal input')
end
end
ntargets=numel(targets);
randomized_targets=zeros(ntargets, 1); %space for output
unq=unique(chunks);
nchunks=numel(unq);
% << permute the target labels randomly, seperately for each chunk
for j=1:nchunks
msk=chunks==unq(j);
rp=randperm(sum(msk));
masked_targets=targets(msk);
randomized_targets(msk)=masked_targets(rp);
end
% <<