4 % @brief Monte Carlo Integration (MCI)
for normalizing constant.
10 % @brief Monte Carlo Integration (MCI)
for normalizing constant.
11 % @fn pfqn_mci(D, N, Z, I, variant)
12 % @param D Service demand matrix.
13 % @param N Population vector.
14 % @param Z Think time vector.
15 % @param I Number of samples (
default: 1e5).
16 % @param variant MCI variant (
'mci',
'imci',
'rm', default:
'imci').
17 % @return G Normalizing constant estimate.
18 % @return lG Logarithm of normalizing constant.
19 % @return lZ Individual random sample log values.
22function [G,lG,lZ] = pfqn_mci(D,N,Z,I,variant)
23% [G,LG,LZ] = PFQN_MCI(D,N,Z,I,VARIANT)
25% Normalizing constant estimation via Monte Carlo Integration
28% [G,lG,lZ] = pfqn_mci(D,N,Z,I,VARIANT)
34% VARIANT -
'mci',
'imci',
'rm'
37% lG - estimate of logG
38% lZ - individual random samples
40% Note: if the script returns a floating point range exception,
41% double(log(mean(exp(sym(lZ))))) provides a better estimate of lG, but it
42%
is very time consuming due to the symbolic operations.
44% Implementation: Giuliano Casale (g.casale@imperial.ac.uk), 16-Aug-2013
46if nargin<3%~exist(
'Z',
'var')
49if nargin<4%~exist(
'I',
'var')
52if nargin<5%~exist('variant','var')
58if isempty(D) || sum(D(:))<1e-4
59 lGn = - sum(factln(N)) + sum(N.*log(sum(Z,1)));
65%tput = N./(Z+sum(D)+max(D).*(sum(N)-1)); % balanced job bounds
66%tput = N./Z; % balanced job bounds
69if strcmpi(variant,'imci') % improved mci
70 tput = pfqn_bs(D,N,Z);
72 gamma = max( 0.01, 1-util )'; % MonteQueue 2.0 recommendation
73elseif strcmpi(variant,'mci') % original mci
74 tput = pfqn_bs(D,N,Z);
79 gamma(i) = 1/sqrt(max(N)); % MonteQueue 2.0 recommendation
81 gamma(i) = 1-util(i); % MonteQueue 2.0 recommendation
84elseif strcmpi(variant,'rm') % repairman problem
85 tput = N./(sum(D,1)+Z+max(D,1)*(sum(N)-1)); % a single queue
90 gamma(i) = 1/sqrt(max(N)); % MonteQueue 2.0 recommendation
92 gamma(i) = 1-util(i); % MonteQueue 2.0 recommendation
98 logfact(r) = sum(log(1:N(r))); % log N(r)!
103 if isempty(VL) || size(VL,1) < I || size(VL,2) < M
106 V = repmat(-1./gamma,I,1).*VL(1:I,1:M);
108 % importance sampling
109 lZ = -(ones(1,M) - gamma) * V' - sum(log(gamma)) - sum(logfact) + N*log(V*D+ZI)';
112 lG = logmeanexp(lZ); % return average
114 % line_warning(mfilename,'Floating-point range exception, Monte Carlo integration will return an approximation.');
119 getReport(ME,'basic')