SciBaseTypes-0.1.1.0: Base types and classes for statistics, sciences and humanities
Safe HaskellNone
LanguageHaskell2010

Numeric.LogDomain

Description

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.

Synopsis

Documentation

class LogDomain x where Source #

Instances for LogDomain x should be for specific types.

Associated Types

type Ln x :: * Source #

The type family to connect a type x with the type Ln x in the log-domain.

Methods

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.

lindom :: Ln x -> x Source #

Transport a value Ln x back into the linear domain x.

Instances

Instances details
LogDomain Double Source # 
Instance details

Defined in Numeric.LogDomain

Associated Types

type Ln Double Source #

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.