Skip to content

Commit 63fd846

Browse files
committed
add a simple controler
1 parent c2db98d commit 63fd846

File tree

1 file changed

+31
-1
lines changed

1 file changed

+31
-1
lines changed

src/controlers.jl

Lines changed: 31 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
export InsertSampleRatioControler, AsyncInsertSampleRatioControler
1+
export InsertSampleRatioControler, InsertSampleControler, AsyncInsertSampleRatioControler
22

33
mutable struct InsertSampleRatioControler
44
ratio::Float64
@@ -31,6 +31,36 @@ function on_sample!(c::InsertSampleRatioControler)
3131
end
3232
end
3333

34+
"""
35+
InsertSampleControler(n, threshold)
36+
37+
Used in [`Trajectory`](@ref). The `threshold` means the minimal number of
38+
insertings before sampling. The `n` is the number of samples until stopping.
39+
"""
40+
mutable struct InsertSampleControler
41+
n::Int
42+
threshold::Int
43+
n_inserted::Int
44+
n_sampled::Int
45+
end
46+
47+
InsertSampleControler(n, threshold) = InsertSampleControler(n, threshold, 0, 0)
48+
49+
function on_insert!(c::InsertSampleControler, n::Int)
50+
if n > 0
51+
c.n_inserted += n
52+
end
53+
end
54+
55+
function on_sample!(c::InsertSampleControler)
56+
if c.n_inserted >= c.threshold
57+
if c.n_sampled < c.n
58+
c.n_sampled += 1
59+
true
60+
end
61+
end
62+
end
63+
3464
#####
3565

3666
mutable struct AsyncInsertSampleRatioControler

0 commit comments

Comments
 (0)