-
Notifications
You must be signed in to change notification settings - Fork 22
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Move LatentGP to AbstractGPs.jl (#25)
* Move latent_gp from LatentGPs.jl * Move latent_gp from LatentGPs.jl * Manually define gaussian likelihood * Bump patch version
- Loading branch information
Showing
5 changed files
with
50 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,7 @@ | ||
name = "AbstractGPs" | ||
uuid = "99985d1d-32ba-4be9-9821-2ec096f28918" | ||
authors = ["willtebbutt <[email protected]>"] | ||
version = "0.2.0" | ||
version = "0.2.1" | ||
|
||
[deps] | ||
Distributions = "31c24e10-a181-5473-b8eb-7969acd0382f" | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
""" | ||
LatentGP(f<:GP, lik) | ||
- `fx` is a `FiniteGP`. | ||
- `lik` is the log likelihood function which maps sample from f to corresposing | ||
conditional likelihood distributions. | ||
""" | ||
struct LatentGP{T<:AbstractGPs.FiniteGP, S} | ||
fx::T | ||
lik::S | ||
end | ||
|
||
function Distributions.rand(rng::AbstractRNG, lgp::LatentGP) | ||
f = rand(rng, lgp.fx) | ||
y = rand(rng, lgp.lik(f)) | ||
return (f=f, y=y) | ||
end | ||
|
||
""" | ||
logpdf(lgp::LatentGP, y::NamedTuple{(:f, :y)}) | ||
```math | ||
log p(y, f; x) | ||
``` | ||
Returns the joint log density of the gaussian process output `f` and real output `y`. | ||
""" | ||
function Distributions.logpdf(lgp::LatentGP, y::NamedTuple{(:f, :y)}) | ||
return logpdf(lgp.fx, y.f) + logpdf(lgp.lik(y.f), y.y) | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
@testset "latent_gp" begin | ||
gp = GP(SqExponentialKernel()) | ||
x = rand(10) | ||
y = rand(10) | ||
fx = gp(x, 1e-5) | ||
|
||
lgp = LatentGP(fx, x -> MvNormal(x, 0.1)) | ||
@test typeof(lgp) <: LatentGP | ||
@test typeof(lgp.fx) <: AbstractGPs.FiniteGP | ||
f = rand(10) | ||
@test typeof(logpdf(lgp, (f=f, y=y))) <: Real | ||
@test typeof(rand(lgp)) <: NamedTuple{(:f, :y)} | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
ac4f85f
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@JuliaRegistrator register()
ac4f85f
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Registration pull request created: JuliaRegistries/General/17520
After the above pull request is merged, it is recommended that a tag is created on this repository for the registered package version.
This will be done automatically if the Julia TagBot GitHub Action is installed, or can be done manually through the github interface, or via: