ad 0.17 → 0.18
raw patch · 3 files changed
+58/−22 lines, 3 filesPVP ok
version bump matches the API change (PVP)
API changes (from Hackage documentation)
+ Numeric.AD: gradF :: (Traversable f, Functor g, Num a) => (forall s. (Mode s) => f (AD s a) -> g (AD s a)) -> f a -> g (f a)
+ Numeric.AD: gradF' :: (Traversable f, Functor g, Num a) => (forall s. (Mode s) => f (AD s a) -> g (AD s a)) -> f a -> g (a, f a)
+ Numeric.AD: gradWithF :: (Traversable f, Functor g, Num a) => (a -> a -> b) -> (forall s. (Mode s) => f (AD s a) -> g (AD s a)) -> f a -> g (f b)
+ Numeric.AD: gradWithF' :: (Traversable f, Functor g, Num a) => (a -> a -> b) -> (forall s. (Mode s) => f (AD s a) -> g (AD s a)) -> f a -> g (a, f b)
+ Numeric.AD: jacobianT :: (Traversable f, Functor g, Num a) => (forall s. (Mode s) => f (AD s a) -> g (AD s a)) -> f a -> f (g a)
+ Numeric.AD: jacobianWithT :: (Traversable f, Functor g, Num a) => (a -> a -> b) -> (forall s. (Mode s) => f (AD s a) -> g (AD s a)) -> f a -> f (g b)
+ Numeric.AD.Reverse: gradF :: (Traversable f, Functor g, Num a) => (forall s. (Mode s) => f (AD s a) -> g (AD s a)) -> f a -> g (f a)
+ Numeric.AD.Reverse: gradF' :: (Traversable f, Functor g, Num a) => (forall s. (Mode s) => f (AD s a) -> g (AD s a)) -> f a -> g (a, f a)
+ Numeric.AD.Reverse: gradWithF :: (Traversable f, Functor g, Num a) => (a -> a -> b) -> (forall s. (Mode s) => f (AD s a) -> g (AD s a)) -> f a -> g (f b)
+ Numeric.AD.Reverse: gradWithF' :: (Traversable f, Functor g, Num a) => (a -> a -> b) -> (forall s. (Mode s) => f (AD s a) -> g (AD s a)) -> f a -> g (a, f b)
Files
- Numeric/AD.hs +19/−8
- Numeric/AD/Reverse.hs +38/−13
- ad.cabal +1/−1
Numeric/AD.hs view
@@ -15,15 +15,24 @@ module Numeric.AD (- -- * Gradients+ -- * Gradients (Reverse Mode) grad, grad' , gradWith, gradWith' - -- * Jacobians+ -- * Jacobians (Mixed Mode) , jacobian, jacobian' , jacobianWith, jacobianWith' - -- * Derivatives (Forward)+ -- * Jacobians (Reverse Mode)+ , gradF+ , gradF'+ , gradWithF+ , gradWithF'++ -- * Jacobians (Forward Mode)+ , jacobianT, jacobianWithT++ -- * Derivatives (Forward Mode) , diff , diffF @@ -37,7 +46,7 @@ , diffs0 , diffs0F - -- * Directional Derivatives (Forward)+ -- * Directional Derivatives (Forward Mode) , du , du' , duF@@ -46,14 +55,16 @@ -- * Taylor Series (Tower) , taylor , taylor0++ -- * Maclaurin Series (Tower) , maclaurin , maclaurin0 - -- * Monadic Combinators (Forward)+ -- * Monadic Combinators (Forward Mode) , diffM , diffM' - -- * Monadic Combinators (Reverse)+ -- * Monadic Combinators (Reverse Mode) , gradM , gradM' , gradWithM@@ -69,9 +80,9 @@ import Control.Applicative import Numeric.AD.Classes (Mode(..)) import Numeric.AD.Internal (AD(..), probed, unprobe)-import Numeric.AD.Forward (diff, diff', diffF, diffF', du, du', duF, duF', diffM, diffM') +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)-import Numeric.AD.Reverse (grad, grad', gradWith, gradWith', gradM, gradM', gradWithM, gradWithM')+import Numeric.AD.Reverse (grad, grad', gradWith, gradWith', gradM, gradM', gradWithM, gradWithM', gradF, gradF', gradWithF, gradWithF') import qualified Numeric.AD.Forward as Forward import qualified Numeric.AD.Reverse as Reverse
Numeric/AD/Reverse.hs view
@@ -41,6 +41,11 @@ , gradM' , gradWithM , gradWithM'+ -- * Synonyms+ , gradF+ , gradF'+ , gradWithF+ , gradWithF' -- * Exposed Types , AD(..) , Mode(..)@@ -87,43 +92,63 @@ r = f vs {-# INLINE gradWith' #-} --- | The 'jacobian' function calculates the jacobian of a non-scalar-to-non-scalar function with reverse AD lazily in @m@ passes for @m@ outputs.+-- | 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) => (forall s. Mode s => f (AD s a) -> g (AD s a)) -> f a -> g (f a)+gradF = jacobian+{-# INLINE gradF #-}++-- | An alias for 'gradF' jacobian :: (Traversable f, Functor g, Num a) => (forall s. Mode s => f (AD s a) -> g (AD s a)) -> f a -> g (f a) jacobian f as = unbind vs . partialArray bds <$> f vs where (vs, bds) = bind as {-# INLINE jacobian #-} --- | The 'jacobian'' 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 '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) => (forall s. Mode s => f (AD s a) -> g (AD s a)) -> f a -> g (a, f a)+gradF' = jacobian' +{-# INLINE gradF' #-}++-- | An alias for 'gradF'' jacobian' :: (Traversable f, Functor g, Num a) => (forall s. Mode s => f (AD s a) -> g (AD s 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' #-} --- | 'jacobianWith g f' calculates the jacobian of a non-scalar-to-non-scalar function @f@ with reverse AD lazily in @m@ passes for @m@ outputs.+-- | '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@. ----- > jacobian == jacobianWith (\_ dx -> dx)--- > jacobianWith const == (\f x -> const x <$> f x)+-- > gradF == gradWithF (\_ dx -> dx)+-- > gradWithF const == (\f x -> const x <$> f x) ---jacobianWith :: (Traversable f, Functor g, Num a) => (a -> a -> b) -> (forall s. Mode s => f (AD s a) -> g (AD s a)) -> f a -> g (f b)-jacobianWith g f as = unbindWith g vs . partialArray bds <$> f vs where+gradWithF :: (Traversable f, Functor g, Num a) => (a -> a -> b) -> (forall s. Mode s => f (AD s a) -> g (AD s 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) -> (forall s. Mode s => f (AD s a) -> g (AD s a)) -> f a -> g (f b)+jacobianWith = gradWithF {-# INLINE jacobianWith #-} --- | 'jacobianWith' 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 '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' == jacobianWith' (\_ dx -> dx)+-- > jacobian' == gradWithF' (\_ dx -> dx) ---jacobianWith' :: (Traversable f, Functor g, Num a) => (a -> a -> b) -> (forall s. Mode s => f (AD s a) -> g (AD s a)) -> f a -> g (a, f b)-jacobianWith' g f as = row <$> f vs where+gradWithF' :: (Traversable f, Functor g, Num a) => (a -> a -> b) -> (forall s. Mode s => f (AD s a) -> g (AD s 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) -> (forall s. Mode s => f (AD s a) -> g (AD s a)) -> f a -> g (a, f b)+jacobianWith' = gradWithF' {-# INLINE jacobianWith' #-} diff :: Num a => (forall s. Mode s => AD s a -> AD s a) -> a -> a
ad.cabal view
@@ -1,5 +1,5 @@ Name: ad-Version: 0.17+Version: 0.18 License: BSD3 License-File: LICENSE Copyright: Edward Kmett 2010