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) #print("evidencepot.variables:", evidencedpot.table) conditionedpot = condpot(evidencedpot, burglar) print("p(burglar|alarm=yes)") print("conditionedpot.variables:", conditionedpot.variables) print("conditionedpot.table: \n", conditionedpot.table) # jointpot = multpots(pot); % joint distribution evidencedpot = setpot(jointpot, [alarm, radio], [yes, yes]) conditionedpot = condpot(evidencedpot, burglar)
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 #drawNet(dag(pot),variable); #disp('p(butler|knife=used):') #disptable(condpot(setpot(jointpot,knife,used),butler),variable);
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 #print "evidencepot.variables:", evidencedpot.table conditionedpot = condpot(evidencedpot, burglar) print "p(burglar|alarm=yes)" print "conditionedpot.variables:", conditionedpot.variables print "conditionedpot.table: \n", conditionedpot.table # jointpot = multpots(pot); % joint distribution evidencedpot = setpot(jointpot, [alarm, radio], [yes, yes]) conditionedpot = condpot(evidencedpot, burglar)
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 #evidencedpot.variables = evidencedpot.variables[1:] print "................................................" print "evidencedpot.variables:", evidencedpot.variables print "evidencedpot.table: \n", evidencedpot.table conditionedpot = condpot(evidencedpot, butler) print "conditionedpot.variables:", conditionedpot.variables print "conditionedpot.table: \n", conditionedpot.table # jointpot = multpots(pot); % joint distribution #drawNet(dag(pot),variable); #disp('p(butler|knife=used):') #disptable(condpot(setpot(jointpot,knife,used),butler),variable);