annotate core/magnatagatune/tests_evals/get_data_compact.m @ 0:e9a9cd732c1e tip

first hg version after svn
author wolffd
date Tue, 10 Feb 2015 15:05:51 +0000
parents
children
rev   line source
wolffd@0 1 function [clip_dict, X, Y, valididx] = get_data_compact(clips, featureVec, simdata)
wolffd@0 2 % ---
wolffd@0 3 % instead of creating a new three feature vectors
wolffd@0 4 % for each constraint, this function links back to the
wolffd@0 5 % FIRST occurrence of a distinct clip and its features
wolffd@0 6 %
wolffd@0 7 % TODO: try to always link ALL occurences of a feature
wolffd@0 8 % / clip in the rankings
wolffd@0 9 % ---
wolffd@0 10
wolffd@0 11 global comparison_ids;
wolffd@0 12 global comparison_invids;
wolffd@0 13
wolffd@0 14 % ---
wolffd@0 15 % build the clip dictionary
wolffd@0 16 % ---
wolffd@0 17 uniclip = unique(reshape( simdata, 1, []));
wolffd@0 18 last_clip_pos = zeros(1, numel(uniclip));
wolffd@0 19
wolffd@0 20 clip_dict = [];
wolffd@0 21 Y = {};
wolffd@0 22 idx_newclip = 1;
wolffd@0 23 valididx = logical([]);
wolffd@0 24
wolffd@0 25 % cycle all constraints of one cv bin
wolffd@0 26 for j = 1:size(simdata,1)
wolffd@0 27
wolffd@0 28
wolffd@0 29 % save the first clip
wolffd@0 30 constraint = simdata(j,:);
wolffd@0 31
wolffd@0 32 % ---
wolffd@0 33 % check where the clip is and if there
wolffd@0 34 % is space to write cosntraint data
wolffd@0 35 %
wolffd@0 36 % If not, a position is created
wolffd@0 37 a = find_clip(constraint(1), 1);
wolffd@0 38 b = find_clip(constraint(2), 0);
wolffd@0 39 c = find_clip(constraint(3), 0);
wolffd@0 40
wolffd@0 41 % [a,b,c] -> clip a more similar to clip b than to clip c
wolffd@0 42
wolffd@0 43 % adress weightings
wolffd@0 44 if numel(constraint) == 4
wolffd@0 45 Y(a,:) = {b, c, (constraint(4))};
wolffd@0 46 else
wolffd@0 47 Y(a,:) = {b, c};
wolffd@0 48 end
wolffd@0 49 end
wolffd@0 50
wolffd@0 51 % ---
wolffd@0 52 % get feature data
wolffd@0 53 % NOTE: this uses an index of the comparison clips
wolffd@0 54 % ---
wolffd@0 55 X = featureVec(:,(comparison_invids(clip_dict)));
wolffd@0 56
wolffd@0 57 for i = find(~valididx)
wolffd@0 58 if size(Y,2) == 3
wolffd@0 59 Y(i,:) = {[], [], 0};
wolffd@0 60 else
wolffd@0 61 Y(i,:) = {[], []};
wolffd@0 62 end
wolffd@0 63 end
wolffd@0 64
wolffd@0 65 function clip_idx = find_clip(clip, write)
wolffd@0 66 uc_idx = find(uniclip == clip);
wolffd@0 67
wolffd@0 68 % ---
wolffd@0 69 % do we have a place of this clip?
wolffd@0 70 %
wolffd@0 71 % NOTE: last_clip_pos has to be reset after every write
wolffd@0 72 % ---
wolffd@0 73 if (last_clip_pos(uc_idx) == 0) || ...
wolffd@0 74 write && (numel(valididx) >= last_clip_pos(uc_idx)) &&...
wolffd@0 75 (valididx(last_clip_pos(uc_idx)) == 1)
wolffd@0 76
wolffd@0 77 % if not, create one
wolffd@0 78 clip_idx = idx_newclip;
wolffd@0 79 clip_dict(clip_idx) = clip;
wolffd@0 80 valididx(clip_idx) = false;
wolffd@0 81
wolffd@0 82 % and save into last pos
wolffd@0 83 last_clip_pos(uc_idx) = clip_idx;
wolffd@0 84
wolffd@0 85 idx_newclip = idx_newclip + 1;
wolffd@0 86 else
wolffd@0 87 clip_idx = last_clip_pos(uc_idx);
wolffd@0 88 end
wolffd@0 89
wolffd@0 90 if write
wolffd@0 91 valididx(clip_idx) = true;
wolffd@0 92 end
wolffd@0 93
wolffd@0 94 end
wolffd@0 95
wolffd@0 96 end