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

Implement loglikelihood #141

Closed
wants to merge 6 commits into from
Closed
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
2 changes: 2 additions & 0 deletions src/abstract_gp.jl
Original file line number Diff line number Diff line change
Expand Up @@ -200,6 +200,8 @@ function logpdf(f::FiniteGP, Y::AbstractMatrix{<:Real})
return -((size(Y, 1) * T(log(2π)) + logdet(C)) .+ diag_Xt_invA_X(C, Y .- μ)) ./ 2
end

Distributions.loglikelihood(f::FiniteGP, y::AbstractVector{<:Real}) = logpdf(f, y)
Distributions.loglikelihood(f::FiniteGP, y::AbstractMatrix{<:Real}) = sum(logpdf(f, y))
"""
elbo(f::FiniteGP, y::AbstractVector{<:Real}, u::FiniteGP)

Expand Down
2 changes: 2 additions & 0 deletions test/Project.toml
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ Random = "9a3f8284-a2c9-5f02-9a11-845980a1fd5c"
Statistics = "10745b16-79ce-11e8-11f9-7d13ad32a3b2"
Test = "8dfed614-e22c-5e08-85e1-65c5234f0b40"
TimerOutputs = "a759f4b9-e2f1-59dc-863e-4aeb61b1ea8f"
Turing = "fce5fe82-541a-59a6-adf8-730c64b5f9a0"
Zygote = "e88e6eb3-aa80-5325-afca-941959d7151f"

[compat]
Expand All @@ -20,5 +21,6 @@ Documenter = "0.25"
FiniteDifferences = "0.10"
Flux = "0.9, 0.10, 0.11"
TimerOutputs = "0.5"
Turing = "0.14.10"
Zygote = "0.5"
julia = "1.3"
24 changes: 24 additions & 0 deletions test/integration/turing.jl
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
# Ensure that using Stheno inside of Turing doesn't error.
@testset "turing" begin

# make some fake data
l = 0.4
σ² = 1.3
σ²_n = 0.05 # noise
x_ = collect(range(-4.0, 4.0; length=10))
y_ = rand(GP(σ² * stretch(Matern52(), 1 / l), GPC())(x_, σ²_n))

# prior model
@model gp0(y,x) = begin
σ² ~ LogNormal(0, 1)
l ~ LogNormal(0, 1)
σ²_n ~ LogNormal(0, 1)
k = σ² * stretch(Matern52(), 1 ./ l)
f = GP(k, GPC())
y ~ f(x, σ²_n + 1e-3)
end

# sample from posterior
m = gp0(y_, x_)
chain = sample(m, HMC(0.01, 100), 2)
end
8 changes: 7 additions & 1 deletion test/runtests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ using Statistics
using Stheno
using Test
using TimerOutputs
using Turing
using Zygote

using Stheno: ew, pw, mean_vector, cov, cov_diag
Expand Down Expand Up @@ -67,7 +68,7 @@ include("test_util.jl")
include(joinpath("flux", "neural_kernel_network.jl"))
end

println("doctests")
println("doctests:")
@timedtestset "doctests" begin
DocMeta.setdocmeta!(
Stheno,
Expand All @@ -77,6 +78,11 @@ include("test_util.jl")
)
doctest(Stheno)
end

println("turing:")
@timedtestset "turing" begin
include(joinpath("integration", "turing.jl"))
end
end

display(to)