annotate core/tools/machine_learning/cvpartition_trunctrain.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 % ---
wolffd@0 2 % class cvpartition_trunctrain
wolffd@0 3 % NOTE: this is a fake cvpartition double for
wolffd@0 4 % using cvpartitions in truncated-training size experiments
wolffd@0 5 % ---
wolffd@0 6 classdef cvpartition_trunctrain
wolffd@0 7
wolffd@0 8 properties (Hidden)
wolffd@0 9
wolffd@0 10 mtest;
wolffd@0 11 mtraining;
wolffd@0 12 end
wolffd@0 13 properties
wolffd@0 14 N;
wolffd@0 15 NumTestSets;
wolffd@0 16 TrainSize;
wolffd@0 17 TestSize;
wolffd@0 18 end
wolffd@0 19
wolffd@0 20
wolffd@0 21 methods
wolffd@0 22
wolffd@0 23 % ---
wolffd@0 24 % constuctor: directly calculates the truncated testset
wolffd@0 25 % ---
wolffd@0 26 function P = cvpartition_trunctrain(Pin, perctrain)
wolffd@0 27
wolffd@0 28 P.N = Pin.N;
wolffd@0 29 P.NumTestSets = Pin.NumTestSets;
wolffd@0 30
wolffd@0 31 for i = 1:Pin.NumTestSets
wolffd@0 32
wolffd@0 33 % copy testing data
wolffd@0 34 P.TestSize(i) = Pin.TestSize(i);
wolffd@0 35 P.mtest{i} = Pin.test(i);
wolffd@0 36
wolffd@0 37 % calculate new training size
wolffd@0 38 P.TrainSize(i) = ceil(perctrain * Pin.TrainSize(i));
wolffd@0 39
wolffd@0 40 % get actual training indices
wolffd@0 41 idx = find(Pin.training(i));
wolffd@0 42
wolffd@0 43 % ---
wolffd@0 44 % TODO: save the permutation in a global variable,
wolffd@0 45 % tomake the same smaller set available
wolffd@0 46 % for all further experiments.
wolffd@0 47 % moreover, it would be great if the smaller training sets
wolffd@0 48 % are subsets of the bigger ones
wolffd@0 49 % ---
wolffd@0 50 tokeep = randperm(numel(idx));
wolffd@0 51 tokeep = tokeep(1:P.TrainSize(i));
wolffd@0 52
wolffd@0 53 % get indices to keep
wolffd@0 54 idx = idx(tokeep);
wolffd@0 55
wolffd@0 56 % build truncated training set
wolffd@0 57 P.mtraining{i} = false(P.N, 1);
wolffd@0 58 P.mtraining{i}(idx) = true;
wolffd@0 59 end
wolffd@0 60 end
wolffd@0 61
wolffd@0 62 function out = test(P, i)
wolffd@0 63
wolffd@0 64 out = P.mtest{i};
wolffd@0 65 end
wolffd@0 66
wolffd@0 67 function out = training(P, i)
wolffd@0 68
wolffd@0 69 out = P.mtraining{i};
wolffd@0 70 end
wolffd@0 71
wolffd@0 72 end
wolffd@0 73 end