Skip to content
Snippets Groups Projects
Commit 4be4bce5 authored by François  LAURENT's avatar François LAURENT
Browse files

backward compatible rng seeding

parent 7ceee8d2
No related branches found
No related tags found
No related merge requests found
Pipeline #112516 failed
name = "PlanarLarvae"
uuid = "c2615984-ef14-4d40-b148-916c85b43307"
authors = ["François Laurent", "Institut Pasteur"]
version = "0.14"
version = "0.14a"
[deps]
DelimitedFiles = "8bb1440f-4735-579b-a4ab-409b98df4dab"
......
......@@ -322,17 +322,19 @@ end
abstract type RatioBasedSampling end
struct ClassRatios <: RatioBasedSampling
mutable struct ClassRatios <: RatioBasedSampling
selectors
majority_minority_ratio
rng
seed
end
struct IntraClassRatios <: RatioBasedSampling
mutable struct IntraClassRatios <: RatioBasedSampling
selectors
majority_minority_ratio
intraclass
rng
seed
end
function withselectors(sampler::T, selectors) where {T}
......@@ -364,9 +366,9 @@ function ratiobasedsampling(selectors, majority_minority_ratio; seed=nothing, rn
if isnothing(rng)
rng = Random.default_rng()
end
Random.seed!(rng, seed)
#Random.seed!(rng, seed)
end
LazyIndex(ClassRatios(asselectors(selectors), majority_minority_ratio, rng))
LazyIndex(ClassRatios(asselectors(selectors), majority_minority_ratio, rng, seed))
end
function ratiobasedsampling(selectors, majority_minority_ratio, intraclass;
......@@ -376,7 +378,7 @@ function ratiobasedsampling(selectors, majority_minority_ratio, intraclass;
if isnothing(rng)
rng = Random.default_rng()
end
Random.seed!(rng, seed)
#Random.seed!(rng, seed)
end
intraclass = if intraclass isa Pair
Dict(asselector(intraclass.first) => intraclass.second)
......@@ -384,7 +386,7 @@ function ratiobasedsampling(selectors, majority_minority_ratio, intraclass;
Dict(asselector(selector) => f for (selector, f) in intraclass)
end
LazyIndex(IntraClassRatios(asselectors(selectors), majority_minority_ratio, intraclass,
rng))
rng, seed))
end
function init!(_)
......@@ -677,6 +679,7 @@ function sample(f, loader::DataLoader, features=:spine; kwargs...)
end
function sample(file::Formats.PreloadedFile, window, ix::LazyIndex, features; kwargs...)
ix.sampler.rng = Random.seed!(Random.default_rng(), ix.sampler.seed)
sample(ix.sampler, file, window, ix.targetcounts[file], features; kwargs...)
end
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment