-
Notifications
You must be signed in to change notification settings - Fork 20
/
latent_gp.jl
47 lines (38 loc) · 1.1 KB
/
latent_gp.jl
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
"""
LatentGP(f<:GP, lik, Σy)
- `f` is a `AbstractGP`.
- `lik` is the log likelihood function which maps sample from f to corresposing
conditional likelihood distributions.
- `Σy` is the observation noise
"""
struct LatentGP{Tf<:AbstractGP,Tlik,TΣy}
f::Tf
lik::Tlik
Σy::TΣy
end
"""
LatentFiniteGP(fx<:FiniteGP, lik)
- `fx` is a `FiniteGP`.
- `lik` is the log likelihood function which maps sample from f to corresposing
conditional likelihood distributions.
"""
struct LatentFiniteGP{Tfx<:FiniteGP,Tlik}
fx::Tfx
lik::Tlik
end
(lgp::LatentGP)(x) = LatentFiniteGP(lgp.f(x, lgp.Σy), lgp.lik)
function Distributions.rand(rng::AbstractRNG, lfgp::LatentFiniteGP)
f = rand(rng, lfgp.fx)
y = rand(rng, lfgp.lik(f))
return (f=f, y=y)
end
"""
logpdf(lfgp::LatentFiniteGP, 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(lfgp::LatentFiniteGP, y::NamedTuple{(:f, :y)})
return logpdf(lfgp.fx, y.f) + logpdf(lfgp.lik(y.f), y.y)
end