def pearl_after_remove_(s, sprime, y, aprime, mprime):
        p = 0.0
        for ua, un, um, us in product(UA.domains.get_all(),
                                      UN.domains.get_all(),
                                      UM.domains.get_all(),
                                      US.domains.get_all()):
            e = Event({
                UA: ua,
                UN: un,
                UM: um,
                US: us,
                A: aprime,
                M: mprime,
                S: sprime
            })
            c = Event({A: aprime, M: mprime, S: sprime})
            ps = event.get_group(tuple(
                e.values()))['prob'].sum() / condition.get_group(
                    tuple(c.values()))['prob'].sum()

            for a, n, m in product(A.domains.get_all(), N.domains.get_all(),
                                   M.domains.get_all()):
                p += cbn.find_prob (Event ({A: a}), Event ({UA: ua})) * \
                  cbn.find_prob (Event ({M: m}), Event ({S: s, A: a, UM: um})) * \
                  cbn.find_prob (Event ({N: n}), Event ({S: s, A: a, UN: un})) * \
                  cbn.find_prob (Event ({Y: y}), Event ({S: s, A: a, N: n, M: m, UY: 1})) * \
                  ps
        return p
 def random_assign(self, event: Event, target: Event, p: float):
     convert(event)
     convert(target)
     groupby_object = self.df.groupby(event.keys())
     name = tuple(event.values())
     if name.__len__() == 1:
         name = name[0]
     try:
         index = groupby_object.get_group(name).index
         target_index = random.sample(list(index),
                                      int(round(index.__len__() * p)))
         col = self.df.columns.get_loc(target.keys()[0])
         self.df.ix[target_index, col] = target.values()[0]
     except KeyError:
         pass
 def get_marginal_prob(self, event: Event):
     convert(event)
     groupby_object = self.df.groupby(event.keys())
     name = tuple(event.values())
     if name.__len__() == 1:
         name = name[0]
     try:
         return groupby_object.get_group(name).__len__()
     except:
         return 0
 def count(self, event: Event, condition: Event, relationship: str):
     convert(event)
     convert(condition)
     groupby_object = self.df.groupby(condition.keys())
     name = tuple(condition.values())
     if name.__len__() == 1:
         name = name[0]
     try:
         group = groupby_object.get_group(name)
         key0 = event.keys()[0]
         key1 = event.keys()[1]
         if relationship == 'equal':
             sub_group = group[group[key0] == group[key1]]
             return sub_group.__len__() / group.__len__()
         else:
             sub_group = group[group[key0] != group[key1]]
             return sub_group.__len__() / group.__len__()
     except:
         return 0