Safe Haskell | None |
---|---|
Language | Haskell2010 |
This module provides log-domain functionality. Ed Kmett provides, with
log-domain
, a generic way to handle numbers in the log-domain, some which
is used under the hood here. We want some additional type safety and also
connect with the SemiRing
module.
Documentation
class LogDomain x where Source #
Instances for LogDomain x
should be for specific types.
logdom :: MonadError String m => x -> m (Ln x) Source #
Transport a value in x
into the log-domain. logdom
should throw an
exception if log x
is not valid.
unsafelogdom :: x -> Ln x Source #
Unsafely transport x into the log-domain.
Transport a value Ln x
back into the linear domain x
.
sumS :: (Monad m, Ord a, RealFloat a, Show a) => Log a -> Stream m (Log a) -> m (Log a) Source #
This is similar to sum
but requires only one pass over the
data. It will be useful if the first two elements in the stream are large.
If the user has some control over how the stream is generated, this function
might show better performance than sum
and better numeric
stability than 'fold 0 (+)'
TODO this needs to be benchmarked against fold 0 (+)
, since in
DnaProteinAlignment
sumS
seems to be slower!
logsumexpS :: (Monad m, Ord a, Num a, Floating a) => Stream m a -> m a Source #
log-sum-exp
for streams, without incurring examining the stream twice,
but with the potential for numeric problems. In pricinple, the numeric error
of this function should be better than individual binary function
application and worse than an optimized sum
function.
Needs to be written in direct style, as otherwise any constructors (to tell us if we collected two elements already) remain.