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