Copyright (c) Edward Kmett 2010-2015 BSD3 ekmett@gmail.com experimental GHC only None 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 Kahn a 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 a (Kahn a))

Instances

 (Num a, Bounded a) => Bounded (Kahn a) (Num a, Enum a) => Enum (Kahn a) (Num a, Eq a) => Eq (Kahn a) Floating a => Floating (Kahn a) Fractional a => Fractional (Kahn a) Num a => Num (Kahn a) (Num a, Ord a) => Ord (Kahn a) Real a => Real (Kahn a) RealFloat a => RealFloat (Kahn a) RealFrac a => RealFrac (Kahn a) Show a => Show (Kahn a) Source MuRef (Kahn a) Source Erf a => Erf (Kahn a) InvErf a => InvErf (Kahn a) Num a => Mode (Kahn a) Source Num a => Jacobian (Kahn a) Source Num a => Grad (Kahn a) [a] (a, [a]) a Source Grad i o o' a => Grad (Kahn a -> i) (a -> o) (a -> o') a Source type DeRef (Kahn a) = Tape a Source type Scalar (Kahn a) = a Source type D (Kahn a) = Id a Source

data Tape a t Source

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

Constructors

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

Instances

 (Data a, Data t) => Data (Tape a t) Source (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!

partialArray :: Num a => (Int, Int) -> Kahn a -> Array Int a Source

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

partialMap :: Num a => Kahn a -> IntMap a Source

Return an `IntMap` of sparse partials

derivative :: Num a => Kahn a -> a Source

derivative' :: Num a => Kahn a -> (a, a) Source

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

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

class Num a => Grad i o o' a | i -> a o o', o -> a i o', o' -> a i o where Source

Methods

pack :: i -> [Kahn a] -> Kahn a Source

unpack :: ([a] -> [a]) -> o Source

unpack' :: ([a] -> (a, [a])) -> o' Source

Instances

 Num a => Grad (Kahn a) [a] (a, [a]) a Source Grad i o o' a => Grad (Kahn a -> i) (a -> o) (a -> o') a Source

bind :: Traversable f => f a -> (f (Kahn a), (Int, Int)) Source

unbind :: Functor f => f (Kahn a) -> Array Int a -> f a Source

unbindMap :: (Functor f, Num a) => f (Kahn a) -> IntMap a -> f a Source

unbindWith :: (Functor f, Num a) => (a -> b -> c) -> f (Kahn a) -> Array Int b -> f c Source

unbindMapWithDefault :: (Functor f, Num a) => b -> (a -> b -> c) -> f (Kahn a) -> IntMap b -> f c Source

primal :: Num a => Kahn a -> a Source

var :: a -> Int -> Kahn a Source