Skip to content

Commit

Permalink
add bayes.jl
Browse files Browse the repository at this point in the history
  • Loading branch information
mschauer committed Mar 19, 2024
1 parent 633781e commit 586f6df
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 19 deletions.
2 changes: 1 addition & 1 deletion src/Mitosis.jl
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,6 @@ include("wgaussian.jl")
include("markov.jl")
include("rules.jl")
include("regression.jl")

include("bayes.jl")

end # module
18 changes: 18 additions & 0 deletions src/bayes.jl
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@

function conditional(p::Gaussian{(:μ, :Σ)}, A, B)
Z = p.Σ[A,B]*inv(p.Σ[B,B])
β = p.μ[A] - Z*p.μ[B]
Σ = p.Σ[A,A] - Z*p.Σ[B,A]
kernel(Gaussian; μ=AffineMap(Z, β), Σ=ConstantMap(Σ))
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
18 changes: 0 additions & 18 deletions src/gauss.jl
Original file line number Diff line number Diff line change
Expand Up @@ -129,21 +129,3 @@ function conditional(p::Gaussian{(:μ, :Σ)}, A, B, xB)
Z = p.Σ[A,B]*inv(p.Σ[B,B])
Gaussian{(:μ, :Σ)}(p.μ[A] + Z*(xB - p.μ[B]), p.Σ[A,A] - Z*p.Σ[B,A])
end

function conditional(p::Gaussian{(:μ, :Σ)}, A, B)
Z = p.Σ[A,B]*inv(p.Σ[B,B])
β = p.μ[A] - Z*p.μ[B]
Σ = p.Σ[A,A] - Z*p.Σ[B,A]
kernel(Gaussian; μ=AffineMap(Z, β), Σ=ConstantMap(Σ))
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

0 comments on commit 586f6df

Please sign in to comment.