ad-3.1.4: Automatic Differentiation

Portability GHC only experimental ekmett@gmail.com None

Numeric.AD.Internal.Chain

Description

Reverse-Mode Automatic Differentiation using a single 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.

Synopsis

# Documentation

data Chain s a whereSource

Constructors

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

Instances

 Typeable2 Chain (Mode (Chain s), Mode (D (Chain s)), Reifies s Tape, Lifted (Chain s)) => Jacobian (Chain s) Primal (Chain s) (Reifies s Tape, Lifted (Chain s)) => Mode (Chain s) Reifies s Tape => Lifted (Chain s) Primal (Chain s) => Var (Chain s) Show a => Show (Chain s a)

newtype Tape Source

Constructors

 Tape FieldsgetTape :: 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) => AD (Chain 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) -> AD (Chain s) a -> Array Int aSource

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

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

Return an `IntMap` of sparse partials

derivativeOf :: (Reifies s Tape, Num a) => Proxy s -> AD (Chain s) a -> aSource

Helper that extracts the derivative of a chain when the chain was constructed with one variable.

derivativeOf' :: (Reifies s Tape, Num a) => Proxy s -> AD (Chain s) a -> (a, a)Source

Helper that extracts both the primal and derivative of a chain when the chain was constructed with one variable.