aima/probability.py
def weighted_sample(bn, e):
    """Sample an event from bn that's consistent with the evidence e;
    return the event and its weight, the likelihood that the event
    accords to the evidence."""
    w = 1
    event = dict(e) # boldface x in Fig. 14.15
    for node in bn.nodes:
        Xi = node.variable
        if Xi in e:
            w *= node.p(e[Xi], event)
        else:
            event[Xi] = node.sample(event)
    return event, w
def weighted_sample(bn, e):
    """Sample an event from bn that's consistent with the evidence e;
    return the event and its weight, the likelihood that the event
    accords to the evidence."""
    w = 1
    event = dict(e) # boldface x in Fig. 14.15
    for node in bn.nodes:
        Xi = node.variable
        if Xi in e:
            w *= node.p(e[Xi], event)
        else:
            event[Xi] = node.sample(event)
    return event, w
def weighted_sample ( bn , e ) : w = 1 event = dict ( e ) # boldface x in Fig. 14.15 for node in bn . nodes : Xi = node . variable if Xi in e : w *= node . p ( e [ Xi ] , event ) else : event [ Xi ] = node . sample ( event ) return event , w
Sample an event from bn that's consistent with the evidence e;
    return the event and its weight, the likelihood that the event
    accords to the evidence.
Sample an event from bn that s consistent with the evidence e ; return the event and its weight the likelihood that the event accords to the evidence .