Esempio n. 1
0
  def influence_from_state(self, bdeltas, bcounts, gdeltas, gcounts, c=None):
    if c is None:
        c = self.c
    binf = compute_bad_score(bdeltas, bcounts, c)
    ginfs = [gdelta for gdelta,gcount in zip(gdeltas, gcounts) if gcount]
    ginf = ginfs and max(ginfs) or 0
    ret = self.l * binf - (1. - self.l) * ginf

    return ret
Esempio n. 2
0
  def influences(self, rule, cs=[]):
    """
    compute influences for a list of c values
    """
    bdeltas, bcounts, gdeltas, gcounts = self.influence_state(rule)
    ginfs = [gdelta for gdelta,gcount in zip(gdeltas, gcounts) if gcount]
    
    ret = []
    for c in cs:
      binf = compute_bad_score(bdeltas, bcounts, c)
      ginf = ginfs and max(ginfs) or 0
      res = self.l * binf - (1. - self.l) * ginf

      ret.append(res)
    return ret
Esempio n. 3
0
    def create_inf_func(self, l):
      if self.inf_state is None:
        raise Exception("inf_state is None, cant' create inf_func")

      inf_state = self.inf_state
      vs = [gv for gv, gc in zip(inf_state[2], inf_state[3]) if gc]
      if vs:
        maxg = max(vs)
      else:
        maxg = 0
      bds, bcs = [], []
      for idx in xrange(len(inf_state[0])):
        bd, bc = inf_state[0][idx], inf_state[1][idx]
        if valid_number(bd) and valid_number(bc):
          bds.append(bd)
          bcs.append(bc)
      f = lambda c: l*compute_bad_score(bds, bcs, c) - (1.-l)*maxg
      return f