-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcohcorr_test.m
105 lines (91 loc) · 3.53 KB
/
cohcorr_test.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
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
function cohcorr_test(fid, samplenum, statenum, gamblenum, lprnum)
% cohcorr_test performs tests of the nadir point calculations
%
% Synopsis:
% [Mtime0, Mtime, ...
% Ftime0, Ftime] = cohcorr_test(statenum, gamblenum, lprnum)
%
% Input:
% fid = file id, file to write output to
% statenum = an integer, the size of the possibility space
% gamblenum = an integer, the size of the gamble space
% lprnum = an integer, the numer of lower previsions for which a nadir
% point must be calculated
%
% Output in file:
% Mtime0 = the cputime needed to compute the minimal set of linear
% constraints characterizing coherence
% Mtime = the running time of the nadir calculations, divided by the
% number of extreme points computed, averaged over the lprnum
% trials, when using the minimal set of constraints
% Ftime0 = the cputime needed to generate the 'free' set of linear
% constraints characterizing coherence
% Ftime = the running time of the nadir calculations, divided by the
% number of extreme points computed, averaged over the lprnum
% trials, when using the 'free' constraints
% maximals = the number of maximal dominated coherent lower previsions
%
% Background & Method:
%
% See also COHCORR_BENSOLVE, RANDLPRS_BND,
% COH_CONSTRAINTS_CDDMEX, COH_FREE_CONSTRAINTS.
% how finely do we distinguish zero?
eps = 10^(-8);
k = 0;
do
% randomly select, without replacement, gamblenum NNZM gambles with
% approximate sparsity .5
K = randomK(statenum, gamblenum, .5);
% calculate the minimal set of linear constraints characterizing
% coherence
start = cputime;
Mconstraints = coh_constraints_vertrays(K);
stop = cputime;
Mtime0 = stop - start;
% generate the 'free' set of linear constraints characterizing
% coherence
start = cputime;
Fconstraints = coh_free_constraints(K);
stop = cputime;
Ftime0 = stop - start;
% randomly generate a lower previsions
lprs = randlprs_bnd(lprnum, K);
% initial values
Mtime = 0;
Ftime = 0;
% test the time it takes for a nadir computation for the lower
% prevision generated
for lpr = lprs
try
% when using the minimal set of constraints characterizing coherence
start = cputime;
[Mcohcorr, Mmaxnum] = cohcorr_bensolve(Mconstraints, lpr);
stop = cputime;
Mtime = Mtime + (stop - start);
% when using the 'free' set of constraints characterizing coherence
start = cputime;
[Fcohcorr, Fmaxnum] = cohcorr_bensolve(Fconstraints, lpr);
stop = cputime;
Ftime = Ftime + (stop - start);
excess = sum(abs(Mcohcorr - Fcohcorr));
correction = sum(abs(Mcohcorr - lpr));
if excess > eps
% alert the user if both approaches give different nadir points
K, lpr, Mcohcorr, Fcohcorr, excess
% error(['The minimal and free constraints give different' ...
% 'answers (' num2str(Mmaxnum) ' vs. ' num2str(Fmaxnum) ')' ...
% 'or roundoff error excess (' num2str(excess) ').']);
elseif correction > eps
% only record if the original lpr was incoherent
fprintf(fid, '%1.1e\t%1.1e\t%1.1e\t%1.1e\t%u\r\n', ...
Mtime0, Mtime, Ftime0, Ftime, Mmaxnum);
k += 1; k
else
correction
end
catch
% drop cdd numerical instability-infected cases
end_try_catch
end
until k >= lprnum * samplenum
end