Пример #1
0
table[yes, no, yes] = 0.99
table[yes, no, no] = 0.0001
table[no][:][:] = 1 - table[yes][:][:]
pot[alarm].table = table

pot[radio].variables = np.array([radio, earthquake])
pot[radio].card = np.array([2, 2])
table = np.zeros((2, 2))
table[yes, yes] = 1
table[no, yes] = 0
table[yes, no] = 0
table[no, no] = 1
pot[radio].table = table

#va = potvariables(pot)
jointpot = multpots(pot)
#print("jointpot.variables:", jointpot.variables)
#print("jointpot.card:", jointpot.card)
#print("jointpot.table:", jointpot.table)

#print(jointpot.variables)
DAG = dag(pot) # Generate the DAG adjacency matrix
print("DAG adjacency matrix: \n", DAG)

evidencedpot = setpot(jointpot, alarm, yes)
#FIXME: arbitrary setting
#evidencedpot.variables = evidencedpot.variables[1:]
#print("................................................")
#print("evidencedpot.variables:", evidencedpot.variables)
#print("evidencedpot.table: \n", evidencedpot.table)
Пример #2
0
table[murderer] =0.2
table[notmurderer] =0.8
pot[maid].table = table
#print "maid created at:", pot[maid]

pot[knife].variables=np.array([knife,butler,maid])  # define array below using this variable order
pot[knife].card = np.array([2, 2, 2])
table = np.zeros((2,2,2))
table[used, notmurderer, notmurderer]=0.3
table[used, notmurderer, murderer]   =0.2
table[used, murderer,    notmurderer]=0.6
table[used, murderer,    murderer]   =0.1
pot[knife].table = table
pot[knife].table[notused][:][:]=1-pot[knife].table[used][:][:] # due to normalisation

jointpot = multpots(pot) # joint distribution


DAG = dag(pot) # Generate the DAG adjacency matrix
print "DAG adjacency matrix: \n", DAG

evidencedpot = setpot(jointpot,knife,used)
#FIXME: arbitrary setting
#evidencedpot.variables = evidencedpot.variables[1:]

conditionedpot = condpot(evidencedpot,[butler])
print "conditionedpot.variables:", conditionedpot.variables
print "conditionedpot.card:", conditionedpot.card
print "conditionedpot.table: \n", conditionedpot.table
# jointpot = multpots(pot); % joint distribution
Пример #3
0
table[yes, no, yes] = 0.99
table[yes, no, no] = 0.0001
table[no][:][:] = 1 - table[yes][:][:]
pot[alarm].table = table

pot[radio].variables = np.array([radio, earthquake])
pot[radio].card = np.array([2, 2])
table = np.zeros((2, 2))
table[yes, yes] = 1
table[no, yes] = 0
table[yes, no] = 0
table[no, no] = 1
pot[radio].table = table

#va = potvariables(pot)
jointpot = multpots(pot)
#print "jointpot.variables:", jointpot.variables
#print "jointpot.card:", jointpot.card
#print "jointpot.table:", jointpot.table

#print jointpot.variables
DAG = dag(pot)  # Generate the DAG adjacency matrix
print "DAG adjacency matrix: \n", DAG

evidencedpot = setpot(jointpot, alarm, yes)
#FIXME: arbitrary setting
#evidencedpot.variables = evidencedpot.variables[1:]
#print "................................................"
#print "evidencedpot.variables:", evidencedpot.variables
#print "evidencedpot.table: \n", evidencedpot.table
Пример #4
0
print "maid created at:", pot[maid]

pot[knife].variables = np.array(
    [knife, butler, maid])  # define array below using this variable order
pot[knife].card = np.array([2, 2, 2])
table = np.zeros((2, 2, 2))
table[used, notmurderer, notmurderer] = 0.3
table[used, notmurderer, murderer] = 0.2
table[used, murderer, notmurderer] = 0.6
table[used, murderer, murderer] = 0.1
pot[knife].table = table
pot[knife].table[
    notused][:][:] = 1 - pot[knife].table[used][:][:]  # due to normalisation
print "knife created at:", pot[knife]

jointpot = multpots(pot)  # joint distribution
#FIXME: arbitrary set order and swaped
#jointpot.variables = [0,1,2]
#jointpot.table = np.swapaxes(jointpot.table,0,2)
print "jointpot.variables:", jointpot.variables
print "joint distribution generated as: jointpot \n", jointpot.table

sum = jointpot.table.sum()
print "knife = ", variable[knife].domain[used], "maid = ", variable[
    maid].domain[murderer], "butler = ", variable[butler].domain[murderer]

DAG = dag(pot)  # Generate the DAG adjacency matrix
print "DAG adjacency matrix: \n", DAG

evidencedpot = setpot(jointpot, knife, used)
#FIXME: arbitrary setting