Skip to content

Commit e8b90a4

Browse files
authored
fix: bug in chapter05 (#43)
Thanks!
1 parent 3ded6eb commit e8b90a4

File tree

2 files changed

+13
-15
lines changed

2 files changed

+13
-15
lines changed

notebooks/Chapter05_Blackjack.jl

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
### A Pluto.jl notebook ###
2-
# v0.12.18
2+
# v0.14.7
33

44
using Markdown
55
using InteractiveUtils
@@ -269,13 +269,13 @@ INIT_STATE = state(static_env)
269269
GOLD_VAL = -0.27726
270270

271271
# ╔═╡ ecade5b4-5e61-11eb-0fd5-d1b149adbece
272-
Base.@kwdef struct StoreMSE <: AbstractHook
273-
mse::Vector{Float64} = []
272+
begin
273+
Base.@kwdef struct StoreMSE <: AbstractHook
274+
mse::Vector{Float64} = []
275+
end
276+
(f::StoreMSE)(::PostEpisodeStage, agent, env) = push!(f.mse, (GOLD_VAL - agent.policy.π_target.learner.approximator[1](INIT_STATE))^2)
274277
end
275278

276-
# ╔═╡ fdf615da-5e61-11eb-0df8-dbb3810a408d
277-
(f::StoreMSE)(::PostEpisodeStage, agent, env) = push!(f.mse, (GOLD_VAL - agent.policy.π_target.learner.approximator[1](INIT_STATE))^2)
278-
279279
# ╔═╡ 4f8a0a80-5e64-11eb-13db-3b117cdd35b6
280280
target_policy_mapping = (env, V) -> sum_hand(env.env.player_hand) in (20, 21) ? 2 : 1
281281

@@ -389,7 +389,6 @@ end
389389
# ╠═e31a1da6-5e61-11eb-09ac-1f29247434ca
390390
# ╠═f1437b16-5e61-11eb-2f14-976483f8d924
391391
# ╠═ecade5b4-5e61-11eb-0fd5-d1b149adbece
392-
# ╠═fdf615da-5e61-11eb-0df8-dbb3810a408d
393392
# ╠═4f8a0a80-5e64-11eb-13db-3b117cdd35b6
394393
# ╠═5f5473ba-5e64-11eb-1b37-7706eb629b45
395394
# ╠═bceb8f5a-5e63-11eb-25fb-1d73dc919323

notebooks/Chapter05_Left_Right.jl

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
### A Pluto.jl notebook ###
2-
# v0.12.18
2+
# v0.14.7
33

44
using Markdown
55
using InteractiveUtils
@@ -82,14 +82,14 @@ end
8282
RLBase.prob(::typeof(π_t), s, a) = a == 1 ? 1.0 : 0.
8383

8484
# ╔═╡ 88b48522-5e20-11eb-00df-65834ec124b2
85-
struct CollectValue <: AbstractHook
86-
values::Vector{Float64}
87-
CollectValue() = new([])
85+
begin
86+
struct CollectValue <: AbstractHook
87+
values::Vector{Float64}
88+
CollectValue() = new([])
89+
end
90+
(f::CollectValue)(::PostEpisodeStage, agent, env) = push!(f.values, agent.policy.π_target.learner.approximator[2](1))
8891
end
8992

90-
# ╔═╡ 8c218bba-5e20-11eb-1840-d5e92d1830da
91-
(f::CollectValue)(::PostEpisodeStage, agent, env) = push!(f.values, agent.policy.π_target.learner.approximator[2](1))
92-
9393
# ╔═╡ 4e0a26b0-5e21-11eb-01bf-85db236b9bf8
9494
begin
9595
p = plot()
@@ -120,5 +120,4 @@ end
120120
# ╠═597bbcd2-5e21-11eb-10c9-7db2f46cfffb
121121
# ╠═9cdef3ba-5e21-11eb-1cfd-fb1abbf1d608
122122
# ╠═88b48522-5e20-11eb-00df-65834ec124b2
123-
# ╠═8c218bba-5e20-11eb-1840-d5e92d1830da
124123
# ╠═4e0a26b0-5e21-11eb-01bf-85db236b9bf8

0 commit comments

Comments
 (0)