annotate main/comm/inst/symerr.m @ 9666:67d4cfc5eeb3 octave-forge

comm: update license to GPLv3+
author carandraug
date Tue, 13 Mar 2012 04:31:21 +0000
parents 2de537641f94
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
2382
5056d2d5eb72 Changed the directory structure of comm to match the package system
hauberg
parents:
diff changeset
1 ## Copyright (C) 2003 David Bateman
5056d2d5eb72 Changed the directory structure of comm to match the package system
hauberg
parents:
diff changeset
2 ##
9666
67d4cfc5eeb3 comm: update license to GPLv3+
carandraug
parents: 4404
diff changeset
3 ## This program is free software; you can redistribute it and/or modify it under
67d4cfc5eeb3 comm: update license to GPLv3+
carandraug
parents: 4404
diff changeset
4 ## the terms of the GNU General Public License as published by the Free Software
67d4cfc5eeb3 comm: update license to GPLv3+
carandraug
parents: 4404
diff changeset
5 ## Foundation; either version 3 of the License, or (at your option) any later
67d4cfc5eeb3 comm: update license to GPLv3+
carandraug
parents: 4404
diff changeset
6 ## version.
2382
5056d2d5eb72 Changed the directory structure of comm to match the package system
hauberg
parents:
diff changeset
7 ##
9666
67d4cfc5eeb3 comm: update license to GPLv3+
carandraug
parents: 4404
diff changeset
8 ## This program is distributed in the hope that it will be useful, but WITHOUT
67d4cfc5eeb3 comm: update license to GPLv3+
carandraug
parents: 4404
diff changeset
9 ## ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
67d4cfc5eeb3 comm: update license to GPLv3+
carandraug
parents: 4404
diff changeset
10 ## FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
67d4cfc5eeb3 comm: update license to GPLv3+
carandraug
parents: 4404
diff changeset
11 ## details.
2382
5056d2d5eb72 Changed the directory structure of comm to match the package system
hauberg
parents:
diff changeset
12 ##
9666
67d4cfc5eeb3 comm: update license to GPLv3+
carandraug
parents: 4404
diff changeset
13 ## You should have received a copy of the GNU General Public License along with
67d4cfc5eeb3 comm: update license to GPLv3+
carandraug
parents: 4404
diff changeset
14 ## this program; if not, see <http://www.gnu.org/licenses/>.
2382
5056d2d5eb72 Changed the directory structure of comm to match the package system
hauberg
parents:
diff changeset
15
5056d2d5eb72 Changed the directory structure of comm to match the package system
hauberg
parents:
diff changeset
16 ## -*- texinfo -*-
5056d2d5eb72 Changed the directory structure of comm to match the package system
hauberg
parents:
diff changeset
17 ## @deftypefn {Function File} {[@var{num}, @var{rate}] = } symerr (@var{a},@var{b})
5056d2d5eb72 Changed the directory structure of comm to match the package system
hauberg
parents:
diff changeset
18 ## @deftypefnx {Function File} {[@var{num}, @var{rate}] = } symerr (@var{...},@var{flag})
5056d2d5eb72 Changed the directory structure of comm to match the package system
hauberg
parents:
diff changeset
19 ## @deftypefnx {Function File} {[@var{num}, @var{rate} @var{ind}] = } symerr (@var{...})
5056d2d5eb72 Changed the directory structure of comm to match the package system
hauberg
parents:
diff changeset
20 ##
5056d2d5eb72 Changed the directory structure of comm to match the package system
hauberg
parents:
diff changeset
21 ## Compares two matrices and returns the number of symbol errors and the
5056d2d5eb72 Changed the directory structure of comm to match the package system
hauberg
parents:
diff changeset
22 ## symbol error rate. The variables @var{a} and @var{b} can be either:
5056d2d5eb72 Changed the directory structure of comm to match the package system
hauberg
parents:
diff changeset
23 ##
5056d2d5eb72 Changed the directory structure of comm to match the package system
hauberg
parents:
diff changeset
24 ## @table @asis
5056d2d5eb72 Changed the directory structure of comm to match the package system
hauberg
parents:
diff changeset
25 ## @item Both matrices
5056d2d5eb72 Changed the directory structure of comm to match the package system
hauberg
parents:
diff changeset
26 ## In this case both matrices must be the same size and then by default the
5056d2d5eb72 Changed the directory structure of comm to match the package system
hauberg
parents:
diff changeset
27 ## the return values @var{num} and @var{rate} are the overall number of symbol
5056d2d5eb72 Changed the directory structure of comm to match the package system
hauberg
parents:
diff changeset
28 ## errors and the overall symbol error rate.
5056d2d5eb72 Changed the directory structure of comm to match the package system
hauberg
parents:
diff changeset
29 ## @item One column vector
5056d2d5eb72 Changed the directory structure of comm to match the package system
hauberg
parents:
diff changeset
30 ## In this case the column vector is used for symbol error comparision
5056d2d5eb72 Changed the directory structure of comm to match the package system
hauberg
parents:
diff changeset
31 ## column-wise with the matrix. The returned values @var{num} and @var{rate}
5056d2d5eb72 Changed the directory structure of comm to match the package system
hauberg
parents:
diff changeset
32 ## are then row vectors containing the num of symbol errors and the symbol
5056d2d5eb72 Changed the directory structure of comm to match the package system
hauberg
parents:
diff changeset
33 ## error rate for each of the column-wise comparisons. The number of rows in
5056d2d5eb72 Changed the directory structure of comm to match the package system
hauberg
parents:
diff changeset
34 ## the matrix must be the same as the length of the column vector
5056d2d5eb72 Changed the directory structure of comm to match the package system
hauberg
parents:
diff changeset
35 ## @item One row vector
5056d2d5eb72 Changed the directory structure of comm to match the package system
hauberg
parents:
diff changeset
36 ## In this case the row vector is used for symbol error comparision row-wise
5056d2d5eb72 Changed the directory structure of comm to match the package system
hauberg
parents:
diff changeset
37 ## with the matrix. The returned values @var{num} and @var{rate} are then
5056d2d5eb72 Changed the directory structure of comm to match the package system
hauberg
parents:
diff changeset
38 ## column vectors containing the num of symbol errors and the symbol error rate
5056d2d5eb72 Changed the directory structure of comm to match the package system
hauberg
parents:
diff changeset
39 ## for each of the row-wise comparisons. The number of columns in the matrix
5056d2d5eb72 Changed the directory structure of comm to match the package system
hauberg
parents:
diff changeset
40 ## must be the same as the length of the row vector
5056d2d5eb72 Changed the directory structure of comm to match the package system
hauberg
parents:
diff changeset
41 ## @end table
5056d2d5eb72 Changed the directory structure of comm to match the package system
hauberg
parents:
diff changeset
42 ##
5056d2d5eb72 Changed the directory structure of comm to match the package system
hauberg
parents:
diff changeset
43 ## This behaviour can be overridden with the variable @var{flag}. @var{flag}
5056d2d5eb72 Changed the directory structure of comm to match the package system
hauberg
parents:
diff changeset
44 ## can take the value 'column-wise', 'row-wise' or 'overall'. A column-wise
5056d2d5eb72 Changed the directory structure of comm to match the package system
hauberg
parents:
diff changeset
45 ## comparision is not possible with a row vector and visa-versa.
5056d2d5eb72 Changed the directory structure of comm to match the package system
hauberg
parents:
diff changeset
46 ## @end deftypefn
5056d2d5eb72 Changed the directory structure of comm to match the package system
hauberg
parents:
diff changeset
47
5056d2d5eb72 Changed the directory structure of comm to match the package system
hauberg
parents:
diff changeset
48 ## 2003 FEB 13
5056d2d5eb72 Changed the directory structure of comm to match the package system
hauberg
parents:
diff changeset
49 ## initial release
5056d2d5eb72 Changed the directory structure of comm to match the package system
hauberg
parents:
diff changeset
50
5056d2d5eb72 Changed the directory structure of comm to match the package system
hauberg
parents:
diff changeset
51 function [num, rate, ind] = symerr (a, b, _flag)
5056d2d5eb72 Changed the directory structure of comm to match the package system
hauberg
parents:
diff changeset
52
5056d2d5eb72 Changed the directory structure of comm to match the package system
hauberg
parents:
diff changeset
53 if ((nargin < 2) || (nargin > 4))
5056d2d5eb72 Changed the directory structure of comm to match the package system
hauberg
parents:
diff changeset
54 usage ("[num rate ind] = symerr (a, b [,flag])");
5056d2d5eb72 Changed the directory structure of comm to match the package system
hauberg
parents:
diff changeset
55 endif
5056d2d5eb72 Changed the directory structure of comm to match the package system
hauberg
parents:
diff changeset
56 if (any(any(isinf(a))) || any(any(isnan(a))) || any(any(isinf(b))) || ...
5056d2d5eb72 Changed the directory structure of comm to match the package system
hauberg
parents:
diff changeset
57 any(any(isnan(b))) || !real(a) || !real(b) || ...
5056d2d5eb72 Changed the directory structure of comm to match the package system
hauberg
parents:
diff changeset
58 any(any((floor(a)) != a)) || any(any((floor(b)) != b)) || ...
5056d2d5eb72 Changed the directory structure of comm to match the package system
hauberg
parents:
diff changeset
59 any(any(a < 0)) || any(any(b < 0)))
5056d2d5eb72 Changed the directory structure of comm to match the package system
hauberg
parents:
diff changeset
60 error ("symerr: a and b must contain only postive integers");
5056d2d5eb72 Changed the directory structure of comm to match the package system
hauberg
parents:
diff changeset
61 endif
5056d2d5eb72 Changed the directory structure of comm to match the package system
hauberg
parents:
diff changeset
62
5056d2d5eb72 Changed the directory structure of comm to match the package system
hauberg
parents:
diff changeset
63 [ar,ac] = size(a);
5056d2d5eb72 Changed the directory structure of comm to match the package system
hauberg
parents:
diff changeset
64 [br,bc] = size(b);
5056d2d5eb72 Changed the directory structure of comm to match the package system
hauberg
parents:
diff changeset
65
5056d2d5eb72 Changed the directory structure of comm to match the package system
hauberg
parents:
diff changeset
66 if ((ar == br) && (ac == bc))
5056d2d5eb72 Changed the directory structure of comm to match the package system
hauberg
parents:
diff changeset
67 type = "matrix";
5056d2d5eb72 Changed the directory structure of comm to match the package system
hauberg
parents:
diff changeset
68 flag = "overall";
5056d2d5eb72 Changed the directory structure of comm to match the package system
hauberg
parents:
diff changeset
69 c = 1;
5056d2d5eb72 Changed the directory structure of comm to match the package system
hauberg
parents:
diff changeset
70 elseif (any([ar,br] == 1))
5056d2d5eb72 Changed the directory structure of comm to match the package system
hauberg
parents:
diff changeset
71 type = "row";
5056d2d5eb72 Changed the directory structure of comm to match the package system
hauberg
parents:
diff changeset
72 flag = "row";
5056d2d5eb72 Changed the directory structure of comm to match the package system
hauberg
parents:
diff changeset
73 if (ac != bc)
5056d2d5eb72 Changed the directory structure of comm to match the package system
hauberg
parents:
diff changeset
74 error ("symerr: row-wise comparison must have the same number of columns in inputs");
5056d2d5eb72 Changed the directory structure of comm to match the package system
hauberg
parents:
diff changeset
75 endif
5056d2d5eb72 Changed the directory structure of comm to match the package system
hauberg
parents:
diff changeset
76 if (ar == 1)
5056d2d5eb72 Changed the directory structure of comm to match the package system
hauberg
parents:
diff changeset
77 a = ones(br,1) * a;
5056d2d5eb72 Changed the directory structure of comm to match the package system
hauberg
parents:
diff changeset
78 else
5056d2d5eb72 Changed the directory structure of comm to match the package system
hauberg
parents:
diff changeset
79 b = ones(ar,1) * b;
5056d2d5eb72 Changed the directory structure of comm to match the package system
hauberg
parents:
diff changeset
80 endif
5056d2d5eb72 Changed the directory structure of comm to match the package system
hauberg
parents:
diff changeset
81 elseif (any([ac,bc] == 1))
5056d2d5eb72 Changed the directory structure of comm to match the package system
hauberg
parents:
diff changeset
82 type = "column";
5056d2d5eb72 Changed the directory structure of comm to match the package system
hauberg
parents:
diff changeset
83 flag = "column";
5056d2d5eb72 Changed the directory structure of comm to match the package system
hauberg
parents:
diff changeset
84 if (ar != br)
5056d2d5eb72 Changed the directory structure of comm to match the package system
hauberg
parents:
diff changeset
85 error ("symerr: column-wise comparison must have the same number of rows in inputs");
5056d2d5eb72 Changed the directory structure of comm to match the package system
hauberg
parents:
diff changeset
86 endif
5056d2d5eb72 Changed the directory structure of comm to match the package system
hauberg
parents:
diff changeset
87 if (ac == 1)
5056d2d5eb72 Changed the directory structure of comm to match the package system
hauberg
parents:
diff changeset
88 a = a * ones(1,bc);
5056d2d5eb72 Changed the directory structure of comm to match the package system
hauberg
parents:
diff changeset
89 else
5056d2d5eb72 Changed the directory structure of comm to match the package system
hauberg
parents:
diff changeset
90 b = b * ones(1,ac);
5056d2d5eb72 Changed the directory structure of comm to match the package system
hauberg
parents:
diff changeset
91 endif
5056d2d5eb72 Changed the directory structure of comm to match the package system
hauberg
parents:
diff changeset
92 else
5056d2d5eb72 Changed the directory structure of comm to match the package system
hauberg
parents:
diff changeset
93 error ("symerr: matrix sizes must match");
5056d2d5eb72 Changed the directory structure of comm to match the package system
hauberg
parents:
diff changeset
94 endif
5056d2d5eb72 Changed the directory structure of comm to match the package system
hauberg
parents:
diff changeset
95
5056d2d5eb72 Changed the directory structure of comm to match the package system
hauberg
parents:
diff changeset
96 if (nargin > 2)
5056d2d5eb72 Changed the directory structure of comm to match the package system
hauberg
parents:
diff changeset
97 if (ischar(_flag))
5056d2d5eb72 Changed the directory structure of comm to match the package system
hauberg
parents:
diff changeset
98 if (strcmp(_flag,"row-wise"))
5056d2d5eb72 Changed the directory structure of comm to match the package system
hauberg
parents:
diff changeset
99 if (strcmp(type,"column"))
5056d2d5eb72 Changed the directory structure of comm to match the package system
hauberg
parents:
diff changeset
100 error ("symerr: row-wise comparison not possible with column inputs");
5056d2d5eb72 Changed the directory structure of comm to match the package system
hauberg
parents:
diff changeset
101 endif
5056d2d5eb72 Changed the directory structure of comm to match the package system
hauberg
parents:
diff changeset
102 flag = "row";
5056d2d5eb72 Changed the directory structure of comm to match the package system
hauberg
parents:
diff changeset
103 elseif (strcmp(_flag,"column-wise"))
5056d2d5eb72 Changed the directory structure of comm to match the package system
hauberg
parents:
diff changeset
104 if (strcmp(type,"row"))
5056d2d5eb72 Changed the directory structure of comm to match the package system
hauberg
parents:
diff changeset
105 error ("symerr: column-wise comparison not possible with row inputs");
5056d2d5eb72 Changed the directory structure of comm to match the package system
hauberg
parents:
diff changeset
106 endif
5056d2d5eb72 Changed the directory structure of comm to match the package system
hauberg
parents:
diff changeset
107 flag = "column";
5056d2d5eb72 Changed the directory structure of comm to match the package system
hauberg
parents:
diff changeset
108 elseif (strcmp(_flag,"overall"))
5056d2d5eb72 Changed the directory structure of comm to match the package system
hauberg
parents:
diff changeset
109 flag = "overall";
5056d2d5eb72 Changed the directory structure of comm to match the package system
hauberg
parents:
diff changeset
110 else
5056d2d5eb72 Changed the directory structure of comm to match the package system
hauberg
parents:
diff changeset
111 error ("symerr: unrecognized string argument");
5056d2d5eb72 Changed the directory structure of comm to match the package system
hauberg
parents:
diff changeset
112 endif
5056d2d5eb72 Changed the directory structure of comm to match the package system
hauberg
parents:
diff changeset
113 else
5056d2d5eb72 Changed the directory structure of comm to match the package system
hauberg
parents:
diff changeset
114 error ("symerr: unrecognized argument");
5056d2d5eb72 Changed the directory structure of comm to match the package system
hauberg
parents:
diff changeset
115 endif
5056d2d5eb72 Changed the directory structure of comm to match the package system
hauberg
parents:
diff changeset
116 endif
5056d2d5eb72 Changed the directory structure of comm to match the package system
hauberg
parents:
diff changeset
117
5056d2d5eb72 Changed the directory structure of comm to match the package system
hauberg
parents:
diff changeset
118 ## Call the core error function to count the bit errors
2605
4ee580968fce Some INDEX fixes. Many more needed
adb014
parents: 2382
diff changeset
119 ind = (__errcore__(a,b) != 0);
2382
5056d2d5eb72 Changed the directory structure of comm to match the package system
hauberg
parents:
diff changeset
120
5056d2d5eb72 Changed the directory structure of comm to match the package system
hauberg
parents:
diff changeset
121 switch (flag)
5056d2d5eb72 Changed the directory structure of comm to match the package system
hauberg
parents:
diff changeset
122 case 'row',
5056d2d5eb72 Changed the directory structure of comm to match the package system
hauberg
parents:
diff changeset
123 if (strcmp(type,"matrix") && (ac == 1))
5056d2d5eb72 Changed the directory structure of comm to match the package system
hauberg
parents:
diff changeset
124 num = ind;
5056d2d5eb72 Changed the directory structure of comm to match the package system
hauberg
parents:
diff changeset
125 else
5056d2d5eb72 Changed the directory structure of comm to match the package system
hauberg
parents:
diff changeset
126 num = sum(ind')';
5056d2d5eb72 Changed the directory structure of comm to match the package system
hauberg
parents:
diff changeset
127 endif
5056d2d5eb72 Changed the directory structure of comm to match the package system
hauberg
parents:
diff changeset
128 rate = num / max(ac,bc);
5056d2d5eb72 Changed the directory structure of comm to match the package system
hauberg
parents:
diff changeset
129 case 'column',
5056d2d5eb72 Changed the directory structure of comm to match the package system
hauberg
parents:
diff changeset
130 if (strcmp(type,"matrix") && (ar == 1))
5056d2d5eb72 Changed the directory structure of comm to match the package system
hauberg
parents:
diff changeset
131 num = ind;
5056d2d5eb72 Changed the directory structure of comm to match the package system
hauberg
parents:
diff changeset
132 else
5056d2d5eb72 Changed the directory structure of comm to match the package system
hauberg
parents:
diff changeset
133 num = sum(ind);
5056d2d5eb72 Changed the directory structure of comm to match the package system
hauberg
parents:
diff changeset
134 endif
5056d2d5eb72 Changed the directory structure of comm to match the package system
hauberg
parents:
diff changeset
135 rate = num / max(ar,br);
5056d2d5eb72 Changed the directory structure of comm to match the package system
hauberg
parents:
diff changeset
136 case 'overall',
5056d2d5eb72 Changed the directory structure of comm to match the package system
hauberg
parents:
diff changeset
137 num = sum(sum(ind));
5056d2d5eb72 Changed the directory structure of comm to match the package system
hauberg
parents:
diff changeset
138 rate = num / max(ar,br) / max(ac,bc);
5056d2d5eb72 Changed the directory structure of comm to match the package system
hauberg
parents:
diff changeset
139 otherwise
5056d2d5eb72 Changed the directory structure of comm to match the package system
hauberg
parents:
diff changeset
140 error("impossible");
5056d2d5eb72 Changed the directory structure of comm to match the package system
hauberg
parents:
diff changeset
141 endswitch
5056d2d5eb72 Changed the directory structure of comm to match the package system
hauberg
parents:
diff changeset
142
5056d2d5eb72 Changed the directory structure of comm to match the package system
hauberg
parents:
diff changeset
143 endfunction