Skip to content
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

Save gradients #351

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
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
8 changes: 7 additions & 1 deletion src/sampler.jl
Original file line number Diff line number Diff line change
Expand Up @@ -163,6 +163,7 @@ function sample(
adaptor::AbstractAdaptor = NoAdaptation(),
n_adapts::Int = min(div(n_samples, 10), 1_000);
drop_warmup = false,
keep_gradients = false,
verbose::Bool = true,
progress::Bool = false,
(pm_next!)::Function = pm_next!,
Expand Down Expand Up @@ -225,7 +226,12 @@ function sample(
# Store sample
if !drop_warmup || i > n_adapts
j = i - drop_warmup * n_adapts
θs[j], stats[j] = t.z.θ, tstat
if keep_gradients
sample = [t.z.θ; t.z.ℓπ]
else
sample = t.z.θ
end
θs[j], stats[j] = sample, tstat
end
end
# Report end of sampling
Expand Down