1%{ @file sn_get_residt_from_respt.m
2 % @brief Computes residence times from response times
4 % @author LINE Development Team
8 % @brief Computes residence times from response times
11 % This function converts response times to residence times by accounting
12 %
for visit ratios at each station.
16 % WN = sn_get_residt_from_respt(sn, RN, WH)
21 % <tr><th>Name<th>Description
22 % <tr><td>sn<td>Network structure
23 % <tr><td>RN<td>Average response times
24 % <tr><td>WH<td>Residence time handles
29 % <tr><th>Name<th>Description
30 % <tr><td>WN<td>Average residence times
33function WN=sn_get_residt_from_respt(sn, RN, WH)
39% sn.visits
is cell array of stateful-indexed matrices (nstateful x nclasses)
40% We need to convert to station-indexed matrix (M x K) using statefulToStation
41Vstateful = cellsum(sn.
visits);
43for sf = 1:sn.nstateful
44 stationIdx = sn.statefulToStation(sf);
45 if ~isnan(stationIdx) && stationIdx >= 1 && stationIdx <= M
46 V(stationIdx, :) = V(stationIdx, :) + Vstateful(sf, :);
52 if isempty(WH) || WH{ist,k}.disabled
54 elseif ~isempty(RN) && RN(ist,k) > 0
55 if RN(ist,k) < GlobalConstants.FineTol
56 WN(ist,k) = RN(ist,k);
58 c = find(sn.chains(:, k));
59 refclass = sn.refclass(c);
61 WN(ist,k) = RN(ist,k) * V(ist,k) / sum(V(sn.refstat(k), refclass));
63 WN(ist,k) = RN(ist,k) * V(ist,k) / sum(V(sn.refstat(k), sn.inchain{c}));
70WN(WN < 10 * GlobalConstants.FineTol) = 0;
71WN(WN < GlobalConstants.FineTol) = 0;