-
Notifications
You must be signed in to change notification settings - Fork 14
/
Copy pathgenzmgp.m
74 lines (63 loc) · 2.44 KB
/
genzmgp.m
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% John P Cunningham
% 2011
%
% genzmgp.m
%
% This is a wrapper function for the software provided by Alan Genz for
% lattice point MGP calculation, available at the time of writing as
% qsclatmvnv.m at
% http://www.math.wsu.edu/faculty/genz/software/software.html
%
% This function just formats the inputs and outputs as expected by testMGP
% and other methods.
%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
function [ logmgp , mgp , errGenz ] = genzmgp( m , K , C , lB , uB , numPoints)
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% some useful parameters
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
errorCheck = 0; % cleaner, but requires a bit more computation...
n = length(m);
p = size(C,2);
% number of integration points to use with Genz method
if nargin < 6 || isempty(numPoints)
% then set it to a big number
numPoints = 50000;
end
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% first some error checking
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
if errorCheck
% check sizes
if n~=size(C,1) || n~=size(K,1) || n~=size(K,2)
fprintf('ERROR: the mean vector is not the same size as the columns of C or K (or K is not square).\n');
keyboard
end
% check norms of C.
if any(abs(sum(C.*C,1)-1)>1e-6)
fprintf('WARNING: the columns of C should be unit norm. We will correct that here, but you better make sure C and W are correct.\n');
%fprintf('C^T*W should change, which will change the answer, but we will correct that... Check C, W, Cold, Wold before continuing...\n');
Cold = C;
%Wold = W;
C = C./repmat(sqrt(sum(C.*C)),n,1);
%W = W.*repmat(sqrt(sum(C.*C)),n,1);
end
% check Sigma
if norm(K - K')>1e-14;
fprintf('ERROR: your covariance matrix is not symmetric.\n');
keyboard;
end
end
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% now format as expected by QSCLATMVNV
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
a = lB - C'*m; % must adjust the bounding box to be around a zero centered distribution
b = uB - C'*m; % by definition the halfspace always extends to infty
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% call and return
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
[ mgp , errGenz ] = qsclatmvnv( numPoints, K , a , C' , b );
% return
logmgp = log(mgp);
end