ad-4.2.1.1: Automatic Differentiation

Copyright(c) Edward Kmett 2012-2014
LicenseBSD3
Maintainerekmett@gmail.com
Stabilityexperimental
PortabilityGHC only
Safe HaskellNone
LanguageHaskell2010

Numeric.AD.Internal.Reverse

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 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.

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

(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 

newtype Tape Source

Constructors

Tape 

Fields

getTape :: IORef Head
 

data Head Source

Constructors

Head !Int Cells 

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