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

RFC: Refactor LatentGP API slightly #216

Draft
wants to merge 3 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
2 changes: 1 addition & 1 deletion Project.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
name = "AbstractGPs"
uuid = "99985d1d-32ba-4be9-9821-2ec096f28918"
authors = ["JuliaGaussianProcesses Team"]
version = "0.4.0"
version = "0.5.0-DEV"

[deps]
ChainRulesCore = "d360d2e6-b24c-11e9-a2a3-2a2ae2dbcce4"
Expand Down
8 changes: 5 additions & 3 deletions src/latent_gp.jl
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,10 @@
LatentGP(f<:GP, lik, Σy)

- `f` is a `AbstractGP`.
- `lik` is the likelihood function which maps samples from `f` to the corresponding
conditional likelihood distributions (i.e., `lik` must return a `Distribution` compatible with the observations).
- `lik` is a function mapping inputs `x` to a likelihood function, itself mapping samples
from `f` to the corresponding conditional likelihood distributions (i.e., `lik` must
return another function, which returns a `Distribution` compatible with the observations
when called at values of the latent process).
- `Σy` is the noise under which the latent GP is "observed"; this represents the jitter used to avoid numeric instability and should generally be small.

"""
Expand All @@ -26,7 +28,7 @@ struct LatentFiniteGP{Tfx<:FiniteGP,Tlik}
lik::Tlik
end

(lgp::LatentGP)(x) = LatentFiniteGP(lgp.f(x, lgp.Σy), lgp.lik)
(lgp::LatentGP)(x) = LatentFiniteGP(lgp.f(x, lgp.Σy), lgp.lik(x))

function Distributions.rand(rng::AbstractRNG, lfgp::LatentFiniteGP)
f = rand(rng, lfgp.fx)
Expand Down
3 changes: 1 addition & 2 deletions test/latent_gp.jl
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,9 @@
x = rand(10)
y = rand(10)

lgp = LatentGP(gp, x -> MvNormal(x, 0.1), 1e-5)
lgp = LatentGP(gp, x -> (f -> MvNormal(f, 0.1)), 1e-5)
Copy link
Member

Choose a reason for hiding this comment

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

This constructor of MvNormal was deprecated (JuliaStats/Distributions.jl#1362), it should be replaced with e.g.

Suggested change
lgp = LatentGP(gp, x -> (f -> MvNormal(f, 0.1)), 1e-5)
lgp = LatentGP(gp, x -> (f -> MvNormal(f, 0.01 * I)), 1e-5)

@test lgp isa LatentGP
@test lgp.f isa AbstractGPs.AbstractGP
@test lgp.Σy isa Real

lfgp = lgp(x)
@test lfgp isa AbstractGPs.LatentFiniteGP
Expand Down