Skip to content

Commit 11fd95d

Browse files
committed
add an l to controller
1 parent 0721dd2 commit 11fd95d

File tree

4 files changed

+37
-37
lines changed

4 files changed

+37
-37
lines changed

src/Trajectories.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
module Trajectories
22

33
include("samplers.jl")
4-
include("controlers.jl")
4+
include("controllers.jl")
55
include("traces.jl")
66
include("episodes.jl")
77
include("trajectory.jl")

src/controlers.jl renamed to src/controllers.jl

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,28 +1,28 @@
1-
export InsertSampleRatioControler, InsertSampleControler, AsyncInsertSampleRatioControler
1+
export InsertSampleRatioController, InsertSampleController, AsyncInsertSampleRatioController
22

3-
mutable struct InsertSampleRatioControler
3+
mutable struct InsertSampleRatioController
44
ratio::Float64
55
threshold::Int
66
n_inserted::Int
77
n_sampled::Int
88
end
99

1010
"""
11-
InsertSampleRatioControler(ratio, threshold)
11+
InsertSampleRatioController(ratio, threshold)
1212
1313
Used in [`Trajectory`](@ref). The `threshold` means the minimal number of
1414
insertings before sampling. The `ratio` balances the number of insertings and
1515
the number of samplings.
1616
"""
17-
InsertSampleRatioControler(ratio, threshold) = InsertSampleRatioControler(ratio, threshold, 0, 0)
17+
InsertSampleRatioController(ratio, threshold) = InsertSampleRatioController(ratio, threshold, 0, 0)
1818

19-
function on_insert!(c::InsertSampleRatioControler, n::Int)
19+
function on_insert!(c::InsertSampleRatioController, n::Int)
2020
if n > 0
2121
c.n_inserted += n
2222
end
2323
end
2424

25-
function on_sample!(c::InsertSampleRatioControler)
25+
function on_sample!(c::InsertSampleRatioController)
2626
if c.n_inserted >= c.threshold
2727
if c.n_sampled <= (c.n_inserted - c.threshold) * c.ratio
2828
c.n_sampled += 1
@@ -32,27 +32,27 @@ function on_sample!(c::InsertSampleRatioControler)
3232
end
3333

3434
"""
35-
InsertSampleControler(n, threshold)
35+
InsertSampleController(n, threshold)
3636
3737
Used in [`Trajectory`](@ref). The `threshold` means the minimal number of
3838
insertings before sampling. The `n` is the number of samples until stopping.
3939
"""
40-
mutable struct InsertSampleControler
40+
mutable struct InsertSampleController
4141
n::Int
4242
threshold::Int
4343
n_inserted::Int
4444
n_sampled::Int
4545
end
4646

47-
InsertSampleControler(n, threshold) = InsertSampleControler(n, threshold, 0, 0)
47+
InsertSampleController(n, threshold) = InsertSampleController(n, threshold, 0, 0)
4848

49-
function on_insert!(c::InsertSampleControler, n::Int)
49+
function on_insert!(c::InsertSampleController, n::Int)
5050
if n > 0
5151
c.n_inserted += n
5252
end
5353
end
5454

55-
function on_sample!(c::InsertSampleControler)
55+
function on_sample!(c::InsertSampleController)
5656
if c.n_inserted >= c.threshold
5757
if c.n_sampled < c.n
5858
c.n_sampled += 1
@@ -63,7 +63,7 @@ end
6363

6464
#####
6565

66-
mutable struct AsyncInsertSampleRatioControler
66+
mutable struct AsyncInsertSampleRatioController
6767
ratio::Float64
6868
threshold::Int
6969
n_inserted::Int
@@ -72,15 +72,15 @@ mutable struct AsyncInsertSampleRatioControler
7272
ch_out::Channel
7373
end
7474

75-
function AsyncInsertSampleRatioControler(
75+
function AsyncInsertSampleRatioController(
7676
ratio,
7777
threshold,
7878
; ch_in_sz=1,
7979
ch_out_sz=1,
8080
n_inserted=0,
8181
n_sampled=0
8282
)
83-
AsyncInsertSampleRatioControler(
83+
AsyncInsertSampleRatioController(
8484
ratio,
8585
threshold,
8686
n_inserted,

src/rendering.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,7 @@ function Base.convert(r::Type{Term.AbstractRenderable}, t::Trajectory; width=88)
110110
Panel(
111111
convert(r, t.container; width=width - 8) /
112112
Panel(convert(Term.Tree, t.sampler); title="sampler", style="yellow3", fit=true, width=width - 8) /
113-
Panel(convert(Term.Tree, t.controler); title="controler", style="yellow3", fit=true, width=width - 8);
113+
Panel(convert(Term.Tree, t.controller); title="controller", style="yellow3", fit=true, width=width - 8);
114114
title="Trajectory",
115115
style="yellow3",
116116
width=width,

src/trajectory.jl

Lines changed: 21 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,11 @@ using Base.Threads
44

55

66
"""
7-
Trajectory(container, sampler, controler)
7+
Trajectory(container, sampler, controller)
88
99
The `container` is used to store experiences. Common ones are [`Traces`](@ref)
1010
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
1212
or not.
1313
1414
Supported methoes are:
@@ -21,35 +21,35 @@ Supported methoes are:
2121
Base.@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
5454
end
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)
6464
end
6565

6666
struct CallMsg
@@ -69,21 +69,21 @@ struct CallMsg
6969
kw::Any
7070
end
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

7575
Base.append!(t::Trajectory; kw...) = append!(t, values(kw))
7676

7777
function 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)
8282
end
8383

8484
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)
8787
nothing
8888
else
8989
sample(t.sampler, t.container)
@@ -101,5 +101,5 @@ end
101101

102102
Base.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

Comments
 (0)