Skip to content

Commit

Permalink
make test of iterator(...) more robust
Browse files Browse the repository at this point in the history
  • Loading branch information
ablaom committed Apr 23, 2024
1 parent 54ed311 commit d0002b3
Showing 1 changed file with 19 additions and 19 deletions.
38 changes: 19 additions & 19 deletions test/hyperparam/one_dimensional_range_methods.jl
Original file line number Diff line number Diff line change
Expand Up @@ -233,31 +233,31 @@ end
@testset "NominalSampler" begin

r = range(Char, :(model.dummy), values=collect("cab"))
N = 10000

@testset "probability vector specified" begin
s = MLJBase.sampler(r, [0.1, 0.2, 0.7])
rng = StableRNG(600)
dict = Dist.countmap(rand(rng,s, 1000))
c, a, b = map(x -> dict[x], collect("cab"))
@test a == 201 && b == 714 && c == 85
# to compute half-width of 95% confidence intervals, for counts of a Bernoulli process
# with probability `p`, sampled `N` times:
halfwidth(p, N) = 1.96*sqrt(p*(1 - p))*sqrt(N)

rng = StableRNG(89);
dict = Dist.countmap(rand(rng, s, 1000))
c, a, b = map(x -> dict[x], collect("cab"))
@test a == 173 && b == 733 && c == 94
@testset "probability vector specified" begin
p = Dict('c'=>0.1, 'a'=>0.2, 'b'=>0.7)
rng = StableRNG(660)
s = MLJBase.sampler(r, [p[class] for class in "cab"])
counts = Dist.countmap(rand(rng,s, N))
for class in "abc"
μ = p[class]*N
@test abs(counts[class] - μ) < halfwidth(p[class], N)
end
end

@testset "probability vector unspecified (uniform)" begin
s = MLJBase.sampler(r)
rng = StableRNG(55)
dict = Dist.countmap(rand(rng,s, 1000))
c, a, b = map(x -> dict[x], collect("cab"))
@test a == 361 && b == 335 && c == 304

rng = StableRNG(550)
dict = Dist.countmap(rand(rng, s, 1000))
c, a, b = map(x -> dict[x], collect("cab"))
@test a == 332 && b == 356 && c == 312
rng = StableRNG(660)
counts = Dist.countmap(rand(rng,s, N))
for class in "abc"
μ = N/3
@test abs(counts[class] - μ) < halfwidth(1/3, N)
end
end

end
Expand Down

0 comments on commit d0002b3

Please sign in to comment.