3 % @file pfqn_mmsample2.m
4 % @brief Monte Carlo sampling
for repairman models
using McKenna-Mitra
form.
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.
20function [G,lG] = pfqn_mmsample2(L,N,Z,samples)
21% [G,LG] = PFQN_MMSAMPLE2(L,N,Z,SAMPLES)
23% Monte carlo sampling
for normalizing constant of a repairmen model
24% based on McKenna-Mitra integral
form
26% Scale so that all coefficients are >=1.
27scaleFactor = 1e-7 + min([L(:);Z(:)]);
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)]
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';
44lG = lmax + log(sum(exp(lterms-lmax))) - sum(factln(N));
45lG = lG + sum(N)*log(scaleFactor); % rescale