-
Notifications
You must be signed in to change notification settings - Fork 32
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* using `LinearAlgebra.Cholesky` * add `vectorize` for `LKJCholesky` * add `vectorize` test * add forgotten `end` * Update test/utils.jl Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com> * fix typo * add `reconstruct` methods for LKJ/LKJCholesky inv bijectors * bump patch * bump Bijectors compat * Update src/utils.jl Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com> * add Bijectors v0.13 compat * add `inittrans` method for `CholeskyVariate` * add `LKJ`/`LKJCholesky` tests Co-authored-by: torfjelde * include tests * Update test/lkj.jl Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com> * Update test/lkj.jl Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com> * make tests more accurate * Update test/lkj.jl Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com> * Update test/lkj.jl Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com> * Update test/lkj.jl Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com> * Update test/lkj.jl Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com> * Update test/lkj.jl Co-authored-by: Tor Erlend Fjelde <tor.erlend95@gmail.com> * Update test/lkj.jl Co-authored-by: Tor Erlend Fjelde <tor.erlend95@gmail.com> * Update test/lkj.jl Co-authored-by: Tor Erlend Fjelde <tor.erlend95@gmail.com> * test `LKJCholesky` for both `'U'` and `'L'` * remove unnecessary `float` wrap * Update test/lkj.jl Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com> --------- Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com> Co-authored-by: Tor Erlend Fjelde <tor.erlend95@gmail.com>
- Loading branch information
1 parent
5f74696
commit e6dd4ef
Showing
7 changed files
with
81 additions
and
3 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
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,55 @@ | ||
using Bijectors: pd_from_upper, pd_from_lower | ||
|
||
function pd_from_triangular(X::AbstractMatrix, uplo::Char) | ||
return uplo == 'U' ? pd_from_upper(X) : pd_from_lower(X) | ||
end | ||
|
||
@model lkj_prior_demo() = x ~ LKJ(2, 1) | ||
@model lkj_chol_prior_demo(uplo) = x ~ LKJCholesky(2, 1, uplo) | ||
|
||
# Same for both distributions | ||
target_mean = vec(Matrix{Float64}(I, 2, 2)) | ||
|
||
_lkj_atol = 0.05 | ||
|
||
@testset "Sample from x ~ LKJ(2, 1)" begin | ||
model = lkj_prior_demo() | ||
# `SampleFromPrior` will sample in constrained space. | ||
@testset "SampleFromPrior" begin | ||
samples = sample(model, SampleFromPrior(), 1_000) | ||
@test mean(map(Base.Fix2(getindex, Colon()), samples)) ≈ target_mean atol = | ||
_lkj_atol | ||
end | ||
|
||
# `SampleFromUniform` will sample in unconstrained space. | ||
@testset "SampleFromUniform" begin | ||
samples = sample(model, SampleFromUniform(), 1_000) | ||
@test mean(map(Base.Fix2(getindex, Colon()), samples)) ≈ target_mean atol = | ||
_lkj_atol | ||
end | ||
end | ||
|
||
@testset "Sample from x ~ LKJCholesky(2, 1, $(uplo))" for uplo in ['U', 'L'] | ||
model = lkj_chol_prior_demo(uplo) | ||
# `SampleFromPrior` will sample in unconstrained space. | ||
@testset "SampleFromPrior" begin | ||
samples = sample(model, SampleFromPrior(), 1_000) | ||
# Build correlation matrix from factor | ||
corr_matrices = map(samples) do s | ||
M = reshape(s.metadata.vals, (2, 2)) | ||
pd_from_triangular(M, uplo) | ||
end | ||
@test vec(mean(corr_matrices)) ≈ target_mean atol = _lkj_atol | ||
end | ||
|
||
# `SampleFromUniform` will sample in unconstrained space. | ||
@testset "SampleFromUniform" begin | ||
samples = sample(model, SampleFromUniform(), 1_000) | ||
# Build correlation matrix from factor | ||
corr_matrices = map(samples) do s | ||
M = reshape(s.metadata.vals, (2, 2)) | ||
pd_from_triangular(M, uplo) | ||
end | ||
@test vec(mean(corr_matrices)) ≈ target_mean atol = _lkj_atol | ||
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
e6dd4ef
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
e6dd4ef
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/86195
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: