Skip to content

Commit

Permalink
added test case for the corner case X/Y in Z
Browse files Browse the repository at this point in the history
  • Loading branch information
naseweisssss committed Nov 17, 2024
1 parent 830c208 commit cae8914
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 0 deletions.
5 changes: 5 additions & 0 deletions src/experimental/ProbabilisticGraphicalModels/bayesnet.jl
Original file line number Diff line number Diff line change
Expand Up @@ -215,6 +215,11 @@ end
function is_conditionally_independent(
bn::BayesianNetwork{V}, X::V, Y::V, Z::Vector{V}
) where {V}
println("debugging: X: $X, Y: $Y, Z: $Z")
if X in Z || Y in Z
return true
end

# Get vertex IDs
x_id = bn.names_to_ids[X]
y_id = bn.names_to_ids[Y]
Expand Down
21 changes: 21 additions & 0 deletions test/experimental/ProbabilisticGraphicalModels/bayesnet.jl
Original file line number Diff line number Diff line change
Expand Up @@ -214,6 +214,27 @@ using JuliaBUGS.ProbabilisticGraphicalModels:
@test !is_conditionally_independent(bn, :A, :C, [:B])
end

@testset "Bayes Ball Algorithm Tests" begin
# Create a simple network: A → B → C
bn = BayesianNetwork{Symbol}()
add_stochastic_vertex!(bn, :A, Normal(0, 1), false)
add_stochastic_vertex!(bn, :B, Normal(0, 1), false)
add_stochastic_vertex!(bn, :C, Normal(0, 1), false)
add_edge!(bn, :A, :B)
add_edge!(bn, :B, :C)

@testset "Corner Case: X or Y in Z" begin
# Test case where X is in Z
@test is_conditionally_independent(bn, :A, :C, [:A]) # A ⊥ C | A

# Test case where Y is in Z
@test is_conditionally_independent(bn, :A, :C, [:C]) # A ⊥ C | C

# Test case where both X and Y are in Z
@test is_conditionally_independent(bn, :A, :C, [:A, :C]) # A ⊥ C | A, C
end
end

@testset "Complex Structure" begin
bn = BayesianNetwork{Symbol}()

Expand Down

0 comments on commit cae8914

Please sign in to comment.