Esempio n. 1
0
def exact_bayesian():
    '''
    bayesian_inference
    '''
    A = Factor(name='A',
                values=[0, 1],
                cpd=[0.5, 0.5])
    B = Factor(name='B',
                values=[0, 1],
                cpd=[0.5, 0.5])
    C = Factor(name='C|A,B',
                values=[0, 1],
                cond=[A, B],
                cpd=[1, 0, 1, 0, 1, 0, 0, 1])
    print C.query(query=[A], evidence={C: 0, B: 0})
Esempio n. 2
0
def bayesian_inference():
    '''
    bayesian_inference
    '''
    A = Factor(name='A',
                values=[0, 1],
                cpd=[0.6, 0.4])
    B = Factor(name='B',
                values=[0, 1],
                cpd=[0.7, 0.3])
    C = Factor(name='C',
                values=[0, 1],
                cond=[A, B],
                cpd=[0.7, 0.3, 0.9, 0.1, 0.8, 0.2, 0.6, 0.4])
    print C
    print C.joint().marginal(B.var[-1]).reduce(var=C.var[-1], value=0)._norm()
    print C.query([A], {C: 0})
    print C.query([A], [C])