Kahan#
The kahan package provides efficient implementations of Kahan’s algorithms for numerical summation and other basic statistical calculations. These algorithms are designed to reduce the loss of precision that can occur when adding a large number of floating-point values.
For more information on Kahan’s algorithms and their implementation in the kahan package, please see the package documentation.
References:
Kahan, W. (1965). Pracniques: Further remarks on reducing truncation errors. Communications of the ACM, 8(1), 40-41.
Summary#
Cumulative mean. |
|
|
Cumulative sum. |
Cumulative mean and variance. |
|
|
Return the mean of iterable `a'. |
|
Return the sum of iterable `a'. |
Functions#
- kahan.cummean(a)#
Cumulative mean.
Return an iterator over yielding cumulative means of an input sequence
Parameters#
- aiterable
Input sequence
Returns#
- iterator
An iterator that yields cumulative means.
Examples#
>>> list(cummean([1, 2, 3, 4])) [1.0, 1.5, 2.0, 2.5]
- kahan.cumsum(a)#
Cumulative sum.
Return an iterator over yielding cumulative sums of an input sequence
Parameters#
- aiterable
Input sequence
Returns#
- iterator
An iterator that yields cumulative sums.
Examples#
>>> list(cumsum([1, 2, 3, 4])) [1.0, 3.0, 6.0, 10.0]
- kahan.cumvariance(a)#
Cumulative mean and variance.
Return an iterator over yielding pairs of cumulative mean and cumulative variance of an input sequence
Parameters#
- aiterable
Input sequence
Returns#
- iterator
An iterator that yields pairs of cumulative mean and cumulative variance.
Examples#
>>> list(cumvariance([1, 7, 4])) [(1.0, 0.0), (4.0, 9.0), (4.0, 6.0)]