Portability GHC only experimental ekmett@gmail.com None

Description

Higher order derivatives via a "dual number tower".

Synopsis

# Documentation

data Sparse a s Source

We only store partials in sorted order, so the map contained in a partial will only contain partials with equal or greater keys to that of the map in which it was found. This should be key for efficiently computing sparse hessians. there are only (n + k - 1) choose k distinct nth partial derivatives of a function with k inputs.

Instances

 Typeable2 Sparse (Num a, Bounded a) => Bounded (Sparse a s) (Num a, Enum a) => Enum (Sparse a s) (Num a, Eq a) => Eq (Sparse a s) Floating a => Floating (Sparse a s) Fractional a => Fractional (Sparse a s) (Data a, Data s) => Data (Sparse a s) Num a => Num (Sparse a s) (Num a, Ord a) => Ord (Sparse a s) Real a => Real (Sparse a s) RealFloat a => RealFloat (Sparse a s) RealFrac a => RealFrac (Sparse a s) Show a => Show (Sparse a s) Erf a => Erf (Sparse a s) InvErf a => InvErf (Sparse a s) Num a => Mode (Sparse a s) Num a => Jacobian (Sparse a s) Num a => Grad (Sparse a ()) [a] (a, [a]) a Grads i o a => Grads (Sparse a () -> i) (a -> o) a Num a => Grads (Sparse a ()) (Cofree [] a) a Grad i o o' a => Grad (Sparse a () -> i) (a -> o) (a -> o') a

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

grad' :: (Traversable f, Num a) => (forall s. f (Sparse a s) -> Sparse a s) -> f a -> (a, f a)Source

gradWith :: (Traversable f, Num a) => (a -> a -> b) -> (forall s. f (Sparse a s) -> Sparse a s) -> f a -> f bSource

gradWith' :: (Traversable f, Num a) => (a -> a -> b) -> (forall s. f (Sparse a s) -> Sparse a s) -> f a -> (a, f b)Source

Unfortunately, variadicity comes at the expense of being able to use quantification to avoid sensitivity confusion, so be careful when counting the number of `auto` calls you use when taking the gradient of a function that takes gradients!

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

Instances

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

grads :: (Traversable f, Num a) => (forall s. f (Sparse a s) -> Sparse a s) -> f a -> Cofree f aSource

class Num a => Grads i o a | i -> a o, o -> a iSource

Instances

 Grads i o a => Grads (Sparse a () -> i) (a -> o) a Num a => Grads (Sparse a ()) (Cofree [] a) a

# Sparse Jacobians (synonyms)

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

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

jacobianWith :: (Traversable f, Functor g, Num a) => (a -> a -> b) -> (forall s. f (Sparse a s) -> g (Sparse a s)) -> f a -> g (f b)Source

jacobianWith' :: (Traversable f, Functor g, Num a) => (a -> a -> b) -> (forall s. f (Sparse a s) -> g (Sparse a s)) -> f a -> g (a, f b)Source

jacobians :: (Traversable f, Functor g, Num a) => (forall s. f (Sparse a s) -> g (Sparse a s)) -> f a -> g (Cofree f a)Source

# Sparse Hessians

hessian :: (Traversable f, Num a) => (forall s. f (Sparse a s) -> Sparse a s) -> f a -> f (f a)Source

hessian' :: (Traversable f, Num a) => (forall s. f (Sparse a s) -> Sparse a s) -> f a -> (a, f (a, f a))Source

hessianF :: (Traversable f, Functor g, Num a) => (forall s. f (Sparse a s) -> g (Sparse a s)) -> f a -> g (f (f a))Source

hessianF' :: (Traversable f, Functor g, Num a) => (forall s. f (Sparse a s) -> g (Sparse a s)) -> f a -> g (a, f (a, f a))Source