Book Image

Mastering Probabilistic Graphical Models with Python

By : Ankur Ankan
Book Image

Mastering Probabilistic Graphical Models with Python

By: Ankur Ankan

Overview of this book

Table of Contents (14 chapters)
Mastering Probabilistic Graphical Models Using Python
Credits
About the Authors
About the Reviewers
www.PacktPub.com
Preface
Index

Finding the most probable assignment


In the previous section, we computed the maximum unnormalized probability value, but for MAP, we need to compute the states of the variables corresponding to the one in which this value occurs. Taking our earlier example of the network A B, we first computed , but the state of the variable B for which P(b|a) gives the maximum value also depends on the state of the variable A. So, we will first need to compute and then compute the state of B accordingly. So, from the CPDs of the network, we can see that . Now we will look for , which gives us . Hence, we get the maximum values corresponding to and .

Also, the computational cost of this operation is not high, as we are simply doing another pass over the factors that have already been computed. Hence, the cost would be linear in the number of variables in the network.

Now, let's continue the previous code example and do some map queries over the networks using pgmpy:

In [20]: model_inference.map_query...