From 7075809732d53f6b238eb3527f0593473f42331d Mon Sep 17 00:00:00 2001 From: ST John Date: Wed, 30 Mar 2022 15:16:57 +0300 Subject: [PATCH 1/8] be more specific about what types work --- src/finite_gp_projection.jl | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/finite_gp_projection.jl b/src/finite_gp_projection.jl index d09cf139..c7337c3a 100644 --- a/src/finite_gp_projection.jl +++ b/src/finite_gp_projection.jl @@ -4,7 +4,7 @@ The finite-dimensional projection of the AbstractGP `f` at `x`. Assumed to be observed under Gaussian noise with zero mean and covariance matrix `Σy` """ -struct FiniteGP{Tf<:AbstractGP,Tx<:AbstractVector,TΣ} <: AbstractMvNormal +struct FiniteGP{Tf<:AbstractGP,Tx<:AbstractVector,TΣ<:AbstractMatrix{<:Real}} <: AbstractMvNormal f::Tf x::Tx Σy::TΣ From f16843311c554cc2626be2c70dcb373ab6c2d332 Mon Sep 17 00:00:00 2001 From: st-- Date: Wed, 30 Mar 2022 15:52:16 +0300 Subject: [PATCH 2/8] Update src/finite_gp_projection.jl Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com> --- src/finite_gp_projection.jl | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/finite_gp_projection.jl b/src/finite_gp_projection.jl index c7337c3a..5d4ee2e1 100644 --- a/src/finite_gp_projection.jl +++ b/src/finite_gp_projection.jl @@ -4,7 +4,8 @@ The finite-dimensional projection of the AbstractGP `f` at `x`. Assumed to be observed under Gaussian noise with zero mean and covariance matrix `Σy` """ -struct FiniteGP{Tf<:AbstractGP,Tx<:AbstractVector,TΣ<:AbstractMatrix{<:Real}} <: AbstractMvNormal +struct FiniteGP{Tf<:AbstractGP,Tx<:AbstractVector,TΣ<:AbstractMatrix{<:Real}} <: + AbstractMvNormal f::Tf x::Tx Σy::TΣ From ca3cfba426d7a690a01fff25528e3d061c9079b2 Mon Sep 17 00:00:00 2001 From: ST John Date: Thu, 31 Mar 2022 10:57:04 +0300 Subject: [PATCH 3/8] add test --- test/finite_gp_projection.jl | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/test/finite_gp_projection.jl b/test/finite_gp_projection.jl index bdcf114f..596e3ecb 100644 --- a/test/finite_gp_projection.jl +++ b/test/finite_gp_projection.jl @@ -243,6 +243,15 @@ end first(FiniteDifferences.grad(central_fdm(3, 1), Base.Fix1(logpdf, fx), y)) @test Distributions.sqmahal!(r, fx, Y) ≈ Distributions.sqmahal(fx, Y) end + + @testset "FiniteGP with UniformScaling" begin + f = GP(SqExponentialKernel()) + fx = f(rand(10), 2.0*I) + # for now, just check that it runs + _ = mean(fx) + _ = mean_and_cov(fx) + _ = rand(fx) + end end @testset "Docs" begin From 0ee4a3969bb669887ad18744d9eeeaa22c75dbcd Mon Sep 17 00:00:00 2001 From: ST John Date: Thu, 31 Mar 2022 11:00:50 +0300 Subject: [PATCH 4/8] add constructor for UniformScaling --- src/finite_gp_projection.jl | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/finite_gp_projection.jl b/src/finite_gp_projection.jl index 5d4ee2e1..30a5fa0f 100644 --- a/src/finite_gp_projection.jl +++ b/src/finite_gp_projection.jl @@ -21,6 +21,10 @@ function FiniteGP(f::AbstractGP, x::AbstractVector, σ²::Real=default_σ²) return FiniteGP(f, x, Fill(σ², length(x))) end +function FiniteGP(f::AbstractGP, x::AbstractVector, σ²::UniformScaling) + return FiniteGP(f, x, σ²[1, 1]) +end + ## conversions Base.convert(::Type{MvNormal}, f::FiniteGP) = MvNormal(mean_and_cov(f)...) function Base.convert(::Type{MvNormal{T}}, f::FiniteGP) where {T} From d6fc7014f0d005d834a177ea1086bea83ddbed6e Mon Sep 17 00:00:00 2001 From: st-- Date: Thu, 31 Mar 2022 11:01:10 +0300 Subject: [PATCH 5/8] Update test/finite_gp_projection.jl Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com> --- test/finite_gp_projection.jl | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/finite_gp_projection.jl b/test/finite_gp_projection.jl index 596e3ecb..1f8a888c 100644 --- a/test/finite_gp_projection.jl +++ b/test/finite_gp_projection.jl @@ -246,7 +246,7 @@ end @testset "FiniteGP with UniformScaling" begin f = GP(SqExponentialKernel()) - fx = f(rand(10), 2.0*I) + fx = f(rand(10), 2.0 * I) # for now, just check that it runs _ = mean(fx) _ = mean_and_cov(fx) From 213b3464b226a677bb5e42e5948411669b7047e1 Mon Sep 17 00:00:00 2001 From: ST John Date: Fri, 1 Apr 2022 19:43:48 +0300 Subject: [PATCH 6/8] protect line --- src/finite_gp_projection.jl | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/finite_gp_projection.jl b/src/finite_gp_projection.jl index 52833ecc..be7a0f5b 100644 --- a/src/finite_gp_projection.jl +++ b/src/finite_gp_projection.jl @@ -18,7 +18,7 @@ end const default_σ² = 1e-18 function FiniteGP(f::AbstractGP, x::AbstractVector, σ²::Real=default_σ²) - return FiniteGP(f, x, ScalMat(length(x), σ²)) + return FiniteGP(f, x, ScalMat(length(x), σ²)) # keep this when merging in master/#306 end function FiniteGP(f::AbstractGP, x::AbstractVector, σ²::UniformScaling) From ddbd5f09a4735583256f420416e66602d1382eaf Mon Sep 17 00:00:00 2001 From: Hong Ge <3279477+yebai@users.noreply.github.com> Date: Wed, 28 May 2025 20:46:55 +0100 Subject: [PATCH 7/8] Create ad.jl --- src/util/ad.jl | 6 ++++++ 1 file changed, 6 insertions(+) create mode 100644 src/util/ad.jl diff --git a/src/util/ad.jl b/src/util/ad.jl new file mode 100644 index 00000000..388a2389 --- /dev/null +++ b/src/util/ad.jl @@ -0,0 +1,6 @@ +import ChainRulesCore: ProjectTo, Tangent +using PDMats: ScalMat + +ProjectTo(x::T) where {T<:ScalMat} = ProjectTo{T}(; dim=x.dim, value=ProjectTo(x.value)) +(pr::ProjectTo{<:ScalMat})(dx::ScalMat) = ScalMat(pr.dim, pr.value(dx.value)) +(pr::ProjectTo{<:ScalMat})(dx::Tangent{<:ScalMat}) = ScalMat(pr.dim, pr.value(dx.value)) From 3f9897ef8149b5957c609279ee83bc54b6eb4665 Mon Sep 17 00:00:00 2001 From: Hong Ge <3279477+yebai@users.noreply.github.com> Date: Wed, 28 May 2025 20:47:56 +0100 Subject: [PATCH 8/8] Update AbstractGPs.jl --- src/AbstractGPs.jl | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/AbstractGPs.jl b/src/AbstractGPs.jl index b0cd6885..87ffaa34 100644 --- a/src/AbstractGPs.jl +++ b/src/AbstractGPs.jl @@ -59,6 +59,9 @@ include("latent_gp.jl") # Plotting utilities. include("util/plotting.jl") +# Autodiff utilities +include("util/ad.jl") + # Testing utilities. include("util/TestUtils.jl")