-
Notifications
You must be signed in to change notification settings - Fork 69
/
Copy pathbaby.jl
62 lines (54 loc) · 1.31 KB
/
baby.jl
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
function T(s, a, sp)
# if we feed the baby, probability that it becomes not hungry is 1.0
if a == :feed
if sp == :not_hungry
return 1.0
else
return 0.0
end
# if we don't feed baby...
else
# baby remains hungry if unfed
if s == :hungry
if sp == :hungry
return 1.0
else
return 0.0
end
else
# 10% chance of baby becoming hungry given it is not hungry and unfed
if sp == :hungry
return 0.1
else
return 0.9
end
end
end
end
function O(a, sp, o)
if sp == :hungry
p_cry = 0.8
else
p_cry = 0.1
end
if o == :cry
return p_cry
else
return 1.0 - p_cry
end
end
function update_belief(b, a, o)
bp = Dict()
for sp in [:hungry, :not_hungry]
sum_over_s = 0.0
for s in [:hungry, :not_hungry]
sum_over_s += T(s, a, sp) * b[s]
end
bp[sp] = O(a, sp, o) * sum_over_s
end
# normalize so that probabilities sum to 1
bp_sum = bp[:hungry] + bp[:not_hungry]
bp[:hungry] = bp[:hungry] / bp_sum
bp[:not_hungry] = bp[:not_hungry] / bp_sum
return bp
end