Application5


Below is the summary of the simulation performed on 5 samples (each containing 4 numbers) and the subroutines used to compute the mean values.





def kahansum(input):
    summ = c = 0
    for num in input:
        y = num - c
        t = summ + y
        c = (t - summ) - y
        summ = t
    return summ

def neumaiersum(input):
    sum = input[0]
    c = 0.0
    for i in range(1, len(input)):
        t = sum + input[i]
        if abs(sum) > abs(input[i]):
            c += (sum - t) + input[i]
        else:
            c += (input[i] - t) + sum
        sum = t
    return sum + c

def knuth_mean(input):
    mean = 0
    m = 1
    for n in input:
        d = n - mean
        tot = m
        mean += d / tot
        m += 1
    return mean

Commenti

Post popolari in questo blog

Welford Algorithm

Research 6 - Derivation of Chebyshev's inequality and its application to prove the (weak) LLN

Research 7 -- Central Limit Theorem, LLN, and most common probability distributions