def tally_mistrust(explainer, exps, predict_probas, untrustworthy):
  trust_fn = lambda prev, curr: (prev > 0.5 and curr > 0.5) or (prev <= 0.5 and curr <= 0.5)
  trust_fn_all = lambda exp, unt: len([x[0] for x in exp if x[0] in unt]) == 0
  mistrust = 0
  for i in range(len(exps)):
    if explainer in ['lime', 'parzen']:
      exp, mean = exps[i]
      if explainer == 'lime':
        prev_tot = sum([x[1] for x in exp]) + mean
      elif explainer == 'parzen':
        prev_tot = mean
      tot = prev_tot - sum([x[1] for x in exp if x[0] in untrustworthy])
      if not trust_fn(tot, prev_tot):
        mistrust += 1
    else:
      exp = exps[i]
      if not trust_fn_all(exp, untrustworthy):
        mistrust += 1
  return mistrust
dataset/ETHPy150Open marcotcr/lime-experiments/compare_classifiers.py/tally_mistrust/original