1% r = CheckProbVector(pi, sub, prec)
3% Checks
if the vector
is a valid probability vector: the
4% vector has only non-negative elements, the sum of the
7% If parameter
"sub" is set to
true, it checks
if the
8% vector
is a valid substochastic vector: the vector has
9% only non-negative elements, the sum of the elements are
14% pi : vector, shape (1, M) or (M, 1)
17% If
false, the procedure checks
for stochastic,
if
18%
true, it checks
for sub-stochastic
property. The
19%
default value
is false.
20% prec : double, optional
21% Numerical precision. Entries with absolute value
22% less than prec are considered to be zeros. The
23%
default value
is 1e-14.
28% The result of the check.
30function r = CheckProbVector (pi,sub,prec)
32 global BuToolsVerbose;
33 global BuToolsCheckInput;
34 if isempty(BuToolsCheckInput)
35 BuToolsCheckInput =
true;
37 global BuToolsCheckPrecision;
38 if isempty(BuToolsCheckPrecision)
39 BuToolsCheckPrecision = 1e-14;
42 if ~exist(
'prec',
'var')
43 prec = BuToolsCheckPrecision;
46 if ~exist('sub','var')
54 fprintf ('CheckProbVector: The vector has negative element (precision: %g)!\n', prec);
60 if sum(pi)>1+prec*numel(pi)
62 fprintf ('CheckProbVector: The sum of the substochastic vector
is not less than 1 (precision: %g)!\n', prec);
67 if abs(sum(pi)-1)>prec*numel(pi)
69 fprintf ('CheckProbVector: The sum of the vector
is not 1 (precision: %g)!\n', prec);