Created
March 27, 2012 06:14
-
-
Save stefanv/2213246 to your computer and use it in GitHub Desktop.
PGM course: compute P(L1)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import numpy as np | |
| P_D = np.array([0.6, 0.4]) | |
| P_I = np.array([0.7, 0.3]) | |
| P_G_ID = np.array([ | |
| [[0.3, 0.05], | |
| [0.9, 0.5]], | |
| [[0.4, 0.25], | |
| [0.08, 0.3]], | |
| [[0.3, 0.7], | |
| [0.02, 0.2]] | |
| ]) | |
| P_L_G = np.array( | |
| [[0.1, 0.4, 0.99], | |
| [0.9, 0.6, 0.01]] | |
| ) | |
| P_ID = P_I[..., None] * P_D | |
| P_GID = P_G_ID * P_ID | |
| P_G = np.sum(P_GID, axis=(-1, -2)) | |
| P_LG = P_L_G * P_G | |
| # Marginalize the joint distribution over G | |
| # where L=1. | |
| # | |
| # P(L1) ~= 0.502336 | |
| print P_LG[1, :].sum() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment