def calc_easy_bts_binary(responses, meta_true): """Calculate easiest binary version of bts using own answers and predicted percentage of ppl endorsing true Args: responses: list where elt is 0 if subject said false and 1 if subject said true. meta_true: list where elt is subject's prediction of fraction of ppl endorsing true. Returns: dict where each field (bts, surprise, accuracy) points to an np.array with an elt for each subject. """ assert len(responses) == len(meta_true) do_assert = True xbar_true = jmutils.mean(responses) xbar_true = jmutils.bound(xbar_true, 0.01, 0.99) xbar = [1 - xbar_true, xbar_true] meta_true_trimmed = [jmutils.bound(mt, 0.01, 0.99) for mt in meta_true] meta_false = [1 - et for et in meta_true_trimmed] log_ybar = [jmutils.log_geo_mean(meta_false), jmutils.log_geo_mean(meta_true_trimmed)] #if (xbar_true != jmutils.mean(responses)) or (len(responses) == 1): # do_assert = False easy_bts = calc_generic_bts(xbar, log_ybar, responses, zip(meta_false, meta_true_trimmed)) return easy_bts
def calc_log_ybar(predictions): """Calculate log(ybar) given meta predictions. Args: predictions: list where each sublist gives the predictions for a subject of the fraction of ppl endorsing each constructed answer. Returns: list where each element is log geometric mean of predictions about each answer. """ num_answers = len(predictions[0]) log_ybar = [0] * num_answers for k in range(num_answers): ans_predictions = [s[k] for s in predictions] if ans_predictions.count(0) > 0: print "got a zero" log_ybar[k] = jmutils.log_geo_mean(ans_predictions) #log geo mean is mean of logs. return log_ybar