-
Notifications
You must be signed in to change notification settings - Fork 16
/
check_urn_model_validity.m
74 lines (57 loc) · 1.37 KB
/
check_urn_model_validity.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
function [argsok] = check_urn_model_validity(p,pi,m,mi)
%CHECK_URN_MODEL_VALIDITY
%
% This function check that the arguments provided to compute_surprise
% function are ok in the sense that they represent a realistic urn model:
% An urn with p balls inside, pi white and p-pi black, and m balls are
% drawm and one looks for the probability that at least mi of them are
% white.
%
% Inputs: p, total number of balls in the urn
% pi, number of white balls in the urn
% m, number of drawn balls
% mi, number of white balls in the drawn balls
%
% Carlo Nicolini, Istituto Italiano di Tecnologia (2016).
argsok = true;
if ( mi<0 )
error('Integer overflow: negative mi');
end
if ( m<0 )
error('Integer overflow: negative m');
end
if ( pi<0 )
error('Integer overflow: negative pi');
end
if ( p<0 )
error('Integer overflow: negative p');
end
if (pi>p)
error('Error: impossible urn model p<pi');
end
if (mi>m)
error('Error: impossible urn model m<mi');
end
if ((m-mi) > (p-pi) )
error('Error: impossible urn model (p-pi)<(m-mi)');
end
if (pi>p)
error('Error: impossible urn model pi>p');
end
if (mi > pi)
error('Error: impossible urn modelmi>pi');
end
if (mi==0)
argsok=false;
return;
end
if (pi==0)
argsok=false;
return;
end
if ((m-mi) == (p-pi) )
argsok=false;
return;
end
argsok=true;
end