Copyright (c) Edward Kmett 2012-2015 BSD3 ekmett@gmail.com experimental GHC only None Haskell2010

Description

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

# Documentation

data Reverse s a where Source #

Constructors

 Zero :: Reverse s a Lift :: a -> Reverse s a Reverse :: !Int -> a -> Reverse s a
Instances

newtype Tape Source #

Constructors

Constructors

data Cells where Source #

Constructors

 Nil :: Cells Unary :: !Int -> a -> Cells -> Cells Binary :: !Int -> !Int -> a -> a -> Cells -> Cells

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 #

Return an Array of partials given bounds for the variable IDs.

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.

bind :: Traversable f => f a -> (f (Reverse s a), (Int, Int)) Source #

unbind :: Functor f => f (Reverse s a) -> Array Int a -> f a Source #

unbindMap :: (Functor f, Num a) => f (Reverse s a) -> IntMap a -> f a Source #

unbindWith :: (Functor f, Num a) => (a -> b -> c) -> f (Reverse s a) -> Array Int b -> f c Source #

unbindMapWithDefault :: (Functor f, Num a) => b -> (a -> b -> c) -> f (Reverse s a) -> IntMap b -> f c Source #

var :: a -> Int -> Reverse s a Source #

primal :: Num a => Reverse s a -> a Source #