From 7075809732d53f6b238eb3527f0593473f42331d Mon Sep 17 00:00:00 2001 From: ST John Date: Wed, 30 Mar 2022 15:16:57 +0300 Subject: [PATCH 1/6] 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/6] 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/6] 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/6] 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/6] 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/6] 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)