Copyright | (c) Edward Kmett 2010-2014 |
---|---|
License | BSD3 |
Maintainer | ekmett@gmail.com |
Stability | experimental |
Portability | GHC only |
Safe Haskell | None |
Language | Haskell2010 |
Forward mode automatic differentiation
- data AD s a
- data Forward a
- auto :: Mode t => Scalar t -> t
- grad :: (Traversable f, Num a) => (forall s. f (AD s (Forward a)) -> AD s (Forward a)) -> f a -> f a
- grad' :: (Traversable f, Num a) => (forall s. f (AD s (Forward a)) -> AD s (Forward a)) -> f a -> (a, f a)
- gradWith :: (Traversable f, Num a) => (a -> a -> b) -> (forall s. f (AD s (Forward a)) -> AD s (Forward a)) -> f a -> f b
- gradWith' :: (Traversable f, Num a) => (a -> a -> b) -> (forall s. f (AD s (Forward a)) -> AD s (Forward a)) -> f a -> (a, f b)
- jacobian :: (Traversable f, Traversable g, Num a) => (forall s. f (AD s (Forward a)) -> g (AD s (Forward a))) -> f a -> g (f a)
- jacobian' :: (Traversable f, Traversable g, Num a) => (forall s. f (AD s (Forward a)) -> g (AD s (Forward a))) -> f a -> g (a, f a)
- jacobianWith :: (Traversable f, Traversable g, Num a) => (a -> a -> b) -> (forall s. f (AD s (Forward a)) -> g (AD s (Forward a))) -> f a -> g (f b)
- jacobianWith' :: (Traversable f, Traversable g, Num a) => (a -> a -> b) -> (forall s. f (AD s (Forward a)) -> g (AD s (Forward a))) -> f a -> g (a, f b)
- jacobianT :: (Traversable f, Functor g, Num a) => (forall s. f (AD s (Forward a)) -> g (AD s (Forward a))) -> f a -> f (g a)
- jacobianWithT :: (Traversable f, Functor g, Num a) => (a -> a -> b) -> (forall s. f (AD s (Forward a)) -> g (AD s (Forward a))) -> f a -> f (g b)
- hessianProduct :: (Traversable f, Num a) => (forall s. f (AD s (On (Forward (Forward a)))) -> AD s (On (Forward (Forward a)))) -> f (a, a) -> f a
- hessianProduct' :: (Traversable f, Num a) => (forall s. f (AD s (On (Forward (Forward a)))) -> AD s (On (Forward (Forward a)))) -> f (a, a) -> f (a, a)
- diff :: Num a => (forall s. AD s (Forward a) -> AD s (Forward a)) -> a -> a
- diff' :: Num a => (forall s. AD s (Forward a) -> AD s (Forward a)) -> a -> (a, a)
- diffF :: (Functor f, Num a) => (forall s. AD s (Forward a) -> f (AD s (Forward a))) -> a -> f a
- diffF' :: (Functor f, Num a) => (forall s. AD s (Forward a) -> f (AD s (Forward a))) -> a -> f (a, a)
- du :: (Functor f, Num a) => (forall s. f (AD s (Forward a)) -> AD s (Forward a)) -> f (a, a) -> a
- du' :: (Functor f, Num a) => (forall s. f (AD s (Forward a)) -> AD s (Forward a)) -> f (a, a) -> (a, a)
- duF :: (Functor f, Functor g, Num a) => (forall s. f (AD s (Forward a)) -> g (AD s (Forward a))) -> f (a, a) -> g a
- duF' :: (Functor f, Functor g, Num a) => (forall s. f (AD s (Forward a)) -> g (AD s (Forward a))) -> f (a, a) -> g (a, a)
Documentation
Bounded a => Bounded (AD s a) | |
Enum a => Enum (AD s a) | |
Eq a => Eq (AD s a) | |
Floating a => Floating (AD s a) | |
Fractional a => Fractional (AD s a) | |
Num a => Num (AD s a) | |
Ord a => Ord (AD s a) | |
Read a => Read (AD s a) | |
Real a => Real (AD s a) | |
RealFloat a => RealFloat (AD s a) | |
RealFrac a => RealFrac (AD s a) | |
Show a => Show (AD s a) | |
Erf a => Erf (AD s a) | |
InvErf a => InvErf (AD s a) | |
Mode a => Mode (AD s a) | |
Typeable (* -> * -> *) AD | |
type Scalar (AD s a) = Scalar a |
Forward
mode AD
(Num a, Bounded a) => Bounded (Forward a) | |
(Num a, Enum a) => Enum (Forward a) | |
(Num a, Eq a) => Eq (Forward a) | |
Floating a => Floating (Forward a) | |
Fractional a => Fractional (Forward a) | |
Data a => Data (Forward a) | |
Num a => Num (Forward a) | |
(Num a, Ord a) => Ord (Forward a) | |
Real a => Real (Forward a) | |
RealFloat a => RealFloat (Forward a) | |
RealFrac a => RealFrac (Forward a) | |
Show a => Show (Forward a) | |
Erf a => Erf (Forward a) | |
InvErf a => InvErf (Forward a) | |
Num a => Mode (Forward a) | |
Num a => Jacobian (Forward a) | |
Typeable (* -> *) Forward | |
type Scalar (Forward a) = a | |
type D (Forward a) = Id a |
Gradient
grad :: (Traversable f, Num a) => (forall s. f (AD s (Forward a)) -> AD s (Forward a)) -> f a -> f a Source
Compute the gradient of a function using forward mode AD.
Note, this performs O(n) worse than grad
for n
inputs, in exchange for better space utilization.
grad' :: (Traversable f, Num a) => (forall s. f (AD s (Forward a)) -> AD s (Forward a)) -> f a -> (a, f a) Source
Compute the gradient and answer to a function using forward mode AD.
Note, this performs O(n) worse than grad'
for n
inputs, in exchange for better space utilization.
gradWith :: (Traversable f, Num a) => (a -> a -> b) -> (forall s. f (AD s (Forward a)) -> AD s (Forward a)) -> f a -> f b Source
Compute the gradient of a function using forward mode AD and combine the result with the input using a user-specified function.
Note, this performs O(n) worse than gradWith
for n
inputs, in exchange for better space utilization.
gradWith' :: (Traversable f, Num a) => (a -> a -> b) -> (forall s. f (AD s (Forward a)) -> AD s (Forward a)) -> f a -> (a, f b) Source
Compute the gradient of a function using forward mode AD and the answer, and combine the result with the input using a user-specified function.
Note, this performs O(n) worse than gradWith'
for n
inputs, in exchange for better space utilization.
>>>
gradWith' (,) sum [0..4]
(10,[(0,1),(1,1),(2,1),(3,1),(4,1)])
Jacobian
jacobian :: (Traversable f, Traversable g, Num a) => (forall s. f (AD s (Forward a)) -> g (AD s (Forward a))) -> f a -> g (f a) Source
jacobian' :: (Traversable f, Traversable g, Num a) => (forall s. f (AD s (Forward a)) -> g (AD s (Forward a))) -> f a -> g (a, f a) Source
jacobianWith :: (Traversable f, Traversable g, Num a) => (a -> a -> b) -> (forall s. f (AD s (Forward a)) -> g (AD s (Forward a))) -> f a -> g (f b) Source
Compute the Jacobian using Forward
mode AD
and combine the output with the input. This must transpose the result, so jacobianWithT
is faster, and allows more result types.
jacobianWith' :: (Traversable f, Traversable g, Num a) => (a -> a -> b) -> (forall s. f (AD s (Forward a)) -> g (AD s (Forward a))) -> f a -> g (a, f b) Source
Transposed Jacobian
jacobianT :: (Traversable f, Functor g, Num a) => (forall s. f (AD s (Forward a)) -> g (AD s (Forward a))) -> f a -> f (g a) Source
A fast, simple, transposed Jacobian computed with forward-mode AD.
jacobianWithT :: (Traversable f, Functor g, Num a) => (a -> a -> b) -> (forall s. f (AD s (Forward a)) -> g (AD s (Forward a))) -> f a -> f (g b) Source
Hessian Product
hessianProduct :: (Traversable f, Num a) => (forall s. f (AD s (On (Forward (Forward a)))) -> AD s (On (Forward (Forward a)))) -> f (a, a) -> f a Source
Compute the product of a vector with the Hessian using forward-on-forward-mode AD.
hessianProduct' :: (Traversable f, Num a) => (forall s. f (AD s (On (Forward (Forward a)))) -> AD s (On (Forward (Forward a)))) -> f (a, a) -> f (a, a) Source
Compute the gradient and hessian product using forward-on-forward-mode AD.
Derivatives
diffF :: (Functor f, Num a) => (forall s. AD s (Forward a) -> f (AD s (Forward a))) -> a -> f a Source
diffF' :: (Functor f, Num a) => (forall s. AD s (Forward a) -> f (AD s (Forward a))) -> a -> f (a, a) Source
Directional Derivatives
du :: (Functor f, Num a) => (forall s. f (AD s (Forward a)) -> AD s (Forward a)) -> f (a, a) -> a Source
Compute the directional derivative of a function given a zipped up Functor
of the input values and their derivatives
du' :: (Functor f, Num a) => (forall s. f (AD s (Forward a)) -> AD s (Forward a)) -> f (a, a) -> (a, a) Source
Compute the answer and directional derivative of a function given a zipped up Functor
of the input values and their derivatives