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;
31% The quadrature nodes must be SORTED: v mixes uniform draws with a logspace
32% grid, so diff(v) on the raw concatenation is sign-indefinite and the panel
33% widths below would be negative.
34v = sort([rand(1,ceil(c*samples)),logspace(0,5,ceil(samples*(1-c)))]); % sample more below the mean of the exponential
35du = [v(1),diff(v)]'; % panel widths, first panel covering [0,v(1)]
36u = repmat(v',1,R);
37% McKenna-Mitra: G = 1/prod(N_r!) * int_0^inf exp(-u) prod_r (Z_r + L_r u)^N_r du.
38% The integrand is (Z_r + L_r*u), NOT (Z_r + L_r)*u -- the latter is a different
39% function that happens to have the same value at u = 1.
40ZL = log(repmat(Z,size(u,1),1) + repmat(L(1,1:R),size(u,1),1).*u);
41% see _kb/03-api-layer.md (pfqn/ family: scaling, log-domain switches, dispatch gates)
42lterms = log(du) - v' + ZL*N';
43lmax = max(lterms);
44lG = lmax + log(sum(exp(lterms-lmax))) - sum(factln(N));
45lG = lG + sum(N)*log(scaleFactor); % rescale
46G = exp(lG);
47end
Definition fjtag.m:161