@@ -20,6 +20,9 @@ $(TYPEDFIELDS)
2020 " Toggle for projecting messages onto the hermitian subspace immediately after update through BP equation"
2121 project_hermitian:: Bool = true
2222
23+ " When true, preserve bipartite structure of BPEnv inherited from input network"
24+ bipartite:: Bool = false
25+
2326 " Output verbosity level"
2427 verbosity:: Int = 2
2528end
@@ -54,21 +57,43 @@ function leading_boundary(env₀::BPEnv, network::InfiniteSquareNetwork, alg::Be
5457 return env, ϵ
5558 end
5659end
57- function leading_boundary(env₀:: BPEnv , state, args... )
58- return leading_boundary(env₀, InfiniteSquareNetwork(state), args... )
60+ function leading_boundary(env₀:: BPEnv , state:: InfiniteState , alg:: BeliefPropagation )
61+ if alg. bipartite
62+ @assert _state_bipartite_check(state)
63+ end
64+ return leading_boundary(env₀, InfiniteSquareNetwork(state), alg)
5965end
6066
6167"""
6268One iteration to update the BP environment.
6369"""
6470function bp_iteration(network:: InfiniteSquareNetwork , env:: BPEnv , alg:: BeliefPropagation )
65- messages = map(eachindex(env)) do I
66- M = update_message(I, network, env)
67- normalize!(M)
68- alg. project_hermitian && (M = project_hermitian!!(M))
69- return M
71+ if alg. bipartite
72+ @assert size(network, 1 ) == size(network, 2 ) == 2
73+ messages = similar(env. messages)
74+ for (d, r) in Iterators. product(1 : 4 , 1 : 2 )
75+ # update BP env around 1st column of state
76+ # [N/S, 1:2, 1], [E/W, 1:2, 2]
77+ c = (d == NORTH || d == SOUTH) ? 1 : 2
78+ I = CartesianIndex(d, r, c)
79+ M = update_message(I, network, env)
80+ normalize!(M)
81+ alg. project_hermitian && (M = project_hermitian!!(M))
82+ messages[I] = M
83+ # copy to the other column
84+ I′ = CartesianIndex(d, _next(r, 2 ), _next(c, 2 ))
85+ messages[I′] = copy(M)
86+ end
87+ return BPEnv(messages)
88+ else
89+ messages = map(eachindex(env)) do I
90+ M = update_message(I, network, env)
91+ normalize!(M)
92+ alg. project_hermitian && (M = project_hermitian!!(M))
93+ return M
94+ end
95+ return BPEnv(messages)
7096 end
71- return BPEnv(messages)
7297end
7398
7499"""
0 commit comments