def compute_fraction_top_names(test, test_pis, top=10, bottom=10):
    # Use the average pi to compute the predicted top 10 names
    test_pi_mean = np.mean(test_pis, axis=0)

    # Sort names in decreasing order of predicted probability
    pred_perm = np.argsort(-test_pi_mean, axis=1)
    data_perm = np.argsort(-test.data, axis=1)

    # Compute number of top names predicted per year (averaged over states)
    top_scores = np.array([len(np.intersect1d(pp[:top],dp[:top]))
                           for pp,dp in zip(pred_perm, data_perm)])

    bottom_scores = np.array([len(np.intersect1d(pp[-bottom:],dp[-bottom:]))
                              for pp,dp in zip(pred_perm, data_perm)])

    results = np.zeros((len(np.unique(test.years)), 4))
    for i,yr in enumerate(sorted(np.unique(test.years))):
        results[i,0] = top_scores[test.years==yr].mean(0)
        results[i,1] = top_scores[test.years==yr].std(0)

        results[i,2] = bottom_scores[test.years==yr].mean(0)
        results[i,3] = bottom_scores[test.years==yr].std(0)

        print("Top: %d:  %.2f +- %.2f" % (yr, results[i,0], results[i,1]))
        print("Bot: %d:  %.2f +- %.2f" % (yr, results[i,2], results[i,3]))

    return results


##############
#  plotting  #
##############
dataset/ETHPy150Open HIPS/pgmult/experiments/census_gp.py/compute_fraction_top_names/original