Copyright | (c) Edward Kmett 2012-2014 |
---|---|
License | BSD3 |
Maintainer | ekmett@gmail.com |
Stability | experimental |
Portability | GHC only |
Safe Haskell | None |
Language | Haskell2010 |
Reverse-Mode Automatic Differentiation using a single Wengert list (or "tape").
This version uses Data.Reflection
to find and update the tape.
This is asymptotically faster than using Reverse
, which
is forced to reify and topologically sort the graph, but it requires
a fairly expensive rendezvous during construction when updated using
multiple threads.
- data Reverse s a where
- newtype Tape = Tape {}
- data Head = Head !Int Cells
- data Cells where
- reifyTape :: Int -> (forall s. Reifies s Tape => Proxy s -> r) -> r
- partials :: forall s a. (Reifies s Tape, Num a) => Reverse s a -> [a]
- partialArrayOf :: (Reifies s Tape, Num a) => Proxy s -> (Int, Int) -> Reverse s a -> Array Int a
- partialMapOf :: (Reifies s Tape, Num a) => Proxy s -> Reverse s a -> IntMap a
- derivativeOf :: (Reifies s Tape, Num a) => Proxy s -> Reverse s a -> a
- derivativeOf' :: (Reifies s Tape, Num a) => Proxy s -> Reverse s a -> (a, a)
- bind :: Traversable f => f a -> (f (Reverse s a), (Int, Int))
- unbind :: Functor f => f (Reverse s a) -> Array Int a -> f a
- unbindMap :: (Functor f, Num a) => f (Reverse s a) -> IntMap a -> f a
- unbindWith :: (Functor f, Num a) => (a -> b -> c) -> f (Reverse s a) -> Array Int b -> f c
- unbindMapWithDefault :: (Functor f, Num a) => b -> (a -> b -> c) -> f (Reverse s a) -> IntMap b -> f c
- var :: a -> Int -> Reverse s a
- varId :: Reverse s a -> Int
- primal :: Num a => Reverse s a -> a
Documentation
(Reifies * s Tape, Num a, Bounded a) => Bounded (Reverse s a) | |
(Reifies * s Tape, Num a, Enum a) => Enum (Reverse s a) | |
(Reifies * s Tape, Num a, Eq a) => Eq (Reverse s a) | |
(Reifies * s Tape, Floating a) => Floating (Reverse s a) | |
(Reifies * s Tape, Fractional a) => Fractional (Reverse s a) | |
(Reifies * s Tape, Num a) => Num (Reverse s a) | |
(Reifies * s Tape, Num a, Ord a) => Ord (Reverse s a) | |
(Reifies * s Tape, Real a) => Real (Reverse s a) | |
(Reifies * s Tape, RealFloat a) => RealFloat (Reverse s a) | |
(Reifies * s Tape, RealFrac a) => RealFrac (Reverse s a) | |
Show a => Show (Reverse s a) | |
(Reifies * s Tape, Erf a) => Erf (Reverse s a) | |
(Reifies * s Tape, InvErf a) => InvErf (Reverse s a) | |
(Reifies * s Tape, Num a) => Mode (Reverse s a) | |
(Reifies * s Tape, Num a) => Jacobian (Reverse s a) | |
Typeable (* -> * -> *) Reverse | |
type Scalar (Reverse s a) = a | |
type D (Reverse s a) = Id a |
reifyTape :: Int -> (forall s. Reifies s Tape => Proxy s -> r) -> r Source
Construct a tape that starts with n
variables.
partials :: forall s a. (Reifies s Tape, Num a) => Reverse s a -> [a] Source
Extract the partials from the current chain for a given AD variable.
partialArrayOf :: (Reifies s Tape, Num a) => Proxy s -> (Int, Int) -> Reverse s a -> Array Int a Source
partialMapOf :: (Reifies s Tape, Num a) => Proxy s -> Reverse s a -> IntMap a Source
Return an IntMap
of sparse partials
derivativeOf :: (Reifies s Tape, Num a) => Proxy s -> Reverse s a -> a Source
Helper that extracts the derivative of a chain when the chain was constructed with 1 variable.
derivativeOf' :: (Reifies s Tape, Num a) => Proxy s -> Reverse s a -> (a, a) Source
Helper that extracts both the primal and derivative of a chain when the chain was constructed with 1 variable.