@@ -4,11 +4,11 @@ using Base.Threads
44
55
66"""
7- Trajectory(container, sampler, controler )
7+ Trajectory(container, sampler, controller )
88
99The `container` is used to store experiences. Common ones are [`Traces`](@ref)
1010or [`Episodes`](@ref). The `sampler` is used to sample experience batches from
11- the `container`. The `controler ` controls whether it is time to sample a batch
11+ the `container`. The `controller ` controls whether it is time to sample a batch
1212or not.
1313
1414Supported methoes are:
@@ -21,35 +21,35 @@ Supported methoes are:
2121Base. @kwdef struct Trajectory{C,S,T}
2222 container:: C
2323 sampler:: S
24- controler :: T
24+ controller :: T
2525
2626 Trajectory (c:: C , s:: S , t:: T ) where {C,S,T} = new {C,S,T} (c, s, t)
2727
28- function Trajectory (container:: C , sampler:: S , controler :: T ) where {C,S,T<: AsyncInsertSampleRatioControler }
28+ function Trajectory (container:: C , sampler:: S , controller :: T ) where {C,S,T<: AsyncInsertSampleRatioController }
2929 t = Threads. @spawn while true
30- for msg in controler . ch_in
30+ for msg in controller . ch_in
3131 if msg. f === Base. push! || msg. f === Base. append!
3232 n_pre = length (container)
3333 msg. f (container, msg. args... ; msg. kw... )
3434 n_post = length (container)
35- controler . n_inserted += n_post - n_pre
35+ controller . n_inserted += n_post - n_pre
3636 else
3737 msg. f (container, msg. args... ; msg. kw... )
3838 end
3939
40- if controler . n_inserted >= controler . threshold
41- if controler . n_sampled <= (controler . n_inserted - controler . threshold) * controler . ratio
40+ if controller . n_inserted >= controller . threshold
41+ if controller . n_sampled <= (controller . n_inserted - controller . threshold) * controller . ratio
4242 batch = sample (sampler, container)
43- put! (controler . ch_out, batch)
44- controler . n_sampled += 1
43+ put! (controller . ch_out, batch)
44+ controller . n_sampled += 1
4545 end
4646 end
4747 end
4848 end
4949
50- bind (controler . ch_in, t)
51- bind (controler . ch_out, t)
52- new {C,S,T} (container, sampler, controler )
50+ bind (controller . ch_in, t)
51+ bind (controller . ch_out, t)
52+ new {C,S,T} (container, sampler, controller )
5353 end
5454end
5555
@@ -60,7 +60,7 @@ function Base.push!(t::Trajectory, x)
6060 n_pre = length (t. container)
6161 push! (t. container, x)
6262 n_post = length (t. container)
63- on_insert! (t. controler , n_post - n_pre)
63+ on_insert! (t. controller , n_post - n_pre)
6464end
6565
6666struct CallMsg
@@ -69,21 +69,21 @@ struct CallMsg
6969 kw:: Any
7070end
7171
72- Base. push! (t:: Trajectory{<:Any,<:Any,<:AsyncInsertSampleRatioControler } , args... ; kw... ) = put! (t. controler . ch_in, CallMsg (Base. push!, args, kw))
73- Base. append! (t:: Trajectory{<:Any,<:Any,<:AsyncInsertSampleRatioControler } , args... ; kw... ) = put! (t. controler . ch_in, CallMsg (Base. append!, args, kw))
72+ Base. push! (t:: Trajectory{<:Any,<:Any,<:AsyncInsertSampleRatioController } , args... ; kw... ) = put! (t. controller . ch_in, CallMsg (Base. push!, args, kw))
73+ Base. append! (t:: Trajectory{<:Any,<:Any,<:AsyncInsertSampleRatioController } , args... ; kw... ) = put! (t. controller . ch_in, CallMsg (Base. append!, args, kw))
7474
7575Base. append! (t:: Trajectory ; kw... ) = append! (t, values (kw))
7676
7777function Base. append! (t:: Trajectory , x)
7878 n_pre = length (t. container)
7979 append! (t. container, x)
8080 n_post = length (t. container)
81- on_insert! (t. controler , n_post - n_pre)
81+ on_insert! (t. controller , n_post - n_pre)
8282end
8383
8484function Base. take! (t:: Trajectory )
85- res = on_sample! (t. controler )
86- if isnothing (res)
85+ res = on_sample! (t. controller )
86+ if isnothing (res) && ! isnothing (t . controller)
8787 nothing
8888 else
8989 sample (t. sampler, t. container)
101101
102102Base. iterate (t:: Trajectory , state) = iterate (t)
103103
104- Base. iterate (t:: Trajectory{<:Any,<:Any,<:AsyncInsertSampleRatioControler } , args... ) = iterate (t. controler . ch_out, args... )
105- Base. take! (t:: Trajectory{<:Any,<:Any,<:AsyncInsertSampleRatioControler } ) = take! (t. controler . ch_out)
104+ Base. iterate (t:: Trajectory{<:Any,<:Any,<:AsyncInsertSampleRatioController } , args... ) = iterate (t. controller . ch_out, args... )
105+ Base. take! (t:: Trajectory{<:Any,<:Any,<:AsyncInsertSampleRatioController } ) = take! (t. controller . ch_out)
0 commit comments