Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

**BREAKING** improve structs & constructors #306

Draft
wants to merge 9 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 7 additions & 2 deletions src/finite_gp_projection.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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Σ} <: AbstractMvNormal
struct FiniteGP{Tf<:AbstractGP,Tx<:AbstractVector,TΣ<:AbstractMatrix{<:Real}} <:
AbstractMvNormal
f::Tf
x::Tx
Σy::TΣ
Expand All @@ -17,7 +18,11 @@ end
const default_σ² = 1e-18

function FiniteGP(f::AbstractGP, x::AbstractVector, σ²::Real=default_σ²)
return FiniteGP(f, x, Fill(σ², length(x)))
return FiniteGP(f, x, ScalMat(length(x), σ²))
end

function FiniteGP(f::AbstractGP, x::AbstractVector, σ²::UniformScaling)
return FiniteGP(f, x, σ²[1, 1])
end

## conversions
Expand Down
9 changes: 9 additions & 0 deletions test/finite_gp_projection.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down