-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathuniversal_dice_paradox.jl
More file actions
69 lines (59 loc) · 1.5 KB
/
universal_dice_paradox.jl
File metadata and controls
69 lines (59 loc) · 1.5 KB
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
# https://www.reddit.com/r/math/comments/17qcx8u/the_paradox_that_broke_me/
using TinyPPL.Distributions
using TinyPPL.Evaluation
import Random
@ppl function six_in_a_row(N)
i = 1
nsix = 0
while true
x = {:x => i} ~ DiscreteUniform(1,6)
if isodd(x)
{:odd} ~ Dirac(true)
break
end
if x == 6
nsix += 1
else
nsix = 0
end
if nsix == N
{:odd} ~ Dirac(false)
break
end
i += 1
end
return i # number of dice rolls until we see `N` 6s in a row
end
@ppl function nth_six(N)
i = 1
nsix = 0
while true
x = {:x => i} ~ DiscreteUniform(1,6)
if isodd(x)
{:odd} ~ Dirac(true)
break
end
if x == 6
nsix += 1
end
if nsix == N
{:odd} ~ Dirac(false)
break
end
i += 1
end
return i # number of dice rolls until we see `N` 6s
end
no_odds = Observations(:odd => false)
N = 5
args = (N,)
Random.seed!(0)
retvals, lp = likelihood_weighting(six_in_a_row, args, no_odds, 10_000_000, Evaluation.retval_completion);
W = exp.(lp);
# expected number of dice rolls until we see `N` 6s in a row GIVEN that no odds show up
retvals'W
Random.seed!(0)
retvals, lp = likelihood_weighting(nth_six, args, no_odds, 10_000_000, Evaluation.retval_completion);
W = exp.(lp);
# expected number of dice rolls until we see `N` 6s GIVEN that no odds show up
retvals'W