def get_gauge_prob(bayes_net, gauge_hot):
    """Calculate the marginal
    probability of the gauge 
    showing hot (T/F) in the 
    power plant system."""
    # TOOD: finish this function
    G_node = bayes_net.get_node_by_name('gauge')
    engine = JunctionTreeEngine(bayes_net)
    Q = engine.marginal(G_node)[0]
    index = Q.generate_index([True],range(Q.nDims))
    gauge_prob = Q[index]
    return gauge_prob
def get_alarm_prob(bayes_net, alarm_rings):
    """Calculate the marginal 
    probability of the alarm 
    ringing (T/F) in the 
    power plant system."""
    # TODO: finish this function
    A_node = bayes_net.get_node_by_name('alarm')
    engine = JunctionTreeEngine(bayes_net)
    Q = engine.marginal(A_node)[0]
    index = Q.generate_index([True],range(Q.nDims))
    alarm_prob = Q[index]
    return alarm_prob
def get_temperature_prob(bayes_net,temp_hot):
    """Calculate theprobability of the 
    temperature being hot (T/F) in the
    power plant system, given that the
    alarm sounds and neither the gauge
    nor alarm is faulty."""
    # TODO: finish this function
    A_node = bayes_net.get_node_by_name('alarm')
    F_A_node = bayes_net.get_node_by_name('faulty alarm')
    F_G_node = bayes_net.get_node_by_name('faulty gauge')
    T_node = bayes_net.get_node_by_name('temperature')
    engine = JunctionTreeEngine(bayes_net)
    engine.evidence[A_node] = True
    engine.evidence[F_A_node] = False
    engine.evidence[F_G_node] = False
    Q = engine.marginal(T_node)[0]
    index = Q.generate_index([True],range(Q.nDims))
    temp_prob = Q[index]
    return temp_prob
Esempio n. 4
0
def get_ghost_prob(bayes_net):
    """Calculate theprobability of the
    temperature being hot (T/F) in the
    power plant system, given that the
    alarm sounds and neither the gauge
    nor alarm is faulty."""
    # TODO: finish this function
    A1 = bayes_net.get_node_by_name('alarm 1')
    A2 = bayes_net.get_node_by_name('alarm 2')
    G = bayes_net.get_node_by_name('ghost')

    engine = JunctionTreeEngine(bayes_net)
    engine.evidence[A2] = True
    engine.evidence[A1] = True
    Q = engine.marginal(G)[0]
    index = Q.generate_index([True],range(Q.nDims))
    temp_prob = Q[index]

    engine2 = EnumerationEngine(bayes_net)
    engine2.evidence[A2] = True # A won against B
    engine2.evidence[A1] = True # A won against B

    Q = engine.marginal(G)[0]
    posterior = Q.table
    print "Or:" , posterior.tolist()
    return temp_prob
Esempio n. 5
0
def get_temperature_prob(bayes_net,temp_hot):
    """Calculate the probability of the temperature being hot (T/F) in the power plant system, given that the
      alarm sounds and neither the gauge nor alarm is faulty."""
    # TODO: finish this function
    T_node = bayes_net.get_node_by_name('temperature')
    F_A_node = bayes_net.get_node_by_name('faulty alarm')
    F_G_node = bayes_net.get_node_by_name('faulty gauge')
    A_node = bayes_net.get_node_by_name('alarm')
    engine = JunctionTreeEngine(bayes_net)
    engine.evidence[A_node] = True # alarm sounds
    engine.evidence[F_A_node] = False # alarm is NOT faulty
    engine.evidence[F_G_node] = False # gauge is NOT faulty
    Q = engine.marginal(T_node)[0]
    index = Q.generate_index([temp_hot],range(Q.nDims))
    prob = Q[index]
    return prob
Esempio n. 6
0
def get_temperature_prob(bayes_net, temp_hot):
    """Calculate the conditional probability 
    of the temperature being hot (T/F) in the
    power plant system, given that the
    alarm sounds and neither the gauge
    nor alarm is faulty."""
    # TODO: finish this function
    # raise NotImplementedError
    A_node = bayes_net.get_node_by_name("alarm")
    F_A_node = bayes_net.get_node_by_name("faulty alarm")
    F_G_node = bayes_net.get_node_by_name("faulty gauge")
    T_node = bayes_net.get_node_by_name("temperature")
    engine = JunctionTreeEngine(bayes_net)
    engine.evidence[A_node] = True
    engine.evidence[F_G_node] = False
    engine.evidence[F_A_node] = False
    Q = engine.marginal(T_node)[0]
    index = Q.generate_index([temp_hot], range(Q.nDims))
    temp_prob = Q[index]
    return temp_prob
Esempio n. 7
0
def get_temperature_prob(bayes_net, temp_hot):
    """Calculate theprobability of the temperature being hot (T/F) in the power plant system, given that the alarm sounds and neither the gauge nor alarm is faulty."""
    engine = JunctionTreeEngine(bayes_net)
    G_node = bayes_net.get_node_by_name('gauge')
    F_G_node = bayes_net.get_node_by_name('faulty gauge')
    T_node = bayes_net.get_node_by_name('temperature')
    A_node = bayes_net.get_node_by_name('alarm')
    F_A_node = bayes_net.get_node_by_name('faulty alarm')
    # True of False
    temp_hot = temp_hot
    engine.evidence[F_A_node] = False
    engine.evidence[F_G_node] = False
    engine.evidence[A_node] = True
    Q = engine.marginal(T_node)[0]
    index = Q.generate_index([False], range(Q.nDims))
    temp_prob_false = Q[index]
    temp_prob_true = float(1 - Q[index])
    temp_prob = temp_prob_true
    print "The probability of temperature=true (hot) given,"
    print "F_A = false, F_G = false, and alarm sounds"
    print "temp_prob:  ", temp_prob
    # the probability that the temperature is actually hot, given that the alarm sounds and the alarm and gauge are both working
    return temp_prob