Copyright | (c) Edward Kmett 2012-2015 |
---|---|
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 Kahn
, which
is forced to reify and topologically sort the graph, but it requires
a fairly expensive rendezvous during construction when updated using
multiple threads.
Synopsis
- 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
data Reverse s a where Source #
Instances
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.