Skip to content

Commit 2c41d54

Browse files
committed
fix docs
1 parent b14253f commit 2c41d54

File tree

4 files changed

+61
-1
lines changed

4 files changed

+61
-1
lines changed

docs/src/api/public.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@ RescaledArray
4343
TensorNetworkModel
4444
ArtifactProblemSpec
4545
UAIModel
46+
BeliefPropgation
4647
```
4748

4849
## Functions
@@ -56,6 +57,7 @@ marginals
5657
maximum_logp
5758
most_probable_config
5859
probability
60+
belief_propagate
5961
dataset_from_artifact
6062
problem_from_artifact
6163
read_model
@@ -69,4 +71,6 @@ sample
6971
update_evidence!
7072
update_temperature
7173
random_matrix_product_state
74+
random_matrix_product_uai
75+
random_tensor_train_uai
7276
```

docs/src/tensor-networks.md

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -205,6 +205,13 @@ Some of these have been implemented in the
205205
[OMEinsum](https://github.com/under-Peter/OMEinsum.jl) package. Please check
206206
[Performance Tips](@ref) for more details.
207207

208+
## Belief propagation
209+
210+
Belief propagation[^Yedidia2003] is a message passing algorithm that can be used to compute the marginals of a probabilistic graphical model. It has close connections with the tensor networks. It can be viewed as a way to gauge the tensor networks[^Tindall2023], and can be combined with tensor networks to achieve better performance[^Wang2024].
211+
212+
Belief propagation is an approximate method, and the quality of the approximation can be improved by the loop series expansion[^Evenbly2024].
213+
214+
208215
## References
209216

210217
[^Orus2014]:
@@ -227,3 +234,15 @@ Some of these have been implemented in the
227234

228235
[^Liu2023]:
229236
Liu J G, Gao X, Cain M, et al. Computing solution space properties of combinatorial optimization problems via generic tensor networks[J]. SIAM Journal on Scientific Computing, 2023, 45(3): A1239-A1270.
237+
238+
[^Yedidia2003]:
239+
Yedidia, J.S., Freeman, W.T., Weiss, Y., 2003. Understanding belief propagation and its generalizations, in: Exploring Artificial Intelligence in the New Millennium. Morgan Kaufmann Publishers Inc., San Francisco, CA, USA, pp. 239–269.
240+
241+
[^Wang2024]:
242+
Wang, Y., Zhang, Y.E., Pan, F., Zhang, P., 2024. Tensor Network Message Passing. Phys. Rev. Lett. 132, 117401. https://doi.org/10.1103/PhysRevLett.132.117401
243+
244+
[^Tindall2023]:
245+
Tindall, J., Fishman, M.T., 2023. Gauging tensor networks with belief propagation. SciPost Phys. 15, 222. https://doi.org/10.21468/SciPostPhys.15.6.222
246+
247+
[^Evenbly2024]:
248+
Evenbly, G., Pancotti, N., Milsted, A., Gray, J., Chan, G.K.-L., 2024. Loop Series Expansions for Tensor Networks. https://doi.org/10.48550/arXiv.2409.03108

src/belief.jl

Lines changed: 32 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,14 @@
1+
"""
2+
$TYPEDEF
3+
BeliefPropgation(nvars::Int, t2v::AbstractVector{Vector{Int}}, tensors::AbstractVector{AbstractArray{T}}) where T
4+
5+
A belief propagation object.
6+
7+
### Fields
8+
- `t2v::Vector{Vector{Int}}`: a mapping from tensors to variables
9+
- `v2t::Vector{Vector{Int}}`: a mapping from variables to tensors
10+
- `tensors::Vector{AbstractArray{T}}`: the tensors
11+
"""
112
struct BeliefPropgation{T}
213
t2v::Vector{Vector{Int}} # a mapping from tensors to variables
314
v2t::Vector{Vector{Int}} # a mapping from variables to tensors
@@ -16,6 +27,12 @@ function BeliefPropgation(nvars::Int, t2v::AbstractVector{Vector{Int}}, tensors:
1627
end
1728
return BeliefPropgation(t2v, v2t, tensors)
1829
end
30+
31+
"""
32+
$(TYPEDSIGNATURES)
33+
34+
Construct a belief propagation object from a [`UAIModel`](@ref).
35+
"""
1936
function BeliefPropgation(uai::UAIModel{T}) where T
2037
return BeliefPropgation(uai.nvars, [collect(Int, f.vars) for f in uai.factors], AbstractArray{T}[f.vals for f in uai.factors])
2138
end
@@ -83,7 +100,18 @@ function initial_state(bp::BeliefPropgation{T}) where T
83100
return BPState(deepcopy(edges_vectors), edges_vectors)
84101
end
85102

86-
# belief propagation, update the tensors on the edges of the tensor network
103+
"""
104+
$(TYPEDSIGNATURES)
105+
106+
Run the belief propagation algorithm, and return the final state and the information about the convergence.
107+
108+
### Arguments
109+
- `bp::BeliefPropgation`: the belief propagation object
110+
111+
### Keyword Arguments
112+
- `max_iter::Int=100`: the maximum number of iterations
113+
- `tol::Float64=1e-6`: the tolerance for the convergence
114+
"""
87115
function belief_propagate(bp::BeliefPropgation; max_iter::Int=100, tol::Float64=1e-6)
88116
state = initial_state(bp)
89117
info = belief_propagate!(bp, state; max_iter=max_iter, tol=tol)
@@ -112,6 +140,9 @@ function contraction_results(state::BPState{T}) where T
112140
return [sum(reduce((x, y) -> x .* y, mi)) for mi in state.message_in]
113141
end
114142

143+
"""
144+
$(TYPEDSIGNATURES)
145+
"""
115146
function marginals(state::BPState{T}) where T
116147
return Dict([v] => normalize!(reduce((x, y) -> x .* y, mi), 1) for (v, mi) in enumerate(state.message_in))
117148
end

src/utils.jl

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -339,6 +339,12 @@ function random_matrix_product_state(::Type{T}, n::Int, chi::Int, d::Int=2) wher
339339
end
340340
random_matrix_product_state(n::Int, chi::Int, d::Int=2) = random_matrix_product_state(ComplexF64, n, chi, d)
341341

342+
"""
343+
$TYPEDSIGNATURES
344+
345+
Generate a random UAIModel that represents a matrix product state (MPS).
346+
Similar to [`random_matrix_product_state`](@ref), but returns the UAIModel directly.
347+
"""
342348
function random_matrix_product_uai(::Type{T}, n::Int, chi::Int, d::Int=2) where T
343349
# chi ^ (n-1) * (variance^n)^2 == 1/d^n
344350
variance = d^(-1/2) * chi^(-1/2+1/2n)

0 commit comments

Comments
 (0)