Skip to content

Instantly share code, notes, and snippets.

@mkowoods
Created May 16, 2015 00:48
Show Gist options
  • Save mkowoods/a79db5bf1dc6f470320b to your computer and use it in GitHub Desktop.
Save mkowoods/a79db5bf1dc6f470320b to your computer and use it in GitHub Desktop.
Bayesian Network Analysis
#-------------------------------------------------------------------------------
# Name: module1
# Purpose:
#
# Author: mwoods
#
# Created: 15/05/2015
# Copyright: (c) mwoods 2015
# Licence: <your licence>
#-------------------------------------------------------------------------------
#Quick Marginal Probability Calculation
#How weather on day 1 vs day effect ice cream eating on day 1 and 2
# W1 -> W2 -> i2
# |
# v
# i1
W1 = {'s': 0.6, 'r' : 0.4}
W2_W1 = {('r', 's') : 0.3, ('s', 's') : 0.7, ('s', 'r') : 0.5, ('r', 'r') : 0.5}
I_W = {('t','s') : 0.9, ( 'f', 's') : 0.1, ('t', 'r') : 0.2, ('f', 'r'): 0.8}
joint_distribution = {}
for w1, p_w1 in W1.items():
for w2_w1, p_w2_w1 in W2_W1.items():
for i1_w1, p_i1_w1 in I_W.items():
for i2_w2, p_i2_w2 in I_W.items():
if w2_w1[1] == w1 and i1_w1[1] == w1 and w2_w1[1] == w1 and i2_w2[1] == w2_w1[0]:
#print w1, i1_w1[0], w2_w1[0], i2_w2[0], p_w1*p_w2_w1*p_i1_w1*p_i2_w2
joint_distribution[(w1, i1_w1[0], w2_w1[0], i2_w2[0])] = p_w1*p_w2_w1*p_i1_w1*p_i2_w2
def query(marginal, conditions, cols):
pass
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment