Portability | GHC only |
---|---|
Stability | experimental |
Maintainer | ekmett@gmail.com |
Safe Haskell | None |
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 a s 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 a s -> [a]
- partialArrayOf :: (Reifies s Tape, Num a) => Proxy s -> (Int, Int) -> Reverse a s -> Array Int a
- partialMapOf :: (Reifies s Tape, Num a) => Proxy s -> Reverse a s -> IntMap a
- derivativeOf :: (Reifies s Tape, Num a) => Proxy s -> Reverse a s -> a
- derivativeOf' :: (Reifies s Tape, Num a) => Proxy s -> Reverse a s -> (a, a)
- bind :: Traversable f => f a -> (f (Reverse a s), (Int, Int))
- unbind :: Functor f => f (Reverse a s) -> Array Int a -> f a
- unbindMap :: (Functor f, Num a) => f (Reverse a s) -> IntMap a -> f a
- unbindWith :: (Functor f, Num a) => (a -> b -> c) -> f (Reverse a s) -> Array Int b -> f c
- unbindMapWithDefault :: (Functor f, Num a) => b -> (a -> b -> c) -> f (Reverse a s) -> IntMap b -> f c
- var :: a -> Int -> Reverse a s
- varId :: Reverse a s -> Int
- primal :: Num a => Reverse a s -> a
Documentation
Typeable2 Reverse | |
(Reifies * s Tape, Num a, Bounded a) => Bounded (Reverse a s) | |
(Reifies * s Tape, Num a, Enum a) => Enum (Reverse a s) | |
(Reifies * s Tape, Num a, Eq a) => Eq (Reverse a s) | |
(Reifies * s Tape, Floating a) => Floating (Reverse a s) | |
(Reifies * s Tape, Fractional a) => Fractional (Reverse a s) | |
(Reifies * s Tape, Num a) => Num (Reverse a s) | |
(Reifies * s Tape, Num a, Ord a) => Ord (Reverse a s) | |
(Reifies * s Tape, Real a) => Real (Reverse a s) | |
(Reifies * s Tape, RealFloat a) => RealFloat (Reverse a s) | |
(Reifies * s Tape, RealFrac a) => RealFrac (Reverse a s) | |
Show a => Show (Reverse a s) | |
(Reifies * s Tape, Erf a) => Erf (Reverse a s) | |
(Reifies * s Tape, InvErf a) => InvErf (Reverse a s) | |
(Num a, Reifies * s Tape) => Mode (Reverse a s) | |
(Reifies * s Tape, Num a) => Jacobian (Reverse a s) |
reifyTape :: Int -> (forall s. Reifies s Tape => Proxy s -> r) -> rSource
Construct a tape that starts with n
variables.
partials :: forall s a. (Reifies s Tape, Num a) => Reverse a s -> [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 a s -> Array Int aSource
partialMapOf :: (Reifies s Tape, Num a) => Proxy s -> Reverse a s -> IntMap aSource
Return an IntMap
of sparse partials
derivativeOf :: (Reifies s Tape, Num a) => Proxy s -> Reverse a s -> aSource
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 a s -> (a, a)Source
Helper that extracts both the primal and derivative of a chain when the chain was constructed with 1 variable.