def mh_similarity(sample1, sample2):
    """
    Calculates the Marista-Horn similarity for two samples.

    .. note:

        sample1 and sample2 should be the same length, and
        the sum of each sample should be greater than 0.

    Args:

        sample1: list of frequencies for sample 1
        sample2: list of frequencies for sample 2

    Returns:

        float: Marista-Horn similarity (between 0 and 1)
    """
    X = sum(sample1)
    Y = sum(sample2)
    XY = X * Y
    sumXiYi = 0
    sumXiSq = 0
    sumYiSq = 0
    for x, y in zip(sample1, sample2):
        sumXiYi += x * y
        sumXiSq += x * x
        sumYiSq += y * y
    num = 2 * sumXiYi
    denom = (float(sumXiSq) / (X * X) + float(sumYiSq) / (Y * Y)) * XY
    return 1.0 * num / denom
