1function [SAMPLES,LAST,FIRST]=map_sample(MAP,nSamples,pi,seed)
2% [SAMPLES,LAST]=map_sample(MAP,NUM,S0, SEED) - Generate a random sample
3% of inter-arrival times
6% MAP: a MAP in the form of {D0,D1}
7% NUM: number of samples to be generated
8% S0: phase where the MAP starts
for generating the first sample (DEFAULT:
9% random). if it
is a vector it
is interpreted as the probability of
10% starting from a phase
11% SEED: seed used by the random number generator
15% SAMPLES: set of N inter-arrival time samples
16% LAST: vector of absorbing phases for each sample
17% FIRST: vector of entering phase for each sample
20% - [SAMPLES,LAST]=map_sample(MAP,10) - sample of 10 inter-arrival times
21% - [SAMPLES,LAST,FIRST]=map_sample(MAP,10,2) - sample of 10 inter-arrival
22% times starting from phase 2
24% * WARNING: the script can be memory consuming and quite slow for
25% samples sizes greater than N=10000 *
29 SAMPLES=exprnd(map_mean(MAP),nSamples,1);
35 % pi=map_piq(MAP); % time stationary initialization
36 pi=map_pie(MAP); % interval stationary initialization
42% pi=zeros(1,length(MAP{1}));
47initState=min(find(r<=cumsum(pi)));
48RUNS=floor(nSamples/10000);
54 [S,L,F]=sub_map_sample(MAP,10000,LS);
55 SAMPLES(end+1:end+length(S),1)=S(:);
56 LAST(end+1:end+length(L),1)=L(:);
57 FIRST(end+1:end+length(L),1)=F(:);
60[S,L,F]=sub_map_sample(MAP,mod(nSamples,10000),LS);
61SAMPLES(end+1:end+length(S),1)=S(:);
62LAST(end+1:end+length(L),1)=L(:);
63FIRST(end+1:end+length(L),1)=F(:);
66function [SAMPLES,LAST,FIRST]=sub_map_sample(MAP,nSamples,initState)
68nStates=length(MAP{1});
72 p(i,b*nStates+j)=MAP{b+1}(i,j)/abs(MAP{1}(i,i));
81 cdf(i,:)=cumsum(p(i,:));
92 destState=find(cdf(curState,:)>=rand,1,
'first');
95 destState=destState-nStates;
103 maxpathlen=maxpathlen+5;
108holdTimes=-1./diag(MAP{1});
114 H(find(
visits==i))=holdTimes(i);
118 SAMPLES=SAMPLES+exprnd(H(:,i));