-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
8 changed files
with
89 additions
and
68 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
|
||
const SMWR = Union{SampleMultiAlgRSWRSKIP, SampleMultiAlgWRSWRSKIP} | ||
|
||
reduce_samples(t) = error() | ||
function reduce_samples(t, ss::T...) where {T<:SMWR} | ||
nt = length(ss) | ||
v = Vector{Vector{get_type_rs(t, ss...)}}(undef, nt) | ||
ns = rand(ss[1].rng, Multinomial(length(value(ss[1])), get_ps(ss...))) | ||
Threads.@threads for i in 1:nt | ||
v[i] = sample(ss[i].rng, value(ss[i]), ns[i]; replace = false) | ||
end | ||
return reduce(vcat, v) | ||
end | ||
|
||
function get_ps(ss::SampleMultiAlgRSWRSKIP...) | ||
sum_w = sum(getfield(s, :seen_k) for s in ss) | ||
return [s.seen_k/sum_w for s in ss] | ||
end | ||
function get_ps(ss::SampleMultiAlgWRSWRSKIP...) | ||
sum_w = sum(getfield(s, :state) for s in ss) | ||
return [s.state/sum_w for s in ss] | ||
end | ||
|
||
get_type_rs(::TypeS, s1::T, ss::T...) where {T<:SMWR} = eltype(value(s1)) | ||
function get_type_rs(::TypeUnion, s1::T, ss::T...) where {T<:SMWR} | ||
return Union{eltype(value(s1)), Union{(eltype(value(s)) for s in ss)...}} | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,7 @@ | ||
|
||
struct TypeS end | ||
struct TypeUnion end | ||
|
||
@hybrid struct RefVal{T} | ||
value::T | ||
RefVal{T}() where T = new{T}() | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters