]> Creatis software - CreaPhase.git/blob - octave_packages/nnet-0.1.13/__analyzerows.m
Add a useful package (from Source forge) for octave
[CreaPhase.git] / octave_packages / nnet-0.1.13 / __analyzerows.m
1 ## Copyright (C) 2008 Michel D. Schmid  <michaelschmid@users.sourceforge.net>
2 ##
3 ##
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)
7 ## any later version.
8 ##
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.
13 ##
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/>.
17
18 ## -*- texinfo -*-
19 ## @deftypefn {Function File} {} @var{retmatrix} = __analyzerows(@var{matrix})
20 ## @code{__analyzerows} takes a matrix as input argument and checks what kind of
21 ## data are contained in the rows.
22 ##   a.) binary values? Means the row contains only 0 and 1
23 ##   b.) unique values?
24 ##   c.) Min values are several times contained in the row
25 ##   d.) Max values are several times contained in the row
26 ## @end deftypefn
27
28 ## Author: mds
29
30 function retmatrix = __analyzerows(matrix)
31
32   ## check number of inputs
33   error(nargchk(1,1,nargin));
34
35   nRows = size(matrix,1);   # get number or rows
36   retmatrix = zeros(nRows,4);
37   doneVec = zeros(nRows,1);
38
39   ## now let's check which rows are binary
40   i = 1;
41   while (i <= nRows)
42     vec = matrix(i,:);
43     n1 = find(vec==1);
44     n0 = find(vec==0);
45     if (length(n1)==0 || length(n0)==0)
46       #do nothing
47     else
48       if (length(vec)==(length(n1)+length(n0)))
49         # in this case, the vector contains only ones and zeros
50         retmatrix(i,1) = 1;
51         doneVec(i) = 1;
52       endif
53     endif
54     i += 1;
55   endwhile
56
57   ## now let's check which rows are unique
58   i = 1;
59   while (i <= nRows)
60     if (doneVec(i)==0)
61       vec = matrix(i,:);
62       n1 = find(vec==vec(1));
63       if (length(vec)==(length(n1)))
64         # in this case, the vector contains only unique data
65         retmatrix(i,2) = 1;
66         doneVec(i) = 1;
67       endif
68     endif
69   i += 1;
70   endwhile
71
72   
73   ## now let's check how often we can find the min value
74   i = 1;
75   while (i <= nRows)
76         if (doneVec(i)==0)
77       vec = matrix(i,:);
78       n1 = min(vec);
79           retmatrix(i,3) = length(find(n1==vec));
80         endif
81   i += 1;
82   endwhile
83   
84   ## now let's check how often we can find the max value
85   i = 1;
86   while (i <= nRows)
87         if (doneVec(i)==0)
88       vec = matrix(i,:);
89       n1 = max(vec);
90           retmatrix(i,4) = length(find(n1==vec));
91         endif
92   i += 1;
93   endwhile
94
95 endfunction
96
97 %!shared b, retmat
98 %! disp("testing __analyzerows")
99 %! b = [1 0 0 1; 1 0 0 0; 1 2 0 1];
100 %! retmat = __analyzerows(b);
101 %!assert(retmat(1,1)==1);#%!assert(retmat(1,1)==1);
102 %!assert(retmat(2,1)==1);
103 %!assert(retmat(3,1)==0);
104 %! b = [1 0 0 2; 1 0 0 0; 1 1 1 1];
105 %! retmat = __analyzerows(b);
106 %!assert(retmat(1,2)==0);
107 %!assert(retmat(2,2)==0);
108 %!assert(retmat(3,2)==1);
109 %! b = [1 0 0 2; 1 0 0 0; 1 1 1 1];
110 %! retmat = __analyzerows(b);
111 %!assert(retmat(1,3)==2);
112 %!assert(retmat(2,3)==0);
113 %!assert(retmat(3,3)==0);
114 %! retmat = __analyzerows(b);
115 %!assert(retmat(1,4)==1);
116 %!assert(retmat(2,4)==0);
117 %!assert(retmat(3,4)==0);