Portability | GHC only |
---|---|

Stability | experimental |

Maintainer | ekmett@gmail.com |

Safe Haskell | None |

Forward mode automatic differentiation

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

# Documentation

`Forward`

mode AD

Typeable2 Forward | |

(Num a, Bounded a) => Bounded (Forward a s) | |

(Num a, Enum a) => Enum (Forward a s) | |

(Num a, Eq a) => Eq (Forward a s) | |

Floating a => Floating (Forward a s) | |

Fractional a => Fractional (Forward a s) | |

(Data a, Data s) => Data (Forward a s) | |

Num a => Num (Forward a s) | |

(Num a, Ord a) => Ord (Forward a s) | |

Real a => Real (Forward a s) | |

RealFloat a => RealFloat (Forward a s) | |

RealFrac a => RealFrac (Forward a s) | |

Show a => Show (Forward a s) | |

Erf a => Erf (Forward a s) | |

InvErf a => InvErf (Forward a s) | |

Num a => Mode (Forward a s) | |

Num a => Jacobian (Forward a s) |

# Gradient

grad :: (Traversable f, Num a) => (forall s. f (Forward a s) -> Forward a s) -> f a -> f aSource

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 (Forward a s) -> Forward a s) -> 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 (Forward a s) -> Forward a s) -> f a -> f bSource

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 (Forward a s) -> Forward a s) -> 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.

`>>>`

(10,[(0,1),(1,1),(2,1),(3,1),(4,1)])`gradWith' (,) sum [0..4]`

# Jacobian

jacobian :: (Traversable f, Traversable g, Num a) => (forall s. f (Forward a s) -> g (Forward a s)) -> f a -> g (f a)Source

jacobian' :: (Traversable f, Traversable g, Num a) => (forall s. f (Forward a s) -> g (Forward a s)) -> f a -> g (a, f a)Source

Compute the Jacobian using `Forward`

mode `AD`

along with the actual answer.

jacobianWith :: (Traversable f, Traversable g, Num a) => (a -> a -> b) -> (forall s. f (Forward a s) -> g (Forward a s)) -> 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 (Forward a s) -> g (Forward a s)) -> f a -> g (a, 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, Num a) => (forall s. f (Forward a s) -> g (Forward a s)) -> 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 (Forward a s) -> g (Forward a s)) -> f a -> f (g b)Source

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

mode `AD`

that combines the output with the input.

# Hessian Product

hessianProduct :: (Traversable f, Num a) => (forall s s'. f (On (Forward (Forward a s') s)) -> On (Forward (Forward a s') s)) -> f (a, a) -> f aSource

Compute the product of a vector with the Hessian using forward-on-forward-mode AD.

hessianProduct' :: (Traversable f, Num a) => (forall s s'. f (On (Forward (Forward a s') s)) -> On (Forward (Forward a s') s)) -> f (a, a) -> f (a, a)Source

Compute the gradient and hessian product using forward-on-forward-mode AD.

# Derivatives

diff :: Num a => (forall s. Forward a s -> Forward a s) -> a -> aSource

The `diff`

function calculates the first derivative of a scalar-to-scalar function by forward-mode `AD`

`>>>`

1.0`diff sin 0`

# Directional Derivatives

du :: (Functor f, Num a) => (forall s. f (Forward a s) -> Forward a s) -> f (a, a) -> aSource

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 (Forward a s) -> Forward a s) -> 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