Skip to content

Commit

Permalink
Gibbs Sampling (#39)
Browse files Browse the repository at this point in the history
Gibbs Samplong.
  • Loading branch information
AnthonyPerez authored and tawheeler committed Dec 11, 2016
1 parent 7bb0c94 commit 7914624
Show file tree
Hide file tree
Showing 7 changed files with 738 additions and 2 deletions.
7 changes: 7 additions & 0 deletions src/BayesNets.jl
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@ export

parents,
children,
markov_blanket_cpds,
markov_blanket,
has_edge,
enforce_topological_order!,

Expand All @@ -34,6 +36,9 @@ export

rand_cpd,
rand_table_weighted,
BayesNetSampler,
gibbs_sample,
GibbsSampler,

table,
sumout,
Expand Down Expand Up @@ -62,10 +67,12 @@ export
bayesian_score_components,
bayesian_score


include("bayes_nets.jl")
include("io.jl")
include("sampling.jl")
include("learning.jl")
include("gibbs.jl")

include("DiscreteBayesNet/ndgrid.jl")
include("DiscreteBayesNet/factors.jl")
Expand Down
23 changes: 23 additions & 0 deletions src/bayes_nets.jl
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,29 @@ function children(bn::BayesNet, target::NodeName)
NodeName[name(bn.cpds[j]) for j in out_neighbors(bn.dag, i)]
end

"""
Returns all CPDs that involve the target as a list of CPDs
The variables in these CPDs collectively include the parents, children, and parents of children of the target
"""
function markov_blanket_cpds(bn::BayesNet, target::NodeName)
markov_blanket_cpds = CPD[get(bn, child_name) for child_name in children(bn, target)]
push!(markov_blanket_cpds, get(bn, target))
return markov_blanket_cpds
end

"""
Return the children, parents, and parents of children (excluding target) as a Set of NodeNames
"""
function markov_blanket(bn::BayesNet, target::NodeName)
nodeNames = NodeName[]
for child in children(bn, target)
append!(nodeNames, parents(bn, child))
push!(nodeNames, child)
end
append!(nodeNames, parents(bn, target))
return setdiff(Set(nodeNames), Set(NodeName[target]))
end

function has_edge(bn::BayesNet, parent::NodeName, child::NodeName)
u = get(bn.name_to_index, parent, 0)
v = get(bn.name_to_index, child, 0)
Expand Down
Loading

0 comments on commit 7914624

Please sign in to comment.