Skip to content

Move samples to Matrix #34

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
Dec 20, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 5 additions & 5 deletions src/samplers.jl
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ sample(s::BatchSampler{names}, t::AbstractTraces) where {names} = sample(s, t, n

function sample(s::BatchSampler, t::AbstractTraces, names)
inds = rand(s.rng, 1:length(t), s.batch_size)
NamedTuple{names}(map(x -> t[x][inds], names))
NamedTuple{names}(map(x -> collect(t[x][inds]), names))
end

# !!! avoid iterating an empty trajectory
Expand All @@ -67,7 +67,7 @@ sample(s::BatchSampler{nothing}, t::CircularPrioritizedTraces) = sample(s, t, ke

function sample(s::BatchSampler, t::CircularPrioritizedTraces, names)
inds, priorities = rand(s.rng, t.priorities, s.batch_size)
NamedTuple{(:key, :priority, names...)}((t.keys[inds], priorities, map(x -> t.traces[x][inds], names)...))
NamedTuple{(:key, :priority, names...)}((t.keys[inds], priorities, map(x -> collect(t.traces[x][inds]), names)...))
end

#####
Expand Down Expand Up @@ -172,13 +172,13 @@ function sample(nbs::NStepBatchSampler, ts, ::Val{SS′ART}, inds)
foldr(((rr, tt), init) -> rr + nbs.γ * init * (1 - tt), zip(r⃗, t⃗); init=0.0f0)
end

NamedTuple{SS′ART}((s, s′, a, r, t))
NamedTuple{SS′ART}(map(collect, (s, s′, a, r, t)))
end

function sample(s::NStepBatchSampler, ts, ::Val{SS′L′ART}, inds)
s, s′, a, r, t = sample(s, ts, Val(SSART), inds)
l = consecutive_view(ts[:next_legal_actions_mask], inds)
NamedTuple{SSLART}((s, s′, l, a, r, t))
NamedTuple{SSLART}(map(collect, (s, s′, l, a, r, t)))
end

function sample(s::NStepBatchSampler{names}, t::CircularPrioritizedTraces) where {names}
Expand All @@ -187,4 +187,4 @@ function sample(s::NStepBatchSampler{names}, t::CircularPrioritizedTraces) where
(key=t.keys[inds], priority=priorities),
sample(s, t.traces, Val(names), inds)
)
end
end