@@ -4,11 +4,11 @@ using Base.Threads
4
4
5
5
6
6
"""
7
- Trajectory(container, sampler, controler )
7
+ Trajectory(container, sampler, controller )
8
8
9
9
The `container` is used to store experiences. Common ones are [`Traces`](@ref)
10
10
or [`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
12
12
or not.
13
13
14
14
Supported methoes are:
@@ -21,35 +21,35 @@ Supported methoes are:
21
21
Base. @kwdef struct Trajectory{C,S,T}
22
22
container:: C
23
23
sampler:: S
24
- controler :: T
24
+ controller :: T
25
25
26
26
Trajectory (c:: C , s:: S , t:: T ) where {C,S,T} = new {C,S,T} (c, s, t)
27
27
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 }
29
29
t = Threads. @spawn while true
30
- for msg in controler . ch_in
30
+ for msg in controller . ch_in
31
31
if msg. f === Base. push! || msg. f === Base. append!
32
32
n_pre = length (container)
33
33
msg. f (container, msg. args... ; msg. kw... )
34
34
n_post = length (container)
35
- controler . n_inserted += n_post - n_pre
35
+ controller . n_inserted += n_post - n_pre
36
36
else
37
37
msg. f (container, msg. args... ; msg. kw... )
38
38
end
39
39
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
42
42
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
45
45
end
46
46
end
47
47
end
48
48
end
49
49
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 )
53
53
end
54
54
end
55
55
@@ -60,7 +60,7 @@ function Base.push!(t::Trajectory, x)
60
60
n_pre = length (t. container)
61
61
push! (t. container, x)
62
62
n_post = length (t. container)
63
- on_insert! (t. controler , n_post - n_pre)
63
+ on_insert! (t. controller , n_post - n_pre)
64
64
end
65
65
66
66
struct CallMsg
@@ -69,21 +69,21 @@ struct CallMsg
69
69
kw:: Any
70
70
end
71
71
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))
74
74
75
75
Base. append! (t:: Trajectory ; kw... ) = append! (t, values (kw))
76
76
77
77
function Base. append! (t:: Trajectory , x)
78
78
n_pre = length (t. container)
79
79
append! (t. container, x)
80
80
n_post = length (t. container)
81
- on_insert! (t. controler , n_post - n_pre)
81
+ on_insert! (t. controller , n_post - n_pre)
82
82
end
83
83
84
84
function Base. take! (t:: Trajectory )
85
- res = on_sample! (t. controler )
86
- if isnothing (res) && ! isnothing (t. controler )
85
+ res = on_sample! (t. controller )
86
+ if isnothing (res) && ! isnothing (t. controller )
87
87
nothing
88
88
else
89
89
sample (t. sampler, t. container)
101
101
102
102
Base. iterate (t:: Trajectory , state) = iterate (t)
103
103
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