import math


def sample_entropy(rate_list):
    """Calculates the sample entropy of a time_series."""
    S = len(rate_list)
    rate_set = set(rate_list)
    HX = 0
    for i in rate_set:
        ni = rate_list.count(i)
        HX += (ni / S) * (math.log(ni / S, 2))
    return -HX