Exemple #1
0
 def Earthquake(self, sample):
     if sample['Alarm']:
         if sample['Burglary']:
             return probability(0.0020212)
         else:
             return probability(0.36755)
     else:
         if sample['Burglary']:
             return probability(0.0016672)
         else:
             return probability(0.0014222)
Exemple #2
0
 def Burglary(self, sample):
     if sample['Alarm']:
         if sample['Earthquake']:
             return probability(0.00327)
         else:
             return probability(0.485)
     else:
         if sample['Earthquake']:
             return probability(7.05e-05)
         else:
             return probability(6.01e-05)
Exemple #3
0
 def sample(self, event):
     """
     Sample from the distribution for this variable conditioned
     on event's values for parent_variables. That is, return True/False
     at random according with the conditional probability given the
     parents.
     """
     return probability(self.p(True, event))
Exemple #4
0
def markov_blanket_sample(X, e, bn):
    """
    Return a sample from P(X | mb) where mb denotes that the
    variables in the Markov blanket of X take their values from event
    e (which must assign a value to each). The Markov blanket of X is
    X's parents, children, and children's parents.
    """
    Xnode = bn.variable_node(X)
    Q = ProbDist(X)
    for xi in bn.variable_values(X):
        ei = extend(e, X, xi)
        # [Equation 13.12:]
        Q[xi] = Xnode.p(xi, e) * product(
            Yj.p(ei[Yj.variable], ei) for Yj in Xnode.children)
    # (assuming a Boolean variable here)
    return probability(Q.normalize()[True])
Exemple #5
0
 def JongCalls(self, sample):
     if sample['Alarm']:
         return probability(0.9)
     else:
         return probability(0.05)
Exemple #6
0
 def MaryCalls(self, sample):
     if sample['Alarm']:
         return probability(0.7)
     else:
         return probability(0.01)
Exemple #7
0
 def feature_bagging(dataset, p=0.7):
     """Feature bagging with probability p to retain an attribute"""
     inputs = [i for i in dataset.inputs if probability(p)]
     return inputs or dataset.inputs