Copyright | (c) Edward Kmett 2010-2015 |
---|---|

License | BSD3 |

Maintainer | ekmett@gmail.com |

Stability | experimental |

Portability | GHC only |

Safe Haskell | None |

Language | Haskell2010 |

Forward Mode AD specialized to `Double`

. This enables the entire structure
to be unboxed.

- data AD s a
- data ForwardDouble
- grad :: Traversable f => (forall s. f (AD s ForwardDouble) -> AD s ForwardDouble) -> f Double -> f Double
- grad' :: Traversable f => (forall s. f (AD s ForwardDouble) -> AD s ForwardDouble) -> f Double -> (Double, f Double)
- gradWith :: Traversable f => (Double -> Double -> b) -> (forall s. f (AD s ForwardDouble) -> AD s ForwardDouble) -> f Double -> f b
- gradWith' :: Traversable f => (Double -> Double -> b) -> (forall s. f (AD s ForwardDouble) -> AD s ForwardDouble) -> f Double -> (Double, f b)
- jacobian :: (Traversable f, Traversable g) => (forall s. f (AD s ForwardDouble) -> g (AD s ForwardDouble)) -> f Double -> g (f Double)
- jacobian' :: (Traversable f, Traversable g) => (forall s. f (AD s ForwardDouble) -> g (AD s ForwardDouble)) -> f Double -> g (Double, f Double)
- jacobianWith :: (Traversable f, Traversable g) => (Double -> Double -> b) -> (forall s. f (AD s ForwardDouble) -> g (AD s ForwardDouble)) -> f Double -> g (f b)
- jacobianWith' :: (Traversable f, Traversable g) => (Double -> Double -> b) -> (forall s. f (AD s ForwardDouble) -> g (AD s ForwardDouble)) -> f Double -> g (Double, f b)
- jacobianT :: (Traversable f, Functor g) => (forall s. f (AD s ForwardDouble) -> g (AD s ForwardDouble)) -> f Double -> f (g Double)
- jacobianWithT :: (Traversable f, Functor g) => (Double -> Double -> b) -> (forall s. f (AD s ForwardDouble) -> g (AD s ForwardDouble)) -> f Double -> f (g b)
- diff :: (forall s. AD s ForwardDouble -> AD s ForwardDouble) -> Double -> Double
- diff' :: (forall s. AD s ForwardDouble -> AD s ForwardDouble) -> Double -> (Double, Double)
- diffF :: Functor f => (forall s. AD s ForwardDouble -> f (AD s ForwardDouble)) -> Double -> f Double
- diffF' :: Functor f => (forall s. AD s ForwardDouble -> f (AD s ForwardDouble)) -> Double -> f (Double, Double)
- du :: Functor f => (forall s. f (AD s ForwardDouble) -> AD s ForwardDouble) -> f (Double, Double) -> Double
- du' :: Functor f => (forall s. f (AD s ForwardDouble) -> AD s ForwardDouble) -> f (Double, Double) -> (Double, Double)
- duF :: (Functor f, Functor g) => (forall s. f (AD s ForwardDouble) -> g (AD s ForwardDouble)) -> f (Double, Double) -> g Double
- duF' :: (Functor f, Functor g) => (forall s. f (AD s ForwardDouble) -> g (AD s ForwardDouble)) -> f (Double, Double) -> g (Double, Double)

# Documentation

Bounded a => Bounded (AD s a) Source # | |

Enum a => Enum (AD s a) Source # | |

Eq a => Eq (AD s a) Source # | |

Floating a => Floating (AD s a) Source # | |

Fractional a => Fractional (AD s a) Source # | |

Num a => Num (AD s a) Source # | |

Ord a => Ord (AD s a) Source # | |

Read a => Read (AD s a) Source # | |

Real a => Real (AD s a) Source # | |

RealFloat a => RealFloat (AD s a) Source # | |

RealFrac a => RealFrac (AD s a) Source # | |

Show a => Show (AD s a) Source # | |

Erf a => Erf (AD s a) Source # | |

InvErf a => InvErf (AD s a) Source # | |

Mode a => Mode (AD s a) Source # | |

type Scalar (AD s a) Source # | |

data ForwardDouble Source #

# Gradient

grad :: Traversable f => (forall s. f (AD s ForwardDouble) -> AD s ForwardDouble) -> f Double -> f Double 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 => (forall s. f (AD s ForwardDouble) -> AD s ForwardDouble) -> f Double -> (Double, f Double) 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 => (Double -> Double -> b) -> (forall s. f (AD s ForwardDouble) -> AD s ForwardDouble) -> f Double -> 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 => (Double -> Double -> b) -> (forall s. f (AD s ForwardDouble) -> AD s ForwardDouble) -> f Double -> (Double, 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.

`>>>`

(10.0,[(0.0,1.0),(1.0,1.0),(2.0,1.0),(3.0,1.0),(4.0,1.0)])`gradWith' (,) sum [0..4]`

# Jacobian

jacobian :: (Traversable f, Traversable g) => (forall s. f (AD s ForwardDouble) -> g (AD s ForwardDouble)) -> f Double -> g (f Double) Source #

jacobian' :: (Traversable f, Traversable g) => (forall s. f (AD s ForwardDouble) -> g (AD s ForwardDouble)) -> f Double -> g (Double, f Double) Source #

Compute the Jacobian using `Forward`

mode `AD`

along with the actual answer.

jacobianWith :: (Traversable f, Traversable g) => (Double -> Double -> b) -> (forall s. f (AD s ForwardDouble) -> g (AD s ForwardDouble)) -> f Double -> 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) => (Double -> Double -> b) -> (forall s. f (AD s ForwardDouble) -> g (AD s ForwardDouble)) -> f Double -> g (Double, f b) Source #

Compute the Jacobian using `Forward`

mode `AD`

combined with the input using a user specified function, along with the actual answer.

# Transposed Jacobian

jacobianT :: (Traversable f, Functor g) => (forall s. f (AD s ForwardDouble) -> g (AD s ForwardDouble)) -> f Double -> f (g Double) Source #

A fast, simple, transposed Jacobian computed with forward-mode AD.

jacobianWithT :: (Traversable f, Functor g) => (Double -> Double -> b) -> (forall s. f (AD s ForwardDouble) -> g (AD s ForwardDouble)) -> f Double -> f (g b) Source #

A fast, simple, transposed Jacobian computed with `Forward`

mode `AD`

that combines the output with the input.

# Derivatives

diff :: (forall s. AD s ForwardDouble -> AD s ForwardDouble) -> Double -> Double Source #

diff' :: (forall s. AD s ForwardDouble -> AD s ForwardDouble) -> Double -> (Double, Double) Source #

diffF :: Functor f => (forall s. AD s ForwardDouble -> f (AD s ForwardDouble)) -> Double -> f Double Source #

diffF' :: Functor f => (forall s. AD s ForwardDouble -> f (AD s ForwardDouble)) -> Double -> f (Double, Double) Source #

# Directional Derivatives

du :: Functor f => (forall s. f (AD s ForwardDouble) -> AD s ForwardDouble) -> f (Double, Double) -> Double Source #

Compute the directional derivative of a function given a zipped up `Functor`

of the input values and their derivatives

du' :: Functor f => (forall s. f (AD s ForwardDouble) -> AD s ForwardDouble) -> f (Double, Double) -> (Double, Double) Source #

Compute the answer and directional derivative of a function given a zipped up `Functor`

of the input values and their derivatives