Skip to content

Commit

Permalink
also likelihood<->kernel
Browse files Browse the repository at this point in the history
  • Loading branch information
mschauer committed Mar 19, 2024
1 parent 04bcdc5 commit 633781e
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 0 deletions.
1 change: 1 addition & 0 deletions src/Mitosis.jl
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ include("mt.jl")
export Gaussian, conditional, marginal, Copy, fuse, weighted
export Traced, BFFG, left′, right′, forward, backward, backwardfilter, forwardsampler
export BF, density, logdensity, , kernel, correct, Kernel, WGaussian, Gaussian, ConstantMap, AffineMap, LinearMap, GaussKernel
export likelihood

function independent_sum
end
Expand Down
7 changes: 7 additions & 0 deletions src/gauss.jl
Original file line number Diff line number Diff line change
Expand Up @@ -139,4 +139,11 @@ end

function marginal(p::Gaussian{(:μ, :Σ)}, A)
Gaussian{(:μ, :Σ)}(p.μ[A], p.Σ[A,A])
end

function likelihood(k::AffineGaussianKernel, obs)
q = backward(BFFG(), k, obs; unfused=true)[2].y
F, Γ, c = params(q)
c0 = Mitosis.logdensity0(Gaussian{(:F,:Γ)}(F, Γ))
WGaussian{(:F,:Γ, :c)}(F, Γ, c - c0)
end
5 changes: 5 additions & 0 deletions test/gauss.jl
Original file line number Diff line number Diff line change
Expand Up @@ -36,4 +36,9 @@ end
π = marginal(q, 1:d1)
k = conditional(q, d1+1:d, 1:d1)
@test k(π) marginal(q, d1+1:d)
x = rand(π)
obs = rand(k(x))

@test logdensity(k(x), obs) logdensity(likelihood(k, obs), x)

end

0 comments on commit 633781e

Please sign in to comment.