LINE Solver
MATLAB API documentation
Loading...
Searching...
No Matches
pfqn_mmsample2.m
1%{
2%{
3 % @file pfqn_mmsample2.m
4 % @brief Monte Carlo sampling for repairman models using McKenna-Mitra form.
5%}
6%}
7
8%{
9%{
10 % @brief Monte Carlo sampling for repairman models using McKenna-Mitra form.
11 % @fn pfqn_mmsample2(L, N, Z, samples)
12 % @param L Service demand vector.
13 % @param N Population vector.
14 % @param Z Think time vector.
15 % @param samples Number of samples.
16 % @return G Normalizing constant estimate.
17 % @return lG Logarithm of normalizing constant.
18%}
19%}
20function [G,lG] = pfqn_mmsample2(L,N,Z,samples)
21% [G,LG] = PFQN_MMSAMPLE2(L,N,Z,SAMPLES)
22
23% Monte carlo sampling for normalizing constant of a repairmen model
24% based on McKenna-Mitra integral form
25R = length(N);
26% Scale so that all coefficients are >=1.
27scaleFactor = 1e-7 + min([L(:);Z(:)]);
28L = L/scaleFactor;
29Z = Z/scaleFactor;
30c = 0.5;
31v = [rand(1,ceil(c*samples)),logspace(0,5,ceil(samples*(1-c)))]; % sample more below the mean of the exponential
32du = [0,diff(v)]';
33u = repmat(v',1,R);
34ZL = log(repmat(Z+L(1,1:R),size(u,1),1).*u);
35lG = du + -v' + ZL*N';
36lG = max(lG) - sum(factln(N)); % get largest
37lG = lG + sum(N)*log(scaleFactor); % rescale
38G = exp(lG);
39end