|
1 | 1 | ### A Pluto.jl notebook ### |
2 | | -# v0.12.18 |
| 2 | +# v0.14.3 |
3 | 3 |
|
4 | 4 | using Markdown |
5 | 5 | using InteractiveUtils |
@@ -61,14 +61,15 @@ Now we create a testbed to calulate the average reward and perfect action percen |
61 | 61 | """ |
62 | 62 | A customized hook to record whether the action to take is the best action or not. |
63 | 63 | """ |
64 | | -Base.@kwdef struct CollectBestActions <: AbstractHook |
65 | | - best_action::Int |
66 | | - isbest::Vector{Bool} = [] |
67 | | -end |
| 64 | +begin |
| 65 | + Base.@kwdef struct CollectBestActions <: AbstractHook |
| 66 | + best_action::Int |
| 67 | + isbest::Vector{Bool} = [] |
| 68 | + end |
68 | 69 |
|
69 | | -# ╔═╡ d0186892-4aad-11eb-080c-d985066abbc6 |
70 | | -function (h::CollectBestActions)(::PreActStage, agent, env, action) |
71 | | - push!(h.isbest, h.best_action==action) |
| 70 | + function (h::CollectBestActions)(::PreActStage, agent, env, action) |
| 71 | + push!(h.isbest, h.best_action==action) |
| 72 | + end |
72 | 73 | end |
73 | 74 |
|
74 | 75 | # ╔═╡ 1ff8d726-4aad-11eb-0d88-c7f6080c4072 |
@@ -208,16 +209,17 @@ Note that there's a keyword argument named `baseline` in the `GradientBanditLear |
208 | 209 | """ |
209 | 210 |
|
210 | 211 | # ╔═╡ b291cb0c-4b1f-11eb-3ee5-cfcdfdcae00b |
211 | | -Base.@kwdef mutable struct SampleAvg |
212 | | - t::Int = 0 |
213 | | - avg::Float64 = 0.0 |
214 | | -end |
| 212 | +begin |
| 213 | + Base.@kwdef mutable struct SampleAvg |
| 214 | + t::Int = 0 |
| 215 | + avg::Float64 = 0.0 |
| 216 | + end |
215 | 217 |
|
216 | | -# ╔═╡ d61f3168-4b1f-11eb-2a20-2f3d1bb69cd9 |
217 | | -function (s::SampleAvg)(x) |
218 | | - s.t += 1 |
219 | | - s.avg += (x - s.avg) / s.t |
220 | | - s.avg |
| 218 | + function (s::SampleAvg)(x) |
| 219 | + s.t += 1 |
| 220 | + s.avg += (x - s.avg) / s.t |
| 221 | + s.avg |
| 222 | + end |
221 | 223 | end |
222 | 224 |
|
223 | 225 | # ╔═╡ e0e72a60-4b1f-11eb-1001-89777fd3d0f7 |
|
263 | 265 | # ╟─69bc9e66-4a5c-11eb-0288-1930cdb31d9d |
264 | 266 | # ╟─c0ca4172-4aac-11eb-255d-8b0005441fb0 |
265 | 267 | # ╠═4bf0f782-4aad-11eb-291c-afa853f150a3 |
266 | | -# ╠═d0186892-4aad-11eb-080c-d985066abbc6 |
267 | 268 | # ╟─1ff8d726-4aad-11eb-0d88-c7f6080c4072 |
268 | 269 | # ╠═1fbc2952-4b1b-11eb-3b65-75c1058a9537 |
269 | 270 | # ╠═db64341a-4b1b-11eb-3f7b-f11b26f442f4 |
|
275 | 276 | # ╠═6d93c3d0-4b1e-11eb-2b41-af6689ba72f4 |
276 | 277 | # ╟─04e8320c-4b1f-11eb-3340-47f7392a8282 |
277 | 278 | # ╠═b291cb0c-4b1f-11eb-3ee5-cfcdfdcae00b |
278 | | -# ╠═d61f3168-4b1f-11eb-2a20-2f3d1bb69cd9 |
279 | 279 | # ╠═e0e72a60-4b1f-11eb-1001-89777fd3d0f7 |
280 | 280 | # ╠═42525d24-4b20-11eb-099c-b10c90af166e |
281 | 281 | # ╠═aad675d2-4b80-11eb-3d78-a1ef731d7d8b |
0 commit comments