LINE Solver
MATLAB API documentation
Loading...
Searching...
No Matches
Q_RAP_ParsePara.m
1function Q_RAP_ParsePara2(C,C_name,D,D_name)
2%Q_RAP_ParsePara checks the validity of the input matrices C, D as a
3%representation of RAP. The evaluated conditions are necessary but not
4%sufficient.
5
6% check numeric
7if (~isnumeric(C))
8 error('MATLAB:Q_RAP_ParsePara:InvalidInput',...
9 '%s has to be numeric', C_name);
10end
11if (~isnumeric(D))
12 error('MATLAB:Q_RAP_ParsePara:InvalidInput',...
13 '%s has to be numeric', D_name);
14end
15
16% check real
17if (~isreal(C))
18 error('MATLAB:Q_RAP_ParsePara:InvalidInput',...
19 '%s has to be a real matrix', C_name);
20end
21if (~isreal(D))
22 error('MATLAB:Q_RAP_ParsePara:InvalidInput',...
23 '%s has to be a real matrix', D_name);
24end
25
26% check dimension
27if (size(C,1) ~= size(C,2))
28 error('MATLAB:Q_RAP_ParsePara:InvalidInput',...
29 '%s is not a square matrix', C_name);
30end
31if (size(D,1) ~= size(D,2))
32 error('MATLAB:Q_RAP_ParsePara:InvalidInput',...
33 '%s is not a square matrix', D_name);
34end
35if (size(C,1) ~= size(D,1))
36 error('MATLAB:Q_RAP_ParsePara:InvalidInput',...
37 'The matrices %s and %s do not have the same dimension', C_name, D_name);
38end
39
40% check zero row sum
41if (max(sum(C+D,2)) > 10^(-14)) || (min(sum(C+D,2)) < -10^(-14))
42 error('MATLAB:Q_RAP_ParsePara:InvalidInput',...
43 'The matrix %s+%s must have zero row sum', C_name, D_name);
44end
45
46%check dominant eigenvalue
47if (max(real(eig(C))) > -10^(-14))
48 error('MATLAB:Q_RAP_ParsePara:InvalidInput',...
49 'The dominant eigenvalue of the matrix %s must have negative real part', C_name);
50end
51if (max(real(eig(C+D))) > 10^(-14)) || (max(real(eig(C+D))) < -10^(-14))
52 error('MATLAB:Q_RAP_ParsePara:InvalidInput',...
53 'The dominant eigenvalue of the matrix %s+%s must have zero real part', C_name, D_name);
54end
55
56%check non-negative moments
57m = size(C,1);
58invC = inv(C);
59P = -invC*D;
60pi = stat(P);
61m1 = -pi*invC*ones(m,1);
62if (m1 < -10^(-14))
63 error('MATLAB:Q_RAP_ParsePara:InvalidInput',...
64 'The first moment of the stationary inter-event distribution of the RAP must be non-negative');
65end
66m2 = 2*pi*invC*invC*ones(m,1);
67if (m2 < -10^(-14))
68 error('MATLAB:Q_RAP_ParsePara:InvalidInput',...
69 'The second moment of the stationary inter-event distribution of the RAP must be non-negative');
70end
71var = m2 - m1^2;
72if (var < -10^(-14))
73 error('MATLAB:Q_RAP_ParsePara:InvalidInput',...
74 'The variance of the stationary inter-event distribution of the RAP(%s,%s) must be non-negative', C_name, D_name);
75end
76m11 = pi*invC*P*invC*ones(m,1);
77if (m11 < -10^(-14))
78 error('MATLAB:Q_RAP_ParsePara:InvalidInput',...
79 'The first joint moment of two succesive inter-events of the stationary RAP(%s,%s) must be non-negative', C_name, D_name);
80end
81
82%check non-negative stationary inter-event density
83stdev = sqrt(var);
84limSup = m1 + 10*stdev;
85quantile = pi*expm(C*limSup)*ones(m,1);
86while quantile > 10^-6
87 limSup = limSup + stdev;
88 quantile = pi*expm(C*limSup)*ones(m,1);
89end
90numPoints = 200;
91for x=1:numPoints
92 if( -pi*expm(C*x/numPoints*limSup)*C*ones(m,1) < -10^(-14) )
93 error('MATLAB:Q_RAP_ParsePara:InvalidInput',...
94 'The stationaty inter-event density function of the RAP(%s,%s) is negative', C_name, D_name);
95 end
96end
97
98%check non-negative joint density
99stdev = sqrt(var);
100limSup = m1 + 5*stdev;
101quantile = pi*expm(C*limSup)*D*expm(C*limSup)*ones(m,1);
102while quantile > 10^-6
103 limSup = limSup + stdev;
104 quantile = pi*expm(C*limSup)*D*expm(C*limSup)*ones(m,1);
105end
106numPoints = 100;
107for x=1:numPoints
108 for y=1:numPoints
109 if( pi*expm(C*x/numPoints*limSup)*D*expm(C*y/numPoints*limSup)*D*ones(m,1) < -10^(-14) )
110 error('MATLAB:Q_RAP_ParsePara:InvalidInput',...
111 'The stationary joint inter-event density function of the RAP(%s,%s) is negative', C_name, D_name);
112 end
113 end
114end
115