annotate core/magnatagatune/sim_from_comparison_UNfair_components.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 [partBinTrn, partBinTst, partBinNoTrn] = sim_from_comparison_UNfair_components(comparison, comparison_ids, k, trainpart, filename)
wolffd@0 2 %
wolffd@0 3 % FOR ISMIR 2012
wolffd@0 4 %
wolffd@0 5 % creates a cross-validation partitioning of the
wolffd@0 6 % similarity data in "multiG", NOT PRESERVING the
wolffd@0 7 % connected components in it during partitioning
wolffd@0 8
wolffd@0 9 % ---
wolffd@0 10 % get the similarity multigraph and remove cycles
wolffd@0 11 % ---
wolffd@0 12 cprint(2, 'creating graph')
wolffd@0 13 % Gm = ClipSimGraphMulti(comparison, comparison_ids);
wolffd@0 14 % Gm.remove_cycles_length2;
wolffd@0 15 cprint(2, 'loading Multigraph for Similarity Constraints')
wolffd@0 16 load('comp_SimGraphMulti.mat', 'G');
wolffd@0 17
wolffd@0 18
wolffd@0 19 % get similarity data
wolffd@0 20 [weights, a, b, c] = G.similarities();
wolffd@0 21
wolffd@0 22 % ---
wolffd@0 23 % We randomise the constraint succession
wolffd@0 24 % ---
wolffd@0 25 datPermu = randperm(numel(a));
wolffd@0 26 a = a(datPermu);
wolffd@0 27 b = b(datPermu);
wolffd@0 28 c = c(datPermu);
wolffd@0 29 weights = weights(datPermu);
wolffd@0 30
wolffd@0 31 % ---
wolffd@0 32 % NOTE: we try the easy route: partition the graphs
wolffd@0 33 % and look at which constraints balance we end up with
wolffd@0 34 % ---
wolffd@0 35 P = cvpartition(numel(a), 'k', k);
wolffd@0 36
wolffd@0 37 % ---
wolffd@0 38 % here we export similarity test sets
wolffd@0 39 % ---
wolffd@0 40 cprint(2, 'export test similarity')
wolffd@0 41 partBinTst = {};
wolffd@0 42 for i = 1:P.NumTestSets % test runs
wolffd@0 43
wolffd@0 44 partBinTst{i} = [a(P.test(i))' b(P.test(i))' c(P.test(i))' weights(P.test(i))];
wolffd@0 45 end
wolffd@0 46
wolffd@0 47
wolffd@0 48 % ---
wolffd@0 49 % Note: This uses a "truly" increasing training set
wolffd@0 50 % to do the partial training partition
wolffd@0 51 % ---
wolffd@0 52 cprint(2, 'export train similarity')
wolffd@0 53 for m = 1:numel(trainpart)
wolffd@0 54
wolffd@0 55 % save test indices
wolffd@0 56 Ptrain(m) = cvpartition_trunctrain_incsubsets(P, trainpart(m));
wolffd@0 57 end
wolffd@0 58
wolffd@0 59 % ---
wolffd@0 60 % here we export similarity training sets
wolffd@0 61 % ---
wolffd@0 62 partBinTrn = {};
wolffd@0 63 for i = 1:P.NumTestSets % train runs
wolffd@0 64
wolffd@0 65 for m = 1:numel(trainpart) % increasing training sets
wolffd@0 66
wolffd@0 67 % get training indices
wolffd@0 68 idxB = Ptrain(m).training(i);
wolffd@0 69
wolffd@0 70 % save into cell
wolffd@0 71 partBinTrn{i,m} = [a(idxB)' b(idxB)' c(idxB)' weights(idxB)];
wolffd@0 72 end
wolffd@0 73 end
wolffd@0 74
wolffd@0 75 partBinNoTrn = {};
wolffd@0 76 for i = 1:P.NumTestSets % train runs
wolffd@0 77
wolffd@0 78 for m = 1:numel(trainpart) % increasing training sets
wolffd@0 79
wolffd@0 80 % get training indices
wolffd@0 81 idxB = ~Ptrain(m).training(i) & ~Ptrain(m).test(i);
wolffd@0 82
wolffd@0 83 % save into cell
wolffd@0 84 partBinNoTrn{i,m} = [a(idxB)' b(idxB)' c(idxB)' weights(idxB)];
wolffd@0 85 end
wolffd@0 86 end
wolffd@0 87
wolffd@0 88 if nargin == 5
wolffd@0 89 save(filename, 'partBinTrn', 'partBinTst', 'partBinNoTrn')
wolffd@0 90 end
wolffd@0 91 end