Skip to content

Instantly share code, notes, and snippets.

@stefanv
Created March 27, 2012 06:14
Show Gist options
  • Select an option

  • Save stefanv/2213246 to your computer and use it in GitHub Desktop.

Select an option

Save stefanv/2213246 to your computer and use it in GitHub Desktop.
PGM course: compute P(L1)
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