ad-4.2.0.1: Automatic Differentiation

PortabilityGHC only
Stabilityexperimental
Maintainerekmett@gmail.com
Safe HaskellNone

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 whereSource

Constructors

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

Instances

Typeable2 Reverse 
(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) 

newtype Tape Source

Constructors

Tape 

Fields

getTape :: IORef Head
 

data Head Source

Constructors

Head !Int Cells 

data Cells whereSource

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) -> rSource

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 aSource

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

partialMapOf :: (Reifies s Tape, Num a) => Proxy s -> Reverse s a -> IntMap aSource

Return an IntMap of sparse partials

derivativeOf :: (Reifies s Tape, Num a) => Proxy s -> Reverse s a -> 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 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 aSource

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

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

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

var :: a -> Int -> Reverse s aSource

primal :: Num a => Reverse s a -> aSource