1% r = CheckProbMatrix(
P, transient, prec)
3% Checks
if the matrix
is a valid probability matrix: the
4% matrix
is a square matrix, the matrix has positive or
5% zero off-diagonal elements, the rowsum of the matrix
is 1.
7% If
"transient" is true, it checks
if the matrix
is a
8% valid transient probability matrix: the matrix
is a square
9% matrix, the matrix has positive or zero off-diagonal
10% elements, the rowsum of the matrix
is less than or equal
11% to 1, the maximum absolute eigenvalue
is less than 1.
15%
P : matrix, shape (M,M)
17% transient : bool, optional
18% If
true, the procedure checks
if P is a transient
19% probability matrix, otherwise it checks
if it
is
20% a valid probability matrix. The
default value
is
22% prec : double, optional
23% Entries with absolute value less than prec are
24% considered to be zeros. The
default value
is 1e-14.
29% The result of the check.
31function r = CheckProbMatrix (
P,transient,prec)
33 global BuToolsVerbose;
34 global BuToolsCheckInput;
35 if isempty(BuToolsCheckInput)
36 BuToolsCheckInput =
true;
38 global BuToolsCheckPrecision;
39 if isempty(BuToolsCheckPrecision)
40 BuToolsCheckPrecision = 1e-14;
43 if ~exist(
'prec',
'var')
44 prec = BuToolsCheckPrecision;
47 if ~exist('transient','var')
53 if size(
P,1)~=size(
P,2)
55 fprintf ('CheckProbMatrix: the matrix
is not a square matrix!\n');
62 fprintf ('CheckProbMatrix: the matrix has negative element (precision: %g)!\n', prec);
68 if any(sum(
P,2)-1>size(
P,2)*prec)
70 fprintf ('CheckProbMatrix: The rowsum of the matrix (transient)
is not less or equal than 1 (precision: %g)!\n', prec);
75 if max(real(eig(
P)))>=1-prec
77 fprintf ('CheckProbMatrix: The real part of the largest eigenvalue of the transient matrix
is not less than 1 (precision: %g)!\n', prec);
82 if any(abs(sum(
P,2)-1)>size(
P,2)*prec)
84 fprintf ('CheckProbMatrix: The rowsum of the matrix
is not 1 (precision: %g)!\n', prec);