Skip to content

Commit

Permalink
BP Efficiency Improvement (#194)
Browse files Browse the repository at this point in the history
  • Loading branch information
JoeyT1994 authored Sep 3, 2024
1 parent 806d897 commit 174cb4d
Showing 1 changed file with 7 additions and 6 deletions.
13 changes: 7 additions & 6 deletions src/caches/beliefpropagationcache.jl
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ end

function message(bp_cache::BeliefPropagationCache, edge::PartitionEdge)
mts = messages(bp_cache)
return get(mts, edge, default_message(bp_cache, edge))
return get(() -> default_message(bp_cache, edge), mts, edge)
end
function messages(bp_cache::BeliefPropagationCache, edges; kwargs...)
return map(edge -> message(bp_cache, edge; kwargs...), edges)
Expand Down Expand Up @@ -152,15 +152,16 @@ end
function environment(bp_cache::BeliefPropagationCache, verts::Vector)
partition_verts = partitionvertices(bp_cache, verts)
messages = environment(bp_cache, partition_verts)
central_tensors = ITensor[
tensornetwork(bp_cache)[v] for v in setdiff(vertices(bp_cache, partition_verts), verts)
]
central_tensors = factors(bp_cache, setdiff(vertices(bp_cache, partition_verts), verts))
return vcat(messages, central_tensors)
end

function factors(bp_cache::BeliefPropagationCache, verts::Vector)
return ITensor[tensornetwork(bp_cache)[v] for v in verts]
end

function factor(bp_cache::BeliefPropagationCache, vertex::PartitionVertex)
ptn = partitioned_tensornetwork(bp_cache)
return collect(eachtensor(subgraph(ptn, vertex)))
return factors(bp_cache, vertices(bp_cache, vertex))
end

"""
Expand Down

0 comments on commit 174cb4d

Please sign in to comment.