LINE Solver
MATLAB API documentation
Loading...
Searching...
No Matches
sampleSysAggr.m
1function tranSysState = sampleSysAggr(self, numEvents)
2% TRANSYSSTATE = SAMPLESYSAGGR(NUMSAMPLES)
3options = self.getOptions;
4options.force = true;
5if isempty(self.result) || ~isfield(self.result,'infGen')
6 runAnalyzer(self);
7end
8[infGen, eventFilt] = getGenerator(self);
9[stateSpace, localStateSpace] = getStateSpace(self);
10stateSpaceAggr = getStateSpaceAggr(self);
11
12sn = self.getStruct;
13initState = sn.state;
14% see _kb/11-conventions-and-gotchas.md (CTMC state-vector padding) for rationale
15spaceWidths = zeros(1,length(initState));
16s0 = [];
17for isf=1:length(initState)
18 w = size(localStateSpace{isf},2);
19 spaceWidths(isf) = w;
20 s0 = [s0, zeros(1,w-length(initState{isf})), initState{isf}];
21end
22nst = cumsum([1,spaceWidths]);
23
24% set initial state
25pi0 = zeros(1,size(stateSpace,1));
26pi0(matchrow(stateSpace,s0))=1;
27
28% filter all CTMC events as a marked Markovian arrival process
29D1 = cellsum(eventFilt);
30D0 = infGen-D1;
31MMAP = mmap_normalize([{D0},{D1},eventFilt(:)']);
32
33% now sampel the MMAP
34[sjt,event,~,~,sts] = mmap_sample(MMAP,numEvents, pi0);
35
36sn = self.getStruct;
37tranSysState = struct();
38tranSysState.handle = self.model.getStatefulNodes';
39tranSysState.t = cumsum([0,sjt(1:end-1)']');
40for isf=1:length(initState)
41 tranSysState.state{isf} = stateSpace(sts,(nst(isf):nst(isf+1)-1));
42 [~,tranSysState.state{isf}] = State.toMarginal(sn,sn.statefulToNode(isf),tranSysState.state{isf});
43end
44
45tranSysState.event = {};
46for e = 1:length(event)
47 for a=1:length(sn.sync{event(e)}.active)
48 tranSysState.event{end+1} = sn.sync{event(e)}.active{a};
49 tranSysState.event{end}.t = tranSysState.t(e);
50 end
51 for p=1:length(sn.sync{event(e)}.passive)
52 tranSysState.event{end+1} = sn.sync{event(e)}.passive{p};
53 tranSysState.event{end}.t = tranSysState.t(e);
54 end
55end
56tranSysState.isaggregate = true;
57end