-
Notifications
You must be signed in to change notification settings - Fork 19
Proximal operator for the entropy of location-scale families #168
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
Changes from all commits
Commits
Show all changes
25 commits
Select commit
Hold shift + click to select a range
51e5750
add proximal operator for the entropy of location-scale families
Red-Portal 79ee37e
add missing files
Red-Portal 7d8ea1f
apply formatter
Red-Portal f7a4079
apply formatter
Red-Portal 9d2a694
apply formatter
Red-Portal d960dc9
apply formatter
Red-Portal 11baeb9
run formatter
Red-Portal ea4f86c
run formatter
Red-Portal 09b81d7
run formatter
Red-Portal 317986f
increment version
Red-Portal fb9ec58
fix formatting
Red-Portal 010e1f4
improve docstring for zero gradient entropy estimators
Red-Portal 8b147cd
Merge branch 'proximal_entropy_location_scale' of github.com:TuringLa…
Red-Portal 3f187e8
add missing file
Red-Portal 7f01712
add documentation for proximal operator
Red-Portal 780b850
run formatter
Red-Portal ebb07f0
fix improve type stability
Red-Portal cff3416
Merge branch 'proximal_entropy_location_scale' of github.com:TuringLa…
Red-Portal d70a720
apply formatter
Red-Portal ce33a00
Merge branch 'main' of github.com:TuringLang/AdvancedVI.jl into proxi…
Red-Portal 3c5cb5a
Merge branch 'proximal_entropy_location_scale' of github.com:TuringLa…
Red-Portal 188541b
fix typo in doctring
Red-Portal cc20911
fix typo in comment
Red-Portal 88d3665
apply code review comments
Red-Portal d1eb2d3
bump compat bound for subprojects
Red-Portal File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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,61 @@ | ||
|
|
||
| """ | ||
| ProximalLocationScaleEntropy() | ||
|
|
||
| Proximal operator for the entropy of a location-scale distribution, which is defined as | ||
| ```math | ||
| \\mathrm{prox}(\\lambda) = \\argmin_{\\lambda^{\\prime}} - \\mathbb{H}(q_{\\lambda^{\\prime}}) + \\frac{1}{2 \\gamma_t} \\left\\lVert \\lambda - \\lambda^{\\prime} \\right\\rVert , | ||
| ``` | ||
| where \$\\gamma_t\$ is the stepsize the optimizer used with the proximal operator. | ||
| This assumes the variational family is `<:VILocationScale` and the optimizer is one of the following: | ||
| - `DoG` | ||
| - `DoWG` | ||
| - `Descent` | ||
|
|
||
| For ELBO maximization, since this proximal operator handles the entropy, the gradient estimator for the ELBO must ignore the entropy term. | ||
| That is, the `entropy` keyword argument of `RepGradELBO` muse be one of the following: | ||
| - `ClosedFormEntropyZeroGradient` | ||
| - `StickingTheLandingEntropyZeroGradient` | ||
| """ | ||
| struct ProximalLocationScaleEntropy <: AbstractOperator end | ||
|
|
||
| function apply(::ProximalLocationScaleEntropy, family, state, params, restructure) | ||
| return error("`ProximalLocationScaleEntropy` only supports `<:MvLocationScale`.") | ||
| end | ||
|
|
||
| function stepsize_from_optimizer_state(rule::Optimisers.AbstractRule, state) | ||
| return error( | ||
| "`ProximalLocationScaleEntropy` does not support optimization rule $(typeof(rule))." | ||
| ) | ||
| end | ||
|
|
||
| stepsize_from_optimizer_state(rule::Descent, ::Any) = rule.eta | ||
|
|
||
| function stepsize_from_optimizer_state(::DoG, state) | ||
| _, v, r = state | ||
| return r / sqrt(v) | ||
| end | ||
|
|
||
| function stepsize_from_optimizer_state(::DoWG, state) | ||
| _, v, r = state | ||
| return r * r / sqrt(v) | ||
| end | ||
|
|
||
| function apply( | ||
| ::ProximalLocationScaleEntropy, | ||
| ::Type{<:MvLocationScale}, | ||
| leaf::Optimisers.Leaf{<:Union{<:DoG,<:DoWG,<:Descent},S}, | ||
| params, | ||
| restructure, | ||
| ) where {S} | ||
| q = restructure(params) | ||
|
|
||
| stepsize = stepsize_from_optimizer_state(leaf.rule, leaf.state) | ||
| diag_idx = diagind(q.scale) | ||
| scale_diag = q.scale[diag_idx] | ||
| @. q.scale[diag_idx] = scale_diag + (sqrt(scale_diag^2 + 4 * stepsize) - scale_diag) / 2 | ||
|
|
||
| params, _ = Optimisers.destructure(q) | ||
|
|
||
| return params | ||
| end |
This file contains hidden or 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 hidden or 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,3 +1,4 @@ | ||
|
|
||
| AD_repgradelbo_distributionsad = if TEST_GROUP == "Enzyme" | ||
| Dict( | ||
| :Enzyme => AutoEnzyme(; | ||
|
|
||
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.