-- Hoogle documentation, generated by Haddock -- See Hoogle, http://www.haskell.org/hoogle/ -- | Automatic Differentiation -- -- Forward-, reverse- and mixed- mode automatic differentiation -- combinators with a common API. -- -- Type-level "branding" is used to both prevent the end user from -- confusing infinitesimals and to limit unsafe access to the -- implementation details of each Mode. -- -- The combinators in Numeric.AD choose from a variety of -- automatic differentiation modes, based on the arity of their inputs -- and outputs. @package ad @version 0.31.0 module Numeric.AD.Internal.Combinators zipWithT :: (Foldable f, Traversable g) => (a -> b -> c) -> f a -> g b -> g c zipWithDefaultT :: (Foldable f, Traversable g) => a -> (a -> b -> c) -> f a -> g b -> g c on :: (a -> a -> b) -> (c -> a) -> c -> c -> b module Numeric.AD.Internal.Comonad class (Functor f) => Copointed f extract :: (Copointed f) => f a -> a class (Copointed f) => Comonad f duplicate :: (Comonad f) => f a -> f (f a) extend :: (Comonad f) => (f a -> b) -> f a -> f b module Numeric.AD.Internal.Stream data Stream f a (:<) :: a -> f (Stream f a) -> Stream f a unfoldS :: (Functor f) => (a -> (b, f a)) -> a -> Stream f b headS :: Stream f a -> a tailS :: Stream f a -> f (Stream f a) instance (Show a, Show (f (Stream f a))) => Show (Stream f a) instance (Typeable1 f, Data (f (Stream f a)), Data a) => Data (Stream f a) instance (Typeable1 f, Typeable a) => Typeable (Stream f a) instance (Typeable1 f) => Typeable1 (Stream f) instance (Traversable f) => Traversable (Stream f) instance (Foldable f) => Foldable (Stream f) instance (Functor f) => Comonad (Stream f) instance (Functor f) => Copointed (Stream f) instance (Functor f) => Functor (Stream f) module Numeric.AD.Internal.Tensors data Tensors f a (:-) :: a -> Tensors f (f a) -> Tensors f a headT :: Tensors f a -> a tailT :: Tensors f a -> Tensors f (f a) tensors :: (Functor f) => Stream f a -> Tensors f a instance (Typeable1 f, Typeable a) => Typeable (Tensors f a) instance (Typeable1 f) => Typeable1 (Tensors f) instance (Functor f) => Copointed (Tensors f) instance (Traversable f) => Traversable (Tensors f) instance (Foldable f) => Foldable (Tensors f) instance (Functor f) => Functor (Tensors f) module Numeric.AD.Tensors data Tensors f a (:-) :: a -> Tensors f (f a) -> Tensors f a headT :: Tensors f a -> a tailT :: Tensors f a -> Tensors f (f a) tensors :: (Functor f) => Stream f a -> Tensors f a data Stream f a (:<) :: a -> f (Stream f a) -> Stream f a headS :: Stream f a -> a tailS :: Stream f a -> f (Stream f a) unfoldS :: (Functor f) => (a -> (b, f a)) -> a -> Stream f b class (Functor f) => Copointed f extract :: (Copointed f) => f a -> a class (Copointed f) => Comonad f duplicate :: (Comonad f) => f a -> f (f a) extend :: (Comonad f) => (f a -> b) -> f a -> f b module Numeric.AD.Internal.Classes class (Lifted t) => Mode t lift :: (Mode t, Num a) => a -> t a (<+>) :: (Mode t, Num a) => t a -> t a -> t a (*^) :: (Mode t, Num a) => a -> t a -> t a (^*) :: (Mode t, Num a) => t a -> a -> t a (^/) :: (Mode t, Fractional a) => t a -> a -> t a zero :: (Mode t, Num a) => t a one :: (Mode t, Num a) => t a -- | Jacobian is used by deriveMode but is not exposed via -- Mode to prevent its abuse by end users via the AD data -- type. class (Mode t, Mode (D t)) => Jacobian t where { type family D t :: * -> *; } unary :: (Jacobian t, Num a) => (a -> a) -> D t a -> t a -> t a lift1 :: (Jacobian t, Num a) => (a -> a) -> (D t a -> D t a) -> t a -> t a lift1_ :: (Jacobian t, Num a) => (a -> a) -> (D t a -> D t a -> D t a) -> t a -> t a binary :: (Jacobian t, Num a) => (a -> a -> a) -> D t a -> D t a -> t a -> t a -> t a lift2 :: (Jacobian t, Num a) => (a -> a -> a) -> (D t a -> D t a -> (D t a, D t a)) -> t a -> t a -> t a lift2_ :: (Jacobian t, Num a) => (a -> a -> a) -> (D t a -> D t a -> D t a -> (D t a, D t a)) -> t a -> t a -> t a -- | Primal is used by deriveMode but is not exposed via -- the Mode class to prevent its abuse by end users via the AD -- data type. -- -- It provides direct access to the result, stripped of its derivative -- information, but this is unsafe in general as (lift . primal) would -- discard derivative information. The end user is protected from -- accidentally using this function by the universal quantification on -- the various combinators we expose. class Primal t primal :: (Primal t, Num a) => t a -> a -- | deriveLifted t provides -- --
-- instance Lifted $t ---- -- given supplied instances for -- --
-- instance Lifted $t => Primal $t where ... -- instance Lifted $t => Jacobian $t where ... ---- -- The seemingly redundant Lifted $t constraints are -- caused by Template Haskell staging restrictions. deriveLifted :: Q Type -> Q [Dec] -- | deriveNumeric f g provides the following instances: -- --
-- instance ('Lifted' $f, 'Num' a, 'Enum' a) => 'Enum' ($g a)
-- instance ('Lifted' $f, 'Num' a, 'Eq' a) => 'Eq' ($g a)
-- instance ('Lifted' $f, 'Num' a, 'Ord' a) => 'Ord' ($g a)
-- instance ('Lifted' $f, 'Num' a, 'Bounded' a) => 'Bounded' ($g a)
--
--
--
-- instance ('Lifted' $f, 'Show' a) => 'Show' ($g a)
-- instance ('Lifted' $f, 'Num' a) => 'Num' ($g a)
-- instance ('Lifted' $f, 'Fractional' a) => 'Fractional' ($g a)
-- instance ('Lifted' $f, 'Floating' a) => 'Floating' ($g a)
-- instance ('Lifted' $f, 'RealFloat' a) => 'RealFloat' ($g a)
-- instance ('Lifted' $f, 'RealFrac' a) => 'RealFrac' ($g a)
-- instance ('Lifted' $f, 'Real' a) => 'Real' ($g a)
--
deriveNumeric :: ([Q Pred] -> [Q Pred]) -> Q Type -> Q [Dec]
class Lifted t
showsPrec1 :: (Lifted t, Show a) => Int -> t a -> ShowS
(==!) :: (Lifted t, Num a, Eq a) => t a -> t a -> Bool
compare1 :: (Lifted t, Num a, Ord a) => t a -> t a -> Ordering
fromInteger1 :: (Lifted t, Num a) => Integer -> t a
(+!) :: (Lifted t, Num a) => t a -> t a -> t a
(*!) :: (Lifted t, Num a) => t a -> t a -> t a
(-!) :: (Lifted t, Num a) => t a -> t a -> t a
negate1 :: (Lifted t, Num a) => t a -> t a
signum1 :: (Lifted t, Num a) => t a -> t a
abs1 :: (Lifted t, Num a) => t a -> t a
(/!) :: (Lifted t, Fractional a) => t a -> t a -> t a
recip1 :: (Lifted t, Fractional a) => t a -> t a
fromRational1 :: (Lifted t, Fractional a) => Rational -> t a
toRational1 :: (Lifted t, Real a) => t a -> Rational
pi1 :: (Lifted t, Floating a) => t a
exp1 :: (Lifted t, Floating a) => t a -> t a
sqrt1 :: (Lifted t, Floating a) => t a -> t a
log1 :: (Lifted t, Floating a) => t a -> t a
(**!) :: (Lifted t, Floating a) => t a -> t a -> t a
logBase1 :: (Lifted t, Floating a) => t a -> t a -> t a
sin1 :: (Lifted t, Floating a) => t a -> t a
atan1 :: (Lifted t, Floating a) => t a -> t a
acos1 :: (Lifted t, Floating a) => t a -> t a
asin1 :: (Lifted t, Floating a) => t a -> t a
tan1 :: (Lifted t, Floating a) => t a -> t a
cos1 :: (Lifted t, Floating a) => t a -> t a
sinh1 :: (Lifted t, Floating a) => t a -> t a
atanh1 :: (Lifted t, Floating a) => t a -> t a
acosh1 :: (Lifted t, Floating a) => t a -> t a
asinh1 :: (Lifted t, Floating a) => t a -> t a
tanh1 :: (Lifted t, Floating a) => t a -> t a
cosh1 :: (Lifted t, Floating a) => t a -> t a
properFraction1 :: (Lifted t, RealFrac a, Integral b) => t a -> (b, t a)
truncate1 :: (Lifted t, RealFrac a, Integral b) => t a -> b
floor1 :: (Lifted t, RealFrac a, Integral b) => t a -> b
ceiling1 :: (Lifted t, RealFrac a, Integral b) => t a -> b
round1 :: (Lifted t, RealFrac a, Integral b) => t a -> b
floatRadix1 :: (Lifted t, RealFloat a) => t a -> Integer
floatDigits1 :: (Lifted t, RealFloat a) => t a -> Int
floatRange1 :: (Lifted t, RealFloat a) => t a -> (Int, Int)
decodeFloat1 :: (Lifted t, RealFloat a) => t a -> (Integer, Int)
encodeFloat1 :: (Lifted t, RealFloat a) => Integer -> Int -> t a
exponent1 :: (Lifted t, RealFloat a) => t a -> Int
significand1 :: (Lifted t, RealFloat a) => t a -> t a
scaleFloat1 :: (Lifted t, RealFloat a) => Int -> t a -> t a
isNaN1 :: (Lifted t, RealFloat a) => t a -> Bool
isIEEE1 :: (Lifted t, RealFloat a) => t a -> Bool
isNegativeZero1 :: (Lifted t, RealFloat a) => t a -> Bool
isDenormalized1 :: (Lifted t, RealFloat a) => t a -> Bool
isInfinite1 :: (Lifted t, RealFloat a) => t a -> Bool
atan21 :: (Lifted t, RealFloat a) => t a -> t a -> t a
succ1 :: (Lifted t, Num a, Enum a) => t a -> t a
pred1 :: (Lifted t, Num a, Enum a) => t a -> t a
toEnum1 :: (Lifted t, Num a, Enum a) => Int -> t a
fromEnum1 :: (Lifted t, Num a, Enum a) => t a -> Int
enumFrom1 :: (Lifted t, Num a, Enum a) => t a -> [t a]
enumFromThen1 :: (Lifted t, Num a, Enum a) => t a -> t a -> [t a]
enumFromTo1 :: (Lifted t, Num a, Enum a) => t a -> t a -> [t a]
enumFromThenTo1 :: (Lifted t, Num a, Enum a) => t a -> t a -> t a -> [t a]
minBound1 :: (Lifted t, Num a, Bounded a) => t a
maxBound1 :: (Lifted t, Num a, Bounded a) => t a
class Iso a b
iso :: (Iso a b) => f a -> f b
osi :: (Iso a b) => f b -> f a
instance Iso a a
module Numeric.AD.Internal.Types
-- | AD serves as a common wrapper for different Mode
-- instances, exposing a traditional numerical tower. Universal
-- quantification is used to limit the actions in user code to machinery
-- that will return the same answers under all AD modes, allowing us to
-- use modes interchangeably as both the type level "brand" and
-- dictionary, providing a common API.
newtype AD f a
AD :: f a -> AD f a
runAD :: AD f a -> f a
-- | A scalar-to-scalar automatically-differentiable function.
type UU a = forall s. (Mode s) => AD s a -> AD s a
-- | A scalar-to-non-scalar automatically-differentiable function.
type UF f a = forall s. (Mode s) => AD s a -> f (AD s a)
-- | A non-scalar-to-scalar automatically-differentiable function.
type FU f a = forall s. (Mode s) => f (AD s a) -> AD s a
-- | A non-scalar-to-non-scalar automatically-differentiable function.
type FF f g a = forall s. (Mode s) => f (AD s a) -> g (AD s a)
instance (Typeable1 f, Typeable a, Data (f a), Data a) => Data (AD f a)
instance (Typeable1 f, Typeable a) => Typeable (AD f a)
instance (Typeable1 f) => Typeable1 (AD f)
instance (Lifted f, Real a) => Real (AD f a)
instance (Lifted f, RealFrac a) => RealFrac (AD f a)
instance (Lifted f, RealFloat a) => RealFloat (AD f a)
instance (Lifted f, Floating a) => Floating (AD f a)
instance (Lifted f, Fractional a) => Fractional (AD f a)
instance (Lifted f, Num a) => Num (AD f a)
instance (Lifted f, Show a) => Show (AD f a)
instance (Num a, Lifted f, Bounded a) => Bounded (AD f a)
instance (Num a, Lifted f, Ord a) => Ord (AD f a)
instance (Num a, Lifted f, Eq a) => Eq (AD f a)
instance (Num a, Lifted f, Enum a) => Enum (AD f a)
instance Iso (f a) (AD f a)
instance (Lifted f) => Lifted (AD f)
instance (Mode f) => Mode (AD f)
instance (Primal f) => Primal (AD f)
module Numeric.AD.Internal.Identity
newtype Id a
Id :: a -> Id a
probe :: a -> AD Id a
unprobe :: AD Id a -> a
probed :: f a -> f (AD Id a)
unprobed :: f (AD Id a) -> f a
instance Typeable1 Id
instance Iso a (Id a)
instance (Eq a) => Eq (Id a)
instance (Ord a) => Ord (Id a)
instance (Show a) => Show (Id a)
instance (Enum a) => Enum (Id a)
instance (Bounded a) => Bounded (Id a)
instance (Num a) => Num (Id a)
instance (Real a) => Real (Id a)
instance (Fractional a) => Fractional (Id a)
instance (Floating a) => Floating (Id a)
instance (RealFrac a) => RealFrac (Id a)
instance (RealFloat a) => RealFloat (Id a)
instance (Monoid a) => Monoid (Id a)
instance (Data a) => Data (Id a)
instance Primal Id
instance Mode Id
instance Lifted Id
instance Monad Id
instance Applicative Id
instance Traversable Id
instance Foldable Id
instance Functor Id
module Numeric.AD.Internal
module Numeric.AD.Internal.Composition
-- | Functor composition, used to nest the use of jacobian and grad
newtype ComposeFunctor f g a
ComposeFunctor :: f (g a) -> ComposeFunctor f g a
decomposeFunctor :: ComposeFunctor f g a -> f (g a)
-- | The composition of two AD modes is an AD mode in its own right
newtype ComposeMode f g a
ComposeMode :: f (AD g a) -> ComposeMode f g a
runComposeMode :: ComposeMode f g a -> f (AD g a)
composeMode :: AD f (AD g a) -> AD (ComposeMode f g) a
decomposeMode :: AD (ComposeMode f g) a -> AD f (AD g a)
instance (Typeable1 f, Typeable1 g, Data (f (AD g a)), Data a) => Data (ComposeMode f g a)
instance (Typeable1 f, Typeable1 g, Typeable a) => Typeable (ComposeMode f g a)
instance (Typeable1 f, Typeable1 g) => Typeable1 (ComposeMode f g)
instance (Mode f, Mode g) => Lifted (ComposeMode f g)
instance (Mode f, Mode g) => Mode (ComposeMode f g)
instance (Primal f, Mode g, Primal g) => Primal (ComposeMode f g)
instance (Typeable1 f, Typeable1 g, Data (f (g a)), Data a) => Data (ComposeFunctor f g a)
instance (Typeable1 f, Typeable1 g, Typeable a) => Typeable (ComposeFunctor f g a)
instance (Typeable1 f, Typeable1 g) => Typeable1 (ComposeFunctor f g)
instance (Traversable f, Traversable g) => Traversable (ComposeFunctor f g)
instance (Foldable f, Foldable g) => Foldable (ComposeFunctor f g)
instance (Functor f, Functor g) => Functor (ComposeFunctor f g)
-- | Unsafe and often partial combinators intended for internal usage.
--
-- Handle with care.
module Numeric.AD.Internal.Forward
data Forward a
Forward :: a -> a -> Forward a
tangent :: AD Forward a -> a
bundle :: a -> a -> AD Forward a
unbundle :: AD Forward a -> (a, a)
apply :: (Num a) => (AD Forward a -> b) -> a -> b
bind :: (Traversable f, Num a) => (f (AD Forward a) -> b) -> f a -> f b
bind' :: (Traversable f, Num a) => (f (AD Forward a) -> b) -> f a -> (b, f b)
bindWith :: (Traversable f, Num a) => (a -> b -> c) -> (f (AD Forward a) -> b) -> f a -> f c
bindWith' :: (Traversable f, Num a) => (a -> b -> c) -> (f (AD Forward a) -> b) -> f a -> (b, f c)
transposeWith :: (Functor f, Foldable f, Traversable g) => (b -> f a -> c) -> f (g a) -> g b -> g c
instance Lifted Forward
instance Typeable1 Forward
instance (Show a) => Show (Forward a)
instance (Data a) => Data (Forward a)
instance (Lifted Forward) => Jacobian Forward
instance (Lifted Forward) => Mode Forward
instance Primal Forward
-- | Forward mode automatic differentiation
module Numeric.AD.Forward
grad :: (Traversable f, Num a) => FU f a -> f a -> f a
grad' :: (Traversable f, Num a) => FU f a -> f a -> (a, f a)
gradWith :: (Traversable f, Num a) => (a -> a -> b) -> FU f a -> f a -> f b
gradWith' :: (Traversable f, Num a) => (a -> a -> b) -> FU f a -> f a -> (a, f b)
jacobian :: (Traversable f, Traversable g, Num a) => FF f g a -> f a -> g (f a)
jacobian' :: (Traversable f, Traversable g, Num a) => FF f g a -> f a -> g (a, f a)
jacobianWith :: (Traversable f, Traversable g, Num a) => (a -> a -> b) -> FF f g a -> f a -> g (f b)
jacobianWith' :: (Traversable f, Traversable g, Num a) => (a -> a -> b) -> FF f g a -> f a -> g (a, f b)
-- | 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)
-- | 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)
-- | 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
-- | 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)
-- | 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 -- | The d'UU function calculates the result and first derivative -- of scalar-to-scalar function by Forward AD -- --
-- d' sin == sin &&& cos -- d' f = f &&& d f --diff' :: (Num a) => UU a -> a -> (a, a) -- | The diffF function calculates the first derivative of -- scalar-to-nonscalar function by Forward AD diffF :: (Functor f, Num a) => UF f a -> a -> f a -- | The diffF' function calculates the result and first derivative -- of a scalar-to-non-scalar function by Forward AD diffF' :: (Functor f, Num a) => UF f a -> a -> f (a, a) du :: (Functor f, Num a) => FU f a -> f (a, a) -> a du' :: (Functor f, Num a) => FU f a -> f (a, a) -> (a, a) duF :: (Functor f, Functor g, Num a) => FF f g a -> f (a, a) -> g a duF' :: (Functor f, Functor g, Num a) => FF f g a -> f (a, a) -> g (a, a) -- | The dUM function calculates the first derivative of -- scalar-to-scalar monadic function by Forward AD diffM :: (Monad m, Num a) => UF m a -> a -> m a -- | The d'UM function calculates the result and first derivative -- of a scalar-to-scalar monadic function by Forward AD diffM' :: (Monad m, Num a) => UF m a -> a -> m (a, a) -- | A scalar-to-scalar automatically-differentiable function. type UU a = forall s. (Mode s) => AD s a -> AD s a -- | A scalar-to-non-scalar automatically-differentiable function. type UF f a = forall s. (Mode s) => AD s a -> f (AD s a) -- | A non-scalar-to-scalar automatically-differentiable function. type FU f a = forall s. (Mode s) => f (AD s a) -> AD s a -- | A non-scalar-to-non-scalar automatically-differentiable function. type FF f g a = forall s. (Mode s) => f (AD s a) -> g (AD s a) -- | AD serves as a common wrapper for different Mode -- instances, exposing a traditional numerical tower. Universal -- quantification is used to limit the actions in user code to machinery -- that will return the same answers under all AD modes, allowing us to -- use modes interchangeably as both the type level "brand" and -- dictionary, providing a common API. newtype AD f a AD :: f a -> AD f a runAD :: AD f a -> f a class (Lifted t) => Mode t lift :: (Mode t, Num a) => a -> t a (<+>) :: (Mode t, Num a) => t a -> t a -> t a (*^) :: (Mode t, Num a) => a -> t a -> t a (^*) :: (Mode t, Num a) => t a -> a -> t a (^/) :: (Mode t, Fractional a) => t a -> a -> t a zero :: (Mode t, Num a) => t a -- | Reverse-Mode Automatic Differentiation implementation details -- -- 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.Internal.Reverse -- | Reverse is a Mode using reverse-mode automatic -- differentiation that provides fast diffFU, diff2FU, -- grad, grad2 and a fast jacobian when you -- have a significantly smaller number of outputs than inputs. newtype Reverse a Reverse :: (Tape a (Reverse a)) -> Reverse a -- | A Tape records the information needed back propagate from the -- output to each input during Reverse Mode AD. data Tape a t Lift :: a -> Tape a t Var :: a -> !!Int -> Tape a t Binary :: a -> a -> a -> t -> t -> Tape a t Unary :: a -> a -> t -> Tape a t -- | This returns a list of contributions to the partials. The variable ids -- returned in the list are likely not unique! partials :: (Num a) => AD Reverse a -> [(Int, a)] -- | Return an Array of partials given bounds for the -- variable IDs. partialArray :: (Num a) => (Int, Int) -> AD Reverse a -> Array Int a -- | Return an IntMap of sparse partials partialMap :: (Num a) => AD Reverse a -> IntMap a derivative :: (Num a) => AD Reverse a -> a derivative' :: (Num a) => AD Reverse a -> (a, a) -- | Used to mark variables for inspection during the reverse pass class (Primal v) => Var v var :: (Var v) => a -> Int -> v a varId :: (Var v) => v a -> Int bind :: (Traversable f, Var v) => f a -> (f (v a), (Int, Int)) unbind :: (Functor f, Var v) => f (v a) -> Array Int a -> f a unbindMap :: (Functor f, Var v, Num a) => f (v a) -> IntMap a -> f a unbindWith :: (Functor f, Var v, Num a) => (a -> b -> c) -> f (v a) -> Array Int b -> f c unbindMapWithDefault :: (Functor f, Var v, Num a) => b -> (a -> b -> c) -> f (v a) -> IntMap b -> f c instance Var (AD Reverse) instance Var Reverse instance Monad S instance Lifted Reverse instance Typeable1 Reverse instance Typeable2 Tape instance (Show a) => Show (Reverse a) instance (Show a, Show t) => Show (Tape a t) instance (Data a, Data t) => Data (Tape a t) instance (Lifted Reverse) => Jacobian Reverse instance Primal Reverse instance (Lifted Reverse) => Mode Reverse instance MuRef (Reverse a) -- | 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 -- | 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 -- | 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 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 -- | 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) -- | An alias for gradF jacobian :: (Traversable f, Functor g, Num a) => FF f g a -> f a -> g (f a) -- | An alias for gradF' jacobian' :: (Traversable f, Functor g, Num a) => FF f g a -> f a -> g (a, f a) -- | An alias for gradWithF. jacobianWith :: (Traversable f, Functor g, Num a) => (a -> a -> b) -> FF f g a -> f a -> g (f b) -- | An alias for gradWithF' jacobianWith' :: (Traversable f, Functor g, Num a) => (a -> a -> b) -> FF f g a -> f a -> g (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 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) -- | 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)) -- | 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)) diff :: (Num a) => UU a -> a -> a -- | 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) diffF :: (Functor f, Num a) => UF f a -> a -> f a diffF' :: (Functor f, Num a) => UF f a -> a -> f (a, a) diffM :: (Monad m, Num a) => UF m a -> a -> m a diffM' :: (Monad m, Num a) => UF m a -> a -> m (a, a) gradM :: (Traversable f, Monad m, Num a) => FF f m a -> f a -> m (f a) gradM' :: (Traversable f, Monad m, Num a) => FF f m a -> f a -> m (a, f a) gradWithM :: (Traversable f, Monad m, Num a) => (a -> a -> b) -> FF f m a -> f a -> m (f b) gradWithM' :: (Traversable f, Monad m, Num a) => (a -> a -> b) -> FF f m a -> f a -> m (a, f b) -- | 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) -- | 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) -- | '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' 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) -- | A scalar-to-scalar automatically-differentiable function. type UU a = forall s. (Mode s) => AD s a -> AD s a -- | A scalar-to-non-scalar automatically-differentiable function. type UF f a = forall s. (Mode s) => AD s a -> f (AD s a) -- | A non-scalar-to-scalar automatically-differentiable function. type FU f a = forall s. (Mode s) => f (AD s a) -> AD s a -- | A non-scalar-to-non-scalar automatically-differentiable function. type FF f g a = forall s. (Mode s) => f (AD s a) -> g (AD s a) -- | AD serves as a common wrapper for different Mode -- instances, exposing a traditional numerical tower. Universal -- quantification is used to limit the actions in user code to machinery -- that will return the same answers under all AD modes, allowing us to -- use modes interchangeably as both the type level "brand" and -- dictionary, providing a common API. newtype AD f a AD :: f a -> AD f a runAD :: AD f a -> f a class (Lifted t) => Mode t lift :: (Mode t, Num a) => a -> t a (<+>) :: (Mode t, Num a) => t a -> t a -> t a (*^) :: (Mode t, Num a) => a -> t a -> t a (^*) :: (Mode t, Num a) => t a -> a -> t a (^/) :: (Mode t, Fractional a) => t a -> a -> t a zero :: (Mode t, Num a) => t a module Numeric.AD.Internal.Tower -- | Tower is an AD Mode that calculates a tangent tower by -- forward AD, and provides fast diffsUU, diffsUF newtype Tower a Tower :: [a] -> Tower a getTower :: Tower a -> [a] zeroPad :: (Num a) => [a] -> [a] zeroPadF :: (Functor f, Num a) => [f a] -> [f a] transposePadF :: (Foldable f, Functor f) => a -> f [a] -> [f a] d :: (Num a) => [a] -> a d' :: (Num a) => [a] -> (a, a) withD :: (a, a) -> AD Tower a tangents :: Tower a -> Tower a bundle :: a -> Tower a -> Tower a apply :: (Num a) => (AD Tower a -> b) -> a -> b getADTower :: AD Tower a -> [a] tower :: [a] -> AD Tower a instance Lifted Tower instance Typeable1 Tower instance (Data a) => Data (Tower a) instance (Lifted Tower) => Jacobian Tower instance (Lifted Tower) => Mode Tower instance Primal Tower instance (Show a) => Show (Tower a) -- | Higher order derivatives via a "dual number tower". module Numeric.AD.Tower taylor :: (Fractional a) => UU a -> a -> a -> [a] taylor0 :: (Fractional a) => UU a -> a -> a -> [a] maclaurin :: (Fractional a) => UU a -> a -> [a] maclaurin0 :: (Fractional a) => UU a -> a -> [a] diff :: (Num a) => UU a -> a -> a diff' :: (Num a) => UU a -> a -> (a, a) diffs :: (Num a) => UU a -> a -> [a] diffs0 :: (Num a) => UU a -> a -> [a] diffsF :: (Functor f, Num a) => UF f a -> a -> f [a] diffs0F :: (Functor f, Num a) => UF f a -> a -> f [a] du :: (Functor f, Num a) => FU f a -> f (a, a) -> a du' :: (Functor f, Num a) => FU f a -> f (a, a) -> (a, a) dus :: (Functor f, Num a) => FU f a -> f [a] -> [a] dus0 :: (Functor f, Num a) => FU f a -> f [a] -> [a] duF :: (Functor f, Functor g, Num a) => FF f g a -> f (a, a) -> g a duF' :: (Functor f, Functor g, Num a) => FF f g a -> f (a, a) -> g (a, a) dusF :: (Functor f, Functor g, Num a) => FF f g a -> f [a] -> g [a] dus0F :: (Functor f, Functor g, Num a) => FF f g a -> f [a] -> g [a] diffsM :: (Monad m, Num a) => UF m a -> a -> m [a] diffs0M :: (Monad m, Num a) => UF m a -> a -> m [a] -- | A scalar-to-scalar automatically-differentiable function. type UU a = forall s. (Mode s) => AD s a -> AD s a -- | A scalar-to-non-scalar automatically-differentiable function. type UF f a = forall s. (Mode s) => AD s a -> f (AD s a) -- | A non-scalar-to-scalar automatically-differentiable function. type FU f a = forall s. (Mode s) => f (AD s a) -> AD s a -- | A non-scalar-to-non-scalar automatically-differentiable function. type FF f g a = forall s. (Mode s) => f (AD s a) -> g (AD s a) class (Lifted t) => Mode t lift :: (Mode t, Num a) => a -> t a (<+>) :: (Mode t, Num a) => t a -> t a -> t a (*^) :: (Mode t, Num a) => a -> t a -> t a (^*) :: (Mode t, Num a) => t a -> a -> t a (^/) :: (Mode t, Fractional a) => t a -> a -> t a zero :: (Mode t, Num a) => t a -- | AD serves as a common wrapper for different Mode -- instances, exposing a traditional numerical tower. Universal -- quantification is used to limit the actions in user code to machinery -- that will return the same answers under all AD modes, allowing us to -- use modes interchangeably as both the type level "brand" and -- dictionary, providing a common API. newtype AD f a AD :: f a -> AD f a runAD :: AD f a -> f a module Numeric.AD.Newton -- | The findZero function finds a zero of a scalar function using -- Newton's method; its output is a stream of increasingly accurate -- results. (Modulo the usual caveats.) -- -- Examples: -- --
-- take 10 $ findZero (\\x->x^2-4) 1 -- converge to 2.0 ---- --
-- module Data.Complex -- take 10 $ findZero ((+1).(^2)) (1 :+ 1) -- converge to (0 :+ 1)@ --findZero :: (Fractional a) => UU a -> a -> [a] findZeroM :: (Monad m, Fractional a) => UF m a -> a -> MList m a -- | The inverseNewton function inverts a scalar function using -- Newton's method; its output is a stream of increasingly accurate -- results. (Modulo the usual caveats.) -- -- Example: -- --
-- take 10 $ inverseNewton sqrt 1 (sqrt 10) -- converges to 10 --inverse :: (Fractional a) => UU a -> a -> a -> [a] inverseM :: (Monad m, Fractional a) => UF m a -> a -> a -> MList m a -- | The fixedPoint function find a fixedpoint of a scalar function -- using Newton's method; its output is a stream of increasingly accurate -- results. (Modulo the usual caveats.) -- --
-- take 10 $ fixedPoint cos 1 -- converges to 0.7390851332151607 --fixedPoint :: (Fractional a) => UU a -> a -> [a] fixedPointM :: (Monad m, Fractional a) => UF m a -> a -> MList m a -- | The extremum function finds an extremum of a scalar function -- using Newton's method; produces a stream of increasingly accurate -- results. (Modulo the usual caveats.) -- --
-- take 10 $ extremum cos 1 -- convert to 0 --extremum :: (Fractional a) => UU a -> a -> [a] extremumM :: (Monad m, Fractional a) => UF m a -> a -> MList m a -- | The gradientDescent function performs a multivariate -- optimization, based on the naive-gradient-descent in the file -- stalingrad/examples/flow-tests/pre-saddle-1a.vlad from the -- VLAD compiler Stalingrad sources. Its output is a stream of -- increasingly accurate results. (Modulo the usual caveats.) -- -- It uses reverse mode automatic differentiation to compute the -- gradient. gradientDescent :: (Traversable f, Fractional a, Ord a) => FU f a -> f a -> [f a] gradientDescentM :: (Traversable f, Monad m, Fractional a, Ord a) => FF f m a -> f a -> MList m (f a) gradientAscent :: (Traversable f, Fractional a, Ord a) => FU f a -> f a -> [f a] gradientAscentM :: (Traversable f, Monad m, Fractional a, Ord a) => FF f m a -> f a -> MList m (f a) -- | A scalar-to-scalar automatically-differentiable function. type UU a = forall s. (Mode s) => AD s a -> AD s a -- | A scalar-to-non-scalar automatically-differentiable function. type UF f a = forall s. (Mode s) => AD s a -> f (AD s a) -- | A non-scalar-to-scalar automatically-differentiable function. type FU f a = forall s. (Mode s) => f (AD s a) -> AD s a -- | A non-scalar-to-non-scalar automatically-differentiable function. type FF f g a = forall s. (Mode s) => f (AD s a) -> g (AD s a) -- | AD serves as a common wrapper for different Mode -- instances, exposing a traditional numerical tower. Universal -- quantification is used to limit the actions in user code to machinery -- that will return the same answers under all AD modes, allowing us to -- use modes interchangeably as both the type level "brand" and -- dictionary, providing a common API. newtype AD f a AD :: f a -> AD f a runAD :: AD f a -> f a class (Lifted t) => Mode t lift :: (Mode t, Num a) => a -> t a (<+>) :: (Mode t, Num a) => t a -> t a -> t a (*^) :: (Mode t, Num a) => a -> t a -> t a (^*) :: (Mode t, Num a) => t a -> a -> t a (^/) :: (Mode t, Fractional a) => t a -> a -> t a zero :: (Mode t, Num a) => t a module Numeric.AD.Internal.Iterated data Iterated f a (:|) :: a -> f (Iterated f a) -> Iterated f a tailI :: (Iterated f a) -> f (Iterated f a) unfoldI :: (Functor f) => (a -> (b, f a)) -> a -> Iterated f b bundle :: (Num a) => a -> a -> AD (Iterated Forward) a bind :: (Traversable f, Num a) => (f (AD (Iterated Forward) a) -> b) -> f a -> f b instance (Typeable1 f, Data (f (Iterated f a)), Data a) => Data (Iterated f a) instance (Typeable1 f, Typeable a) => Typeable (Iterated f a) instance (Typeable1 f) => Typeable1 (Iterated f) instance (Mode f, Real a) => Real (Iterated f a) instance (Mode f, RealFrac a) => RealFrac (Iterated f a) instance (Mode f, RealFloat a) => RealFloat (Iterated f a) instance (Mode f, Floating a) => Floating (Iterated f a) instance (Mode f, Fractional a) => Fractional (Iterated f a) instance (Mode f, Num a) => Num (Iterated f a) instance (Mode f, Show a) => Show (Iterated f a) instance (Num a, Mode f, Bounded a) => Bounded (Iterated f a) instance (Num a, Mode f, Ord a) => Ord (Iterated f a) instance (Num a, Mode f, Eq a) => Eq (Iterated f a) instance (Num a, Mode f, Enum a) => Enum (Iterated f a) instance (Mode f) => Lifted (Iterated f) instance (Mode f) => Mode (Iterated f) instance Primal (Iterated f) instance (Traversable f) => Traversable (Iterated f) instance (Foldable f) => Foldable (Iterated f) instance (Functor f) => Comonad (Iterated f) instance (Functor f) => Copointed (Iterated f) instance (Functor f) => Functor (Iterated f) -- | Mixed-Mode Automatic Differentiation. -- -- Each combinator exported from this module chooses an appropriate AD -- mode. module Numeric.AD -- | 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 -- | 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 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 -- | 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) -- | 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 gradM from -- Numeric.AD.Reverse. jacobian :: (Traversable f, Traversable g, Num a) => FF f g a -> f a -> g (f a) -- | 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 gradM' from -- Numeric.AD.Reverse. jacobian' :: (Traversable f, Traversable g, Num a) => FF f g a -> f a -> g (a, f a) -- | 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 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 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 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) gradM :: (Traversable f, Monad m, Num a) => FF f m a -> f a -> m (f a) gradM' :: (Traversable f, Monad m, Num a) => FF f m a -> f a -> m (a, f a) gradWithM :: (Traversable f, Monad m, Num a) => (a -> a -> b) -> FF f m a -> f a -> m (f b) gradWithM' :: (Traversable f, Monad m, Num a) => (a -> a -> b) -> FF f m a -> f a -> m (a, f b) -- | 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) -- | 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) -- | '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' 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) -- | 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) -- | 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) -- | 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) -- | 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)) -- | 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 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) -- | 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 -- | The diffF function calculates the first derivative of -- scalar-to-nonscalar function by Forward AD diffF :: (Functor f, Num a) => UF f a -> a -> f a -- | The d'UU function calculates the result and first derivative -- of scalar-to-scalar function by Forward AD -- --
-- d' sin == sin &&& cos -- d' f = f &&& d f --diff' :: (Num a) => UU a -> a -> (a, a) -- | The diffF' function calculates the result and first derivative -- of a scalar-to-non-scalar function by Forward AD diffF' :: (Functor f, Num a) => UF f a -> a -> f (a, a) diffs :: (Num a) => UU a -> a -> [a] diffsF :: (Functor f, Num a) => UF f a -> a -> f [a] diffs0 :: (Num a) => UU a -> a -> [a] diffs0F :: (Functor f, Num a) => UF f a -> a -> f [a] du :: (Functor f, Num a) => FU f a -> f (a, a) -> a du' :: (Functor f, Num a) => FU f a -> f (a, a) -> (a, a) duF :: (Functor f, Functor g, Num a) => FF f g a -> f (a, a) -> g a duF' :: (Functor f, Functor g, Num a) => FF f g a -> f (a, a) -> g (a, a) dus :: (Functor f, Num a) => FU f a -> f [a] -> [a] dus0 :: (Functor f, Num a) => FU f a -> f [a] -> [a] dusF :: (Functor f, Functor g, Num a) => FF f g a -> f [a] -> g [a] dus0F :: (Functor f, Functor g, Num a) => FF f g a -> f [a] -> g [a] taylor :: (Fractional a) => UU a -> a -> a -> [a] taylor0 :: (Fractional a) => UU a -> a -> a -> [a] maclaurin :: (Fractional a) => UU a -> a -> [a] maclaurin0 :: (Fractional a) => UU a -> a -> [a] -- | The dUM function calculates the first derivative of -- scalar-to-scalar monadic function by Forward AD diffM :: (Monad m, Num a) => UF m a -> a -> m a -- | The d'UM function calculates the result and first derivative -- of a scalar-to-scalar monadic function by Forward AD diffM' :: (Monad m, Num a) => UF m a -> a -> m (a, a) -- | A scalar-to-scalar automatically-differentiable function. type UU a = forall s. (Mode s) => AD s a -> AD s a -- | A scalar-to-non-scalar automatically-differentiable function. type UF f a = forall s. (Mode s) => AD s a -> f (AD s a) -- | A non-scalar-to-scalar automatically-differentiable function. type FU f a = forall s. (Mode s) => f (AD s a) -> AD s a -- | A non-scalar-to-non-scalar automatically-differentiable function. type FF f g a = forall s. (Mode s) => f (AD s a) -> g (AD s a) -- | AD serves as a common wrapper for different Mode -- instances, exposing a traditional numerical tower. Universal -- quantification is used to limit the actions in user code to machinery -- that will return the same answers under all AD modes, allowing us to -- use modes interchangeably as both the type level "brand" and -- dictionary, providing a common API. newtype AD f a AD :: f a -> AD f a runAD :: AD f a -> f a class (Lifted t) => Mode t lift :: (Mode t, Num a) => a -> t a (<+>) :: (Mode t, Num a) => t a -> t a -> t a (*^) :: (Mode t, Num a) => a -> t a -> t a (^*) :: (Mode t, Num a) => t a -> a -> t a (^/) :: (Mode t, Fractional a) => t a -> a -> t a zero :: (Mode t, Num a) => t a -- | Allows the choice of AD Mode to be specified at the term level -- for benchmarking or more complicated usage patterns. module Numeric.AD.Directed grad :: (Traversable f, Num a) => Direction -> FU f a -> f a -> f a grad' :: (Traversable f, Num a) => Direction -> FU f a -> f a -> (a, f a) jacobian :: (Traversable f, Traversable g, Num a) => Direction -> FF f g a -> f a -> g (f a) jacobian' :: (Traversable f, Traversable g, Num a) => Direction -> FF f g a -> f a -> g (a, f a) diff :: (Num a) => Direction -> UU a -> a -> a diff' :: (Num a) => Direction -> UU a -> a -> (a, a) -- | A scalar-to-scalar automatically-differentiable function. type UU a = forall s. (Mode s) => AD s a -> AD s a -- | A scalar-to-non-scalar automatically-differentiable function. type UF f a = forall s. (Mode s) => AD s a -> f (AD s a) -- | A non-scalar-to-scalar automatically-differentiable function. type FU f a = forall s. (Mode s) => f (AD s a) -> AD s a -- | A non-scalar-to-non-scalar automatically-differentiable function. type FF f g a = forall s. (Mode s) => f (AD s a) -> g (AD s a) data Direction Forward :: Direction Reverse :: Direction Tower :: Direction Mixed :: Direction class (Lifted t) => Mode t lift :: (Mode t, Num a) => a -> t a (<+>) :: (Mode t, Num a) => t a -> t a -> t a (*^) :: (Mode t, Num a) => a -> t a -> t a (^*) :: (Mode t, Num a) => t a -> a -> t a (^/) :: (Mode t, Fractional a) => t a -> a -> t a zero :: (Mode t, Num a) => t a -- | AD serves as a common wrapper for different Mode -- instances, exposing a traditional numerical tower. Universal -- quantification is used to limit the actions in user code to machinery -- that will return the same answers under all AD modes, allowing us to -- use modes interchangeably as both the type level "brand" and -- dictionary, providing a common API. newtype AD f a AD :: f a -> AD f a runAD :: AD f a -> f a instance Show Direction instance Eq Direction instance Ord Direction instance Read Direction instance Bounded Direction instance Enum Direction instance Ix Direction