-
Notifications
You must be signed in to change notification settings - Fork 46
Add RankUpdateEuclideanMetric #443
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
base: main
Are you sure you want to change the base?
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||||||
---|---|---|---|---|---|---|---|---|
|
@@ -99,25 +99,36 @@ function Base.show(io::IO, dem::DenseEuclideanMetric) | |||||||
end | ||||||||
|
||||||||
""" | ||||||||
RankUpdateEuclideanMetric{T,M} <: AbstractMetric | ||||||||
RankUpdateEuclideanMetric{T,AM,AB,AD,F} <: AbstractMetric | ||||||||
|
||||||||
A Gaussian Euclidean metric whose inverse is constructed by rank-updates. | ||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||||
|
||||||||
ErikQQY marked this conversation as resolved.
Show resolved
Hide resolved
|
||||||||
# Fields | ||||||||
|
||||||||
$(TYPEDFIELDS) | ||||||||
|
||||||||
# Constructors | ||||||||
|
||||||||
RankUpdateEuclideanMetric(n::Int) | ||||||||
RankUpdateEuclideanMetric(M⁻¹, B, D) | ||||||||
|
||||||||
Construct a Gaussian Euclidean metric of size `(n, n)` with inverse of `M⁻¹`. | ||||||||
- Construct a Gaussian Euclidean metric of size `(n, n)` with `M⁻¹` being diagonal matrix. | ||||||||
- Construct a Gaussian Euclidean metric of `M⁻¹`, where `M⁻¹` should be a full rank positive definite matrix, | ||||||||
and `B` `D` must be chose so that the Woodbury matrix `W = M⁻¹ + B D B^\\mathrm{T}` is positive definite. | ||||||||
Comment on lines
+115
to
+117
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. For the other metrics There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. For Pathfinder to safely convert its There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||||
|
||||||||
# Example | ||||||||
|
||||||||
```julia | ||||||||
julia> RankUpdateEuclideanMetric(3) | ||||||||
RankUpdateEuclideanMetric(diag=[1.0, 1.0, 1.0]) | ||||||||
``` | ||||||||
|
||||||||
# References | ||||||||
|
||||||||
- Ben Bales, Arya Pourzanjani, Aki Vehtari, Linda Petzold, Selecting the Metric in Hamiltonian Monte Carlo, 2019 | ||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The factorized form used here is due to the Pathfinder paper, so I recommend also citing http://jmlr.org/papers/v23/21-0889.html |
||||||||
""" | ||||||||
struct RankUpdateEuclideanMetric{T,AM<:AbstractVecOrMat{T},AB,AD,F} <: AbstractMetric | ||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. More a question than a request: Is there a reason why |
||||||||
# Diagnal of the inverse of the mass matrix | ||||||||
"Diagnal of the inverse of the mass matrix" | ||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||||
M⁻¹::AM | ||||||||
B::AB | ||||||||
D::AD | ||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Is there some nice explanation of what the purpose of There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I haven't seen one place that explains it all. One interpretation comes from the factor model written in #443 (comment). It's useful when most of the structure of the covariance lies on a low-dimensional subspace. One such example is when the a small number of parameters are highly correlated with each other and not with any other parameters, and all remaining parameters are uncorrelated. Typically efficiency of HMC would be hindered by the high correlations, and one would need a dense covariance matrix, but then you end up with quadratic cost for each leapfrog stop. But if you can roughly upper bound the number of correlated parameters as << the number of sampled parameters, you can use a rank-update metric and get linear cost. It's a mouthful, so I'm not certain the explanation belongs here. I think an explanation could wait until adaptation methods (e.g. Bales') are included here. |
||||||||
|
@@ -146,18 +157,23 @@ function RankUpdateEuclideanMetric(::Type{T}, n::Int) where {T} | |||||||
factorization = woodbury_factorize(M⁻¹, B, D) | ||||||||
return RankUpdateEuclideanMetric(M⁻¹, B, D, factorization) | ||||||||
end | ||||||||
|
||||||||
function RankUpdateEuclideanMetric(M⁻¹, B, D) | ||||||||
factorization = woodbury_factorize(M⁻¹, B, D) | ||||||||
return RankUpdateEuclideanMetric(M⁻¹, B, D, factorization) | ||||||||
end | ||||||||
|
||||||||
function RankUpdateEuclideanMetric(::Type{T}, sz::Tuple{Int}) where {T} | ||||||||
return RankUpdateEuclideanMetric(T, first(sz)) | ||||||||
end | ||||||||
RankUpdateEuclideanMetric(sz::Tuple{Int}) = RankUpdateEuclideanMetric(Float64, sz) | ||||||||
|
||||||||
AdvancedHMC.renew(::RankUpdateEuclideanMetric, M⁻¹) = RankUpdateEuclideanMetric(M⁻¹) | ||||||||
renew(::RankUpdateEuclideanMetric, (M⁻¹, B, D)) = RankUpdateEuclideanMetric(M⁻¹, B, D) | ||||||||
|
||||||||
Base.size(metric::RankUpdateEuclideanMetric, dim...) = size(metric.M⁻¹.diag, dim...) | ||||||||
|
||||||||
function Base.show(io::IO, metric::RankUpdateEuclideanMetric) | ||||||||
print(io, "RankUpdateEuclideanMetric(diag=$(diag(metric.M⁻¹)))") | ||||||||
return nothing | ||||||||
function Base.show(io::IO, ::MIME"text/plain", metric::RankUpdateEuclideanMetric) | ||||||||
return print(io, "RankUpdateEuclideanMetric(diag=$(diag(metric.M⁻¹)))") | ||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Here's another example where calling the full-rank part of the inverse-metric |
||||||||
end | ||||||||
|
||||||||
# `rand` functions for `metric` types. | ||||||||
|
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.