Skip to content

Commit

Permalink
Do not use internal PDMats.chol_lower (#133)
Browse files Browse the repository at this point in the history
* Test optimization of variational covariance

* Use ParameterHandling

This is required for the new test

* Add ParameterHandling

* Include new test

* Clean up test script

* Limit PDMats to version 0.11.7

* Use explicit compat interval

Co-authored-by: David Widmann <[email protected]>

* Add/modify compate entries for tests

* Do not use PDMats.chol_lower

* Update Project.toml

* Fix format

Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>

* Remove additional test

Co-authored-by: Simone Carlo Surace <[email protected]>
Co-authored-by: Simone Surace <[email protected]>
Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
  • Loading branch information
4 people authored May 9, 2022
1 parent dec9785 commit a9c3ecd
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 8 deletions.
2 changes: 1 addition & 1 deletion Project.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
name = "ApproximateGPs"
uuid = "298c2ebc-0411-48ad-af38-99e88101b606"
authors = ["JuliaGaussianProcesses Team"]
version = "0.4.1"
version = "0.4.2"

[deps]
AbstractGPs = "99985d1d-32ba-4be9-9821-2ec096f28918"
Expand Down
14 changes: 7 additions & 7 deletions src/SparseVariationalApproximationModule.jl
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ using LinearAlgebra
using Statistics
using StatsBase
using FillArrays: Fill
using PDMats: chol_lower, ScalMat
using PDMats: ScalMat

using AbstractGPs: AbstractGPs
using AbstractGPs:
Expand All @@ -23,7 +23,7 @@ using AbstractGPs:
At_A,
diag_At_A
using GPLikelihoods: GaussianLikelihood, DefaultExpectationMethod, expected_loglikelihood
using ..ApproximateGPs: _chol_cov, _cov
using ..ApproximateGPs: _chol_lower, _chol_cov, _cov

@doc raw"""
Centered()
Expand Down Expand Up @@ -129,7 +129,7 @@ function AbstractGPs.posterior(sva::SparseVariationalApproximation{Centered})
q, fz = sva.q, sva.fz
m, S = mean(q), _chol_cov(q)
Kuu = _chol_cov(fz)
B = chol_lower(Kuu) \ chol_lower(S)
B = _chol_lower(Kuu) \ _chol_lower(S)
α = Kuu \ (m - mean(fz))
data = (Kuu=Kuu, B=B, α=α)
return ApproxPosteriorGP(sva, fz.f, data)
Expand Down Expand Up @@ -179,9 +179,9 @@ function AbstractGPs.posterior(sva::SparseVariationalApproximation{NonCentered})
q, fz = sva.q, sva.fz
m = mean(q)
Kuu = _chol_cov(fz)
α = chol_lower(Kuu)' \ m
α = _chol_lower(Kuu)' \ m
Sv = _chol_cov(q)
B = chol_lower(Sv)
B = _chol_lower(Sv)
data = (Kuu=Kuu, B=B, α=α)
return ApproxPosteriorGP(sva, fz.f, data)
end
Expand Down Expand Up @@ -214,7 +214,7 @@ end
# A = Lk⁻¹ Ku* is the projection matrix used in computing the predictive variance of the SparseVariationalApproximation posterior.
function _A_and_Kuf(f, x)
Kuf = cov(f.prior, inducing_points(f), x)
A = chol_lower(f.data.Kuu) \ Kuf
A = _chol_lower(f.data.Kuu) \ Kuf
return A, Kuf
end

Expand Down Expand Up @@ -366,7 +366,7 @@ function _prior_kl(sva::SparseVariationalApproximation{NonCentered})
C_ε = _cov(sva.q)

# trace_term = tr(C_ε) # does not work due to PDMat / Zygote issues
L = chol_lower(_chol_cov(sva.q))
L = _chol_lower(_chol_cov(sva.q))
trace_term = sum(L .^ 2) # TODO remove AD workaround

return (trace_term + m_ε'm_ε - length(m_ε) - logdet(C_ε)) / 2
Expand Down
2 changes: 2 additions & 0 deletions src/utils.jl
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ if VERSION < v"1.7"
end
end

_chol_lower(a::Cholesky) = a.uplo === 'L' ? a.L : a.U'

_chol_cov(q::AbstractMvNormal) = cholesky(Symmetric(cov(q)))
_chol_cov(q::MvNormal) = cholesky(q.Σ)

Expand Down

2 comments on commit a9c3ecd

@devmotion
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@JuliaRegistrator
Copy link

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/59951

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:

git tag -a v0.4.2 -m "<description of version>" a9c3ecdf577118f163ae70eac40b84db5d9f4f51
git push origin v0.4.2

Please sign in to comment.