File tree Expand file tree Collapse file tree 4 files changed +44
-2
lines changed Expand file tree Collapse file tree 4 files changed +44
-2
lines changed Original file line number Diff line number Diff line change 1
1
name = " GPLikelihoods"
2
2
uuid = " 6031954c-0455-49d7-b3b9-3e1c99afaf40"
3
3
authors = [
" willtebbutt <[email protected] >" ]
4
- version = " 0.1.0 "
4
+ version = " 0.1.1 "
5
5
6
6
[deps ]
7
7
AbstractGPs = " 99985d1d-32ba-4be9-9821-2ec096f28918"
Original file line number Diff line number Diff line change @@ -7,7 +7,9 @@ using Functors
7
7
8
8
import Distributions
9
9
10
- export GaussianLikelihood, PoissonLikelihood
10
+ export GaussianLikelihood,
11
+ HeteroscedasticGaussianLikelihood,
12
+ PoissonLikelihood
11
13
12
14
# Likelihoods
13
15
include (" likelihoods/gaussian.jl" )
Original file line number Diff line number Diff line change @@ -20,3 +20,21 @@ GaussianLikelihood() = GaussianLikelihood(1e-6)
20
20
(l:: GaussianLikelihood )(f:: Real ) = Normal (f, sqrt (l. σ²))
21
21
22
22
(l:: GaussianLikelihood )(fs:: AbstractVector{<:Real} ) = MvNormal (fs, sqrt (l. σ²))
23
+
24
+ """
25
+ HeteroscedasticGaussianLikelihood(σ²)
26
+
27
+ Heteroscedastic Gaussian likelihood.
28
+ This is a Gaussian likelihood whose mean and the log of whose variance are functions of the
29
+ latent process.
30
+
31
+ ```math
32
+ p(y|[f, g]) = Normal(y | f, exp(g))
33
+ ```
34
+ On calling, this would return a normal distribution with mean `f` and variance `exp(g)`.
35
+ """
36
+ struct HeteroscedasticGaussianLikelihood end
37
+
38
+ (:: HeteroscedasticGaussianLikelihood )(f:: AbstractVector{<:Real} ) = Normal (f[1 ], exp (f[2 ]))
39
+
40
+ (:: HeteroscedasticGaussianLikelihood )(fs:: AbstractVector ) = MvNormal (first .(fs), exp .(last .(fs)))
Original file line number Diff line number Diff line change 11
11
@test length (rand (rng, lik (rand (rng, lfgp. fx)))) == 10
12
12
@test keys (Functors. functor (lik)[1 ]) == (:σ² ,)
13
13
end
14
+
15
+ @testset " HeteroscedasticGaussianLikelihood" begin
16
+ rng = MersenneTwister (123 )
17
+ gp = GP (IndependentMOKernel (SqExponentialKernel ()))
18
+ IN_DIM = 3
19
+ OUT_DIM = 2 # one for the mean the other for the log-standard deviation
20
+ N = 10
21
+ x = [rand (rng, IN_DIM) for _ in 1 : N]
22
+ X = MOInput (x, OUT_DIM)
23
+ lik = HeteroscedasticGaussianLikelihood ()
24
+ lgp = LatentGP (gp, lik, 1e-5 )
25
+ lfgp = lgp (X)
26
+
27
+ Y = rand (rng, lfgp. fx)
28
+
29
+ y = [Y[[i + j* N for j in 0 : (OUT_DIM - 1 )]] for i in 1 : N]
30
+ # Replace with mo_inverse_transform once it is merged
31
+
32
+ @test lik (y) isa Distribution
33
+ @test length (rand (rng, lik (y))) == 10
34
+ @test Functors. functor (lik)[1 ] == ()
35
+ end
You can’t perform that action at this time.
0 commit comments