Skip to content

Commit

Permalink
Add option to loglikelihood calculation
Browse files Browse the repository at this point in the history
  • Loading branch information
jangevaare committed Jan 12, 2018
1 parent 5053360 commit 4da8ee1
Showing 1 changed file with 9 additions and 3 deletions.
12 changes: 9 additions & 3 deletions src/loglikelihoods.jl
Original file line number Diff line number Diff line change
@@ -1,13 +1,15 @@
"""
loglikelihood(tree::Tree,
mod::SubstitutionModel,
node_data::Dict{Int64, Sequence})
node_data::Dict{Int64, Sequence},
output_calculations::Bool=false)
Calculates the log likelihood of a tree with sequences observed at all leaves
"""
function loglikelihood(tree::Tree,
mod::SubstitutionModel,
node_data::Dict{Int64, Sequence})
node_data::Dict{Int64, Sequence},
output_calculations::Bool=false)
# Error checking
if !all(map(x -> x in keys(node_data), findleaves(tree)))
error("Some leaves are missing sequence data")
Expand Down Expand Up @@ -36,5 +38,9 @@ function loglikelihood(tree::Tree,
end
end
end
return sum(log.(mod.π' * calculations[visit_order[end]]))
if output_calculations
return sum(log.(mod.π' * calculations[visit_order[end]])), calculations, visit_order
else
return sum(log.(mod.π' * calculations[visit_order[end]]))
end
end

0 comments on commit 4da8ee1

Please sign in to comment.