General Machine Learning Formulas
    Intermezzo  - computing Logarithms
    log2(x) = y <=> 2^y = x

    Definition of Entropy

            k
    E = - SUM ( p[i] log2(p[i])
            i=1
    where
             k = possible values enumerated 1,2,...,k
             p[i] = c[i] / n  is the fraction of elements having value [i]
             with c[i] >= 1 the number of i values and
                                        k
                                    n = SUM  c[i]
                                        i=1

def ml_entropy(lst):
    """
    General Machine Learning Formulas
    Intermezzo  - computing Logarithms
    log2(x) = y <=> 2^y = x

    Definition of Entropy

            k
    E = - SUM ( p[i] log2(p[i])
            i=1
    where
             k = possible values enumerated 1,2,...,k
             p[i] = c[i] / n  is the fraction of elements having value [i]
             with c[i] >= 1 the number of i values and
                                        k
                                    n = SUM  c[i]
                                        i=1
                                        
    """
    tot = sum(lst)
    res = 0
    for v in lst:
        if v > 0:
            p = v / tot
            l = math.log( p, 2)
            res += round(p * l, 6)
    res = round(res * -1, 6)
    print('lst = ', lst, 'entropy = ', res)
    return res