Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Modularising Bayesian Network (Experimental) #271

Merged
merged 9 commits into from
Jan 28, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -4,17 +4,15 @@ using BangBang
using Graphs
using Distributions

include("bayesnet.jl")
include("bayesian_network.jl")
include("conditioning.jl")
include("functions.jl")

export BayesianNetwork,
add_stochastic_vertex!,
add_deterministic_vertex!,
add_edge!,
condition,
condition!,
decondition,
decondition!,
ancestral_sampling,
is_conditionally_independent

end
39 changes: 39 additions & 0 deletions src/experimental/ProbabilisticGraphicalModels/bayesian_network.jl
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
"""
BayesianNetwork

A structure representing a Bayesian Network.
"""
struct BayesianNetwork{V,T,F}
graph::SimpleDiGraph{T}
"names of the variables in the network"
names::Vector{V}
"mapping from variable names to ids"
names_to_ids::Dict{V,T}
"values of each variable in the network"
values::Dict{V,Any} # TODO: make it a NamedTuple for better performance in the future
"distributions of the stochastic variables"
distributions::Vector{Distribution}
"deterministic functions of the deterministic variables"
deterministic_functions::Vector{F}
"ids of the stochastic variables"
stochastic_ids::Vector{T}
"ids of the deterministic variables"
deterministic_ids::Vector{T}
is_stochastic::BitVector
is_observed::BitVector
end

function BayesianNetwork{V}() where {V}
return BayesianNetwork(
SimpleDiGraph{Int}(), # by default, vertex ids are integers
V[],
Dict{V,Int}(),
Dict{V,Any}(),
Distribution[],
Any[],
Int[],
Int[],
BitVector(),
BitVector(),
)
end
331 changes: 0 additions & 331 deletions src/experimental/ProbabilisticGraphicalModels/bayesnet.jl

This file was deleted.

Loading
Loading