-
Notifications
You must be signed in to change notification settings - Fork 33
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Define adjoints for inverse of PlanarLayer (#160)
- Loading branch information
Showing
13 changed files
with
100 additions
and
30 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,8 @@ | ||
# differentation rule for the iterative algorithm in the inverse of `PlanarLayer` | ||
ChainRulesCore.@scalar_rule( | ||
find_alpha(wt_y::Real, wt_u_hat::Real, b::Real), | ||
@setup( | ||
x = inv(1 + wt_u_hat * sech(Ω + b)^2), | ||
), | ||
(x, - tanh(Ω + b) * x, x - 1), | ||
) |
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
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,10 @@ | ||
@testset "chainrules" begin | ||
x, Δx, x̄ = randn(3) | ||
y, Δy, ȳ = randn(3) | ||
z, Δz, z̄ = randn(3) | ||
Δu = randn() | ||
|
||
ỹ = expm1(y) | ||
frule_test(Bijectors.find_alpha, (x, Δx), (ỹ, Δy), (z, Δz); rtol=1e-3, atol=1e-3) | ||
rrule_test(Bijectors.find_alpha, Δu, (x, x̄), (ỹ, ȳ), (z, z̄); rtol=1e-3, atol=1e-3) | ||
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 |
---|---|---|
@@ -0,0 +1,25 @@ | ||
@testset "PlanarLayer" begin | ||
# logpdf of a flow with a planar layer and two-dimensional inputs | ||
test_ad(randn(7)) do θ | ||
layer = PlanarLayer(θ[1:2], θ[3:4], θ[5:5]) | ||
flow = transformed(MvNormal(2, 1), layer) | ||
return logpdf_forward(flow, θ[6:7]) | ||
end | ||
test_ad(randn(11)) do θ | ||
layer = PlanarLayer(θ[1:2], θ[3:4], θ[5:5]) | ||
flow = transformed(MvNormal(2, 1), layer) | ||
return sum(logpdf_forward(flow, reshape(θ[6:end], 2, :))) | ||
end | ||
|
||
# logpdf of a flow with the inverse of a planar layer and two-dimensional inputs | ||
test_ad(randn(7)) do θ | ||
layer = PlanarLayer(θ[1:2], θ[3:4], θ[5:5]) | ||
flow = transformed(MvNormal(2, 1), inv(layer)) | ||
return logpdf_forward(flow, θ[6:7]) | ||
end | ||
test_ad(randn(11)) do θ | ||
layer = PlanarLayer(θ[1:2], θ[3:4], θ[5:5]) | ||
flow = transformed(MvNormal(2, 1), inv(layer)) | ||
return sum(logpdf_forward(flow, reshape(θ[6:end], 2, :))) | ||
end | ||
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
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
3e0d765
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@JuliaRegistrator register
3e0d765
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Registration pull request created: JuliaRegistries/General/27784
After the above pull request is merged, it is recommended that a tag is created on this repository for the registered package version.
This will be done automatically if the Julia TagBot GitHub Action is installed, or can be done manually through the github interface, or via: