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

Fixed bug in docs as reported in #329 #330

Merged
merged 2 commits into from
Sep 23, 2024
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
12 changes: 6 additions & 6 deletions docs/src/examples.md
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ Similarily to the multivariate ADVI example, we could use `Stacked` to get a _bo
```@repl normalizing-flows
d = MvNormal(zeros(2), ones(2));
ibs = inverse.(bijector.((InverseGamma(2, 3), Beta())));
sb = stack(ibs...) # == Stacked(ibs) == Stacked(ibs, [i:i for i = 1:length(ibs)]
sb = Stacked(ibs) # == Stacked(ibs, [i:i for i = 1:length(ibs)]
b = sb ∘ PlanarLayer(2)
td = transformed(d, b);
y = rand(rng, td)
Expand All @@ -128,7 +128,7 @@ struct NLLObjective{R,D,T}
data::T
end

function (obj::NLLObjective)(θs...)
function (obj::NLLObjective)(θs)
transformed_dist = transformed(obj.basedist, obj.reconstruct(θs))
return -sum(Base.Fix1(logpdf, transformed_dist), eachcol(obj.data))
end
Expand All @@ -140,19 +140,19 @@ xs = randn(2, 1000);
f = NLLObjective(reconstruct, MvNormal(2, 1), xs);

# Initial loss.
@info "Initial loss: $(f(θs...))"
@info "Initial loss: $(f(θs))"

# Train using gradient descent.
ε = 1e-3;
for i in 1:100
∇s = Zygote.gradient(f, θs...)
θs = map(θs, ∇s) do θ, ∇
(∇s,) = Zygote.gradient(f, θs)
θs = fmap(θs, ∇s) do θ, ∇
θ - ε .* ∇
end
end

# Final loss
@info "Finall loss: $(f(θs...))"
@info "Final loss: $(f(θs))"

# Very simple check to see if we learned something useful.
samples = rand(transformed(f.basedist, f.reconstruct(θs)), 1000);
Expand Down
Loading