LINE Solver
MATLAB API documentation
Loading...
Searching...
No Matches
CheckDMAPRepresentation.m
1% r = CheckDMAPRepresentation(D0, D1, prec)
2%
3% Checks if the input matrixes define a discrete time MAP.
4%
5% Matrices D0 and D1 must have the same size, D0 must be a
6% transient probability matrix, D1 has only non-negative
7% elements, and the rowsum of D0+D1 is 1 (up to the numerical
8% precision).
9%
10% Parameters
11% ----------
12% D0 : matrix, shape (M,M)
13% The D0 matrix of the DMAP to check
14% D1 : matrix, shape (M,M)
15% The D1 matrix of the DMAP to check
16% prec : double, optional
17% Numerical precision, the default value is 1e-14
18%
19% Returns
20% -------
21% r : bool
22% The result of the check
23
24function r=CheckDMAPRepresentation(d0, d1, prec)
25
26 global BuToolsVerbose;
27 global BuToolsCheckPrecision;
28 if isempty(BuToolsCheckPrecision)
29 BuToolsCheckPrecision = 1e-12;
30 end
31
32 if ~exist('prec','var')
33 prec = BuToolsCheckPrecision;
34 end
35
36 if ~CheckProbMatrix(d0,1,prec)
37 if BuToolsVerbose
38 fprintf('CheckDMAPRepresentation: D0 isn''t a transient probability matrix!\n');
39 end
40 r=false;
41 return;
42 end
43
44 if size(d0,1) ~= size(d1,1) || size(d0,2) ~= size(d1,2)
45 if BuToolsVerbose
46 fprintf('CheckDMAPRepresentation: D0 and D1 have different sizes!\n');
47 end
48 r=false;
49 return;
50 end
51
52 if min(min([d0,d1])) < -prec
53 if BuToolsVerbose
54 fprintf('CheckDMAPRepresentation: One of the matrices has negative element!\n');
55 end
56 r=false;
57 return;
58 end
59
60 if any(abs(sum(d0+d1,2)-1) > prec)
61 if BuToolsVerbose
62 fprintf('CheckDMAPRepresentation: A rowsum of matrix0+matrix1 is not 1 (at precision %g)!\n',prec);
63 end
64 r=false;
65 return;
66 end
67
68 r=true;
69
70end