LINE Solver
MATLAB API documentation
Loading...
Searching...
No Matches
getProb.m
1function Prob = getProb(self, node, state)
2% PROB = GETPROB(NODE, STATE)
3% Steady-state marginal state probability at a node, estimated as the
4% time-weighted fraction of the simulated trajectory spent in STATE. Fully
5% JSON-mediated (via sample()). Mirrors the Python-native getProb().
6%
7% If STATE is omitted, the model's current state for the node is used. Returns
8% 0 if the state is not observed during the simulation.
9
10if nargin < 3
11 state = [];
12end
13if GlobalConstants.DummyMode
14 Prob = NaN;
15 return
16end
17
18sampleResult = self.sample(node, 0);
19if isempty(sampleResult) || ~isstruct(sampleResult) || isempty(sampleResult.t)
20 Prob = 0;
21 return
22end
23
24t = sampleResult.t(:);
25stateMatrix = sampleResult.state;
26nt = numel(t);
27if nt < 2 || isempty(stateMatrix)
28 Prob = 0;
29 return
30end
31
32sn = self.model.getStruct;
33if isa(node, 'Node')
34 nodeIdx = node.index;
35else
36 nodeIdx = node;
37end
38if isempty(state)
39 isf = sn.nodeToStateful(nodeIdx);
40 if iscell(sn.state) && numel(sn.state) >= isf && ~isempty(sn.state{isf})
41 state = sn.state{isf};
42 else
43 state = zeros(1, size(stateMatrix, 2));
44 end
45end
46target = state(:).';
47L = min(numel(target), size(stateMatrix, 2));
48target = target(1:L);
49
50total = t(end) - t(1);
51if total <= 0
52 Prob = 0;
53 return
54end
55
56timeInState = 0;
57for ti = 1:nt-1
58 dt = t(ti+1) - t(ti);
59 if all(abs(stateMatrix(ti, 1:L) - target) < 1e-10)
60 timeInState = timeInState + dt;
61 end
62end
63Prob = timeInState / total;
64end
Definition Station.m:245