def _compare_cat_hist(b1, b2, h1, h2):
    """
    Compare two categorical histograms and return a overlap score based on RMSE
    b1 bin edges of hist 1
    b2 bin edges of hist 2
    h1 histogram values of hist 1
    h2 histogram values of hist 2

    Return rmse-based overlap score
    """
    cbe = list(set(b1) | set(b2))

    total = len(cbe)
    rmse = 0.0

    if sum(h1) == 0 or sum(h2) == 0:
        return 0.0

    for index in range(total):
        sh1 = 0.0
        sh2 = 0.0
        try:
            sh1 = float(h1[b1.index(cbe[index])])
        except Exception as e:
            sh1 = 0.0
        try:
            sh2 = float(h2[b2.index(cbe[index])])
        except Exception as e:
            sh2 = 0.0

        sh1 = sh1 / sum(h1)
        sh2 = sh2 / sum(h2)
        rmse += ((sh1 - sh2) ** 2)

    rmse = (rmse) ** 0.5
    print("Cat: rmse score: {}".format(rmse))
    return rmse