Copyright | (c) Justin Le 2016 |
---|---|
License | BSD3 |
Maintainer | justin@jle.im |
Stability | experimental |
Portability | non-portable |
Safe Haskell | Safe-Inferred |
Language | Haskell2010 |
Provides an interface for computing and propagating uncertainty by using Monte Carlo simulations. These may be more accurate than the normal propagators if the third-order taylor series expansion terms are non-negligible.
Basically simulates sampling from the distribution represented by the given
Uncert
s, applying the function of interest, and aggregating the mean
and standard deviation of the results. x
is treated as
a random variable whose probability density is the normal distribution
with mean +/-
dxx
and standard deviation dx
.
This module attempts to duplicate the API offered by Numeric.Uncertain and is meant to be imported qualified alongside Numeric.Uncertain
import Numeric.Uncertain import qualified Numeric.Uncertain.MonteCarlo as MC
Actions are parameterized over all PrimMonad
instances, so can be run
under both ST
and IO
, making it suitable for exploratory purposes.
All functions require a Gen
from System.Random.MWC for random value
generation purposes.
ghci> import qualified Numeric.Uncertain.MonteCarlo as MC ghci> import System.Random.MWC ghci> let x = 1.52+/-
0.07 ghci> let y = 781.4 +/- 0.3 ghci> let z = 1.53e-1 `withPrecision'
3 ghci> g <-create
ghci> cosh x 2.4 +/- 0.2 ghci> MC.liftU cosh x g 2.4 +/- 0.2 ghci> exp x / z * sin (y ** z) 10.9 +/- 0.9 ghci> MC.liftU3 (\a b c -> exp a / c * sin (b**c)) x y z g 10.8 +/- 1.0 ghci> pi + 3 * logBase x y 52 +/- 5 ghci> MC.liftU2 (\a b -> pi + 3 * logBase a b) x y g 51 +/- 5
Synopsis
- sampleUncert :: PrimMonad m => Uncert Double -> Gen (PrimState m) -> m Double
- liftU :: PrimMonad m => (Double -> Double) -> Uncert Double -> Gen (PrimState m) -> m (Uncert Double)
- liftU2 :: PrimMonad m => (Double -> Double -> Double) -> Uncert Double -> Uncert Double -> Gen (PrimState m) -> m (Uncert Double)
- liftU3 :: PrimMonad m => (Double -> Double -> Double -> Double) -> Uncert Double -> Uncert Double -> Uncert Double -> Gen (PrimState m) -> m (Uncert Double)
- liftU4 :: (PrimMonad m, Applicative m) => (Double -> Double -> Double -> Double -> Double) -> Uncert Double -> Uncert Double -> Uncert Double -> Uncert Double -> Gen (PrimState m) -> m (Uncert Double)
- liftU5 :: PrimMonad m => (Double -> Double -> Double -> Double -> Double -> Double) -> Uncert Double -> Uncert Double -> Uncert Double -> Uncert Double -> Uncert Double -> Gen (PrimState m) -> m (Uncert Double)
- liftUF :: (Traversable f, PrimMonad m) => (f Double -> Double) -> f (Uncert Double) -> Gen (PrimState m) -> m (Uncert Double)
- liftU' :: PrimMonad m => Int -> (Double -> Double) -> Uncert Double -> Gen (PrimState m) -> m (Uncert Double)
- liftU2' :: PrimMonad m => Int -> (Double -> Double -> Double) -> Uncert Double -> Uncert Double -> Gen (PrimState m) -> m (Uncert Double)
- liftU3' :: PrimMonad m => Int -> (Double -> Double -> Double -> Double) -> Uncert Double -> Uncert Double -> Uncert Double -> Gen (PrimState m) -> m (Uncert Double)
- liftU4' :: PrimMonad m => Int -> (Double -> Double -> Double -> Double -> Double) -> Uncert Double -> Uncert Double -> Uncert Double -> Uncert Double -> Gen (PrimState m) -> m (Uncert Double)
- liftU5' :: PrimMonad m => Int -> (Double -> Double -> Double -> Double -> Double -> Double) -> Uncert Double -> Uncert Double -> Uncert Double -> Uncert Double -> Uncert Double -> Gen (PrimState m) -> m (Uncert Double)
- liftUF' :: (Traversable f, PrimMonad m) => Int -> (f Double -> Double) -> f (Uncert Double) -> Gen (PrimState m) -> m (Uncert Double)
Sampling from an Uncert
Lifting functions via Monte Carlo simulation
Fixed iterations
liftU :: PrimMonad m => (Double -> Double) -> Uncert Double -> Gen (PrimState m) -> m (Uncert Double) Source #
liftU2 :: PrimMonad m => (Double -> Double -> Double) -> Uncert Double -> Uncert Double -> Gen (PrimState m) -> m (Uncert Double) Source #
liftU3 :: PrimMonad m => (Double -> Double -> Double -> Double) -> Uncert Double -> Uncert Double -> Uncert Double -> Gen (PrimState m) -> m (Uncert Double) Source #
liftU4 :: (PrimMonad m, Applicative m) => (Double -> Double -> Double -> Double -> Double) -> Uncert Double -> Uncert Double -> Uncert Double -> Uncert Double -> Gen (PrimState m) -> m (Uncert Double) Source #
liftU5 :: PrimMonad m => (Double -> Double -> Double -> Double -> Double -> Double) -> Uncert Double -> Uncert Double -> Uncert Double -> Uncert Double -> Uncert Double -> Gen (PrimState m) -> m (Uncert Double) Source #
liftUF :: (Traversable f, PrimMonad m) => (f Double -> Double) -> f (Uncert Double) -> Gen (PrimState m) -> m (Uncert Double) Source #
Variable iterations
liftU' :: PrimMonad m => Int -> (Double -> Double) -> Uncert Double -> Gen (PrimState m) -> m (Uncert Double) Source #
Like liftU
, but allows you to specify the number of samples to run
the Monte Carlo simulation with.
liftU2' :: PrimMonad m => Int -> (Double -> Double -> Double) -> Uncert Double -> Uncert Double -> Gen (PrimState m) -> m (Uncert Double) Source #
Like liftU2
, but allows you to specify the number of samples to run
the Monte Carlo simulation with.
liftU3' :: PrimMonad m => Int -> (Double -> Double -> Double -> Double) -> Uncert Double -> Uncert Double -> Uncert Double -> Gen (PrimState m) -> m (Uncert Double) Source #
Like liftU3
, but allows you to specify the number of samples to run
the Monte Carlo simulation with.
liftU4' :: PrimMonad m => Int -> (Double -> Double -> Double -> Double -> Double) -> Uncert Double -> Uncert Double -> Uncert Double -> Uncert Double -> Gen (PrimState m) -> m (Uncert Double) Source #
Like liftU4
, but allows you to specify the number of samples to run
the Monte Carlo simulation with.
liftU5' :: PrimMonad m => Int -> (Double -> Double -> Double -> Double -> Double -> Double) -> Uncert Double -> Uncert Double -> Uncert Double -> Uncert Double -> Uncert Double -> Gen (PrimState m) -> m (Uncert Double) Source #
Like liftU5
, but allows you to specify the number of samples to run
the Monte Carlo simulation with.