Skip to content

Commit

Permalink
Refactor likelihoods to prevent anonymous functions
Browse files Browse the repository at this point in the history
  • Loading branch information
ptiede committed Oct 5, 2024
1 parent aed3a5e commit fd1a436
Showing 1 changed file with 50 additions and 18 deletions.
68 changes: 50 additions & 18 deletions src/posterior/likelihood.jl
Original file line number Diff line number Diff line change
Expand Up @@ -15,61 +15,93 @@ are simulated data.
likelihood(d::ConditionedLikelihood, μ) = d.kernel(μ)


struct _Visibility{S,L}
S::S
L::L
end

function (v::_Visibility)(μ)
return ComplexVisLikelihood(baseimage(μ), v.S, v.L)
end

# internal function that creates the likelihood for a set of complex visibilities
function makelikelihood(data::Comrade.EHTObservationTable{<:Comrade.EHTVisibilityDatum})
Σ = noise(data).^2
vis = measurement(data)
lnorm = VLBILikelihoods.lognorm(ComplexVisLikelihood(vis, Σ))
= ConditionedLikelihood(vis) do μ
ComplexVisLikelihood(μ, Σ, lnorm)
end
= ConditionedLikelihood(_Visibility(Σ, lnorm), vis)
return
end

struct _Coherency{S,L}
S::S
L::L
end

function (c::_Coherency)(μ)
return CoherencyLikelihood(baseimage(μ), c.S, c.L)
end

function makelikelihood(data::Comrade.EHTObservationTable{<:Comrade.EHTCoherencyDatum})
Σ = map(x->x.^2, noise(data))
vis = measurement(data)
# lnorm = VLBILikelihoods.lognorm(CoherencyLikelihood(vis, Σ))
= ConditionedLikelihood(vis) do μ
# @info typeof(μ)
CoherencyLikelihood(baseimage(μ), Σ, 0.0)
end
lnorm = VLBILikelihoods.lognorm(CoherencyLikelihood(vis, Σ))
= ConditionedLikelihood(_Coherency(Σ, lnorm), vis)
return
end

struct _VisAmp{S}
S::S
end

function (v::_VisAmp)(μ)
return RiceAmplitudeLikelihood(abs.(baseimage(μ)), v.S)
end

# internal function that creates the likelihood for a set of visibility amplitudes
function makelikelihood(data::Comrade.EHTObservationTable{<:Comrade.EHTVisibilityAmplitudeDatum})
Σ = noise(data).^2
amp = measurement(data)
= ConditionedLikelihood(amp) do μ
RiceAmplitudeLikelihood(abs.(μ), Σ)
end
= ConditionedLikelihood(_VisAmp(Σ), amp)
return
end

struct _LCamp{F,S,L}
f::F
S::S
L::L
end

function (c::_LCamp)(μ)
return AmplitudeLikelihood(c.f(baseimage(μ)), c.S, c.L)
end

# internal function that creates the likelihood for a set of log closure amplitudes
function makelikelihood(data::Comrade.EHTObservationTable{<:Comrade.EHTLogClosureAmplitudeDatum})
Σlca = factornoisecovariance(arrayconfig(data))
f = Base.Fix2(logclosure_amplitudes, designmat(arrayconfig(data)))
amp = measurement(data)
lnorm = VLBILikelihoods.lognorm(AmplitudeLikelihood(amp, Σlca))
= ConditionedLikelihood(amp) do μ
AmplitudeLikelihood(f(μ), Σlca, lnorm)
end
= ConditionedLikelihood(_LCamp(f, Σlca, lnorm), amp)
return
end

struct _CPhase{F,S,L}
f::F
S::S
L::L
end

function (c::_CPhase)(μ)
return ClosurePhaseLikelihood(c.f(baseimage(μ)), c.S, c.L)
end

# internal function that creates the likelihood for a set of closure phase datum
function makelikelihood(data::Comrade.EHTObservationTable{<:Comrade.EHTClosurePhaseDatum})
Σcp = factornoisecovariance(arrayconfig(data))
f = Base.Fix2(closure_phases, designmat(arrayconfig(data)))
phase = measurement(data)
lnorm = VLBILikelihoods.lognorm(ClosurePhaseLikelihood(phase, Σcp))
= ConditionedLikelihood(phase) do μ
ClosurePhaseLikelihood(f(μ), Σcp, lnorm)
end

= ConditionedLikelihood(_CPhase(f, Σcp, lnorm), phase)
return
end

0 comments on commit fd1a436

Please sign in to comment.