Copyright | [2017] Trevor L. McDonell |
---|---|
License | BSD3 |
Maintainer | Trevor L. McDonell <tmcdonell@cse.unsw.edu.au> |
Stability | experimental |
Portability | non-portable (GHC extensions) |
Safe Haskell | None |
Language | Haskell2010 |
Functions for summing floating point numbers more accurately than the
straightforward sum
operation.
In the worst case, the sum
function accumulates error
at a rate proportional to the number of values being summed. The algorithms
in this module implement different methods of compensated summation, which
reduce the accumulation of numeric error so that it grows much more slowly
than the number of inputs (e.g. logarithmically), or remains constant.
Summation type class
class (Elt a, Elt (s a)) => Summation s a where Source #
A class for the summation of floating-point numbers
add :: Exp (s a) -> Exp (s a) -> Exp (s a) Source #
Add a value to the sum
The identity of the summation
into :: Proxy s -> Exp a -> Exp (s a) Source #
Insert a value into the summation
from :: Proxy s -> Exp (s a) -> Exp a Source #
Summarise the result of summation
sum :: (Summation s a, Shape sh) => Proxy s -> Acc (Array (sh :. Int) a) -> Acc (Array sh a) Source #
Sum an array using a particular compensation scheme.
>>>
let xs = [1.0, 1.0e100, 1.0, -1.0e100] :: [Double]
>>>
Prelude.sum xs
0.0
>>>
let ys = fromList (Z:.4) [1.0, 1.0e100, 1.0, -1.0e100] :: Vector Double
>>>
sum kbn (use ys)
Scalar Z [2.0]
Kahan-Babuška-Neumaier summation
Kahan-Babuška-Neumaier summation. This is a little more computationally costly than plain Kahan summation, but is always at least as accurate.
KBN a a |
Summation KBN Double Source # | |
Summation KBN Float Source # | |
Summation KBN CDouble Source # | |
Summation KBN CFloat Source # | |
Elt a => IsProduct Elt (KBN a) Source # | |
(Lift Exp a, Elt (Plain a)) => Lift Exp (KBN a) Source # | |
Elt a => Unlift Exp (KBN (Exp a)) Source # | |
Show a => Show (KBN a) Source # | |
Elt a => Elt (KBN a) Source # | |
type EltRepr (KBN a) Source # | |
type ProdRepr (KBN a) Source # | |
type Plain (KBN a) Source # | |
Order-2 Kahan-Babuška summation
Second-order Kahan-Babuška summation. This is more computationally costly than Kahan-Babuška-Neumaier summation. Its advantage is that it can lose less precision (in admittedly obscure cases).
This method compensates for error in both the sum and the first-order compensation term, hence the use of "second order" in the name.
KB2 a a a |
Summation KB2 Double Source # | |
Summation KB2 Float Source # | |
Summation KB2 CDouble Source # | |
Summation KB2 CFloat Source # | |
Elt a => IsProduct Elt (KB2 a) Source # | |
(Lift Exp a, Elt (Plain a)) => Lift Exp (KB2 a) Source # | |
Elt a => Unlift Exp (KB2 (Exp a)) Source # | |
Show a => Show (KB2 a) Source # | |
Elt a => Elt (KB2 a) Source # | |
type EltRepr (KB2 a) Source # | |
type ProdRepr (KB2 a) Source # | |
type Plain (KB2 a) Source # | |
Kahan summation
Kahan summation. This is the least accurate of the compensated summation methods. This summation method is included only for completeness.
Kahan a a |
Summation Kahan Double Source # | |
Summation Kahan Float Source # | |
Summation Kahan CDouble Source # | |
Summation Kahan CFloat Source # | |
Elt a => IsProduct Elt (Kahan a) Source # | |
(Lift Exp a, Elt (Plain a)) => Lift Exp (Kahan a) Source # | |
Elt a => Unlift Exp (Kahan (Exp a)) Source # | |
Show a => Show (Kahan a) Source # | |
Elt a => Elt (Kahan a) Source # | |
type EltRepr (Kahan a) Source # | |
type ProdRepr (Kahan a) Source # | |
type Plain (Kahan a) Source # | |