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...