Skip to content

Commit

Permalink
remove conditioned descendant
Browse files Browse the repository at this point in the history
  • Loading branch information
naseweisssss committed Nov 18, 2024
1 parent e229cac commit 34a17b2
Showing 1 changed file with 1 addition and 24 deletions.
25 changes: 1 addition & 24 deletions src/experimental/ProbabilisticGraphicalModels/bayesnet.jl
Original file line number Diff line number Diff line change
Expand Up @@ -271,7 +271,7 @@ function is_conditionally_independent(
end

# Case 2: Node is conditioned or has conditioned descendants
if is_conditioned || has_conditioned_descendant(bn, current_id, z_ids)
if is_conditioned
# If this is a collider or descendant of collider
if length(parents) > 1 || !isempty(children)
# Can go to parents regardless of direction
Expand All @@ -285,29 +285,6 @@ function is_conditionally_independent(
return true
end

function has_conditioned_descendant(bn::BayesianNetwork, node_id::Int, z_ids::Set{Int})
visited = falses(nv(bn.graph))
queue = Int[node_id]

while !isempty(queue)
current = popfirst!(queue)

if visited[current]
continue
end
visited[current] = true

if current in z_ids
return true
end

# Add all unvisited children
append!(queue, filter(c -> !visited[c], outneighbors(bn.graph, current)))
end

return false
end

using LinearAlgebra

# Add these structs and methods before the variable_elimination function
Expand Down

0 comments on commit 34a17b2

Please sign in to comment.