Copyright | (c) Edward Kmett 2010-2015 |
---|---|
License | BSD3 |
Maintainer | ekmett@gmail.com |
Stability | experimental |
Portability | GHC only |
Safe Haskell | None |
Language | Haskell2010 |
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
- newtype Kahn a = Kahn (Tape a (Kahn a))
- data Tape a t
- partials :: forall a. Num a => Kahn a -> [(Int, a)]
- partialArray :: Num a => (Int, Int) -> Kahn a -> Array Int a
- partialMap :: Num a => Kahn a -> IntMap a
- derivative :: Num a => Kahn a -> a
- derivative' :: Num a => Kahn a -> (a, a)
- vgrad :: Grad i o o' a => i -> o
- vgrad' :: Grad i o o' a => i -> o'
- class Num a => Grad i o o' a | i -> a o o', o -> a i o', o' -> a i o where
- bind :: Traversable f => f a -> (f (Kahn a), (Int, Int))
- unbind :: Functor f => f (Kahn a) -> Array Int a -> f a
- unbindMap :: (Functor f, Num a) => f (Kahn a) -> IntMap a -> f a
- unbindWith :: (Functor f, Num a) => (a -> b -> c) -> f (Kahn a) -> Array Int b -> f c
- unbindMapWithDefault :: (Functor f, Num a) => b -> (a -> b -> c) -> f (Kahn a) -> IntMap b -> f c
- primal :: Num a => Kahn a -> a
- var :: a -> Int -> Kahn a
- varId :: Kahn a -> Int
Documentation
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.
Instances
A Tape
records the information needed back propagate from the output to each input during reverse Mode
AD.
Instances
(Data a, Data t) => Data (Tape a t) Source # | |
Defined in Numeric.AD.Internal.Kahn gfoldl :: (forall d b. Data d => c (d -> b) -> d -> c b) -> (forall g. g -> c g) -> Tape a t -> c (Tape a t) # gunfold :: (forall b r. Data b => c (b -> r) -> c r) -> (forall r. r -> c r) -> Constr -> c (Tape a t) # toConstr :: Tape a t -> Constr # dataTypeOf :: Tape a t -> DataType # dataCast1 :: Typeable t0 => (forall d. Data d => c (t0 d)) -> Maybe (c (Tape a t)) # dataCast2 :: Typeable t0 => (forall d e. (Data d, Data e) => c (t0 d e)) -> Maybe (c (Tape a t)) # gmapT :: (forall b. Data b => b -> b) -> Tape a t -> Tape a t # gmapQl :: (r -> r' -> r) -> r -> (forall d. Data d => d -> r') -> Tape a t -> r # gmapQr :: (r' -> r -> r) -> r -> (forall d. Data d => d -> r') -> Tape a t -> r # gmapQ :: (forall d. Data d => d -> u) -> Tape a t -> [u] # gmapQi :: Int -> (forall d. Data d => d -> u) -> Tape a t -> u # gmapM :: Monad m => (forall d. Data d => d -> m d) -> Tape a t -> m (Tape a t) # gmapMp :: MonadPlus m => (forall d. Data d => d -> m d) -> Tape a t -> m (Tape a t) # gmapMo :: MonadPlus m => (forall d. Data d => d -> m d) -> Tape a t -> m (Tape a t) # | |
(Show a, Show t) => Show (Tape a t) Source # | |
partials :: forall a. Num a => Kahn a -> [(Int, a)] Source #
This returns a list of contributions to the partials. The variable ids returned in the list are likely not unique!
derivative :: Num a => Kahn a -> a Source #
derivative' :: Num a => Kahn a -> (a, a) Source #
class Num a => Grad i o o' a | i -> a o o', o -> a i o', o' -> a i o where Source #