Skip to content

Commit 3f43238

Browse files
committed
Reformat Asia example
1 parent 36e4940 commit 3f43238

File tree

1 file changed

+19
-11
lines changed

1 file changed

+19
-11
lines changed

examples/asia/main.jl

Lines changed: 19 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -40,14 +40,17 @@
4040
# We now demonstrate how to use the TensorInference.jl package for conducting a
4141
# variety of inference tasks on the Asia network.
4242

43+
# ---
44+
4345
# Import the TensorInference package, which provides the functionality needed
4446
# for working with tensor networks and probabilistic graphical models.
4547
using TensorInference
4648

4749
# ---
4850

49-
# Load the ASIA network model from the `asia.uai` file located in the examples directory.
50-
# See [Model file format (.uai)](@ref) for a description of the format of this file.
51+
# Load the ASIA network model from the `asia.uai` file located in the examples
52+
# directory. See [Model file format (.uai)](@ref) for a description of the
53+
# format of this file.
5154
instance = read_instance(pkgdir(TensorInference, "examples", "asia", "asia.uai"))
5255

5356
# ---
@@ -73,11 +76,12 @@ get_vars(tn)
7376
# ---
7477

7578
# Set an evidence: Assume that the "X-ray" result (variable 7) is positive.
76-
set_evidence!(instance, 7=>0)
79+
set_evidence!(instance, 7 => 0)
7780

7881
# ---
7982

80-
# Since setting an evidence may affect the contraction order of the tensor network, recompute it.
83+
# Since setting an evidence may affect the contraction order of the tensor
84+
# network, recompute it.
8185
tn = TensorNetworkModel(instance)
8286

8387
# ---
@@ -87,20 +91,23 @@ maximum_logp(tn)
8791

8892
# ---
8993

90-
# Generate 10 samples from the probability distribution represented by the model.
94+
# Generate 10 samples from the probability distribution represented by the
95+
# model.
9196
sample(tn, 10)
9297

9398
# ---
9499

95-
# Retrieve not only the maximum log-probability but also the most probable configuration.
96-
# In this configuration, the most likely outcomes are that the patient smokes (variable 3) and has lung cancer (variable 4).
100+
# Retrieve both the maximum log-probability and the most probable
101+
# configuration. In this configuration, the most likely outcomes are that the
102+
# patient smokes (variable 3) and has lung cancer (variable 4).
97103
logp, cfg = most_probable_config(tn)
98104

99105
# ---
100106

101-
# Compute the most probable values of certain variables (e.g., 4 and 7) while marginalizing over others.
102-
# This is known as Maximum a Posteriori (MAP) estimation.
103-
mmap = MMAPModel(instance; queryvars=[4,7])
107+
# Compute the most probable values of certain variables (e.g., 4 and 7) while
108+
# marginalizing over others. This is known as Maximum a Posteriori (MAP)
109+
# estimation.
110+
mmap = MMAPModel(instance; queryvars = [4, 7])
104111

105112
# ---
106113

@@ -109,7 +116,8 @@ most_probable_config(mmap)
109116

110117
# ---
111118

112-
# Compute the total log-probability of having lung cancer. The results suggest that the probability is roughly half.
119+
# Compute the total log-probability of having lung cancer. The results suggest
120+
# that the probability is roughly half.
113121
log_probability(mmap, [1, 0]), log_probability(mmap, [0, 0])
114122

115123
# [^lauritzen1988local]:

0 commit comments

Comments
 (0)