1 ## Copyright (C) 2008 Michel D. Schmid <michaelschmid@users.sourceforge.net>
4 ## This program is free software; you can redistribute it and/or modify it
5 ## under the terms of the GNU General Public License as published by
6 ## the Free Software Foundation; either version 2, or (at your option)
9 ## This program is distributed in the hope that it will be useful, but
10 ## WITHOUT ANY WARRANTY; without even the implied warranty of
11 ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 ## General Public License for more details.
14 ## You should have received a copy of the GNU General Public License
15 ## along with this program; see the file COPYING. If not, see
16 ## <http://www.gnu.org/licenses/>.
19 ## @deftypefn {Function File} {} @var{retmatrix} = __optimizedatasets (@var{matrix},@var{nTrainSets},@var{nTargets},@var{bRand})
20 ## @code{__optimizedatasets} reranges the data sets depending on the input arguments.
21 ## @code{matrix} is the data set matrix containing inputs and outputs (targets) in row order.
22 ## This means for example: the first three rows are inputs and the fourth row is an output row.
23 ## The second argument is used in the optimizing algorithm. All cols with min and max values must
24 ## be in the range of the train data sets. The third argument defines how much rows are equal to the
25 ## neural network targets. These rows must be at the end of the data set!
26 ## The fourth arguemnt is optional and defines if the data sets have to be randomised before
28 ## Default value for bRand is 1, means randomise the columns.
33 function retmatrix = __optimizedatasets(matrix,nTrainSets,nTargets,bRand)
35 ## check number of inputs
36 error(nargchk(3,4,nargin));
45 # if needed, randomise the cols
47 matrix = __randomisecols(matrix);
50 # analyze matrix, which row contains what kind of data?
51 # a.) binary values? Means the row contains only 0 and 1
53 # c.) Min values are several times contained in the row
54 # d.) Max values are several times contained in the row
55 matrix1 = matrix(1:end-nTargets,:);
56 analyzeMatrix = __analyzerows(matrix1);
58 # now sort "matrix" with help of analyzeMatrix
59 # following conditions must be kept:
60 # a.) rows containing unique values aren't sorted!
61 # b.) sort first rows which contains min AND max values only once
62 # c.) sort secondly rows which contains min OR max values only once
63 # d.) at last, sort binary data if still needed!
64 retmatrix = __rerangecolumns(matrix,analyzeMatrix,nTrainSets);
69 %!shared retmatrix, matrix
70 %! disp("testing __optimizedatasets")
71 %! matrix = [1 2 3 2 1 2 3 0 5 4 3 2 2 2 2 2 2; \
72 %! 0 1 1 0 0 0 0 0 0 0 0 0 0 0 1 1 0; \
73 %! -1 3 2 4 9 1 1 1 1 1 9 1 1 1 9 9 0; \
74 %! 2 3 2 3 2 2 2 2 3 3 3 3 1 1 1 1 1];
75 %! ## The last row is equal to the neural network targets
76 %! retmatrix = __optimizedatasets(matrix,9,1);
77 %! ## the above statement can't be tested with assert!
78 %! ## it contains random values! So pass a "success" message
80 %! matrix = [1 2 3 2 1 2 3 0 5 4 3 2 2 2 2 2 2; \
81 %! 0 1 1 0 0 0 0 0 0 0 0 0 0 0 1 1 0; \
82 %! -1 3 2 4 9 1 1 1 1 1 9 1 1 1 9 9 0; \
83 %! 2 3 2 3 2 2 2 2 3 3 3 3 1 1 1 1 1];
84 %! ## The last row is equal to the neural network targets
85 %! retmatrix = __optimizedatasets(matrix,9,1,0);
86 %!assert(retmatrix(1,1)==5);
87 %!assert(retmatrix(2,1)==0);
88 %!assert(retmatrix(3,1)==1);
89 %!assert(retmatrix(4,1)==3);