Skip to content

Commit e2a235b

Browse files
committed
fix-62-69
1 parent b9797d4 commit e2a235b

File tree

3 files changed

+16
-10
lines changed

3 files changed

+16
-10
lines changed

docs/src/tensornetwork.md

Whitespace-only changes.

examples/asia/main.jl

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -60,8 +60,9 @@ tn = TensorNetworkModel(model)
6060

6161
# ---
6262

63-
# Calculate the ``\log_{10}`` partition function
64-
probability(tn) |> first |> log10
63+
# Calculate the partition function.
64+
# Since the factors in this model is normalized, the partition function is the same as total probability, $1$.
65+
probability(tn) |> first
6566

6667
# ---
6768

examples/hard-core-lattice-gas/main.jl

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -26,19 +26,23 @@ using GenericTensorNetworks.Graphs: edges, nv
2626
graph = unit_disk_graph(vec(sites), blockade_radius)
2727
show_graph(graph; locs=sites, texts=fill("", length(sites)))
2828

29-
# These constraints defines a independent set problem that characterized by the following energy based model.
30-
# Let $G = (V, E)$ be a graph, where $V$ is the set of vertices and $E$ be the set of edges. The energy model for the hard-core lattice gas problem is
29+
# These constraints defines an independent set problem that characterized by the following energy based model.
30+
# Let $G = (V, E)$ be a graph, where $V$ is the set of vertices and $E$ is the set of edges.
31+
# The energy model for the hard-core lattice gas problem is
3132
# ```math
32-
# E(\mathbf{n}) = -\sum_{i \in V}w_i n_i + \infty \sum_{(i, j) \in E} n_i n_j
33+
# E(\mathbf{n}) = -\sum_{i \in V}w_i n_i + U \sum_{(i, j) \in E} n_i n_j
3334
# ```
3435
# where $n_i \in \{0, 1\}$ is the number of particles at site $i$, and $w_i$ is the weight associated with it. For unweighted graphs, the weights are uniform.
35-
# The solution space hard-core lattice gas is equivalent to that of an independent set problem. The independent set problem involves finding a set of vertices in a graph such that no two vertices in the set are adjacent (i.e., there is no edge connecting them).
36+
# $U$ is the repulsive interaction strength between two particles.
37+
# To represent the independence constraint, we let $U = \infty$, i.e. coexitence of two particles at two sites connected by an edge is completely forbidden.
38+
# The solution space hard-core lattice gas is equivalent to that of an independent set problem.
39+
# The independent set problem involves finding a set of vertices in a graph such that no two vertices in the set are adjacent (i.e., there is no edge connecting them).
3640
# One can create a tensor network based modeling of an independent set problem with package [`GenericTensorNetworks.jl`](https://github.com/QuEraComputing/GenericTensorNetworks.jl).
3741
using GenericTensorNetworks
3842
problem = IndependentSet(graph; optimizer=GreedyMethod());
3943

40-
# There has been a lot of discussions related to solution space properties in the `GenericTensorNetworks` [documentaion page](https://queracomputing.github.io/GenericTensorNetworks.jl/dev/generated/IndependentSet/).
41-
# In this example, we show how to use `TensorInference` to use probabilistic inference for understand the finite temperature properties of this statistic physics model.
44+
# There are plenty of discussions related to solution space properties in the `GenericTensorNetworks` [documentaion page](https://queracomputing.github.io/GenericTensorNetworks.jl/dev/generated/IndependentSet/).
45+
# In this example, we show how to use `TensorInference` to use probabilistic inference for understand the finite temperature properties of this statistical model.
4246
# We use [`TensorNetworkModel`](@ref) to convert a combinatorial optimization problem to a probabilistic model.
4347
# Here, we let the inverse temperature be $\beta = 3$.
4448

@@ -62,7 +66,8 @@ pmodel2 = TensorNetworkModel(problem, β; mars=[[e.src, e.dst] for e in edges(gr
6266
mars = marginals(pmodel2);
6367

6468
# We show the probability that both sites on an edge are not occupied
65-
show_graph(graph; locs=sites, edge_colors=[(b = mars[[e.src, e.dst]][1, 1]; (1-b, 1-b, 1-b)) for e in edges(graph)], texts=fill("", nv(graph)), edge_line_width=5)
69+
show_graph(graph; locs=sites, edge_colors=[(b = mars[[e.src, e.dst]][1, 1]; (1-b, 1-b, 1-b)) for e in edges(graph)], texts=fill("", nv(graph)),
70+
edge_line_widths=edge_colors=[8*mars[[e.src, e.dst]][1, 1] for e in edges(graph)])
6671

6772
# ## The most likely configuration
6873
# The MAP and MMAP can be used to get the most likely configuration given an evidence.
@@ -90,5 +95,5 @@ sum(config2)
9095
# One can ue [`sample`](@ref) to generate samples from hard-core lattice gas at finite temperature.
9196
# The return value is a matrix, with the columns correspond to different samples.
9297
configs = sample(pmodel3, 1000)
93-
sizes = sum(configs; dims=1)
98+
sizes = sum.(configs)
9499
[count(==(i), sizes) for i=0:34] # counting sizes

0 commit comments

Comments
 (0)