packages feed

ad 0.31.0 → 0.32.0

raw patch · 27 files changed

+970/−891 lines, 27 filesPVP ok

version bump matches the API change (PVP)

API changes (from Hackage documentation)

- Numeric.AD: (*^) :: (Mode t, Num a) => a -> t a -> t a
- Numeric.AD: (<+>) :: (Mode t, Num a) => t a -> t a -> t a
- Numeric.AD: (^*) :: (Mode t, Num a) => t a -> a -> t a
- Numeric.AD: (^/) :: (Mode t, Fractional a) => t a -> a -> t a
- Numeric.AD: AD :: f a -> AD f a
- Numeric.AD: class (Lifted t) => Mode t
- Numeric.AD: diff :: (Num a) => UU a -> a -> a
- Numeric.AD: diff' :: (Num a) => UU a -> a -> (a, a)
- Numeric.AD: diffF :: (Functor f, Num a) => UF f a -> a -> f a
- Numeric.AD: diffF' :: (Functor f, Num a) => UF f a -> a -> f (a, a)
- Numeric.AD: diffM :: (Monad m, Num a) => UF m a -> a -> m a
- Numeric.AD: diffM' :: (Monad m, Num a) => UF m a -> a -> m (a, a)
- Numeric.AD: diffs :: (Num a) => UU a -> a -> [a]
- Numeric.AD: diffs0 :: (Num a) => UU a -> a -> [a]
- Numeric.AD: diffs0F :: (Functor f, Num a) => UF f a -> a -> f [a]
- Numeric.AD: diffsF :: (Functor f, Num a) => UF f a -> a -> f [a]
- Numeric.AD: du :: (Functor f, Num a) => FU f a -> f (a, a) -> a
- Numeric.AD: du' :: (Functor f, Num a) => FU f a -> f (a, a) -> (a, a)
- Numeric.AD: duF :: (Functor f, Functor g, Num a) => FF f g a -> f (a, a) -> g a
- Numeric.AD: duF' :: (Functor f, Functor g, Num a) => FF f g a -> f (a, a) -> g (a, a)
- Numeric.AD: dus :: (Functor f, Num a) => FU f a -> f [a] -> [a]
- Numeric.AD: dus0 :: (Functor f, Num a) => FU f a -> f [a] -> [a]
- Numeric.AD: dus0F :: (Functor f, Functor g, Num a) => FF f g a -> f [a] -> g [a]
- Numeric.AD: dusF :: (Functor f, Functor g, Num a) => FF f g a -> f [a] -> g [a]
- Numeric.AD: grad :: (Traversable f, Num a) => FU f a -> f a -> f a
- Numeric.AD: grad' :: (Traversable f, Num a) => FU f a -> f a -> (a, f a)
- Numeric.AD: gradF :: (Traversable f, Functor g, Num a) => FF f g a -> f a -> g (f a)
- Numeric.AD: gradF' :: (Traversable f, Functor g, Num a) => FF f g a -> f a -> g (a, f a)
- Numeric.AD: gradM :: (Traversable f, Monad m, Num a) => FF f m a -> f a -> m (f a)
- Numeric.AD: gradM' :: (Traversable f, Monad m, Num a) => FF f m a -> f a -> m (a, f a)
- Numeric.AD: gradWith :: (Traversable f, Num a) => (a -> a -> b) -> FU f a -> f a -> f b
- Numeric.AD: gradWith' :: (Traversable f, Num a) => (a -> a -> b) -> FU f a -> f a -> (a, f b)
- Numeric.AD: gradWithF :: (Traversable f, Functor g, Num a) => (a -> a -> b) -> FF f g a -> f a -> g (f b)
- Numeric.AD: gradWithF' :: (Traversable f, Functor g, Num a) => (a -> a -> b) -> FF f g a -> f a -> g (a, f b)
- Numeric.AD: gradWithM :: (Traversable f, Monad m, Num a) => (a -> a -> b) -> FF f m a -> f a -> m (f b)
- Numeric.AD: gradWithM' :: (Traversable f, Monad m, Num a) => (a -> a -> b) -> FF f m a -> f a -> m (a, f b)
- Numeric.AD: hessian :: (Traversable f, Num a) => FU f a -> f a -> f (f a)
- Numeric.AD: hessianProduct :: (Traversable f, Num a) => FU f a -> f (a, a) -> f a
- Numeric.AD: hessianProduct' :: (Traversable f, Num a) => FU f a -> f (a, a) -> f (a, a)
- Numeric.AD: hessianTensor :: (Traversable f, Traversable g, Num a) => FF f g a -> f a -> g (f (f a))
- Numeric.AD: jacobian :: (Traversable f, Traversable g, Num a) => FF f g a -> f a -> g (f a)
- Numeric.AD: jacobian' :: (Traversable f, Traversable g, Num a) => FF f g a -> f a -> g (a, f a)
- Numeric.AD: jacobianT :: (Traversable f, Functor g, Num a) => FF f g a -> f a -> f (g a)
- Numeric.AD: jacobianWith :: (Traversable f, Traversable g, Num a) => (a -> a -> b) -> FF f g a -> f a -> g (f b)
- Numeric.AD: jacobianWith' :: (Traversable f, Traversable g, Num a) => (a -> a -> b) -> FF f g a -> f a -> g (a, f b)
- Numeric.AD: jacobianWithT :: (Traversable f, Functor g, Num a) => (a -> a -> b) -> FF f g a -> f a -> f (g b)
- Numeric.AD: lift :: (Mode t, Num a) => a -> t a
- Numeric.AD: maclaurin :: (Fractional a) => UU a -> a -> [a]
- Numeric.AD: maclaurin0 :: (Fractional a) => UU a -> a -> [a]
- Numeric.AD: newtype AD f a
- Numeric.AD: runAD :: AD f a -> f a
- Numeric.AD: taylor :: (Fractional a) => UU a -> a -> a -> [a]
- Numeric.AD: taylor0 :: (Fractional a) => UU a -> a -> a -> [a]
- Numeric.AD: type UF f a = forall s. (Mode s) => AD s a -> f (AD s a)
- Numeric.AD: type FF f g a = forall s. (Mode s) => f (AD s a) -> g (AD s a)
- Numeric.AD: zero :: (Mode t, Num a) => t a
- Numeric.AD.Directed: (*^) :: (Mode t, Num a) => a -> t a -> t a
- Numeric.AD.Directed: (<+>) :: (Mode t, Num a) => t a -> t a -> t a
- Numeric.AD.Directed: (^*) :: (Mode t, Num a) => t a -> a -> t a
- Numeric.AD.Directed: (^/) :: (Mode t, Fractional a) => t a -> a -> t a
- Numeric.AD.Directed: AD :: f a -> AD f a
- Numeric.AD.Directed: Forward :: Direction
- Numeric.AD.Directed: Mixed :: Direction
- Numeric.AD.Directed: Reverse :: Direction
- Numeric.AD.Directed: Tower :: Direction
- Numeric.AD.Directed: class (Lifted t) => Mode t
- Numeric.AD.Directed: data Direction
- Numeric.AD.Directed: diff :: (Num a) => Direction -> UU a -> a -> a
- Numeric.AD.Directed: diff' :: (Num a) => Direction -> UU a -> a -> (a, a)
- Numeric.AD.Directed: grad :: (Traversable f, Num a) => Direction -> FU f a -> f a -> f a
- Numeric.AD.Directed: grad' :: (Traversable f, Num a) => Direction -> FU f a -> f a -> (a, f a)
- Numeric.AD.Directed: instance Bounded Direction
- Numeric.AD.Directed: instance Enum Direction
- Numeric.AD.Directed: instance Eq Direction
- Numeric.AD.Directed: instance Ix Direction
- Numeric.AD.Directed: instance Ord Direction
- Numeric.AD.Directed: instance Read Direction
- Numeric.AD.Directed: instance Show Direction
- Numeric.AD.Directed: jacobian :: (Traversable f, Traversable g, Num a) => Direction -> FF f g a -> f a -> g (f a)
- Numeric.AD.Directed: jacobian' :: (Traversable f, Traversable g, Num a) => Direction -> FF f g a -> f a -> g (a, f a)
- Numeric.AD.Directed: lift :: (Mode t, Num a) => a -> t a
- Numeric.AD.Directed: newtype AD f a
- Numeric.AD.Directed: runAD :: AD f a -> f a
- Numeric.AD.Directed: type UF f a = forall s. (Mode s) => AD s a -> f (AD s a)
- Numeric.AD.Directed: type FF f g a = forall s. (Mode s) => f (AD s a) -> g (AD s a)
- Numeric.AD.Directed: zero :: (Mode t, Num a) => t a
- Numeric.AD.Forward: (*^) :: (Mode t, Num a) => a -> t a -> t a
- Numeric.AD.Forward: (<+>) :: (Mode t, Num a) => t a -> t a -> t a
- Numeric.AD.Forward: (^*) :: (Mode t, Num a) => t a -> a -> t a
- Numeric.AD.Forward: (^/) :: (Mode t, Fractional a) => t a -> a -> t a
- Numeric.AD.Forward: AD :: f a -> AD f a
- Numeric.AD.Forward: class (Lifted t) => Mode t
- Numeric.AD.Forward: diff :: (Num a) => UU a -> a -> a
- Numeric.AD.Forward: diff' :: (Num a) => UU a -> a -> (a, a)
- Numeric.AD.Forward: diffF :: (Functor f, Num a) => UF f a -> a -> f a
- Numeric.AD.Forward: diffF' :: (Functor f, Num a) => UF f a -> a -> f (a, a)
- Numeric.AD.Forward: diffM :: (Monad m, Num a) => UF m a -> a -> m a
- Numeric.AD.Forward: diffM' :: (Monad m, Num a) => UF m a -> a -> m (a, a)
- Numeric.AD.Forward: du :: (Functor f, Num a) => FU f a -> f (a, a) -> a
- Numeric.AD.Forward: du' :: (Functor f, Num a) => FU f a -> f (a, a) -> (a, a)
- Numeric.AD.Forward: duF :: (Functor f, Functor g, Num a) => FF f g a -> f (a, a) -> g a
- Numeric.AD.Forward: duF' :: (Functor f, Functor g, Num a) => FF f g a -> f (a, a) -> g (a, a)
- Numeric.AD.Forward: grad :: (Traversable f, Num a) => FU f a -> f a -> f a
- Numeric.AD.Forward: grad' :: (Traversable f, Num a) => FU f a -> f a -> (a, f a)
- Numeric.AD.Forward: gradWith :: (Traversable f, Num a) => (a -> a -> b) -> FU f a -> f a -> f b
- Numeric.AD.Forward: gradWith' :: (Traversable f, Num a) => (a -> a -> b) -> FU f a -> f a -> (a, f b)
- Numeric.AD.Forward: hessianProduct :: (Traversable f, Num a) => FU f a -> f (a, a) -> f a
- Numeric.AD.Forward: hessianProduct' :: (Traversable f, Num a) => FU f a -> f (a, a) -> f (a, a)
- Numeric.AD.Forward: jacobian :: (Traversable f, Traversable g, Num a) => FF f g a -> f a -> g (f a)
- Numeric.AD.Forward: jacobian' :: (Traversable f, Traversable g, Num a) => FF f g a -> f a -> g (a, f a)
- Numeric.AD.Forward: jacobianT :: (Traversable f, Functor g, Num a) => FF f g a -> f a -> f (g a)
- Numeric.AD.Forward: jacobianWith :: (Traversable f, Traversable g, Num a) => (a -> a -> b) -> FF f g a -> f a -> g (f b)
- Numeric.AD.Forward: jacobianWith' :: (Traversable f, Traversable g, Num a) => (a -> a -> b) -> FF f g a -> f a -> g (a, f b)
- Numeric.AD.Forward: jacobianWithT :: (Traversable f, Functor g, Num a) => (a -> a -> b) -> FF f g a -> f a -> f (g b)
- Numeric.AD.Forward: lift :: (Mode t, Num a) => a -> t a
- Numeric.AD.Forward: newtype AD f a
- Numeric.AD.Forward: runAD :: AD f a -> f a
- Numeric.AD.Forward: type UF f a = forall s. (Mode s) => AD s a -> f (AD s a)
- Numeric.AD.Forward: type FF f g a = forall s. (Mode s) => f (AD s a) -> g (AD s a)
- Numeric.AD.Forward: zero :: (Mode t, Num a) => t a
- Numeric.AD.Internal.Comonad: class (Copointed f) => Comonad f
- Numeric.AD.Internal.Comonad: class (Functor f) => Copointed f
- Numeric.AD.Internal.Comonad: duplicate :: (Comonad f) => f a -> f (f a)
- Numeric.AD.Internal.Comonad: extend :: (Comonad f) => (f a -> b) -> f a -> f b
- Numeric.AD.Internal.Comonad: extract :: (Copointed f) => f a -> a
- Numeric.AD.Internal.Stream: (:<) :: a -> f (Stream f a) -> Stream f a
- Numeric.AD.Internal.Stream: data Stream f a
- Numeric.AD.Internal.Stream: headS :: Stream f a -> a
- Numeric.AD.Internal.Stream: instance (Foldable f) => Foldable (Stream f)
- Numeric.AD.Internal.Stream: instance (Functor f) => Comonad (Stream f)
- Numeric.AD.Internal.Stream: instance (Functor f) => Copointed (Stream f)
- Numeric.AD.Internal.Stream: instance (Functor f) => Functor (Stream f)
- Numeric.AD.Internal.Stream: instance (Show a, Show (f (Stream f a))) => Show (Stream f a)
- Numeric.AD.Internal.Stream: instance (Traversable f) => Traversable (Stream f)
- Numeric.AD.Internal.Stream: instance (Typeable1 f) => Typeable1 (Stream f)
- Numeric.AD.Internal.Stream: instance (Typeable1 f, Data (f (Stream f a)), Data a) => Data (Stream f a)
- Numeric.AD.Internal.Stream: instance (Typeable1 f, Typeable a) => Typeable (Stream f a)
- Numeric.AD.Internal.Stream: tailS :: Stream f a -> f (Stream f a)
- Numeric.AD.Internal.Stream: unfoldS :: (Functor f) => (a -> (b, f a)) -> a -> Stream f b
- Numeric.AD.Internal.Tensors: (:-) :: a -> Tensors f (f a) -> Tensors f a
- Numeric.AD.Internal.Tensors: data Tensors f a
- Numeric.AD.Internal.Tensors: headT :: Tensors f a -> a
- Numeric.AD.Internal.Tensors: instance (Foldable f) => Foldable (Tensors f)
- Numeric.AD.Internal.Tensors: instance (Functor f) => Copointed (Tensors f)
- Numeric.AD.Internal.Tensors: instance (Functor f) => Functor (Tensors f)
- Numeric.AD.Internal.Tensors: instance (Traversable f) => Traversable (Tensors f)
- Numeric.AD.Internal.Tensors: instance (Typeable1 f) => Typeable1 (Tensors f)
- Numeric.AD.Internal.Tensors: instance (Typeable1 f, Typeable a) => Typeable (Tensors f a)
- Numeric.AD.Internal.Tensors: tailT :: Tensors f a -> Tensors f (f a)
- Numeric.AD.Internal.Tensors: tensors :: (Functor f) => Stream f a -> Tensors f a
- Numeric.AD.Internal.Types: AD :: f a -> AD f a
- Numeric.AD.Internal.Types: instance (Lifted f) => Lifted (AD f)
- Numeric.AD.Internal.Types: instance (Lifted f, Floating a) => Floating (AD f a)
- Numeric.AD.Internal.Types: instance (Lifted f, Fractional a) => Fractional (AD f a)
- Numeric.AD.Internal.Types: instance (Lifted f, Num a) => Num (AD f a)
- Numeric.AD.Internal.Types: instance (Lifted f, Real a) => Real (AD f a)
- Numeric.AD.Internal.Types: instance (Lifted f, RealFloat a) => RealFloat (AD f a)
- Numeric.AD.Internal.Types: instance (Lifted f, RealFrac a) => RealFrac (AD f a)
- Numeric.AD.Internal.Types: instance (Lifted f, Show a) => Show (AD f a)
- Numeric.AD.Internal.Types: instance (Mode f) => Mode (AD f)
- Numeric.AD.Internal.Types: instance (Num a, Lifted f, Bounded a) => Bounded (AD f a)
- Numeric.AD.Internal.Types: instance (Num a, Lifted f, Enum a) => Enum (AD f a)
- Numeric.AD.Internal.Types: instance (Num a, Lifted f, Eq a) => Eq (AD f a)
- Numeric.AD.Internal.Types: instance (Num a, Lifted f, Ord a) => Ord (AD f a)
- Numeric.AD.Internal.Types: instance (Primal f) => Primal (AD f)
- Numeric.AD.Internal.Types: instance (Typeable1 f) => Typeable1 (AD f)
- Numeric.AD.Internal.Types: instance (Typeable1 f, Typeable a) => Typeable (AD f a)
- Numeric.AD.Internal.Types: instance (Typeable1 f, Typeable a, Data (f a), Data a) => Data (AD f a)
- Numeric.AD.Internal.Types: instance Iso (f a) (AD f a)
- Numeric.AD.Internal.Types: newtype AD f a
- Numeric.AD.Internal.Types: runAD :: AD f a -> f a
- Numeric.AD.Internal.Types: type UF f a = forall s. (Mode s) => AD s a -> f (AD s a)
- Numeric.AD.Internal.Types: type FF f g a = forall s. (Mode s) => f (AD s a) -> g (AD s a)
- Numeric.AD.Reverse: (*^) :: (Mode t, Num a) => a -> t a -> t a
- Numeric.AD.Reverse: (<+>) :: (Mode t, Num a) => t a -> t a -> t a
- Numeric.AD.Reverse: (^*) :: (Mode t, Num a) => t a -> a -> t a
- Numeric.AD.Reverse: (^/) :: (Mode t, Fractional a) => t a -> a -> t a
- Numeric.AD.Reverse: AD :: f a -> AD f a
- Numeric.AD.Reverse: class (Lifted t) => Mode t
- Numeric.AD.Reverse: diff :: (Num a) => UU a -> a -> a
- Numeric.AD.Reverse: diff' :: (Num a) => UU a -> a -> (a, a)
- Numeric.AD.Reverse: diffF :: (Functor f, Num a) => UF f a -> a -> f a
- Numeric.AD.Reverse: diffF' :: (Functor f, Num a) => UF f a -> a -> f (a, a)
- Numeric.AD.Reverse: diffM :: (Monad m, Num a) => UF m a -> a -> m a
- Numeric.AD.Reverse: diffM' :: (Monad m, Num a) => UF m a -> a -> m (a, a)
- Numeric.AD.Reverse: grad :: (Traversable f, Num a) => FU f a -> f a -> f a
- Numeric.AD.Reverse: grad' :: (Traversable f, Num a) => FU f a -> f a -> (a, f a)
- Numeric.AD.Reverse: gradF :: (Traversable f, Functor g, Num a) => FF f g a -> f a -> g (f a)
- Numeric.AD.Reverse: gradF' :: (Traversable f, Functor g, Num a) => FF f g a -> f a -> g (a, f a)
- Numeric.AD.Reverse: gradM :: (Traversable f, Monad m, Num a) => FF f m a -> f a -> m (f a)
- Numeric.AD.Reverse: gradM' :: (Traversable f, Monad m, Num a) => FF f m a -> f a -> m (a, f a)
- Numeric.AD.Reverse: gradWith :: (Traversable f, Num a) => (a -> a -> b) -> FU f a -> f a -> f b
- Numeric.AD.Reverse: gradWith' :: (Traversable f, Num a) => (a -> a -> b) -> FU f a -> f a -> (a, f b)
- Numeric.AD.Reverse: gradWithF :: (Traversable f, Functor g, Num a) => (a -> a -> b) -> FF f g a -> f a -> g (f b)
- Numeric.AD.Reverse: gradWithF' :: (Traversable f, Functor g, Num a) => (a -> a -> b) -> FF f g a -> f a -> g (a, f b)
- Numeric.AD.Reverse: gradWithM :: (Traversable f, Monad m, Num a) => (a -> a -> b) -> FF f m a -> f a -> m (f b)
- Numeric.AD.Reverse: gradWithM' :: (Traversable f, Monad m, Num a) => (a -> a -> b) -> FF f m a -> f a -> m (a, f b)
- Numeric.AD.Reverse: hessian :: (Traversable f, Num a) => FU f a -> f a -> f (f a)
- Numeric.AD.Reverse: hessianM :: (Traversable f, Monad m, Num a) => FF f m a -> f a -> m (f (f a))
- Numeric.AD.Reverse: hessianTensor :: (Traversable f, Functor g, Num a) => FF f g a -> f a -> g (f (f a))
- Numeric.AD.Reverse: jacobian :: (Traversable f, Functor g, Num a) => FF f g a -> f a -> g (f a)
- Numeric.AD.Reverse: jacobian' :: (Traversable f, Functor g, Num a) => FF f g a -> f a -> g (a, f a)
- Numeric.AD.Reverse: jacobianWith :: (Traversable f, Functor g, Num a) => (a -> a -> b) -> FF f g a -> f a -> g (f b)
- Numeric.AD.Reverse: jacobianWith' :: (Traversable f, Functor g, Num a) => (a -> a -> b) -> FF f g a -> f a -> g (a, f b)
- Numeric.AD.Reverse: lift :: (Mode t, Num a) => a -> t a
- Numeric.AD.Reverse: newtype AD f a
- Numeric.AD.Reverse: runAD :: AD f a -> f a
- Numeric.AD.Reverse: type UF f a = forall s. (Mode s) => AD s a -> f (AD s a)
- Numeric.AD.Reverse: type FF f g a = forall s. (Mode s) => f (AD s a) -> g (AD s a)
- Numeric.AD.Reverse: zero :: (Mode t, Num a) => t a
- Numeric.AD.Tensors: (:-) :: a -> Tensors f (f a) -> Tensors f a
- Numeric.AD.Tensors: (:<) :: a -> f (Stream f a) -> Stream f a
- Numeric.AD.Tensors: class (Copointed f) => Comonad f
- Numeric.AD.Tensors: class (Functor f) => Copointed f
- Numeric.AD.Tensors: data Stream f a
- Numeric.AD.Tensors: data Tensors f a
- Numeric.AD.Tensors: duplicate :: (Comonad f) => f a -> f (f a)
- Numeric.AD.Tensors: extend :: (Comonad f) => (f a -> b) -> f a -> f b
- Numeric.AD.Tensors: extract :: (Copointed f) => f a -> a
- Numeric.AD.Tensors: headS :: Stream f a -> a
- Numeric.AD.Tensors: headT :: Tensors f a -> a
- Numeric.AD.Tensors: tailS :: Stream f a -> f (Stream f a)
- Numeric.AD.Tensors: tailT :: Tensors f a -> Tensors f (f a)
- Numeric.AD.Tensors: tensors :: (Functor f) => Stream f a -> Tensors f a
- Numeric.AD.Tensors: unfoldS :: (Functor f) => (a -> (b, f a)) -> a -> Stream f b
- Numeric.AD.Tower: (*^) :: (Mode t, Num a) => a -> t a -> t a
- Numeric.AD.Tower: (<+>) :: (Mode t, Num a) => t a -> t a -> t a
- Numeric.AD.Tower: (^*) :: (Mode t, Num a) => t a -> a -> t a
- Numeric.AD.Tower: (^/) :: (Mode t, Fractional a) => t a -> a -> t a
- Numeric.AD.Tower: AD :: f a -> AD f a
- Numeric.AD.Tower: class (Lifted t) => Mode t
- Numeric.AD.Tower: diff :: (Num a) => UU a -> a -> a
- Numeric.AD.Tower: diff' :: (Num a) => UU a -> a -> (a, a)
- Numeric.AD.Tower: diffs :: (Num a) => UU a -> a -> [a]
- Numeric.AD.Tower: diffs0 :: (Num a) => UU a -> a -> [a]
- Numeric.AD.Tower: diffs0F :: (Functor f, Num a) => UF f a -> a -> f [a]
- Numeric.AD.Tower: diffs0M :: (Monad m, Num a) => UF m a -> a -> m [a]
- Numeric.AD.Tower: diffsF :: (Functor f, Num a) => UF f a -> a -> f [a]
- Numeric.AD.Tower: diffsM :: (Monad m, Num a) => UF m a -> a -> m [a]
- Numeric.AD.Tower: du :: (Functor f, Num a) => FU f a -> f (a, a) -> a
- Numeric.AD.Tower: du' :: (Functor f, Num a) => FU f a -> f (a, a) -> (a, a)
- Numeric.AD.Tower: duF :: (Functor f, Functor g, Num a) => FF f g a -> f (a, a) -> g a
- Numeric.AD.Tower: duF' :: (Functor f, Functor g, Num a) => FF f g a -> f (a, a) -> g (a, a)
- Numeric.AD.Tower: dus :: (Functor f, Num a) => FU f a -> f [a] -> [a]
- Numeric.AD.Tower: dus0 :: (Functor f, Num a) => FU f a -> f [a] -> [a]
- Numeric.AD.Tower: dus0F :: (Functor f, Functor g, Num a) => FF f g a -> f [a] -> g [a]
- Numeric.AD.Tower: dusF :: (Functor f, Functor g, Num a) => FF f g a -> f [a] -> g [a]
- Numeric.AD.Tower: lift :: (Mode t, Num a) => a -> t a
- Numeric.AD.Tower: maclaurin :: (Fractional a) => UU a -> a -> [a]
- Numeric.AD.Tower: maclaurin0 :: (Fractional a) => UU a -> a -> [a]
- Numeric.AD.Tower: newtype AD f a
- Numeric.AD.Tower: runAD :: AD f a -> f a
- Numeric.AD.Tower: taylor :: (Fractional a) => UU a -> a -> a -> [a]
- Numeric.AD.Tower: taylor0 :: (Fractional a) => UU a -> a -> a -> [a]
- Numeric.AD.Tower: type UF f a = forall s. (Mode s) => AD s a -> f (AD s a)
- Numeric.AD.Tower: type FF f g a = forall s. (Mode s) => f (AD s a) -> g (AD s a)
- Numeric.AD.Tower: zero :: (Mode t, Num a) => t a
+ Numeric.AD.Classes: (*^) :: (Mode t, Num a) => a -> t a -> t a
+ Numeric.AD.Classes: (<+>) :: (Mode t, Num a) => t a -> t a -> t a
+ Numeric.AD.Classes: (^*) :: (Mode t, Num a) => t a -> a -> t a
+ Numeric.AD.Classes: (^/) :: (Mode t, Fractional a) => t a -> a -> t a
+ Numeric.AD.Classes: class (Copointed f) => Comonad f
+ Numeric.AD.Classes: class (Functor f) => Copointed f
+ Numeric.AD.Classes: class (Lifted t) => Mode t
+ Numeric.AD.Classes: duplicate :: (Comonad f) => f a -> f (f a)
+ Numeric.AD.Classes: extend :: (Comonad f) => (f a -> b) -> f a -> f b
+ Numeric.AD.Classes: extract :: (Copointed f) => f a -> a
+ Numeric.AD.Classes: lift :: (Mode t, Num a) => a -> t a
+ Numeric.AD.Classes: zero :: (Mode t, Num a) => t a
+ Numeric.AD.Mode.Directed: (*^) :: (Mode t, Num a) => a -> t a -> t a
+ Numeric.AD.Mode.Directed: (<+>) :: (Mode t, Num a) => t a -> t a -> t a
+ Numeric.AD.Mode.Directed: (^*) :: (Mode t, Num a) => t a -> a -> t a
+ Numeric.AD.Mode.Directed: (^/) :: (Mode t, Fractional a) => t a -> a -> t a
+ Numeric.AD.Mode.Directed: AD :: f a -> AD f a
+ Numeric.AD.Mode.Directed: Forward :: Direction
+ Numeric.AD.Mode.Directed: Mixed :: Direction
+ Numeric.AD.Mode.Directed: Reverse :: Direction
+ Numeric.AD.Mode.Directed: Tower :: Direction
+ Numeric.AD.Mode.Directed: class (Lifted t) => Mode t
+ Numeric.AD.Mode.Directed: data Direction
+ Numeric.AD.Mode.Directed: diff :: (Num a) => Direction -> UU a -> a -> a
+ Numeric.AD.Mode.Directed: diff' :: (Num a) => Direction -> UU a -> a -> (a, a)
+ Numeric.AD.Mode.Directed: grad :: (Traversable f, Num a) => Direction -> FU f a -> f a -> f a
+ Numeric.AD.Mode.Directed: grad' :: (Traversable f, Num a) => Direction -> FU f a -> f a -> (a, f a)
+ Numeric.AD.Mode.Directed: instance Bounded Direction
+ Numeric.AD.Mode.Directed: instance Enum Direction
+ Numeric.AD.Mode.Directed: instance Eq Direction
+ Numeric.AD.Mode.Directed: instance Ix Direction
+ Numeric.AD.Mode.Directed: instance Ord Direction
+ Numeric.AD.Mode.Directed: instance Read Direction
+ Numeric.AD.Mode.Directed: instance Show Direction
+ Numeric.AD.Mode.Directed: jacobian :: (Traversable f, Traversable g, Num a) => Direction -> FF f g a -> f a -> g (f a)
+ Numeric.AD.Mode.Directed: jacobian' :: (Traversable f, Traversable g, Num a) => Direction -> FF f g a -> f a -> g (a, f a)
+ Numeric.AD.Mode.Directed: lift :: (Mode t, Num a) => a -> t a
+ Numeric.AD.Mode.Directed: newtype AD f a
+ Numeric.AD.Mode.Directed: runAD :: AD f a -> f a
+ Numeric.AD.Mode.Directed: type UF f a = forall s. (Mode s) => AD s a -> f (AD s a)
+ Numeric.AD.Mode.Directed: type FF f g a = forall s. (Mode s) => f (AD s a) -> g (AD s a)
+ Numeric.AD.Mode.Directed: zero :: (Mode t, Num a) => t a
+ Numeric.AD.Mode.Forward: (*^) :: (Mode t, Num a) => a -> t a -> t a
+ Numeric.AD.Mode.Forward: (<+>) :: (Mode t, Num a) => t a -> t a -> t a
+ Numeric.AD.Mode.Forward: (^*) :: (Mode t, Num a) => t a -> a -> t a
+ Numeric.AD.Mode.Forward: (^/) :: (Mode t, Fractional a) => t a -> a -> t a
+ Numeric.AD.Mode.Forward: AD :: f a -> AD f a
+ Numeric.AD.Mode.Forward: class (Lifted t) => Mode t
+ Numeric.AD.Mode.Forward: diff :: (Num a) => UU a -> a -> a
+ Numeric.AD.Mode.Forward: diff' :: (Num a) => UU a -> a -> (a, a)
+ Numeric.AD.Mode.Forward: diffF :: (Functor f, Num a) => UF f a -> a -> f a
+ Numeric.AD.Mode.Forward: diffF' :: (Functor f, Num a) => UF f a -> a -> f (a, a)
+ Numeric.AD.Mode.Forward: diffM :: (Monad m, Num a) => UF m a -> a -> m a
+ Numeric.AD.Mode.Forward: diffM' :: (Monad m, Num a) => UF m a -> a -> m (a, a)
+ Numeric.AD.Mode.Forward: du :: (Functor f, Num a) => FU f a -> f (a, a) -> a
+ Numeric.AD.Mode.Forward: du' :: (Functor f, Num a) => FU f a -> f (a, a) -> (a, a)
+ Numeric.AD.Mode.Forward: duF :: (Functor f, Functor g, Num a) => FF f g a -> f (a, a) -> g a
+ Numeric.AD.Mode.Forward: duF' :: (Functor f, Functor g, Num a) => FF f g a -> f (a, a) -> g (a, a)
+ Numeric.AD.Mode.Forward: grad :: (Traversable f, Num a) => FU f a -> f a -> f a
+ Numeric.AD.Mode.Forward: grad' :: (Traversable f, Num a) => FU f a -> f a -> (a, f a)
+ Numeric.AD.Mode.Forward: gradWith :: (Traversable f, Num a) => (a -> a -> b) -> FU f a -> f a -> f b
+ Numeric.AD.Mode.Forward: gradWith' :: (Traversable f, Num a) => (a -> a -> b) -> FU f a -> f a -> (a, f b)
+ Numeric.AD.Mode.Forward: hessianProduct :: (Traversable f, Num a) => FU f a -> f (a, a) -> f a
+ Numeric.AD.Mode.Forward: hessianProduct' :: (Traversable f, Num a) => FU f a -> f (a, a) -> f (a, a)
+ Numeric.AD.Mode.Forward: jacobian :: (Traversable f, Traversable g, Num a) => FF f g a -> f a -> g (f a)
+ Numeric.AD.Mode.Forward: jacobian' :: (Traversable f, Traversable g, Num a) => FF f g a -> f a -> g (a, f a)
+ Numeric.AD.Mode.Forward: jacobianT :: (Traversable f, Functor g, Num a) => FF f g a -> f a -> f (g a)
+ Numeric.AD.Mode.Forward: jacobianWith :: (Traversable f, Traversable g, Num a) => (a -> a -> b) -> FF f g a -> f a -> g (f b)
+ Numeric.AD.Mode.Forward: jacobianWith' :: (Traversable f, Traversable g, Num a) => (a -> a -> b) -> FF f g a -> f a -> g (a, f b)
+ Numeric.AD.Mode.Forward: jacobianWithT :: (Traversable f, Functor g, Num a) => (a -> a -> b) -> FF f g a -> f a -> f (g b)
+ Numeric.AD.Mode.Forward: lift :: (Mode t, Num a) => a -> t a
+ Numeric.AD.Mode.Forward: newtype AD f a
+ Numeric.AD.Mode.Forward: runAD :: AD f a -> f a
+ Numeric.AD.Mode.Forward: type UF f a = forall s. (Mode s) => AD s a -> f (AD s a)
+ Numeric.AD.Mode.Forward: type FF f g a = forall s. (Mode s) => f (AD s a) -> g (AD s a)
+ Numeric.AD.Mode.Forward: zero :: (Mode t, Num a) => t a
+ Numeric.AD.Mode.Mixed: (*^) :: (Mode t, Num a) => a -> t a -> t a
+ Numeric.AD.Mode.Mixed: (<+>) :: (Mode t, Num a) => t a -> t a -> t a
+ Numeric.AD.Mode.Mixed: (^*) :: (Mode t, Num a) => t a -> a -> t a
+ Numeric.AD.Mode.Mixed: (^/) :: (Mode t, Fractional a) => t a -> a -> t a
+ Numeric.AD.Mode.Mixed: AD :: f a -> AD f a
+ Numeric.AD.Mode.Mixed: class (Lifted t) => Mode t
+ Numeric.AD.Mode.Mixed: diff :: (Num a) => UU a -> a -> a
+ Numeric.AD.Mode.Mixed: diff' :: (Num a) => UU a -> a -> (a, a)
+ Numeric.AD.Mode.Mixed: diffF :: (Functor f, Num a) => UF f a -> a -> f a
+ Numeric.AD.Mode.Mixed: diffF' :: (Functor f, Num a) => UF f a -> a -> f (a, a)
+ Numeric.AD.Mode.Mixed: diffM :: (Monad m, Num a) => UF m a -> a -> m a
+ Numeric.AD.Mode.Mixed: diffM' :: (Monad m, Num a) => UF m a -> a -> m (a, a)
+ Numeric.AD.Mode.Mixed: diffs :: (Num a) => UU a -> a -> [a]
+ Numeric.AD.Mode.Mixed: diffs0 :: (Num a) => UU a -> a -> [a]
+ Numeric.AD.Mode.Mixed: diffs0F :: (Functor f, Num a) => UF f a -> a -> f [a]
+ Numeric.AD.Mode.Mixed: diffsF :: (Functor f, Num a) => UF f a -> a -> f [a]
+ Numeric.AD.Mode.Mixed: du :: (Functor f, Num a) => FU f a -> f (a, a) -> a
+ Numeric.AD.Mode.Mixed: du' :: (Functor f, Num a) => FU f a -> f (a, a) -> (a, a)
+ Numeric.AD.Mode.Mixed: duF :: (Functor f, Functor g, Num a) => FF f g a -> f (a, a) -> g a
+ Numeric.AD.Mode.Mixed: duF' :: (Functor f, Functor g, Num a) => FF f g a -> f (a, a) -> g (a, a)
+ Numeric.AD.Mode.Mixed: dus :: (Functor f, Num a) => FU f a -> f [a] -> [a]
+ Numeric.AD.Mode.Mixed: dus0 :: (Functor f, Num a) => FU f a -> f [a] -> [a]
+ Numeric.AD.Mode.Mixed: dus0F :: (Functor f, Functor g, Num a) => FF f g a -> f [a] -> g [a]
+ Numeric.AD.Mode.Mixed: dusF :: (Functor f, Functor g, Num a) => FF f g a -> f [a] -> g [a]
+ Numeric.AD.Mode.Mixed: grad :: (Traversable f, Num a) => FU f a -> f a -> f a
+ Numeric.AD.Mode.Mixed: grad' :: (Traversable f, Num a) => FU f a -> f a -> (a, f a)
+ Numeric.AD.Mode.Mixed: gradF :: (Traversable f, Functor g, Num a) => FF f g a -> f a -> g (f a)
+ Numeric.AD.Mode.Mixed: gradF' :: (Traversable f, Functor g, Num a) => FF f g a -> f a -> g (a, f a)
+ Numeric.AD.Mode.Mixed: gradM :: (Traversable f, Monad m, Num a) => FF f m a -> f a -> m (f a)
+ Numeric.AD.Mode.Mixed: gradM' :: (Traversable f, Monad m, Num a) => FF f m a -> f a -> m (a, f a)
+ Numeric.AD.Mode.Mixed: gradWith :: (Traversable f, Num a) => (a -> a -> b) -> FU f a -> f a -> f b
+ Numeric.AD.Mode.Mixed: gradWith' :: (Traversable f, Num a) => (a -> a -> b) -> FU f a -> f a -> (a, f b)
+ Numeric.AD.Mode.Mixed: gradWithF :: (Traversable f, Functor g, Num a) => (a -> a -> b) -> FF f g a -> f a -> g (f b)
+ Numeric.AD.Mode.Mixed: gradWithF' :: (Traversable f, Functor g, Num a) => (a -> a -> b) -> FF f g a -> f a -> g (a, f b)
+ Numeric.AD.Mode.Mixed: gradWithM :: (Traversable f, Monad m, Num a) => (a -> a -> b) -> FF f m a -> f a -> m (f b)
+ Numeric.AD.Mode.Mixed: gradWithM' :: (Traversable f, Monad m, Num a) => (a -> a -> b) -> FF f m a -> f a -> m (a, f b)
+ Numeric.AD.Mode.Mixed: hessian :: (Traversable f, Num a) => FU f a -> f a -> f (f a)
+ Numeric.AD.Mode.Mixed: hessianProduct :: (Traversable f, Num a) => FU f a -> f (a, a) -> f a
+ Numeric.AD.Mode.Mixed: hessianProduct' :: (Traversable f, Num a) => FU f a -> f (a, a) -> f (a, a)
+ Numeric.AD.Mode.Mixed: hessianTensor :: (Traversable f, Traversable g, Num a) => FF f g a -> f a -> g (f (f a))
+ Numeric.AD.Mode.Mixed: jacobian :: (Traversable f, Traversable g, Num a) => FF f g a -> f a -> g (f a)
+ Numeric.AD.Mode.Mixed: jacobian' :: (Traversable f, Traversable g, Num a) => FF f g a -> f a -> g (a, f a)
+ Numeric.AD.Mode.Mixed: jacobianT :: (Traversable f, Functor g, Num a) => FF f g a -> f a -> f (g a)
+ Numeric.AD.Mode.Mixed: jacobianWith :: (Traversable f, Traversable g, Num a) => (a -> a -> b) -> FF f g a -> f a -> g (f b)
+ Numeric.AD.Mode.Mixed: jacobianWith' :: (Traversable f, Traversable g, Num a) => (a -> a -> b) -> FF f g a -> f a -> g (a, f b)
+ Numeric.AD.Mode.Mixed: jacobianWithT :: (Traversable f, Functor g, Num a) => (a -> a -> b) -> FF f g a -> f a -> f (g b)
+ Numeric.AD.Mode.Mixed: lift :: (Mode t, Num a) => a -> t a
+ Numeric.AD.Mode.Mixed: maclaurin :: (Fractional a) => UU a -> a -> [a]
+ Numeric.AD.Mode.Mixed: maclaurin0 :: (Fractional a) => UU a -> a -> [a]
+ Numeric.AD.Mode.Mixed: newtype AD f a
+ Numeric.AD.Mode.Mixed: runAD :: AD f a -> f a
+ Numeric.AD.Mode.Mixed: taylor :: (Fractional a) => UU a -> a -> a -> [a]
+ Numeric.AD.Mode.Mixed: taylor0 :: (Fractional a) => UU a -> a -> a -> [a]
+ Numeric.AD.Mode.Mixed: type UF f a = forall s. (Mode s) => AD s a -> f (AD s a)
+ Numeric.AD.Mode.Mixed: type FF f g a = forall s. (Mode s) => f (AD s a) -> g (AD s a)
+ Numeric.AD.Mode.Mixed: zero :: (Mode t, Num a) => t a
+ Numeric.AD.Mode.Reverse: (*^) :: (Mode t, Num a) => a -> t a -> t a
+ Numeric.AD.Mode.Reverse: (<+>) :: (Mode t, Num a) => t a -> t a -> t a
+ Numeric.AD.Mode.Reverse: (^*) :: (Mode t, Num a) => t a -> a -> t a
+ Numeric.AD.Mode.Reverse: (^/) :: (Mode t, Fractional a) => t a -> a -> t a
+ Numeric.AD.Mode.Reverse: AD :: f a -> AD f a
+ Numeric.AD.Mode.Reverse: class (Lifted t) => Mode t
+ Numeric.AD.Mode.Reverse: diff :: (Num a) => UU a -> a -> a
+ Numeric.AD.Mode.Reverse: diff' :: (Num a) => UU a -> a -> (a, a)
+ Numeric.AD.Mode.Reverse: diffF :: (Functor f, Num a) => UF f a -> a -> f a
+ Numeric.AD.Mode.Reverse: diffF' :: (Functor f, Num a) => UF f a -> a -> f (a, a)
+ Numeric.AD.Mode.Reverse: diffM :: (Monad m, Num a) => UF m a -> a -> m a
+ Numeric.AD.Mode.Reverse: diffM' :: (Monad m, Num a) => UF m a -> a -> m (a, a)
+ Numeric.AD.Mode.Reverse: grad :: (Traversable f, Num a) => FU f a -> f a -> f a
+ Numeric.AD.Mode.Reverse: grad' :: (Traversable f, Num a) => FU f a -> f a -> (a, f a)
+ Numeric.AD.Mode.Reverse: gradF :: (Traversable f, Functor g, Num a) => FF f g a -> f a -> g (f a)
+ Numeric.AD.Mode.Reverse: gradF' :: (Traversable f, Functor g, Num a) => FF f g a -> f a -> g (a, f a)
+ Numeric.AD.Mode.Reverse: gradM :: (Traversable f, Monad m, Num a) => FF f m a -> f a -> m (f a)
+ Numeric.AD.Mode.Reverse: gradM' :: (Traversable f, Monad m, Num a) => FF f m a -> f a -> m (a, f a)
+ Numeric.AD.Mode.Reverse: gradWith :: (Traversable f, Num a) => (a -> a -> b) -> FU f a -> f a -> f b
+ Numeric.AD.Mode.Reverse: gradWith' :: (Traversable f, Num a) => (a -> a -> b) -> FU f a -> f a -> (a, f b)
+ Numeric.AD.Mode.Reverse: gradWithF :: (Traversable f, Functor g, Num a) => (a -> a -> b) -> FF f g a -> f a -> g (f b)
+ Numeric.AD.Mode.Reverse: gradWithF' :: (Traversable f, Functor g, Num a) => (a -> a -> b) -> FF f g a -> f a -> g (a, f b)
+ Numeric.AD.Mode.Reverse: gradWithM :: (Traversable f, Monad m, Num a) => (a -> a -> b) -> FF f m a -> f a -> m (f b)
+ Numeric.AD.Mode.Reverse: gradWithM' :: (Traversable f, Monad m, Num a) => (a -> a -> b) -> FF f m a -> f a -> m (a, f b)
+ Numeric.AD.Mode.Reverse: hessian :: (Traversable f, Num a) => FU f a -> f a -> f (f a)
+ Numeric.AD.Mode.Reverse: hessianM :: (Traversable f, Monad m, Num a) => FF f m a -> f a -> m (f (f a))
+ Numeric.AD.Mode.Reverse: hessianTensor :: (Traversable f, Functor g, Num a) => FF f g a -> f a -> g (f (f a))
+ Numeric.AD.Mode.Reverse: jacobian :: (Traversable f, Functor g, Num a) => FF f g a -> f a -> g (f a)
+ Numeric.AD.Mode.Reverse: jacobian' :: (Traversable f, Functor g, Num a) => FF f g a -> f a -> g (a, f a)
+ Numeric.AD.Mode.Reverse: jacobianWith :: (Traversable f, Functor g, Num a) => (a -> a -> b) -> FF f g a -> f a -> g (f b)
+ Numeric.AD.Mode.Reverse: jacobianWith' :: (Traversable f, Functor g, Num a) => (a -> a -> b) -> FF f g a -> f a -> g (a, f b)
+ Numeric.AD.Mode.Reverse: lift :: (Mode t, Num a) => a -> t a
+ Numeric.AD.Mode.Reverse: newtype AD f a
+ Numeric.AD.Mode.Reverse: runAD :: AD f a -> f a
+ Numeric.AD.Mode.Reverse: type UF f a = forall s. (Mode s) => AD s a -> f (AD s a)
+ Numeric.AD.Mode.Reverse: type FF f g a = forall s. (Mode s) => f (AD s a) -> g (AD s a)
+ Numeric.AD.Mode.Reverse: zero :: (Mode t, Num a) => t a
+ Numeric.AD.Mode.Tower: (*^) :: (Mode t, Num a) => a -> t a -> t a
+ Numeric.AD.Mode.Tower: (<+>) :: (Mode t, Num a) => t a -> t a -> t a
+ Numeric.AD.Mode.Tower: (^*) :: (Mode t, Num a) => t a -> a -> t a
+ Numeric.AD.Mode.Tower: (^/) :: (Mode t, Fractional a) => t a -> a -> t a
+ Numeric.AD.Mode.Tower: AD :: f a -> AD f a
+ Numeric.AD.Mode.Tower: class (Lifted t) => Mode t
+ Numeric.AD.Mode.Tower: diff :: (Num a) => UU a -> a -> a
+ Numeric.AD.Mode.Tower: diff' :: (Num a) => UU a -> a -> (a, a)
+ Numeric.AD.Mode.Tower: diffs :: (Num a) => UU a -> a -> [a]
+ Numeric.AD.Mode.Tower: diffs0 :: (Num a) => UU a -> a -> [a]
+ Numeric.AD.Mode.Tower: diffs0F :: (Functor f, Num a) => UF f a -> a -> f [a]
+ Numeric.AD.Mode.Tower: diffs0M :: (Monad m, Num a) => UF m a -> a -> m [a]
+ Numeric.AD.Mode.Tower: diffsF :: (Functor f, Num a) => UF f a -> a -> f [a]
+ Numeric.AD.Mode.Tower: diffsM :: (Monad m, Num a) => UF m a -> a -> m [a]
+ Numeric.AD.Mode.Tower: du :: (Functor f, Num a) => FU f a -> f (a, a) -> a
+ Numeric.AD.Mode.Tower: du' :: (Functor f, Num a) => FU f a -> f (a, a) -> (a, a)
+ Numeric.AD.Mode.Tower: duF :: (Functor f, Functor g, Num a) => FF f g a -> f (a, a) -> g a
+ Numeric.AD.Mode.Tower: duF' :: (Functor f, Functor g, Num a) => FF f g a -> f (a, a) -> g (a, a)
+ Numeric.AD.Mode.Tower: dus :: (Functor f, Num a) => FU f a -> f [a] -> [a]
+ Numeric.AD.Mode.Tower: dus0 :: (Functor f, Num a) => FU f a -> f [a] -> [a]
+ Numeric.AD.Mode.Tower: dus0F :: (Functor f, Functor g, Num a) => FF f g a -> f [a] -> g [a]
+ Numeric.AD.Mode.Tower: dusF :: (Functor f, Functor g, Num a) => FF f g a -> f [a] -> g [a]
+ Numeric.AD.Mode.Tower: lift :: (Mode t, Num a) => a -> t a
+ Numeric.AD.Mode.Tower: maclaurin :: (Fractional a) => UU a -> a -> [a]
+ Numeric.AD.Mode.Tower: maclaurin0 :: (Fractional a) => UU a -> a -> [a]
+ Numeric.AD.Mode.Tower: newtype AD f a
+ Numeric.AD.Mode.Tower: runAD :: AD f a -> f a
+ Numeric.AD.Mode.Tower: taylor :: (Fractional a) => UU a -> a -> a -> [a]
+ Numeric.AD.Mode.Tower: taylor0 :: (Fractional a) => UU a -> a -> a -> [a]
+ Numeric.AD.Mode.Tower: type UF f a = forall s. (Mode s) => AD s a -> f (AD s a)
+ Numeric.AD.Mode.Tower: type FF f g a = forall s. (Mode s) => f (AD s a) -> g (AD s a)
+ Numeric.AD.Mode.Tower: zero :: (Mode t, Num a) => t a
+ Numeric.AD.Types: (:-) :: a -> Tensors f (f a) -> Tensors f a
+ Numeric.AD.Types: (:<) :: a -> f (Stream f a) -> Stream f a
+ Numeric.AD.Types: AD :: f a -> AD f a
+ Numeric.AD.Types: data Stream f a
+ Numeric.AD.Types: data Tensors f a
+ Numeric.AD.Types: headS :: Stream f a -> a
+ Numeric.AD.Types: headT :: Tensors f a -> a
+ Numeric.AD.Types: newtype AD f a
+ Numeric.AD.Types: runAD :: AD f a -> f a
+ Numeric.AD.Types: tailS :: Stream f a -> f (Stream f a)
+ Numeric.AD.Types: tailT :: Tensors f a -> Tensors f (f a)
+ Numeric.AD.Types: tensors :: (Functor f) => Stream f a -> Tensors f a
+ Numeric.AD.Types: type UF f a = forall s. (Mode s) => AD s a -> f (AD s a)
+ Numeric.AD.Types: type FF f g a = forall s. (Mode s) => f (AD s a) -> g (AD s a)
+ Numeric.AD.Types: unfoldS :: (Functor f) => (a -> (b, f a)) -> a -> Stream f b

Files

Numeric/AD.hs view
@@ -1,4 +1,3 @@-{-# LANGUAGE Rank2Types, TypeFamilies #-} ----------------------------------------------------------------------------- -- | -- Module      :  Numeric.AD@@ -8,192 +7,14 @@ -- Stability   :  experimental -- Portability :  GHC only ----- Mixed-Mode Automatic Differentiation.+-- Mixed-mode automatic differentiation combinators. ----- Each combinator exported from this module chooses an appropriate AD mode. -----------------------------------------------------------------------------  module Numeric.AD-    (-    -- * Gradients (Reverse Mode)-      grad-    , grad'-    , gradWith-    , gradWith'--    -- * Jacobians (Mixed Mode)-    , jacobian-    , jacobian'-    , jacobianWith-    , jacobianWith'--    -- * Monadic Gradient/Jacobian (Reverse Mode)-    , gradM-    , gradM'-    , gradWithM-    , gradWithM'--    -- * Functorial Gradient/Jacobian (Reverse Mode)-    , gradF-    , gradF'-    , gradWithF-    , gradWithF'--    -- * Transposed Jacobians (Forward Mode)-    , jacobianT-    , jacobianWithT--    -- * Hessian (Forward-On-Reverse)-    , hessian--    -- * Hessian Tensors (Forward-On-Mixed)-    , hessianTensor--    -- * Hessian Vector Products (Forward-On-Reverse)-    , hessianProduct-    , hessianProduct'--    -- * Derivatives (Forward Mode)-    , diff-    , diffF--    , diff'-    , diffF'--    -- * Derivatives (Tower)-    , diffs-    , diffsF--    , diffs0-    , diffs0F--    -- * Directional Derivatives (Forward Mode)-    , du-    , du'-    , duF-    , duF'--    -- * Directional Derivatives (Tower)-    , dus-    , dus0-    , dusF-    , dus0F--    -- * Taylor Series (Tower)-    , taylor-    , taylor0--    -- * Maclaurin Series (Tower)-    , maclaurin-    , maclaurin0--    -- * Monadic Combinators (Forward Mode)-    , diffM-    , diffM'--    -- * Exposed Types-    , UU, UF, FU, FF-    , AD(..)-    , Mode(..)+    ( module Numeric.AD.Mode.Mixed+    , module Numeric.AD.Newton     ) where -import Data.Traversable (Traversable)-import Data.Foldable (Foldable, foldr')-import Control.Applicative-import Numeric.AD.Internal (AD(..), UU, UF, FU, FF)-import Numeric.AD.Internal.Identity (probed, unprobe)-import Numeric.AD.Internal.Classes  (Mode(..))-import Numeric.AD.Forward  (diff, diff', diffF, diffF', du, du', duF, duF', diffM, diffM', jacobianT, jacobianWithT) -import Numeric.AD.Tower    (diffsF, diffs0F , diffs, diffs0, taylor, taylor0, maclaurin, maclaurin0, dus, dus0, dusF, dus0F)-import Numeric.AD.Reverse  (grad, grad', gradWith, gradWith', gradM, gradM', gradWithM, gradWithM', gradF, gradF', gradWithF, gradWithF')-import Numeric.AD.Internal.Composition--import qualified Numeric.AD.Forward as Forward-import qualified Numeric.AD.Reverse as Reverse---- | Calculate the Jacobian of a non-scalar-to-non-scalar function, automatically choosing between forward and reverse mode AD based on the number of inputs and outputs.------ If you need to support functions where the output is only a 'Functor' or 'Monad', consider 'Numeric.AD.Reverse.jacobian' or 'Numeric.AD.Reverse.gradM' from "Numeric.AD.Reverse".-jacobian :: (Traversable f, Traversable g, Num a) => FF f g a -> f a -> g (f a)-jacobian f bs = snd <$> jacobian' f bs-{-# INLINE jacobian #-}---- | Calculate both the answer and Jacobian of a non-scalar-to-non-scalar function, automatically choosing between forward- and reverse- mode AD based on the relative, number of inputs and outputs.------ If you need to support functions where the output is only a 'Functor' or 'Monad', consider 'Numeric.AD.Reverse.jacobian'' or 'Numeric.AD.Reverse.gradM'' from "Numeric.AD.Reverse".-jacobian' :: (Traversable f, Traversable g, Num a) => FF f g a -> f a -> g (a, f a)-jacobian' f bs | n == 0    = fmap (\x -> (unprobe x, bs)) as-               | n > m     = Reverse.jacobian' f bs-               | otherwise = Forward.jacobian' f bs-    where-        as = f (probed bs)-        n = size bs-        m = size as-        size :: Foldable f => f a -> Int-        size = foldr' (\_ b -> 1 + b) 0-{-# INLINE jacobian' #-}---- | @'jacobianWith' g f@ calculates the Jacobian of a non-scalar-to-non-scalar function, automatically choosing between forward and reverse mode AD based on the number of inputs and outputs.------ The resulting Jacobian matrix is then recombined element-wise with the input using @g@.------ If you need to support functions where the output is only a 'Functor' or 'Monad', consider 'Numeric.AD.Reverse.jacobianWith' or 'Numeric.AD.Reverse.gradWithM' from "Numeric.AD.Reverse".-jacobianWith :: (Traversable f, Traversable g, Num a) => (a -> a -> b) -> FF f g a -> f a -> g (f b)-jacobianWith g f bs = snd <$> jacobianWith' g f bs-{-# INLINE jacobianWith #-}---- | @'jacobianWith'' g f@ calculates the answer and Jacobian of a non-scalar-to-non-scalar function, automatically choosing between forward and reverse mode AD based on the number of inputs and outputs.------ The resulting Jacobian matrix is then recombined element-wise with the input using @g@.------ If you need to support functions where the output is only a 'Functor' or 'Monad', consider 'Numeric.AD.Reverse.jacobianWith'' or 'Numeric.AD.Reverse.gradWithM'' from "Numeric.AD.Reverse".-jacobianWith' :: (Traversable f, Traversable g, Num a) => (a -> a -> b) -> FF f g a -> f a -> g (a, f b)-jacobianWith' g f bs-    | n == 0    = fmap (\x -> (unprobe x, undefined <$> bs)) as-    | n > m     = Reverse.jacobianWith' g f bs-    | otherwise = Forward.jacobianWith' g f bs-    where-        as = f (probed bs)-        n = size bs-        m = size as-        size :: Foldable f => f a -> Int-        size = foldr' (\_ b -> 1 + b) 0-{-# INLINE jacobianWith' #-}---- | @'hessianProduct' f wv@ computes the product of the hessian @H@ of a non-scalar-to-scalar function @f@ at @w = 'fst' <$> wv@ with a vector @v = snd <$> wv@ using \"Pearlmutter\'s method\" from <http://citeseerx.ist.psu.edu/viewdoc/summary?doi=10.1.1.29.6143>, which states:------ > H v = (d/dr) grad_w (w + r v) | r = 0--- --- Or in other words, we take the directional derivative of the gradient.-hessianProduct :: (Traversable f, Num a) => FU f a -> f (a, a) -> f a-hessianProduct f = duF (grad (decomposeMode . f . fmap composeMode))---- | @'hessianProduct'' f wv@ computes both the gradient of a non-scalar-to-scalar @f@ at @w = 'fst' <$> wv@ and the product of the hessian @H@ at @w@ with a vector @v = snd <$> wv@ using \"Pearlmutter's method\". The outputs are returned wrapped in the same functor.------ > H v = (d/dr) grad_w (w + r v) | r = 0--- --- Or in other words, we take the directional derivative of the gradient.--- -hessianProduct' :: (Traversable f, Num a) => FU f a -> f (a, a) -> f (a, a)-hessianProduct' f = duF' (grad (decomposeMode . f . fmap composeMode))---- hessianProductWith' :: (Traversable f, Num a) => (a -> a -> a -> a -> b) -> (forall s. Mode s. f (AD s a) -> AD s a) -> f (a, a) -> f b---- | Compute the hessian via the jacobian of the gradient. gradient is computed in reverse mode and then the jacobian is computed in forward mode.-hessian :: (Traversable f, Num a) => FU f a -> f a -> f (f a)-hessian f = Forward.jacobian (grad (decomposeMode . f . fmap composeMode))---- | Compute the order 3 Hessian tensor on a non-scalar-to-non-scalar function via the forward-mode Jacobian of the mixed-mode Jacobian of the function.-hessianTensor :: (Traversable f, Traversable g, Num a) => FF f g a -> f a -> g (f (f a))-hessianTensor f = decomposeFunctor . Forward.jacobian (ComposeFunctor . jacobian (fmap decomposeMode . f . fmap composeMode))---- data f :> a = a :< f (f :> a)--- data f :- a = a :- (f :- f a) | Zero-{--flatten :: (f :> a) -> (f :- a)-grads :: (Traversable f, Num a) => (forall s. Mode s => f (AD s a) -> AD s a) -> f a -> (f :- a) -grads f b = a :- da :- d2a :- Zero-    (a, da) = grad2 f a-    dda = Forward.jacobian (grad (decomposeMode . f . fmap composeMode)-    ddda = Forward--}+import Numeric.AD.Mode.Mixed+import Numeric.AD.Newton hiding (Mode(..), AD(..), UU, UF, FU, FF)
+ Numeric/AD/Classes.hs view
@@ -0,0 +1,22 @@+-----------------------------------------------------------------------------+-- |+-- Module      :  Numeric.AD.Classes+-- Copyright   :  (c) Edward Kmett 2010+-- License     :  BSD3+-- Maintainer  :  ekmett@gmail.com+-- Stability   :  experimental+-- Portability :  GHC only+--+-----------------------------------------------------------------------------++module Numeric.AD.Classes+    ( +    -- * AD Modes+      Mode(..)+    -- * Comonads+    , Copointed(..)+    , Comonad(..)+    ) where++import Numeric.AD.Internal.Classes+import Numeric.AD.Internal.Comonad
− Numeric/AD/Directed.hs
@@ -1,92 +0,0 @@-{-# LANGUAGE Rank2Types #-}--------------------------------------------------------------------------------- |--- Module      :  Numeric.AD.Directed--- Copyright   :  (c) Edward Kmett 2010--- License     :  BSD3--- Maintainer  :  ekmett@gmail.com--- Stability   :  experimental--- Portability :  GHC only------ Allows the choice of AD 'Mode' to be specified at the term level for--- benchmarking or more complicated usage patterns.--------------------------------------------------------------------------------module Numeric.AD.Directed-    (-    -- * Gradients-      grad-    , grad'-    -- * Jacobians-    , jacobian-    , jacobian'-    -- * Derivatives-    , diff-    , diff'-    -- * Exposed Types-    , UU, UF, FU, FF-    , Direction(..)-    , Mode(..)-    , AD(..)-    ) where--import Prelude hiding (reverse)-import Numeric.AD.Internal-import Data.Traversable (Traversable)-import qualified Numeric.AD.Reverse as R-import qualified Numeric.AD.Forward as F-import qualified Numeric.AD.Tower as T-import qualified Numeric.AD as M-import Data.Ix---- TODO: use a data types a la carte approach, so we can expose more methods here--- rather than just the intersection of all of the functionality-data Direction-    = Forward-    | Reverse-    | Tower-    | Mixed-    deriving (Show, Eq, Ord, Read, Bounded, Enum, Ix)--diff :: Num a => Direction -> UU a -> a -> a-diff Forward = F.diff-diff Reverse = R.diff-diff Tower = T.diff-diff Mixed = F.diff-{-# INLINE diff #-}--diff' :: Num a => Direction -> UU a -> a -> (a, a)-diff' Forward = F.diff'-diff' Reverse = R.diff'-diff' Tower = T.diff'-diff' Mixed = F.diff'-{-# INLINE diff' #-}--jacobian :: (Traversable f, Traversable g, Num a) => Direction -> FF f g a -> f a -> g (f a)-jacobian Forward = F.jacobian-jacobian Reverse = R.jacobian-jacobian Tower = F.jacobian -- error "jacobian Tower: unimplemented"-jacobian Mixed = M.jacobian-{-# INLINE jacobian #-}--jacobian' :: (Traversable f, Traversable g, Num a) => Direction -> FF f g a -> f a -> g (a, f a)-jacobian' Forward = F.jacobian'-jacobian' Reverse = R.jacobian'-jacobian' Tower = F.jacobian' -- error "jacobian' Tower: unimplemented"-jacobian' Mixed = M.jacobian'-{-# INLINE jacobian' #-}--grad :: (Traversable f, Num a) => Direction -> FU f a -> f a -> f a-grad Forward = F.grad-grad Reverse = R.grad-grad Tower   = F.grad -- error "grad Tower: unimplemented"-grad Mixed   = M.grad-{-# INLINE grad #-}--grad' :: (Traversable f, Num a) => Direction -> FU f a -> f a -> (a, f a)-grad' Forward = F.grad'-grad' Reverse = R.grad'-grad' Tower   = F.grad' -- error "grad' Tower: unimplemented"-grad' Mixed   = M.grad'-{-# INLINE grad' #-}-
− Numeric/AD/Forward.hs
@@ -1,178 +0,0 @@-{-# LANGUAGE Rank2Types #-}--------------------------------------------------------------------------------- |--- Module      :  Numeric.AD.Forward--- Copyright   :  (c) Edward Kmett 2010--- License     :  BSD3--- Maintainer  :  ekmett@gmail.com--- Stability   :  experimental--- Portability :  GHC only------ Forward mode automatic differentiation-----------------------------------------------------------------------------------module Numeric.AD.Forward-    (-    -- * Gradient-      grad-    , grad'-    , gradWith-    , gradWith'-    -- * Jacobian-    , jacobian-    , jacobian'-    , jacobianWith-    , jacobianWith'-    -- * Transposed Jacobian-    , jacobianT-    , jacobianWithT-    -- * Hessian Product-    , hessianProduct-    , hessianProduct'-    -- * Derivatives-    , diff-    , diff'-    , diffF-    , diffF'-    -- * Directional Derivatives-    , du-    , du'-    , duF-    , duF'-    -- * Monadic Combinators-    , diffM-    , diffM'-    -- * Exposed Types-    , UU, UF, FU, FF-    , AD(..)-    , Mode(..)-    ) where--import Data.Traversable (Traversable)-import Control.Applicative-import Control.Monad (liftM)-import Numeric.AD.Internal-import Numeric.AD.Internal.Composition-import Numeric.AD.Internal.Forward--du :: (Functor f, Num a) => FU f a -> f (a, a) -> a-du f = tangent . f . fmap (uncurry bundle)-{-# INLINE du #-}--du' :: (Functor f, Num a) => FU f a -> f (a, a) -> (a, a)-du' f = unbundle . f . fmap (uncurry bundle)-{-# INLINE du' #-}--duF :: (Functor f, Functor g, Num a) => FF f g a -> f (a, a) -> g a-duF f = fmap tangent . f . fmap (uncurry bundle)-{-# INLINE duF #-}--duF' :: (Functor f, Functor g, Num a) => FF f g a -> f (a, a) -> g (a, a)-duF' f = fmap unbundle . f . fmap (uncurry bundle)-{-# INLINE duF' #-}---- | The 'diff' function calculates the first derivative of a scalar-to-scalar function by forward-mode 'AD'------ > diff sin == cos-diff :: Num a => UU a -> a -> a-diff f a = tangent $ apply f a-{-# INLINE diff #-}---- | The 'd'UU' function calculates the result and first derivative of scalar-to-scalar function by F'orward' 'AD'--- --- > d' sin == sin &&& cos--- > d' f = f &&& d f-diff' :: Num a => UU a -> a -> (a, a)-diff' f a = unbundle $ apply f a-{-# INLINE diff' #-}---- | The 'diffF' function calculates the first derivative of scalar-to-nonscalar function by F'orward' 'AD'-diffF :: (Functor f, Num a) => UF f a -> a -> f a-diffF f a = tangent <$> apply f a-{-# INLINE diffF #-}---- | The 'diffF'' function calculates the result and first derivative of a scalar-to-non-scalar function by F'orward' 'AD'-diffF' :: (Functor f, Num a) => UF f a -> a -> f (a, a)-diffF' f a = unbundle <$> apply f a-{-# INLINE diffF' #-}---- | The 'dUM' function calculates the first derivative of scalar-to-scalar monadic function by F'orward' 'AD'-diffM :: (Monad m, Num a) => UF m a -> a -> m a-diffM f a = tangent `liftM` apply f a-{-# INLINE diffM #-}---- | The 'd'UM' function calculates the result and first derivative of a scalar-to-scalar monadic function by F'orward' 'AD'-diffM' :: (Monad m, Num a) => UF m a -> a -> m (a, a)-diffM' f a = unbundle `liftM` apply f a-{-# INLINE diffM' #-}---- | A fast, simple transposed Jacobian computed with forward-mode AD.-jacobianT :: (Traversable f, Functor g, Num a) => FF f g a -> f a -> f (g a)-jacobianT f = bind (fmap tangent . f)-{-# INLINE jacobianT #-}---- | A fast, simple transposed Jacobian computed with forward-mode AD.-jacobianWithT :: (Traversable f, Functor g, Num a) => (a -> a -> b) -> FF f g a -> f a -> f (g b)-jacobianWithT g f = bindWith g' f-    where g' a ga = g a . tangent <$> ga-{-# INLINE jacobianWithT #-}--jacobian :: (Traversable f, Traversable g, Num a) => FF f g a -> f a -> g (f a)-jacobian f as = transposeWith (const id) t p-    where-        (p, t) = bind' (fmap tangent . f) as-{-# INLINE jacobian #-}--jacobianWith :: (Traversable f, Traversable g, Num a) => (a -> a -> b) -> FF f g a -> f a -> g (f b)-jacobianWith g f as = transposeWith (const id) t p-    where-        (p, t) = bindWith' g' f as-        g' a ga = g a . tangent <$> ga-{-# INLINE jacobianWith #-}--jacobian' :: (Traversable f, Traversable g, Num a) => FF f g a -> f a -> g (a, f a)-jacobian' f as = transposeWith row t p-    where-        (p, t) = bind' f as-        row x as' = (primal x, tangent <$> as')-{-# INLINE jacobian' #-}--jacobianWith' :: (Traversable f, Traversable g, Num a) => (a -> a -> b) -> FF f g a -> f a -> g (a, f b)-jacobianWith' g f as = transposeWith row t p-    where-        (p, t) = bindWith' g' f as-        row x as' = (primal x, as')-        g' a ga = g a . tangent <$> ga-{-# INLINE jacobianWith' #-}--grad :: (Traversable f, Num a) => FU f a -> f a -> f a-grad f = bind (tangent . f)-{-# INLINE grad #-}--grad' :: (Traversable f, Num a) => FU f a -> f a -> (a, f a)-grad' f as = (primal b, tangent <$> bs)-    where-        (b, bs) = bind' f as-{-# INLINE grad' #-}--gradWith :: (Traversable f, Num a) => (a -> a -> b) -> FU f a -> f a -> f b-gradWith g f = bindWith g (tangent . f)-{-# INLINE gradWith #-}--gradWith' :: (Traversable f, Num a) => (a -> a -> b) -> FU f a -> f a -> (a, f b)-gradWith' g f = bindWith' g (tangent . f)-{-# INLINE gradWith' #-}---- | Compute the product of a vector with the Hessian using forward-on-forward-mode AD. -hessianProduct :: (Traversable f, Num a) => FU f a -> f (a, a) -> f a-hessianProduct f = duF $ grad $ decomposeMode . f . fmap composeMode---- | Compute the gradient and hessian product using forward-on-forward-mode AD. -hessianProduct' :: (Traversable f, Num a) => FU f a -> f (a, a) -> f (a, a)-hessianProduct' f = duF' $ grad $ decomposeMode . f . fmap composeMode---- * Experimental---- data f :> a = a :< f (f :> a)--- gradients :: (Traversable f, Num a) => FU f a -> f a -> (f :> a)
− Numeric/AD/Internal.hs
@@ -1,19 +0,0 @@--- {-# OPTIONS_HADDOCK hide, prune #-}--------------------------------------------------------------------------------- |--- Module      :  Numeric.AD.Internal--- Copyright   :  (c) Edward Kmett 2010--- License     :  BSD3--- Maintainer  :  ekmett@gmail.com--- Stability   :  experimental--- Portability :  GHC only----------------------------------------------------------------------------------module Numeric.AD.Internal-    ( module Numeric.AD.Internal.Classes-    , module Numeric.AD.Internal.Types-    ) where--import Numeric.AD.Internal.Classes-import Numeric.AD.Internal.Types-
Numeric/AD/Internal/Classes.hs view
@@ -28,6 +28,7 @@ import Control.Applicative import Data.Char import Language.Haskell.TH+import Numeric.AD.Internal.Combinators (on)  infixl 8 **! infixl 7 *!, /!, ^*, *^, ^/@@ -155,9 +156,6 @@ square1 :: (Lifted t, Num a) => t a -> t a square1 x = x *! x {-# INLINE square1 #-}--on :: (a -> a -> c) -> (b -> a) -> b -> b -> c-on f g a b = f (g a) (g b)  discrete1 :: (Primal t, Num a) => (a -> c) -> t a -> c discrete1 f x = f (primal x)
Numeric/AD/Internal/Comonad.hs view
@@ -1,5 +1,5 @@ {-# LANGUAGE TypeOperators, TemplateHaskell, ScopedTypeVariables #-}--- {-# OPTIONS_HADDOCK hide #-}+{-# OPTIONS_HADDOCK hide #-} ----------------------------------------------------------------------------- -- | -- Module      :  Numeric.AD.Internal.Comonad
Numeric/AD/Internal/Composition.hs view
@@ -23,7 +23,8 @@ import Data.Typeable (Typeable1(..), Typeable(..), TyCon, mkTyCon, mkTyConApp, typeOfDefault, gcast1) import Data.Foldable (Foldable(foldMap)) import Data.Traversable (Traversable(traverse))-import Numeric.AD.Internal+import Numeric.AD.Internal.Classes+import Numeric.AD.Internal.Types  -- | Functor composition, used to nest the use of jacobian and grad newtype ComposeFunctor f g a = ComposeFunctor { decomposeFunctor :: f (g a) }
Numeric/AD/Internal/Forward.hs view
@@ -33,7 +33,8 @@ import Data.Foldable (Foldable, toList) import Data.Data import Control.Applicative-import Numeric.AD.Internal+import Numeric.AD.Internal.Types+import Numeric.AD.Internal.Classes import Numeric.AD.Internal.Identity  data Forward a = Forward a a deriving (Show, Data, Typeable)
Numeric/AD/Internal/Iterated.hs view
@@ -25,7 +25,8 @@ import Data.Traversable import Data.Data (Data(..), mkDataType, DataType, mkConstr, Constr, constrIndex, Fixity(Infix)) import Data.Typeable (Typeable1(..), Typeable(..), TyCon, mkTyCon, mkTyConApp, typeOfDefault, gcast1)-import Numeric.AD.Internal+import Numeric.AD.Internal.Types+import Numeric.AD.Internal.Classes import Numeric.AD.Internal.Comonad import Numeric.AD.Internal.Combinators (on) -- import qualified Numeric.AD.Internal.Forward
Numeric/AD/Internal/Reverse.hs view
@@ -50,7 +50,8 @@ import Language.Haskell.TH import Data.Data (Data) import Data.Typeable (Typeable)-import Numeric.AD.Internal+import Numeric.AD.Internal.Types+import Numeric.AD.Internal.Classes import Numeric.AD.Internal.Identity  -- | A @Tape@ records the information needed back propagate from the output to each input during 'Reverse' 'Mode' AD.
Numeric/AD/Internal/Stream.hs view
@@ -1,5 +1,5 @@ {-# LANGUAGE StandaloneDeriving, FlexibleContexts, UndecidableInstances #-}--- {-# OPTIONS_HADDOCK hide #-}+{-# OPTIONS_HADDOCK hide #-} ----------------------------------------------------------------------------- -- | -- Module      :  Numeric.AD.Internal.Stream
Numeric/AD/Internal/Tensors.hs view
@@ -1,5 +1,5 @@ {-# LANGUAGE TypeOperators, TemplateHaskell, ScopedTypeVariables #-}--- {-# OPTIONS_HADDOCK hide #-}+{-# OPTIONS_HADDOCK hide #-} ----------------------------------------------------------------------------- -- | -- Module      :  Numeric.AD.Internal.Tensors@@ -22,7 +22,7 @@ import Data.Foldable import Data.Traversable import Data.Monoid-import Data.Typeable (Typeable1(..), Typeable(..), TyCon, mkTyCon, mkTyConApp, typeOfDefault, gcast1)+import Data.Typeable (Typeable1(..), Typeable(..), TyCon, mkTyCon, mkTyConApp, typeOfDefault) import Numeric.AD.Internal.Comonad import Numeric.AD.Internal.Stream 
Numeric/AD/Internal/Tower.hs view
@@ -32,7 +32,8 @@ import Data.Data (Data) import Data.Typeable (Typeable) import Language.Haskell.TH-import Numeric.AD.Internal+import Numeric.AD.Internal.Types+import Numeric.AD.Internal.Classes  -- | @Tower@ is an AD 'Mode' that calculates a tangent tower by forward AD, and provides fast 'diffsUU', 'diffsUF' newtype Tower a = Tower { getTower :: [a] } deriving (Data, Typeable)
Numeric/AD/Internal/Types.hs view
@@ -1,5 +1,5 @@ {-# LANGUAGE Rank2Types, GeneralizedNewtypeDeriving, TemplateHaskell, FlexibleContexts, FlexibleInstances, MultiParamTypeClasses, UndecidableInstances #-}--- {-# OPTIONS_HADDOCK hide, prune #-}+{-# OPTIONS_HADDOCK hide #-} ----------------------------------------------------------------------------- -- | -- Module      :  Numeric.AD.Internal.Types
+ Numeric/AD/Mode/Directed.hs view
@@ -0,0 +1,93 @@+{-# LANGUAGE Rank2Types #-}+-----------------------------------------------------------------------------+-- |+-- Module      :  Numeric.AD.Mode.Directed+-- Copyright   :  (c) Edward Kmett 2010+-- License     :  BSD3+-- Maintainer  :  ekmett@gmail.com+-- Stability   :  experimental+-- Portability :  GHC only+--+-- Allows the choice of AD 'Mode' to be specified at the term level for+-- benchmarking or more complicated usage patterns.+-----------------------------------------------------------------------------++module Numeric.AD.Mode.Directed+    (+    -- * Gradients+      grad+    , grad'+    -- * Jacobians+    , jacobian+    , jacobian'+    -- * Derivatives+    , diff+    , diff'+    -- * Exposed Types+    , UU, UF, FU, FF+    , Direction(..)+    , Mode(..)+    , AD(..)+    ) where++import Prelude hiding (reverse)+import Numeric.AD.Types+import Numeric.AD.Classes+import Data.Traversable (Traversable)+import qualified Numeric.AD.Mode.Reverse as R+import qualified Numeric.AD.Mode.Forward as F+import qualified Numeric.AD.Mode.Tower as T+import qualified Numeric.AD.Mode.Mixed as M+import Data.Ix++-- TODO: use a data types a la carte approach, so we can expose more methods here+-- rather than just the intersection of all of the functionality+data Direction+    = Forward+    | Reverse+    | Tower+    | Mixed+    deriving (Show, Eq, Ord, Read, Bounded, Enum, Ix)++diff :: Num a => Direction -> UU a -> a -> a+diff Forward = F.diff+diff Reverse = R.diff+diff Tower = T.diff+diff Mixed = F.diff+{-# INLINE diff #-}++diff' :: Num a => Direction -> UU a -> a -> (a, a)+diff' Forward = F.diff'+diff' Reverse = R.diff'+diff' Tower = T.diff'+diff' Mixed = F.diff'+{-# INLINE diff' #-}++jacobian :: (Traversable f, Traversable g, Num a) => Direction -> FF f g a -> f a -> g (f a)+jacobian Forward = F.jacobian+jacobian Reverse = R.jacobian+jacobian Tower = F.jacobian -- error "jacobian Tower: unimplemented"+jacobian Mixed = M.jacobian+{-# INLINE jacobian #-}++jacobian' :: (Traversable f, Traversable g, Num a) => Direction -> FF f g a -> f a -> g (a, f a)+jacobian' Forward = F.jacobian'+jacobian' Reverse = R.jacobian'+jacobian' Tower = F.jacobian' -- error "jacobian' Tower: unimplemented"+jacobian' Mixed = M.jacobian'+{-# INLINE jacobian' #-}++grad :: (Traversable f, Num a) => Direction -> FU f a -> f a -> f a+grad Forward = F.grad+grad Reverse = R.grad+grad Tower   = F.grad -- error "grad Tower: unimplemented"+grad Mixed   = M.grad+{-# INLINE grad #-}++grad' :: (Traversable f, Num a) => Direction -> FU f a -> f a -> (a, f a)+grad' Forward = F.grad'+grad' Reverse = R.grad'+grad' Tower   = F.grad' -- error "grad' Tower: unimplemented"+grad' Mixed   = M.grad'+{-# INLINE grad' #-}+
+ Numeric/AD/Mode/Forward.hs view
@@ -0,0 +1,179 @@+{-# LANGUAGE Rank2Types #-}+-----------------------------------------------------------------------------+-- |+-- Module      :  Numeric.AD.Mode.Forward+-- Copyright   :  (c) Edward Kmett 2010+-- License     :  BSD3+-- Maintainer  :  ekmett@gmail.com+-- Stability   :  experimental+-- Portability :  GHC only+--+-- Forward mode automatic differentiation+--+-----------------------------------------------------------------------------++module Numeric.AD.Mode.Forward+    (+    -- * Gradient+      grad+    , grad'+    , gradWith+    , gradWith'+    -- * Jacobian+    , jacobian+    , jacobian'+    , jacobianWith+    , jacobianWith'+    -- * Transposed Jacobian+    , jacobianT+    , jacobianWithT+    -- * Hessian Product+    , hessianProduct+    , hessianProduct'+    -- * Derivatives+    , diff+    , diff'+    , diffF+    , diffF'+    -- * Directional Derivatives+    , du+    , du'+    , duF+    , duF'+    -- * Monadic Combinators+    , diffM+    , diffM'+    -- * Exposed Types+    , UU, UF, FU, FF+    , AD(..)+    , Mode(..)+    ) where++import Data.Traversable (Traversable)+import Control.Applicative+import Control.Monad (liftM)+import Numeric.AD.Types+import Numeric.AD.Internal.Classes+import Numeric.AD.Internal.Composition+import Numeric.AD.Internal.Forward++du :: (Functor f, Num a) => FU f a -> f (a, a) -> a+du f = tangent . f . fmap (uncurry bundle)+{-# INLINE du #-}++du' :: (Functor f, Num a) => FU f a -> f (a, a) -> (a, a)+du' f = unbundle . f . fmap (uncurry bundle)+{-# INLINE du' #-}++duF :: (Functor f, Functor g, Num a) => FF f g a -> f (a, a) -> g a+duF f = fmap tangent . f . fmap (uncurry bundle)+{-# INLINE duF #-}++duF' :: (Functor f, Functor g, Num a) => FF f g a -> f (a, a) -> g (a, a)+duF' f = fmap unbundle . f . fmap (uncurry bundle)+{-# INLINE duF' #-}++-- | The 'diff' function calculates the first derivative of a scalar-to-scalar function by forward-mode 'AD'+--+-- > diff sin == cos+diff :: Num a => UU a -> a -> a+diff f a = tangent $ apply f a+{-# INLINE diff #-}++-- | The 'd'UU' function calculates the result and first derivative of scalar-to-scalar function by F'orward' 'AD'+-- +-- > d' sin == sin &&& cos+-- > d' f = f &&& d f+diff' :: Num a => UU a -> a -> (a, a)+diff' f a = unbundle $ apply f a+{-# INLINE diff' #-}++-- | The 'diffF' function calculates the first derivative of scalar-to-nonscalar function by F'orward' 'AD'+diffF :: (Functor f, Num a) => UF f a -> a -> f a+diffF f a = tangent <$> apply f a+{-# INLINE diffF #-}++-- | The 'diffF'' function calculates the result and first derivative of a scalar-to-non-scalar function by F'orward' 'AD'+diffF' :: (Functor f, Num a) => UF f a -> a -> f (a, a)+diffF' f a = unbundle <$> apply f a+{-# INLINE diffF' #-}++-- | The 'dUM' function calculates the first derivative of scalar-to-scalar monadic function by F'orward' 'AD'+diffM :: (Monad m, Num a) => UF m a -> a -> m a+diffM f a = tangent `liftM` apply f a+{-# INLINE diffM #-}++-- | The 'd'UM' function calculates the result and first derivative of a scalar-to-scalar monadic function by F'orward' 'AD'+diffM' :: (Monad m, Num a) => UF m a -> a -> m (a, a)+diffM' f a = unbundle `liftM` apply f a+{-# INLINE diffM' #-}++-- | A fast, simple transposed Jacobian computed with forward-mode AD.+jacobianT :: (Traversable f, Functor g, Num a) => FF f g a -> f a -> f (g a)+jacobianT f = bind (fmap tangent . f)+{-# INLINE jacobianT #-}++-- | A fast, simple transposed Jacobian computed with forward-mode AD.+jacobianWithT :: (Traversable f, Functor g, Num a) => (a -> a -> b) -> FF f g a -> f a -> f (g b)+jacobianWithT g f = bindWith g' f+    where g' a ga = g a . tangent <$> ga+{-# INLINE jacobianWithT #-}++jacobian :: (Traversable f, Traversable g, Num a) => FF f g a -> f a -> g (f a)+jacobian f as = transposeWith (const id) t p+    where+        (p, t) = bind' (fmap tangent . f) as+{-# INLINE jacobian #-}++jacobianWith :: (Traversable f, Traversable g, Num a) => (a -> a -> b) -> FF f g a -> f a -> g (f b)+jacobianWith g f as = transposeWith (const id) t p+    where+        (p, t) = bindWith' g' f as+        g' a ga = g a . tangent <$> ga+{-# INLINE jacobianWith #-}++jacobian' :: (Traversable f, Traversable g, Num a) => FF f g a -> f a -> g (a, f a)+jacobian' f as = transposeWith row t p+    where+        (p, t) = bind' f as+        row x as' = (primal x, tangent <$> as')+{-# INLINE jacobian' #-}++jacobianWith' :: (Traversable f, Traversable g, Num a) => (a -> a -> b) -> FF f g a -> f a -> g (a, f b)+jacobianWith' g f as = transposeWith row t p+    where+        (p, t) = bindWith' g' f as+        row x as' = (primal x, as')+        g' a ga = g a . tangent <$> ga+{-# INLINE jacobianWith' #-}++grad :: (Traversable f, Num a) => FU f a -> f a -> f a+grad f = bind (tangent . f)+{-# INLINE grad #-}++grad' :: (Traversable f, Num a) => FU f a -> f a -> (a, f a)+grad' f as = (primal b, tangent <$> bs)+    where+        (b, bs) = bind' f as+{-# INLINE grad' #-}++gradWith :: (Traversable f, Num a) => (a -> a -> b) -> FU f a -> f a -> f b+gradWith g f = bindWith g (tangent . f)+{-# INLINE gradWith #-}++gradWith' :: (Traversable f, Num a) => (a -> a -> b) -> FU f a -> f a -> (a, f b)+gradWith' g f = bindWith' g (tangent . f)+{-# INLINE gradWith' #-}++-- | Compute the product of a vector with the Hessian using forward-on-forward-mode AD. +hessianProduct :: (Traversable f, Num a) => FU f a -> f (a, a) -> f a+hessianProduct f = duF $ grad $ decomposeMode . f . fmap composeMode++-- | Compute the gradient and hessian product using forward-on-forward-mode AD. +hessianProduct' :: (Traversable f, Num a) => FU f a -> f (a, a) -> f (a, a)+hessianProduct' f = duF' $ grad $ decomposeMode . f . fmap composeMode++-- * Experimental++-- data f :> a = a :< f (f :> a)+-- gradients :: (Traversable f, Num a) => FU f a -> f a -> (f :> a)
+ Numeric/AD/Mode/Mixed.hs view
@@ -0,0 +1,215 @@+{-# LANGUAGE Rank2Types, TypeFamilies #-}+-----------------------------------------------------------------------------+-- |+-- Module      :  Numeric.AD.Mode.Mixed+-- Copyright   :  (c) Edward Kmett 2010+-- License     :  BSD3+-- Maintainer  :  ekmett@gmail.com+-- Stability   :  experimental+-- Portability :  GHC only+--+-- Mixed-Mode Automatic Differentiation.+--+-- Each combinator exported from this module chooses an appropriate AD mode.+-----------------------------------------------------------------------------++module Numeric.AD.Mode.Mixed+    (+    -- * Gradients (Reverse Mode)+      grad+    , grad'+    , gradWith+    , gradWith'++    -- * Jacobians (Mixed Mode)+    , jacobian+    , jacobian'+    , jacobianWith+    , jacobianWith'++    -- * Monadic Gradient/Jacobian (Reverse Mode)+    , gradM+    , gradM'+    , gradWithM+    , gradWithM'++    -- * Functorial Gradient/Jacobian (Reverse Mode)+    , gradF+    , gradF'+    , gradWithF+    , gradWithF'++    -- * Transposed Jacobians (Forward Mode)+    , jacobianT+    , jacobianWithT++    -- * Hessian (Forward-On-Reverse)+    , hessian++    -- * Hessian Tensors (Forward-On-Mixed)+    , hessianTensor++    -- * Hessian Vector Products (Forward-On-Reverse)+    , hessianProduct+    , hessianProduct'++    -- * Derivatives (Forward Mode)+    , diff+    , diffF++    , diff'+    , diffF'++    -- * Derivatives (Tower)+    , diffs+    , diffsF++    , diffs0+    , diffs0F++    -- * Directional Derivatives (Forward Mode)+    , du+    , du'+    , duF+    , duF'++    -- * Directional Derivatives (Tower)+    , dus+    , dus0+    , dusF+    , dus0F++    -- * Taylor Series (Tower)+    , taylor+    , taylor0++    -- * Maclaurin Series (Tower)+    , maclaurin+    , maclaurin0++    -- * Monadic Combinators (Forward Mode)+    , diffM+    , diffM'++    -- * Exposed Types+    , UU, UF, FU, FF+    , AD(..)+    , Mode(..)+    ) where++import Data.Traversable (Traversable)+import Data.Foldable (Foldable, foldr')+import Control.Applicative++import Numeric.AD.Types (AD(..), UU, UF, FU, FF)+import Numeric.AD.Internal.Identity (probed, unprobe)+import Numeric.AD.Internal.Composition+import Numeric.AD.Classes (Mode(..))++import qualified Numeric.AD.Mode.Forward as Forward+import Numeric.AD.Mode.Forward +    ( diff, diff', diffF, diffF'+    , du, du', duF, duF'+    , diffM, diffM'+    , jacobianT, jacobianWithT+    ) ++import Numeric.AD.Mode.Tower +    ( diffsF, diffs0F, diffs, diffs0+    , taylor, taylor0, maclaurin, maclaurin0+    , dus, dus0, dusF, dus0F+    )++import qualified Numeric.AD.Mode.Reverse as Reverse+import Numeric.AD.Mode.Reverse +    ( grad, grad', gradWith, gradWith'+    , gradM, gradM', gradWithM, gradWithM'+    , gradF, gradF', gradWithF, gradWithF'+    )++-- | Calculate the Jacobian of a non-scalar-to-non-scalar function, automatically choosing between forward and reverse mode AD based on the number of inputs and outputs.+--+-- If you need to support functions where the output is only a 'Functor' or 'Monad', consider 'Numeric.AD.Reverse.jacobian' or 'Numeric.AD.Reverse.gradM' from "Numeric.AD.Reverse".+jacobian :: (Traversable f, Traversable g, Num a) => FF f g a -> f a -> g (f a)+jacobian f bs = snd <$> jacobian' f bs+{-# INLINE jacobian #-}++-- | Calculate both the answer and Jacobian of a non-scalar-to-non-scalar function, automatically choosing between forward- and reverse- mode AD based on the relative, number of inputs and outputs.+--+-- If you need to support functions where the output is only a 'Functor' or 'Monad', consider 'Numeric.AD.Reverse.jacobian'' or 'Numeric.AD.Reverse.gradM'' from "Numeric.AD.Reverse".+jacobian' :: (Traversable f, Traversable g, Num a) => FF f g a -> f a -> g (a, f a)+jacobian' f bs | n == 0    = fmap (\x -> (unprobe x, bs)) as+               | n > m     = Reverse.jacobian' f bs+               | otherwise = Forward.jacobian' f bs+    where+        as = f (probed bs)+        n = size bs+        m = size as+        size :: Foldable f => f a -> Int+        size = foldr' (\_ b -> 1 + b) 0+{-# INLINE jacobian' #-}++-- | @'jacobianWith' g f@ calculates the Jacobian of a non-scalar-to-non-scalar function, automatically choosing between forward and reverse mode AD based on the number of inputs and outputs.+--+-- The resulting Jacobian matrix is then recombined element-wise with the input using @g@.+--+-- If you need to support functions where the output is only a 'Functor' or 'Monad', consider 'Numeric.AD.Reverse.jacobianWith' or 'Numeric.AD.Reverse.gradWithM' from "Numeric.AD.Reverse".+jacobianWith :: (Traversable f, Traversable g, Num a) => (a -> a -> b) -> FF f g a -> f a -> g (f b)+jacobianWith g f bs = snd <$> jacobianWith' g f bs+{-# INLINE jacobianWith #-}++-- | @'jacobianWith'' g f@ calculates the answer and Jacobian of a non-scalar-to-non-scalar function, automatically choosing between forward and reverse mode AD based on the number of inputs and outputs.+--+-- The resulting Jacobian matrix is then recombined element-wise with the input using @g@.+--+-- If you need to support functions where the output is only a 'Functor' or 'Monad', consider 'Numeric.AD.Reverse.jacobianWith'' or 'Numeric.AD.Reverse.gradWithM'' from "Numeric.AD.Reverse".+jacobianWith' :: (Traversable f, Traversable g, Num a) => (a -> a -> b) -> FF f g a -> f a -> g (a, f b)+jacobianWith' g f bs+    | n == 0    = fmap (\x -> (unprobe x, undefined <$> bs)) as+    | n > m     = Reverse.jacobianWith' g f bs+    | otherwise = Forward.jacobianWith' g f bs+    where+        as = f (probed bs)+        n = size bs+        m = size as+        size :: Foldable f => f a -> Int+        size = foldr' (\_ b -> 1 + b) 0+{-# INLINE jacobianWith' #-}++-- | @'hessianProduct' f wv@ computes the product of the hessian @H@ of a non-scalar-to-scalar function @f@ at @w = 'fst' <$> wv@ with a vector @v = snd <$> wv@ using \"Pearlmutter\'s method\" from <http://citeseerx.ist.psu.edu/viewdoc/summary?doi=10.1.1.29.6143>, which states:+--+-- > H v = (d/dr) grad_w (w + r v) | r = 0+-- +-- Or in other words, we take the directional derivative of the gradient.+hessianProduct :: (Traversable f, Num a) => FU f a -> f (a, a) -> f a+hessianProduct f = duF (grad (decomposeMode . f . fmap composeMode))++-- | @'hessianProduct'' f wv@ computes both the gradient of a non-scalar-to-scalar @f@ at @w = 'fst' <$> wv@ and the product of the hessian @H@ at @w@ with a vector @v = snd <$> wv@ using \"Pearlmutter's method\". The outputs are returned wrapped in the same functor.+--+-- > H v = (d/dr) grad_w (w + r v) | r = 0+-- +-- Or in other words, we take the directional derivative of the gradient.+-- +hessianProduct' :: (Traversable f, Num a) => FU f a -> f (a, a) -> f (a, a)+hessianProduct' f = duF' (grad (decomposeMode . f . fmap composeMode))++-- hessianProductWith' :: (Traversable f, Num a) => (a -> a -> a -> a -> b) -> (forall s. Mode s. f (AD s a) -> AD s a) -> f (a, a) -> f b++-- | Compute the hessian via the jacobian of the gradient. gradient is computed in reverse mode and then the jacobian is computed in forward mode.+hessian :: (Traversable f, Num a) => FU f a -> f a -> f (f a)+hessian f = Forward.jacobian (grad (decomposeMode . f . fmap composeMode))++-- | Compute the order 3 Hessian tensor on a non-scalar-to-non-scalar function via the forward-mode Jacobian of the mixed-mode Jacobian of the function.+hessianTensor :: (Traversable f, Traversable g, Num a) => FF f g a -> f a -> g (f (f a))+hessianTensor f = decomposeFunctor . Forward.jacobian (ComposeFunctor . jacobian (fmap decomposeMode . f . fmap composeMode))++-- data f :> a = a :< f (f :> a)+-- data f :- a = a :- (f :- f a) | Zero+{-+flatten :: (f :> a) -> (f :- a)+grads :: (Traversable f, Num a) => (forall s. Mode s => f (AD s a) -> AD s a) -> f a -> (f :- a) +grads f b = a :- da :- d2a :- Zero+    (a, da) = grad2 f a+    dda = Forward.jacobian (grad (decomposeMode . f . fmap composeMode)+    ddda = Forward+-}
+ Numeric/AD/Mode/Reverse.hs view
@@ -0,0 +1,219 @@+{-# LANGUAGE Rank2Types, TemplateHaskell, BangPatterns #-}+-----------------------------------------------------------------------------+-- |+-- Module      :  Numeric.AD.Mode.Reverse+-- Copyright   :  (c) Edward Kmett 2010+-- License     :  BSD3+-- Maintainer  :  ekmett@gmail.com+-- Stability   :  experimental+-- Portability :  GHC only+--+-- Mixed-Mode Automatic Differentiation.+--+-- For reverse mode AD we use 'System.Mem.StableName.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.+--+-----------------------------------------------------------------------------++module Numeric.AD.Mode.Reverse+    (+    -- * Gradient+      grad+    , grad'+    , gradWith+    , gradWith'+    -- * Jacobian+    , jacobian+    , jacobian'+    , jacobianWith+    , jacobianWith'+    -- * Hessian+    , hessian+    , hessianM+    , hessianTensor+    +    -- * Derivatives+    , diff+    , diff'+    , diffF+    , diffF'+    -- * Monadic Combinators+    , diffM+    , diffM'+    , gradM+    , gradM'+    , gradWithM+    , gradWithM'+    -- * Synonyms+    , gradF+    , gradF'+    , gradWithF+    , gradWithF'+    -- * Exposed Types+    , UU, UF, FU, FF+    , AD(..)+    , Mode(..)+    ) where++import Control.Monad (liftM)+import Control.Applicative (WrappedMonad(..),(<$>))+import Data.Traversable (Traversable)++import Numeric.AD.Types+import Numeric.AD.Internal.Classes+import Numeric.AD.Internal.Composition+import Numeric.AD.Internal.Reverse++-- | The 'grad' function calculates the gradient of a non-scalar-to-scalar function with 'Reverse' AD in a single pass.+grad :: (Traversable f, Num a) => FU f a -> f a -> f a+grad f as = unbind vs (partialArray bds $ f vs)+    where (vs,bds) = bind as+{-# INLINE grad #-}++-- | The 'grad'' function calculates the result and gradient of a non-scalar-to-scalar function with 'Reverse' AD in a single pass.+grad' :: (Traversable f, Num a) => FU f a -> f a -> (a, f a)+grad' f as = (primal r, unbind vs $ partialArray bds r)+    where (vs, bds) = bind as+          r = f vs+{-# INLINE grad' #-}++-- | @'grad' g f@ function calculates the gradient of a non-scalar-to-scalar function @f@ with reverse-mode AD in a single pass.+-- The gradient is combined element-wise with the argument using the function @g@.+--+-- > grad == gradWith (\_ dx -> dx)+-- > id == gradWith const+gradWith :: (Traversable f, Num a) => (a -> a -> b) -> FU f a -> f a -> f b+gradWith g f as = unbindWith g vs (partialArray bds $ f vs)+    where (vs,bds) = bind as+{-# INLINE gradWith #-}++-- | @'grad'' g f@ calculates the result and gradient of a non-scalar-to-scalar function @f@ with 'Reverse' AD in a single pass+-- the gradient is combined element-wise with the argument using the function @g@.+--+-- > grad' == gradWith' (\_ dx -> dx)+gradWith' :: (Traversable f, Num a) => (a -> a -> b) -> FU f a -> f a -> (a, f b)+gradWith' g f as = (primal r, unbindWith g vs $ partialArray bds r)+    where (vs, bds) = bind as+          r = f vs+{-# INLINE gradWith' #-}++-- | The 'gradF' function calculates the jacobian of a non-scalar-to-non-scalar function with reverse AD lazily in @m@ passes for @m@ outputs.+gradF :: (Traversable f, Functor g, Num a) => FF f g a -> f a -> g (f a)+gradF = jacobian+{-# INLINE gradF #-}++-- | An alias for 'gradF'+jacobian :: (Traversable f, Functor g, Num a) => FF f g a -> f a -> g (f a)+jacobian f as = unbind vs . partialArray bds <$> f vs where+    (vs, bds) = bind as+{-# INLINE jacobian #-}++-- | The 'gradF'' function calculates both the result and the Jacobian of a nonscalar-to-nonscalar function, using @m@ invocations of reverse AD,+-- where @m@ is the output dimensionality. Applying @fmap snd@ to the result will recover the result of 'gradF'+gradF' :: (Traversable f, Functor g, Num a) => FF f g a -> f a -> g (a, f a)+gradF' = jacobian' +{-# INLINE gradF' #-}++-- | An alias for 'gradF''+jacobian' :: (Traversable f, Functor g, Num a) => FF f g a -> f a -> g (a, f a)+jacobian' f as = row <$> f vs where+    (vs, bds) = bind as+    row a = (primal a, unbind vs (partialArray bds a))+{-# INLINE jacobian' #-}++-- | 'gradWithF g f' calculates the Jacobian of a non-scalar-to-non-scalar function @f@ with reverse AD lazily in @m@ passes for @m@ outputs.+--+-- Instead of returning the Jacobian matrix, the elements of the matrix are combined with the input using the @g@.+--+-- > gradF == gradWithF (\_ dx -> dx)+-- > gradWithF const == (\f x -> const x <$> f x)+--+gradWithF :: (Traversable f, Functor g, Num a) => (a -> a -> b) -> FF f g a -> f a -> g (f b)+gradWithF g f as = unbindWith g vs . partialArray bds <$> f vs where+    (vs, bds) = bind as+{-# INLINE gradWithF #-}++-- | An alias for 'gradWithF'.+jacobianWith :: (Traversable f, Functor g, Num a) => (a -> a -> b) -> FF f g a -> f a -> g (f b)+jacobianWith = gradWithF +{-# INLINE jacobianWith #-}++-- | 'gradWithF' g f' calculates both the result and the Jacobian of a nonscalar-to-nonscalar function @f@, using @m@ invocations of reverse AD,+-- where @m@ is the output dimensionality. Applying @fmap snd@ to the result will recover the result of 'gradWithF'+--+-- Instead of returning the Jacobian matrix, the elements of the matrix are combined with the input using the @g@.+--+-- > jacobian' == gradWithF' (\_ dx -> dx)+--+gradWithF' :: (Traversable f, Functor g, Num a) => (a -> a -> b) -> FF f g a -> f a -> g (a, f b)+gradWithF' g f as = row <$> f vs where+    (vs, bds) = bind as+    row a = (primal a, unbindWith g vs (partialArray bds a))+{-# INLINE gradWithF' #-}++-- | An alias for 'gradWithF''+jacobianWith' :: (Traversable f, Functor g, Num a) => (a -> a -> b) -> FF f g a -> f a -> g (a, f b)+jacobianWith' = gradWithF'+{-# INLINE jacobianWith' #-}++diff :: Num a => UU a -> a -> a+diff f a = derivative $ f (var a 0)+{-# INLINE diff #-}++-- | The 'd'' function calculates the value and derivative, as a+-- pair, of a scalar-to-scalar function.+diff' :: Num a => UU a -> a -> (a, a)+diff' f a = derivative' $ f (var a 0)+{-# INLINE diff' #-}++diffF :: (Functor f, Num a) => UF f a -> a -> f a+diffF f a = derivative <$> f (var a 0)+{-# INLINE diffF #-}++diffF' :: (Functor f, Num a) => UF f a -> a -> f (a, a)+diffF' f a = derivative' <$> f (var a 0)+{-# INLINE diffF' #-}++-- * Monadic Combinators++diffM :: (Monad m, Num a) => UF m a -> a -> m a+diffM f a = liftM derivative $ f (var a 0)+{-# INLINE diffM #-}++diffM' :: (Monad m, Num a) => UF m a -> a -> m (a, a)+diffM' f a = liftM derivative' $ f (var a 0)+{-# INLINE diffM' #-}++gradM :: (Traversable f, Monad m, Num a) => FF f m a -> f a -> m (f a)+gradM f = unwrapMonad . jacobian (WrapMonad . f)+{-# INLINE gradM #-}++gradM' :: (Traversable f, Monad m, Num a) => FF f m a -> f a -> m (a, f a)+gradM' f = unwrapMonad . jacobian' (WrapMonad . f)+{-# INLINE gradM' #-}++gradWithM :: (Traversable f, Monad m, Num a) => (a -> a -> b) -> FF f m a -> f a -> m (f b)+gradWithM g f = unwrapMonad . jacobianWith g (WrapMonad . f)++gradWithM' :: (Traversable f, Monad m, Num a) => (a -> a -> b) -> FF f m a -> f a -> m (a, f b)+gradWithM' g f = unwrapMonad . jacobianWith' g (WrapMonad . f)++-- | Compute the hessian via the jacobian of the gradient. gradient is computed in reverse mode and then the jacobian is computed in reverse mode.+--+-- However, since the @'grad f :: f a -> f a'@ is square this is not as fast as using the forward-mode Jacobian of a reverse mode gradient provided by 'Numeric.AD.hessian' in "Numeric.AD".+hessian :: (Traversable f, Num a) => FU f a -> f a -> f (f a)+hessian f = jacobian (grad (decomposeMode . f . fmap composeMode))++-- | Compute the order 3 Hessian tensor on a non-scalar-to-non-scalar function via the forward-mode Jacobian of the mixed-mode Jacobian of the function.+--+-- While this is less efficient than 'Numeric.AD.hessianTensor' from "Numeric.AD" or 'Numeric.AD.Forward.hessianTensor' from "Numeric.AD.Forward", the type signature is more permissive with regards to the output non-scalar, and it may be more efficient if only a few coefficients of the result are consumed.+hessianTensor :: (Traversable f, Functor g, Num a) => FF f g a -> f a -> g (f (f a))+hessianTensor f = decomposeFunctor . jacobian (ComposeFunctor . jacobian (fmap decomposeMode . f . fmap composeMode))++-- | Compute the hessian via the reverse-mode jacobian of the reverse-mode gradient of a non-scalar-to-scalar monadic action. +--+-- While this is less efficient than 'Numeric.AD.hessianTensor' from "Numeric.AD" or 'Numeric.AD.Forward.hessianTensor' from "Numeric.AD.Forward", the type signature is more permissive with regards to the output non-scalar, and it may be more efficient if only a few coefficients of the result are consumed.+hessianM :: (Traversable f, Monad m, Num a) => FF f m a -> f a -> m (f (f a))+hessianM f = unwrapMonad . hessianTensor (WrapMonad . f)
+ Numeric/AD/Mode/Tower.hs view
@@ -0,0 +1,140 @@+{-# LANGUAGE Rank2Types, BangPatterns #-}+-----------------------------------------------------------------------------+-- |+-- Module      : Numeric.AD.Mode.Tower+-- Copyright   : (c) Edward Kmett 2010+-- License     : BSD3+-- Maintainer  : ekmett@gmail.com+-- Stability   : experimental+-- Portability : GHC only+--+-- Higher order derivatives via a \"dual number tower\".+--+-----------------------------------------------------------------------------++module Numeric.AD.Mode.Tower+    (+    -- * Taylor Series+      taylor+    , taylor0+    -- * Maclaurin Series+    , maclaurin+    , maclaurin0+    -- * Derivatives+    , diff    -- first derivative of (a -> a) +    , diff'   -- answer and first derivative of (a -> a) +    , diffs   -- answer and all derivatives of (a -> a) +    , diffs0  -- zero padded derivatives of (a -> a)+    , diffsF  -- answer and all derivatives of (a -> f a)+    , diffs0F -- zero padded derivatives of (a -> f a)+    -- * Directional Derivatives+    , du      -- directional derivative of (a -> a)+    , du'     -- answer and directional derivative of (a -> a)+    , dus     -- answer and all directional derivatives of (a -> a) +    , dus0    -- answer and all zero padded directional derivatives of (a -> a)+    , duF     -- directional derivative of (a -> f a)+    , duF'    -- answer and directional derivative of (a -> f a)+    , dusF    -- answer and all directional derivatives of (a -> f a)+    , dus0F   -- answer and all zero padded directional derivatives of (a -> a)+    -- * Monadic Combinators+    , diffsM  -- answer and all derivatives of the monadic action (a -> m a)+    , diffs0M -- answer and all zero padded derivatives of (a -> m a)+    -- * Exposed Types+    , UU, UF, FU, FF+    , Mode(..)+    , AD(..)+    ) where++import Control.Monad (liftM)+import Control.Applicative ((<$>))+import Numeric.AD.Types+import Numeric.AD.Classes+import Numeric.AD.Internal.Tower++diffs :: Num a => UU a -> a -> [a]+diffs f a = getADTower $ apply f a+{-# INLINE diffs #-}++diffs0 :: Num a => UU a -> a -> [a]+diffs0 f a = zeroPad (diffs f a)+{-# INLINE diffs0 #-}++diffsF :: (Functor f, Num a) => UF f a -> a -> f [a]+diffsF f a = getADTower <$> apply f a+{-# INLINE diffsF #-}++diffs0F :: (Functor f, Num a) => UF f a -> a -> f [a]+diffs0F f a = (zeroPad . getADTower) <$> apply f a+{-# INLINE diffs0F #-}++diffsM :: (Monad m, Num a) => UF m a -> a -> m [a]+diffsM f a = getADTower `liftM` apply f a+{-# INLINE diffsM #-}++diffs0M :: (Monad m, Num a) => UF m a -> a -> m [a]+diffs0M f a = (zeroPad . getADTower) `liftM` apply f a+{-# INLINE diffs0M #-}++taylor :: Fractional a => UU a -> a -> a -> [a]+taylor f x dx = go 1 1 (diffs f x)+    where+        go !n !acc (a:as) = a * acc : go (n + 1) (acc * dx / n) as+        go _ _ [] = []++taylor0 :: Fractional a => UU a -> a -> a -> [a]+taylor0 f x dx = zeroPad (taylor f x dx)+{-# INLINE taylor0 #-}++maclaurin :: Fractional a => UU a -> a -> [a]+maclaurin f = taylor f 0+{-# INLINE maclaurin #-}++maclaurin0 :: Fractional a => UU a -> a -> [a]+maclaurin0 f = taylor0 f 0+{-# INLINE maclaurin0 #-}++diff :: Num a => UU a -> a -> a+diff f = d . diffs f+{-# INLINE diff #-}++diff' :: Num a => UU a -> a -> (a, a)+diff' f = d' . diffs f+{-# INLINE diff' #-}++du :: (Functor f, Num a) => FU f a -> f (a, a) -> a+du f = d . getADTower . f . fmap withD+{-# INLINE du #-}++du' :: (Functor f, Num a) => FU f a -> f (a, a) -> (a, a)+du' f = d' . getADTower . f . fmap withD+{-# INLINE du' #-}++duF :: (Functor f, Functor g, Num a) => FF f g a -> f (a, a) -> g a+duF f = fmap (d . getADTower) . f . fmap withD+{-# INLINE duF #-}++duF' :: (Functor f, Functor g, Num a) => FF f g a -> f (a, a) -> g (a, a)+duF' f = fmap (d' . getADTower) . f . fmap withD+{-# INLINE duF' #-}++dus :: (Functor f, Num a) => FU f a -> f [a] -> [a]+dus f = getADTower . f . fmap tower+{-# INLINE dus #-}++dus0 :: (Functor f, Num a) => FU f a -> f [a] -> [a]+dus0 f = zeroPad . getADTower . f . fmap tower+{-# INLINE dus0 #-}++dusF :: (Functor f, Functor g, Num a) => FF f g a -> f [a] -> g [a]+dusF f = fmap getADTower . f . fmap tower+{-# INLINE dusF #-}++dus0F :: (Functor f, Functor g, Num a) => FF f g a -> f [a] -> g [a]+dus0F f = fmap getADTower . f . fmap tower+{-# INLINE dus0F #-}++-- TODO: higher order gradients+-- data f :> a = a :< f (f :> a) +-- gradients  :: (Traversable f, Num a) => FU f a -> f a -> f :> a+-- gradientsF, jacobians :: (Traversable f, Functor g, Num a) => FF f g a -> f a -> g (f :> a)+-- gradientsM :: (Traversable f, Monad m, Num a) => FF f m a -> f a -> m (f :> a)
Numeric/AD/Newton.hs view
@@ -35,11 +35,12 @@ import Prelude hiding (all) import Control.Monad (liftM) import Data.MList-import Numeric.AD.Internal import Data.Foldable (all) import Data.Traversable (Traversable)-import Numeric.AD.Forward (diff, diff', diffM, diffM')-import Numeric.AD.Reverse (gradWith', gradWithM')+import Numeric.AD.Types+import Numeric.AD.Classes+import Numeric.AD.Mode.Forward (diff, diff', diffM, diffM')+import Numeric.AD.Mode.Reverse (gradWith', gradWithM') import Numeric.AD.Internal.Composition  -- | The 'findZero' function finds a zero of a scalar function using
− Numeric/AD/Reverse.hs
@@ -1,218 +0,0 @@-{-# LANGUAGE Rank2Types, TemplateHaskell, BangPatterns #-}--------------------------------------------------------------------------------- |--- Module      :  Numeric.AD.Reverse--- Copyright   :  (c) Edward Kmett 2010--- License     :  BSD3--- Maintainer  :  ekmett@gmail.com--- Stability   :  experimental--- Portability :  GHC only------ Mixed-Mode Automatic Differentiation.------ For reverse mode AD we use 'System.Mem.StableName.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.-----------------------------------------------------------------------------------module Numeric.AD.Reverse-    (-    -- * Gradient-      grad-    , grad'-    , gradWith-    , gradWith'-    -- * Jacobian-    , jacobian-    , jacobian'-    , jacobianWith-    , jacobianWith'-    -- * Hessian-    , hessian-    , hessianM-    , hessianTensor-    -    -- * Derivatives-    , diff-    , diff'-    , diffF-    , diffF'-    -- * Monadic Combinators-    , diffM-    , diffM'-    , gradM-    , gradM'-    , gradWithM-    , gradWithM'-    -- * Synonyms-    , gradF-    , gradF'-    , gradWithF-    , gradWithF'-    -- * Exposed Types-    , UU, UF, FU, FF-    , AD(..)-    , Mode(..)-    ) where--import Control.Monad (liftM)-import Control.Applicative (WrappedMonad(..),(<$>))-import Data.Traversable (Traversable)--import Numeric.AD.Internal-import Numeric.AD.Internal.Composition-import Numeric.AD.Internal.Reverse---- | The 'grad' function calculates the gradient of a non-scalar-to-scalar function with 'Reverse' AD in a single pass.-grad :: (Traversable f, Num a) => FU f a -> f a -> f a-grad f as = unbind vs (partialArray bds $ f vs)-    where (vs,bds) = bind as-{-# INLINE grad #-}---- | The 'grad'' function calculates the result and gradient of a non-scalar-to-scalar function with 'Reverse' AD in a single pass.-grad' :: (Traversable f, Num a) => FU f a -> f a -> (a, f a)-grad' f as = (primal r, unbind vs $ partialArray bds r)-    where (vs, bds) = bind as-          r = f vs-{-# INLINE grad' #-}---- | @'grad' g f@ function calculates the gradient of a non-scalar-to-scalar function @f@ with reverse-mode AD in a single pass.--- The gradient is combined element-wise with the argument using the function @g@.------ > grad == gradWith (\_ dx -> dx)--- > id == gradWith const-gradWith :: (Traversable f, Num a) => (a -> a -> b) -> FU f a -> f a -> f b-gradWith g f as = unbindWith g vs (partialArray bds $ f vs)-    where (vs,bds) = bind as-{-# INLINE gradWith #-}---- | @'grad'' g f@ calculates the result and gradient of a non-scalar-to-scalar function @f@ with 'Reverse' AD in a single pass--- the gradient is combined element-wise with the argument using the function @g@.------ > grad' == gradWith' (\_ dx -> dx)-gradWith' :: (Traversable f, Num a) => (a -> a -> b) -> FU f a -> f a -> (a, f b)-gradWith' g f as = (primal r, unbindWith g vs $ partialArray bds r)-    where (vs, bds) = bind as-          r = f vs-{-# INLINE gradWith' #-}---- | The 'gradF' function calculates the jacobian of a non-scalar-to-non-scalar function with reverse AD lazily in @m@ passes for @m@ outputs.-gradF :: (Traversable f, Functor g, Num a) => FF f g a -> f a -> g (f a)-gradF = jacobian-{-# INLINE gradF #-}---- | An alias for 'gradF'-jacobian :: (Traversable f, Functor g, Num a) => FF f g a -> f a -> g (f a)-jacobian f as = unbind vs . partialArray bds <$> f vs where-    (vs, bds) = bind as-{-# INLINE jacobian #-}---- | The 'gradF'' function calculates both the result and the Jacobian of a nonscalar-to-nonscalar function, using @m@ invocations of reverse AD,--- where @m@ is the output dimensionality. Applying @fmap snd@ to the result will recover the result of 'gradF'-gradF' :: (Traversable f, Functor g, Num a) => FF f g a -> f a -> g (a, f a)-gradF' = jacobian' -{-# INLINE gradF' #-}---- | An alias for 'gradF''-jacobian' :: (Traversable f, Functor g, Num a) => FF f g a -> f a -> g (a, f a)-jacobian' f as = row <$> f vs where-    (vs, bds) = bind as-    row a = (primal a, unbind vs (partialArray bds a))-{-# INLINE jacobian' #-}---- | 'gradWithF g f' calculates the Jacobian of a non-scalar-to-non-scalar function @f@ with reverse AD lazily in @m@ passes for @m@ outputs.------ Instead of returning the Jacobian matrix, the elements of the matrix are combined with the input using the @g@.------ > gradF == gradWithF (\_ dx -> dx)--- > gradWithF const == (\f x -> const x <$> f x)----gradWithF :: (Traversable f, Functor g, Num a) => (a -> a -> b) -> FF f g a -> f a -> g (f b)-gradWithF g f as = unbindWith g vs . partialArray bds <$> f vs where-    (vs, bds) = bind as-{-# INLINE gradWithF #-}---- | An alias for 'gradWithF'.-jacobianWith :: (Traversable f, Functor g, Num a) => (a -> a -> b) -> FF f g a -> f a -> g (f b)-jacobianWith = gradWithF -{-# INLINE jacobianWith #-}---- | 'gradWithF' g f' calculates both the result and the Jacobian of a nonscalar-to-nonscalar function @f@, using @m@ invocations of reverse AD,--- where @m@ is the output dimensionality. Applying @fmap snd@ to the result will recover the result of 'gradWithF'------ Instead of returning the Jacobian matrix, the elements of the matrix are combined with the input using the @g@.------ > jacobian' == gradWithF' (\_ dx -> dx)----gradWithF' :: (Traversable f, Functor g, Num a) => (a -> a -> b) -> FF f g a -> f a -> g (a, f b)-gradWithF' g f as = row <$> f vs where-    (vs, bds) = bind as-    row a = (primal a, unbindWith g vs (partialArray bds a))-{-# INLINE gradWithF' #-}---- | An alias for 'gradWithF''-jacobianWith' :: (Traversable f, Functor g, Num a) => (a -> a -> b) -> FF f g a -> f a -> g (a, f b)-jacobianWith' = gradWithF'-{-# INLINE jacobianWith' #-}--diff :: Num a => UU a -> a -> a-diff f a = derivative $ f (var a 0)-{-# INLINE diff #-}---- | The 'd'' function calculates the value and derivative, as a--- pair, of a scalar-to-scalar function.-diff' :: Num a => UU a -> a -> (a, a)-diff' f a = derivative' $ f (var a 0)-{-# INLINE diff' #-}--diffF :: (Functor f, Num a) => UF f a -> a -> f a-diffF f a = derivative <$> f (var a 0)-{-# INLINE diffF #-}--diffF' :: (Functor f, Num a) => UF f a -> a -> f (a, a)-diffF' f a = derivative' <$> f (var a 0)-{-# INLINE diffF' #-}---- * Monadic Combinators--diffM :: (Monad m, Num a) => UF m a -> a -> m a-diffM f a = liftM derivative $ f (var a 0)-{-# INLINE diffM #-}--diffM' :: (Monad m, Num a) => UF m a -> a -> m (a, a)-diffM' f a = liftM derivative' $ f (var a 0)-{-# INLINE diffM' #-}--gradM :: (Traversable f, Monad m, Num a) => FF f m a -> f a -> m (f a)-gradM f = unwrapMonad . jacobian (WrapMonad . f)-{-# INLINE gradM #-}--gradM' :: (Traversable f, Monad m, Num a) => FF f m a -> f a -> m (a, f a)-gradM' f = unwrapMonad . jacobian' (WrapMonad . f)-{-# INLINE gradM' #-}--gradWithM :: (Traversable f, Monad m, Num a) => (a -> a -> b) -> FF f m a -> f a -> m (f b)-gradWithM g f = unwrapMonad . jacobianWith g (WrapMonad . f)--gradWithM' :: (Traversable f, Monad m, Num a) => (a -> a -> b) -> FF f m a -> f a -> m (a, f b)-gradWithM' g f = unwrapMonad . jacobianWith' g (WrapMonad . f)---- | Compute the hessian via the jacobian of the gradient. gradient is computed in reverse mode and then the jacobian is computed in reverse mode.------ However, since the @'grad f :: f a -> f a'@ is square this is not as fast as using the forward-mode Jacobian of a reverse mode gradient provided by 'Numeric.AD.hessian' in "Numeric.AD".-hessian :: (Traversable f, Num a) => FU f a -> f a -> f (f a)-hessian f = jacobian (grad (decomposeMode . f . fmap composeMode))---- | Compute the order 3 Hessian tensor on a non-scalar-to-non-scalar function via the forward-mode Jacobian of the mixed-mode Jacobian of the function.------ While this is less efficient than 'Numeric.AD.hessianTensor' from "Numeric.AD" or 'Numeric.AD.Forward.hessianTensor' from "Numeric.AD.Forward", the type signature is more permissive with regards to the output non-scalar, and it may be more efficient if only a few coefficients of the result are consumed.-hessianTensor :: (Traversable f, Functor g, Num a) => FF f g a -> f a -> g (f (f a))-hessianTensor f = decomposeFunctor . jacobian (ComposeFunctor . jacobian (fmap decomposeMode . f . fmap composeMode))---- | Compute the hessian via the reverse-mode jacobian of the reverse-mode gradient of a non-scalar-to-scalar monadic action. ------ While this is less efficient than 'Numeric.AD.hessianTensor' from "Numeric.AD" or 'Numeric.AD.Forward.hessianTensor' from "Numeric.AD.Forward", the type signature is more permissive with regards to the output non-scalar, and it may be more efficient if only a few coefficients of the result are consumed.-hessianM :: (Traversable f, Monad m, Num a) => FF f m a -> f a -> m (f (f a))-hessianM f = unwrapMonad . hessianTensor (WrapMonad . f)
− Numeric/AD/Tensors.hs
@@ -1,32 +0,0 @@-{-# LANGUAGE TypeOperators, TemplateHaskell, ScopedTypeVariables #-}--------------------------------------------------------------------------------- |--- Module      :  Numeric.AD.Tensors--- Copyright   :  (c) Edward Kmett 2010--- License     :  BSD3--- Maintainer  :  ekmett@gmail.com--- Stability   :  experimental--- Portability :  GHC only-----------------------------------------------------------------------------------module Numeric.AD.Tensors-    ( -    -- * Tensors-      Tensors(..)-    , headT-    , tailT-    , tensors-    -- * f-Branching Streams-    , Stream(..)-    , headS-    , tailS-    , unfoldS-    -- * Comonads-    , Copointed(..)-    , Comonad(..)-    ) where--import Numeric.AD.Internal.Comonad-import Numeric.AD.Internal.Stream-import Numeric.AD.Internal.Tensors
− Numeric/AD/Tower.hs
@@ -1,139 +0,0 @@-{-# LANGUAGE Rank2Types, BangPatterns #-}--------------------------------------------------------------------------------- |--- Module      : Numeric.AD.Tower--- Copyright   : (c) Edward Kmett 2010--- License     : BSD3--- Maintainer  : ekmett@gmail.com--- Stability   : experimental--- Portability : GHC only------ Higher order derivatives via a \"dual number tower\".-----------------------------------------------------------------------------------module Numeric.AD.Tower-    (-    -- * Taylor Series-      taylor-    , taylor0-    -- * Maclaurin Series-    , maclaurin-    , maclaurin0-    -- * Derivatives-    , diff    -- first derivative of (a -> a) -    , diff'   -- answer and first derivative of (a -> a) -    , diffs   -- answer and all derivatives of (a -> a) -    , diffs0  -- zero padded derivatives of (a -> a)-    , diffsF  -- answer and all derivatives of (a -> f a)-    , diffs0F -- zero padded derivatives of (a -> f a)-    -- * Directional Derivatives-    , du      -- directional derivative of (a -> a)-    , du'     -- answer and directional derivative of (a -> a)-    , dus     -- answer and all directional derivatives of (a -> a) -    , dus0    -- answer and all zero padded directional derivatives of (a -> a)-    , duF     -- directional derivative of (a -> f a)-    , duF'    -- answer and directional derivative of (a -> f a)-    , dusF    -- answer and all directional derivatives of (a -> f a)-    , dus0F   -- answer and all zero padded directional derivatives of (a -> a)-    -- * Monadic Combinators-    , diffsM  -- answer and all derivatives of the monadic action (a -> m a)-    , diffs0M -- answer and all zero padded derivatives of (a -> m a)-    -- * Exposed Types-    , UU, UF, FU, FF-    , Mode(..)-    , AD(..)-    ) where--import Control.Monad (liftM)-import Control.Applicative ((<$>))-import Numeric.AD.Internal-import Numeric.AD.Internal.Tower--diffs :: Num a => UU a -> a -> [a]-diffs f a = getADTower $ apply f a-{-# INLINE diffs #-}--diffs0 :: Num a => UU a -> a -> [a]-diffs0 f a = zeroPad (diffs f a)-{-# INLINE diffs0 #-}--diffsF :: (Functor f, Num a) => UF f a -> a -> f [a]-diffsF f a = getADTower <$> apply f a-{-# INLINE diffsF #-}--diffs0F :: (Functor f, Num a) => UF f a -> a -> f [a]-diffs0F f a = (zeroPad . getADTower) <$> apply f a-{-# INLINE diffs0F #-}--diffsM :: (Monad m, Num a) => UF m a -> a -> m [a]-diffsM f a = getADTower `liftM` apply f a-{-# INLINE diffsM #-}--diffs0M :: (Monad m, Num a) => UF m a -> a -> m [a]-diffs0M f a = (zeroPad . getADTower) `liftM` apply f a-{-# INLINE diffs0M #-}--taylor :: Fractional a => UU a -> a -> a -> [a]-taylor f x dx = go 1 1 (diffs f x)-    where-        go !n !acc (a:as) = a * acc : go (n + 1) (acc * dx / n) as-        go _ _ [] = []--taylor0 :: Fractional a => UU a -> a -> a -> [a]-taylor0 f x dx = zeroPad (taylor f x dx)-{-# INLINE taylor0 #-}--maclaurin :: Fractional a => UU a -> a -> [a]-maclaurin f = taylor f 0-{-# INLINE maclaurin #-}--maclaurin0 :: Fractional a => UU a -> a -> [a]-maclaurin0 f = taylor0 f 0-{-# INLINE maclaurin0 #-}--diff :: Num a => UU a -> a -> a-diff f = d . diffs f-{-# INLINE diff #-}--diff' :: Num a => UU a -> a -> (a, a)-diff' f = d' . diffs f-{-# INLINE diff' #-}--du :: (Functor f, Num a) => FU f a -> f (a, a) -> a-du f = d . getADTower . f . fmap withD-{-# INLINE du #-}--du' :: (Functor f, Num a) => FU f a -> f (a, a) -> (a, a)-du' f = d' . getADTower . f . fmap withD-{-# INLINE du' #-}--duF :: (Functor f, Functor g, Num a) => FF f g a -> f (a, a) -> g a-duF f = fmap (d . getADTower) . f . fmap withD-{-# INLINE duF #-}--duF' :: (Functor f, Functor g, Num a) => FF f g a -> f (a, a) -> g (a, a)-duF' f = fmap (d' . getADTower) . f . fmap withD-{-# INLINE duF' #-}--dus :: (Functor f, Num a) => FU f a -> f [a] -> [a]-dus f = getADTower . f . fmap tower-{-# INLINE dus #-}--dus0 :: (Functor f, Num a) => FU f a -> f [a] -> [a]-dus0 f = zeroPad . getADTower . f . fmap tower-{-# INLINE dus0 #-}--dusF :: (Functor f, Functor g, Num a) => FF f g a -> f [a] -> g [a]-dusF f = fmap getADTower . f . fmap tower-{-# INLINE dusF #-}--dus0F :: (Functor f, Functor g, Num a) => FF f g a -> f [a] -> g [a]-dus0F f = fmap getADTower . f . fmap tower-{-# INLINE dus0F #-}---- TODO: higher order gradients--- data f :> a = a :< f (f :> a) --- gradients  :: (Traversable f, Num a) => FU f a -> f a -> f :> a--- gradientsF, jacobians :: (Traversable f, Functor g, Num a) => FF f g a -> f a -> g (f :> a)--- gradientsM :: (Traversable f, Monad m, Num a) => FF f m a -> f a -> m (f :> a)
+ Numeric/AD/Types.hs view
@@ -0,0 +1,31 @@+-----------------------------------------------------------------------------+-- |+-- Module      :  Numeric.AD.Types+-- Copyright   :  (c) Edward Kmett 2010+-- License     :  BSD3+-- Maintainer  :  ekmett@gmail.com+-- Stability   :  experimental+-- Portability :  GHC only+--+-----------------------------------------------------------------------------++module Numeric.AD.Types+    ( +      AD(..)+    -- * Differentiable Functions+    , UU, UF, FU, FF+    -- * Tensors+    , Tensors(..)+    , headT+    , tailT+    , tensors+    -- * f-Branching Streams+    , Stream(..)+    , headS+    , tailS+    , unfoldS+    ) where++import Numeric.AD.Internal.Types+import Numeric.AD.Internal.Stream+import Numeric.AD.Internal.Tensors
TODO view
@@ -1,13 +1,43 @@-* Implement the diffMF, etc. functionality from Numeric.FAD+* Use the f-branching stream and tensors to generate: +    gradients :: Traversable f => FU f a -> f a -> Stream f a + * Allow the type to vary within our AD data type container, in the same fashion as Numeric.FAD. -    Although, while Pearlmutter and Siskind provided the functionality to permit it in derivative combinator, they provided-    no combinators to convert, for instance, a Dual tag Float to a Dual tag Double, so that extra functionality cannot+    Although, while Pearlmutter and Siskind provided the functionality to permit +    it in the derivative combinators, they provided no combinators to convert, +    say, @Dual tag Float@ to a @Dual tag Double@, so that extra functionality cannot     currently be leveraged. -* Provide the ability to use reverse mode locally on FAD inputs, i.e.+  One approach: GADT'd Tape. +    Lets us use local matrix-valued jacobians as blackboxes.+    However, this requires a custom higher-order data-reify. -    reverseCheckpoint :: (forall s. AD s a -> AD s a) -> AD t a -> AD t a +* Do we need some kind of Array implementation? These'd be easy: -* Provide forward-on-reverse computation of Hessians+    (new)?type ADArray s i e = Array i (AD s e) +    (new)?type ADIOArray s i e = IOArray i (AD s e)+    (new)?type ADSTArray s i e = STArray i (AD s e)++  But how to handle possibly unboxed arrays where possible?++    Mode s => ADUArray s i Float+    Mode s => ADIOUArray s i Float+    Mode s => ADSTUArray s i Float++  Forward admits fast unboxed array access, but how to avoid violating quantification over s?++  This seems to require baking the array type for Float and Double directly into the Mode.++  class ( IArray (ADArray s) e+        , MArray (ADSTArray s s') e (ST s')+        , MArray (ADIOArray s) e IO+        , Lifted s) => LiftedArray s e where++     type ADArr s e  :: * -> * -> * +     type ADSTArr s e :: * -> * -> * +     type ADIOArr s e :: * -> * -> *++  newtype ADArray s i e = ADArray (ADArr s e i e)++  class ( LiftedArray s Float, LiftedArray s Double, ...) => Mode s
ad.cabal view
@@ -1,5 +1,5 @@ Name:         ad-Version:      0.31.0+Version:      0.32.0 License:      BSD3 License-File: LICENSE Copyright:    (c) Edward Kmett 2010,@@ -30,14 +30,16 @@  Exposed-Modules:     Numeric.AD-    Numeric.AD.Forward-    Numeric.AD.Reverse-    Numeric.AD.Tower-    Numeric.AD.Directed+    Numeric.AD.Classes+    Numeric.AD.Types     Numeric.AD.Newton-    Numeric.AD.Tensors -    Numeric.AD.Internal+    Numeric.AD.Mode.Mixed+    Numeric.AD.Mode.Forward+    Numeric.AD.Mode.Reverse+    Numeric.AD.Mode.Tower+    Numeric.AD.Mode.Directed+     Numeric.AD.Internal.Classes     Numeric.AD.Internal.Types     Numeric.AD.Internal.Combinators@@ -55,3 +57,4 @@ Extra-Source-Files: TODO GHC-Options: -Wall -fspec-constr  --           -O2+