1function [Pmarg, logPmarg] = getProbMarg(self, ist,
jobclass, state_m)
2% [PMARG, LOGPMARG] = GETPROBMARG(IST, JOBCLASS, STATE_M)
4% Probability distribution
for queue length of a SINGLE
class at a station.
5% Returns
P(n jobs of
class r)
for n=0,1,...,N(r).
7% Compare with getProbAggr: returns probability of a specific per-
class
8% distribution, e.g.,
P(2
class-1, 1
class-2) as a scalar.
13% state_m - (optional) Specific states to query, or [] for all
16% Pmarg - Vector where Pmarg(n+1) =
P(n jobs of this class)
17% logPmarg - Log probabilities for numerical stability
20 line_error(mfilename,'getProbMarg requires station and job class parameters.');
28 line_error(mfilename,'Station number exceeds the number of stations in the model.');
31 line_error(mfilename,'Job class index exceeds the number of
classes in the model.');
34if isempty(self.result)
40 switch self.options.method
42 % Use MVALDMX to get exact marginalized probabilities
43 if ~all(sn.nservers == 1)
44 line_error(mfilename,'MVALDMX exact marginalized probabilities require single-server stations.');
51 S = ones(sn.nstations, 1);
54 [~, ~, ~, ~, ~, Pc] = pfqn_mvaldmx(lambda, D, N, Z, mu, S);
56 % Extract marginal probabilities for the specific station and class
57 % Use the station probabilities from MVALDMX and marginalize for the specific class
58 Q = self.result.Avg.Q;
62 % Create probability vector for this class at this station using binomial approximation
63 Pmarg = zeros(1, nVal + 1);
64 logPmarg = zeros(1, nVal + 1);
67 % Binomial probability with mean qVal
68 logPk = nchoosekln(nVal, k) + k * log(qVal / nVal) + (nVal - k) * log(1 - qVal / nVal);
69 Pmarg(k + 1) = exp(logPk);
70 logPmarg(k + 1) = logPk;
73 % Filter based on state_m if provided
75 if max(state_m) > length(Pmarg) - 1
76 line_error(mfilename,'Requested state exceeds maximum population for this class.');
78 Pmarg = Pmarg(state_m + 1); % +1 for MATLAB indexing
79 logPmarg = logPmarg(state_m + 1);
83 line_error(mfilename,'Failed to compute marginalized probabilities using MVALDMX: %s', ME.message);
87 % Use binomial approximation similar to getProbAggr but for single class
88 Q = self.result.Avg.Q;
92 % Create probability vector for this class at this station
93 Pmarg = zeros(1, nVal + 1);
94 logPmarg = zeros(1, nVal + 1);
97 % Binomial probability with mean qVal
98 % Rainer Schmidt, "An approximate MVA ...", PEVA 29:245-254, 1997
99 logPk = nchoosekln(nVal, k) + k * log(qVal / nVal) + (nVal - k) * log(1 - qVal / nVal);
100 Pmarg(k + 1) = real(exp(logPk));
101 logPmarg(k + 1) = logPk;
104 % Filter based on state_m if provided
106 if max(state_m) > length(Pmarg) - 1
107 line_error(mfilename,'Requested state exceeds maximum population for this class.');
109 Pmarg = Pmarg(state_m + 1); % +1 for MATLAB indexing
110 logPmarg = logPmarg(state_m + 1);
114 % Open class marginal probability
115 if isempty(self.result)
118 U = self.result.Avg.U;
119 Q = self.result.Avg.Q;
121 if sn.sched(ist) == SchedStrategy.INF
122 % Delay (infinite server): Poisson distribution per class
123 %
P(n) = exp(-Q) * Q^n / n!
126 n_max = max(1, ceil(lambda_mean + 5*sqrt(max(lambda_mean, 1))));
129 Pmarg = zeros(1, length(state_m));
130 logPmarg = zeros(1, length(state_m));
131 for idx = 1:length(state_m)
134 logP = n * log(lambda_mean) - lambda_mean - gammaln(n+1);
142 logPmarg(idx) = logP;
143 Pmarg(idx) = real(exp(logP));
145 elseif sn.sched(ist) ~= SchedStrategy.EXT
146 % Queue station: geometric-like marginal distribution
147 % For multiclass open product-form networks:
148 %
P(n_r = k) = (1-rho) * rho_r^k / (1-rho+rho_r)^{k+1}
149 % where rho = sum_r U(ist,r), rho_r = U(ist,r)
151 rho_total = min(sum(U(ist, :),
'omitnan'), 1 - GlobalConstants.FineTol);
153 if rho_r > 0 && rho_total < 1
154 denom = 1 - rho_total + rho_r;
155 ratio = rho_r / denom;
156 if ratio > 0 && ratio < 1
157 n_max = max(1, ceil(-log(1e-10) / (-log(ratio))));
161 n_max = min(n_max, 1000);
167 Pmarg = zeros(1, length(state_m));
168 logPmarg = zeros(1, length(state_m));
169 if rho_total < 1 - GlobalConstants.FineTol
170 denom = 1 - rho_total + rho_r;
171 for idx = 1:length(state_m)
174 logP = log(1 - rho_total) + n * log(rho_r) - (n+1) * log(denom);
177 logP = log(1 - rho_total) - log(denom);
182 logPmarg(idx) = logP;
183 Pmarg(idx) = real(exp(logP));
186 logPmarg = -Inf * ones(1, length(state_m));
187 Pmarg = zeros(1, length(state_m));
190 % Source/External node: no probability distribution