Variable Elimination is a powerful inference algorithm used in probabilistic graphical models, such as Bayesian networks, to perform exact inference. It's particularly useful when dealing with large networks, as it can reduce the complexity of the problem by eliminating variables that are irrelevant to the query. Let's delve into the workings of Variable Elimination with an illustrative example.

Consider a simple Bayesian network with three binary variables: A, B, and C. The network structure is as follows: A → B → C. The conditional probability distributions (CPDs) are given by P(A) = 0.6, P(B|A) = 0.7 if A=true, 0.3 if A=false, and P(C|B) = 0.8 if B=true, 0.2 if B=false. We want to compute P(C=true|A=true).

Variable Elimination Process
Variable Elimination follows a systematic approach to eliminate variables one by one, starting from the variables that are not in the query (here, B) and ending with the variables in the query (here, C).

The algorithm proceeds as follows: First, it eliminates B, then it eliminates A, and finally, it computes P(C=true|A=true).
Eliminating B

To eliminate B, we need to marginalize it out from the joint distribution P(A, B, C). We can do this by summing out B's possible values:
P(C, A) = ∑_B P(A, B, C) = P(A) * (P(B=true|A) * P(C=true|B=true) + P(B=false|A) * P(C=true|B=false))
Eliminating A

Now that we have P(C, A), we can eliminate A by summing out its possible values:
P(C) = ∑_A P(C, A) = P(A=true) * P(C=true|A=true) + P(A=false) * P(C=true|A=false)
Finally, we can compute P(C=true|A=true) by normalizing P(C) with respect to C=true:

P(C=true|A=true) = P(C=true, A=true) / P(C=true)
Variable Elimination with Evidence










![[65] Beta-Elimination](https://i.pinimg.com/originals/8e/3a/f3/8e3af3c561ad991fb44e60e3b0e6bf09.jpg)








So far, we've considered unconstrained inference. Now let's see how Variable Elimination handles evidence. Suppose we observe B=true. We want to compute P(C=true|B=true, A=true).
In this case, we start by eliminating A, then eliminate B (since it's observed), and finally compute P(C=true|B=true, A=true).
Eliminating A
With the evidence B=true, we can eliminate A using the same approach as before, but this time we only consider the case where B=true:
P(C, B=true) = ∑_A P(A, B=true, C) = P(A=true) * P(B=true|A=true) * P(C=true|B=true) + P(A=false) * P(B=true|A=false) * P(C=true|B=true)
Eliminating B
Since B is observed, we can directly compute P(C=true|B=true, A=true) as:
P(C=true|B=true, A=true) = P(C=true, B=true, A=true) / P(B=true, A=true)
In conclusion, Variable Elimination is a versatile algorithm that can handle both unconstrained and constrained inference in probabilistic graphical models. By eliminating variables systematically, it can reduce the complexity of the inference problem, making it practical to use even with large networks. However, the efficiency of the algorithm depends on the structure of the network and the choice of elimination order. Therefore, finding an optimal elimination order is an active area of research in the field of probabilistic graphical models.