Copyright (c) Edward Kmett 2010-2021 BSD3 ekmett@gmail.com experimental GHC only Safe-Inferred Haskell2010

Description

This module provides reverse-mode Automatic Differentiation implementation using linear time topological sorting after the fact.

For this form of reverse-mode AD we use StableName to recover sharing information from the tape to avoid combinatorial explosion, and thus run asymptotically faster than it could without such sharing information, but the use of side-effects contained herein is benign.

Synopsis

# Documentation

newtype KahnDouble Source #

Kahn is a Mode using reverse-mode automatic differentiation that provides fast diffFU, diff2FU, grad, grad2 and a fast jacobian when you have a significantly smaller number of outputs than inputs.

Constructors

 Kahn (Tape KahnDouble)

#### Instances

Instances details

data Tape t Source #

A Tape records the information needed back propagate from the output to each input during reverse Mode AD.

Constructors

 Zero Lift !Double Var !Double !Int Binary !Double !Double !Double t t Unary !Double !Double t

#### Instances

Instances details
 Data t => Data (Tape t) Source # Instance detailsDefined in Numeric.AD.Internal.Kahn.Double Methodsgfoldl :: (forall d b. Data d => c (d -> b) -> d -> c b) -> (forall g. g -> c g) -> Tape t -> c (Tape t) #gunfold :: (forall b r. Data b => c (b -> r) -> c r) -> (forall r. r -> c r) -> Constr -> c (Tape t) #toConstr :: Tape t -> Constr #dataTypeOf :: Tape t -> DataType #dataCast1 :: Typeable t0 => (forall d. Data d => c (t0 d)) -> Maybe (c (Tape t)) #dataCast2 :: Typeable t0 => (forall d e. (Data d, Data e) => c (t0 d e)) -> Maybe (c (Tape t)) #gmapT :: (forall b. Data b => b -> b) -> Tape t -> Tape t #gmapQl :: (r -> r' -> r) -> r -> (forall d. Data d => d -> r') -> Tape t -> r #gmapQr :: forall r r'. (r' -> r -> r) -> r -> (forall d. Data d => d -> r') -> Tape t -> r #gmapQ :: (forall d. Data d => d -> u) -> Tape t -> [u] #gmapQi :: Int -> (forall d. Data d => d -> u) -> Tape t -> u #gmapM :: Monad m => (forall d. Data d => d -> m d) -> Tape t -> m (Tape t) #gmapMp :: MonadPlus m => (forall d. Data d => d -> m d) -> Tape t -> m (Tape t) #gmapMo :: MonadPlus m => (forall d. Data d => d -> m d) -> Tape t -> m (Tape t) # Show t => Show (Tape t) Source # Instance detailsDefined in Numeric.AD.Internal.Kahn.Double MethodsshowsPrec :: Int -> Tape t -> ShowS #show :: Tape t -> String #showList :: [Tape t] -> ShowS #

partials :: KahnDouble -> [(Int, Double)] Source #

This returns a list of contributions to the partials. The variable ids returned in the list are likely not unique!

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

Return an IntMap of sparse partials

vgrad :: Grad i o o' => i -> o Source #

vgrad' :: Grad i o o' => i -> o' Source #

class Grad i o o' | i -> o o', o -> i o', o' -> i o where Source #

Methods

pack :: i -> [KahnDouble] -> KahnDouble Source #

unpack :: (List -> List) -> o Source #

unpack' :: (List -> (Double, List)) -> o' Source #

#### Instances

Instances details
 Grad i o o' => Grad (KahnDouble -> i) (Double -> o) (Double -> o') Source # Instance detailsDefined in Numeric.AD.Internal.Kahn.Double Methodspack :: (KahnDouble -> i) -> [KahnDouble] -> KahnDouble Source #unpack :: (List -> List) -> Double -> o Source #unpack' :: (List -> (Double, List)) -> Double -> o' Source #

unbindWithUArray :: (Functor f, IArray UArray b) => (Double -> b -> c) -> f KahnDouble -> UArray Int b -> f c Source #

unbindWithArray :: Functor f => (Double -> b -> c) -> f KahnDouble -> Array Int b -> f c Source #

unbindMapWithDefault :: Functor f => b -> (Double -> b -> c) -> f KahnDouble -> IntMap b -> f c Source #