-
Notifications
You must be signed in to change notification settings - Fork 25
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> --------- Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
- Loading branch information
1 parent
5f74696
commit fff3bd1
Showing
7 changed files
with
77 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,51 @@ | ||
using Bijectors: pd_from_upper | ||
|
||
@model lkj_prior_demo() = x ~ LKJ(2, 1) | ||
@model lkj_chol_prior_demo() = x ~ LKJCholesky(2, 1, 'U') | ||
|
||
# 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, U)" begin | ||
model = lkj_chol_prior_demo() | ||
# `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 = Float64.(reshape(s.metadata.vals, (2, 2))) | ||
pd_from_upper(M) | ||
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 = Float64.(reshape(s.metadata.vals, (2, 2))) | ||
pd_from_upper(M) | ||
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