{-# LANGUAGE RankNTypes #-}
module Numeric.Uncertain.Correlated (
Corr,
evalCorr,
CVar,
sampleUncert,
sampleExact,
constC,
resolveUncert,
liftC,
liftC2,
liftC3,
liftC4,
liftC5,
liftCF,
)
where
import Control.Monad.Free
import Control.Monad.Trans.State
import qualified Data.IntMap.Strict as M
import Numeric.Uncertain
import Numeric.Uncertain.Correlated.Internal
evalCorr :: Fractional a => (forall s. Corr s a b) -> b
evalCorr :: forall a b. Fractional a => (forall s. Corr s a b) -> b
evalCorr forall s. Corr s a b
c = State (Key, IntMap (Uncert a)) b -> (Key, IntMap (Uncert a)) -> b
forall s a. State s a -> s -> a
evalState (Corr Any a b -> State (Key, IntMap (Uncert a)) b
forall (m :: * -> *) a s b.
(Monad m, Fractional a) =>
Corr s a b -> StateT (Key, IntMap (Uncert a)) m b
corrToState Corr Any a b
forall s. Corr s a b
c) (Key
0, IntMap (Uncert a)
forall a. IntMap a
M.empty)
{-# INLINEABLE evalCorr #-}
sampleUncert :: Uncert a -> Corr s a (CVar s a)
sampleUncert :: forall a s. Uncert a -> Corr s a (CVar s a)
sampleUncert Uncert a
u = CorrF s a (CVar s a) -> Corr s a (CVar s a)
forall (f :: * -> *) (m :: * -> *) a.
(Functor f, MonadFree f m) =>
f a -> m a
liftF (CorrF s a (CVar s a) -> Corr s a (CVar s a))
-> CorrF s a (CVar s a) -> Corr s a (CVar s a)
forall a b. (a -> b) -> a -> b
$ Uncert a -> (CVar s a -> CVar s a) -> CorrF s a (CVar s a)
forall b a c. Uncert b -> (CVar a b -> c) -> CorrF a b c
Gen Uncert a
u CVar s a -> CVar s a
forall a. a -> a
id
{-# INLINE sampleUncert #-}
sampleExact :: a -> Corr s a (CVar s a)
sampleExact :: forall a s. a -> Corr s a (CVar s a)
sampleExact = CVar s a -> Corr s a (CVar s a)
forall a. a -> Corr s a a
forall (m :: * -> *) a. Monad m => a -> m a
return (CVar s a -> Corr s a (CVar s a))
-> (a -> CVar s a) -> a -> Corr s a (CVar s a)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. a -> CVar s a
forall a s. a -> CVar s a
constC
{-# INLINE sampleExact #-}
resolveUncert :: CVar s a -> Corr s a (Uncert a)
resolveUncert :: forall s a. CVar s a -> Corr s a (Uncert a)
resolveUncert CVar s a
v = CorrF s a (Uncert a) -> Corr s a (Uncert a)
forall (f :: * -> *) (m :: * -> *) a.
(Functor f, MonadFree f m) =>
f a -> m a
liftF (CorrF s a (Uncert a) -> Corr s a (Uncert a))
-> CorrF s a (Uncert a) -> Corr s a (Uncert a)
forall a b. (a -> b) -> a -> b
$ CVar s a -> (Uncert a -> Uncert a) -> CorrF s a (Uncert a)
forall a b c. CVar a b -> (Uncert b -> c) -> CorrF a b c
Rei CVar s a
v Uncert a -> Uncert a
forall a. a -> a
id
{-# INLINE resolveUncert #-}