ad-4.4: Automatic Differentiation

Copyright(c) Edward Kmett 2010-2015
LicenseBSD3
Maintainerekmett@gmail.com
Stabilityexperimental
PortabilityGHC only
Safe HaskellNone
LanguageHaskell2010

Numeric.AD.Mode.Forward

Contents

Description

Forward mode automatic differentiation

Synopsis

Documentation

data AD s a Source #

Instances
Bounded a => Bounded (AD s a) Source # 
Instance details

Defined in Numeric.AD.Internal.Type

Methods

minBound :: AD s a #

maxBound :: AD s a #

Enum a => Enum (AD s a) Source # 
Instance details

Defined in Numeric.AD.Internal.Type

Methods

succ :: AD s a -> AD s a #

pred :: AD s a -> AD s a #

toEnum :: Int -> AD s a #

fromEnum :: AD s a -> Int #

enumFrom :: AD s a -> [AD s a] #

enumFromThen :: AD s a -> AD s a -> [AD s a] #

enumFromTo :: AD s a -> AD s a -> [AD s a] #

enumFromThenTo :: AD s a -> AD s a -> AD s a -> [AD s a] #

Eq a => Eq (AD s a) Source # 
Instance details

Defined in Numeric.AD.Internal.Type

Methods

(==) :: AD s a -> AD s a -> Bool #

(/=) :: AD s a -> AD s a -> Bool #

Floating a => Floating (AD s a) Source # 
Instance details

Defined in Numeric.AD.Internal.Type

Methods

pi :: AD s a #

exp :: AD s a -> AD s a #

log :: AD s a -> AD s a #

sqrt :: AD s a -> AD s a #

(**) :: AD s a -> AD s a -> AD s a #

logBase :: AD s a -> AD s a -> AD s a #

sin :: AD s a -> AD s a #

cos :: AD s a -> AD s a #

tan :: AD s a -> AD s a #

asin :: AD s a -> AD s a #

acos :: AD s a -> AD s a #

atan :: AD s a -> AD s a #

sinh :: AD s a -> AD s a #

cosh :: AD s a -> AD s a #

tanh :: AD s a -> AD s a #

asinh :: AD s a -> AD s a #

acosh :: AD s a -> AD s a #

atanh :: AD s a -> AD s a #

log1p :: AD s a -> AD s a #

expm1 :: AD s a -> AD s a #

log1pexp :: AD s a -> AD s a #

log1mexp :: AD s a -> AD s a #

Fractional a => Fractional (AD s a) Source # 
Instance details

Defined in Numeric.AD.Internal.Type

Methods

(/) :: AD s a -> AD s a -> AD s a #

recip :: AD s a -> AD s a #

fromRational :: Rational -> AD s a #

Num a => Num (AD s a) Source # 
Instance details

Defined in Numeric.AD.Internal.Type

Methods

(+) :: AD s a -> AD s a -> AD s a #

(-) :: AD s a -> AD s a -> AD s a #

(*) :: AD s a -> AD s a -> AD s a #

negate :: AD s a -> AD s a #

abs :: AD s a -> AD s a #

signum :: AD s a -> AD s a #

fromInteger :: Integer -> AD s a #

Ord a => Ord (AD s a) Source # 
Instance details

Defined in Numeric.AD.Internal.Type

Methods

compare :: AD s a -> AD s a -> Ordering #

(<) :: AD s a -> AD s a -> Bool #

(<=) :: AD s a -> AD s a -> Bool #

(>) :: AD s a -> AD s a -> Bool #

(>=) :: AD s a -> AD s a -> Bool #

max :: AD s a -> AD s a -> AD s a #

min :: AD s a -> AD s a -> AD s a #

Read a => Read (AD s a) Source # 
Instance details

Defined in Numeric.AD.Internal.Type

Methods

readsPrec :: Int -> ReadS (AD s a) #

readList :: ReadS [AD s a] #

readPrec :: ReadPrec (AD s a) #

readListPrec :: ReadPrec [AD s a] #

Real a => Real (AD s a) Source # 
Instance details

Defined in Numeric.AD.Internal.Type

Methods

toRational :: AD s a -> Rational #

RealFloat a => RealFloat (AD s a) Source # 
Instance details

Defined in Numeric.AD.Internal.Type

Methods

floatRadix :: AD s a -> Integer #

floatDigits :: AD s a -> Int #

floatRange :: AD s a -> (Int, Int) #

decodeFloat :: AD s a -> (Integer, Int) #

encodeFloat :: Integer -> Int -> AD s a #

exponent :: AD s a -> Int #

significand :: AD s a -> AD s a #

scaleFloat :: Int -> AD s a -> AD s a #

isNaN :: AD s a -> Bool #

isInfinite :: AD s a -> Bool #

isDenormalized :: AD s a -> Bool #

isNegativeZero :: AD s a -> Bool #

isIEEE :: AD s a -> Bool #

atan2 :: AD s a -> AD s a -> AD s a #

RealFrac a => RealFrac (AD s a) Source # 
Instance details

Defined in Numeric.AD.Internal.Type

Methods

properFraction :: Integral b => AD s a -> (b, AD s a) #

truncate :: Integral b => AD s a -> b #

round :: Integral b => AD s a -> b #

ceiling :: Integral b => AD s a -> b #

floor :: Integral b => AD s a -> b #

Show a => Show (AD s a) Source # 
Instance details

Defined in Numeric.AD.Internal.Type

Methods

showsPrec :: Int -> AD s a -> ShowS #

show :: AD s a -> String #

showList :: [AD s a] -> ShowS #

Erf a => Erf (AD s a) Source # 
Instance details

Defined in Numeric.AD.Internal.Type

Methods

erf :: AD s a -> AD s a #

erfc :: AD s a -> AD s a #

erfcx :: AD s a -> AD s a #

normcdf :: AD s a -> AD s a #

InvErf a => InvErf (AD s a) Source # 
Instance details

Defined in Numeric.AD.Internal.Type

Methods

inverf :: AD s a -> AD s a #

inverfc :: AD s a -> AD s a #

invnormcdf :: AD s a -> AD s a #

Mode a => Mode (AD s a) Source # 
Instance details

Defined in Numeric.AD.Internal.Type

Associated Types

type Scalar (AD s a) :: Type Source #

Methods

isKnownConstant :: AD s a -> Bool Source #

isKnownZero :: AD s a -> Bool Source #

auto :: Scalar (AD s a) -> AD s a Source #

(*^) :: Scalar (AD s a) -> AD s a -> AD s a Source #

(^*) :: AD s a -> Scalar (AD s a) -> AD s a Source #

(^/) :: AD s a -> Scalar (AD s a) -> AD s a Source #

zero :: AD s a Source #

type Scalar (AD s a) Source # 
Instance details

Defined in Numeric.AD.Internal.Type

type Scalar (AD s a) = Scalar a

data Forward a Source #

Forward mode AD

Instances
(Num a, Bounded a) => Bounded (Forward a) Source # 
Instance details

Defined in Numeric.AD.Internal.Forward

(Num a, Enum a) => Enum (Forward a) Source # 
Instance details

Defined in Numeric.AD.Internal.Forward

Methods

succ :: Forward a -> Forward a #

pred :: Forward a -> Forward a #

toEnum :: Int -> Forward a #

fromEnum :: Forward a -> Int #

enumFrom :: Forward a -> [Forward a] #

enumFromThen :: Forward a -> Forward a -> [Forward a] #

enumFromTo :: Forward a -> Forward a -> [Forward a] #

enumFromThenTo :: Forward a -> Forward a -> Forward a -> [Forward a] #

(Num a, Eq a) => Eq (Forward a) Source # 
Instance details

Defined in Numeric.AD.Internal.Forward

Methods

(==) :: Forward a -> Forward a -> Bool #

(/=) :: Forward a -> Forward a -> Bool #

Floating a => Floating (Forward a) Source # 
Instance details

Defined in Numeric.AD.Internal.Forward

Methods

pi :: Forward a #

exp :: Forward a -> Forward a #

log :: Forward a -> Forward a #

sqrt :: Forward a -> Forward a #

(**) :: Forward a -> Forward a -> Forward a #

logBase :: Forward a -> Forward a -> Forward a #

sin :: Forward a -> Forward a #

cos :: Forward a -> Forward a #

tan :: Forward a -> Forward a #

asin :: Forward a -> Forward a #

acos :: Forward a -> Forward a #

atan :: Forward a -> Forward a #

sinh :: Forward a -> Forward a #

cosh :: Forward a -> Forward a #

tanh :: Forward a -> Forward a #

asinh :: Forward a -> Forward a #

acosh :: Forward a -> Forward a #

atanh :: Forward a -> Forward a #

log1p :: Forward a -> Forward a #

expm1 :: Forward a -> Forward a #

log1pexp :: Forward a -> Forward a #

log1mexp :: Forward a -> Forward a #

Fractional a => Fractional (Forward a) Source # 
Instance details

Defined in Numeric.AD.Internal.Forward

Methods

(/) :: Forward a -> Forward a -> Forward a #

recip :: Forward a -> Forward a #

fromRational :: Rational -> Forward a #

Data a => Data (Forward a) Source # 
Instance details

Defined in Numeric.AD.Internal.Forward

Methods

gfoldl :: (forall d b. Data d => c (d -> b) -> d -> c b) -> (forall g. g -> c g) -> Forward a -> c (Forward a) #

gunfold :: (forall b r. Data b => c (b -> r) -> c r) -> (forall r. r -> c r) -> Constr -> c (Forward a) #

toConstr :: Forward a -> Constr #

dataTypeOf :: Forward a -> DataType #

dataCast1 :: Typeable t => (forall d. Data d => c (t d)) -> Maybe (c (Forward a)) #

dataCast2 :: Typeable t => (forall d e. (Data d, Data e) => c (t d e)) -> Maybe (c (Forward a)) #

gmapT :: (forall b. Data b => b -> b) -> Forward a -> Forward a #

gmapQl :: (r -> r' -> r) -> r -> (forall d. Data d => d -> r') -> Forward a -> r #

gmapQr :: (r' -> r -> r) -> r -> (forall d. Data d => d -> r') -> Forward a -> r #

gmapQ :: (forall d. Data d => d -> u) -> Forward a -> [u] #

gmapQi :: Int -> (forall d. Data d => d -> u) -> Forward a -> u #

gmapM :: Monad m => (forall d. Data d => d -> m d) -> Forward a -> m (Forward a) #

gmapMp :: MonadPlus m => (forall d. Data d => d -> m d) -> Forward a -> m (Forward a) #

gmapMo :: MonadPlus m => (forall d. Data d => d -> m d) -> Forward a -> m (Forward a) #

Num a => Num (Forward a) Source # 
Instance details

Defined in Numeric.AD.Internal.Forward

Methods

(+) :: Forward a -> Forward a -> Forward a #

(-) :: Forward a -> Forward a -> Forward a #

(*) :: Forward a -> Forward a -> Forward a #

negate :: Forward a -> Forward a #

abs :: Forward a -> Forward a #

signum :: Forward a -> Forward a #

fromInteger :: Integer -> Forward a #

(Num a, Ord a) => Ord (Forward a) Source # 
Instance details

Defined in Numeric.AD.Internal.Forward

Methods

compare :: Forward a -> Forward a -> Ordering #

(<) :: Forward a -> Forward a -> Bool #

(<=) :: Forward a -> Forward a -> Bool #

(>) :: Forward a -> Forward a -> Bool #

(>=) :: Forward a -> Forward a -> Bool #

max :: Forward a -> Forward a -> Forward a #

min :: Forward a -> Forward a -> Forward a #

Real a => Real (Forward a) Source # 
Instance details

Defined in Numeric.AD.Internal.Forward

Methods

toRational :: Forward a -> Rational #

RealFloat a => RealFloat (Forward a) Source # 
Instance details

Defined in Numeric.AD.Internal.Forward

RealFrac a => RealFrac (Forward a) Source # 
Instance details

Defined in Numeric.AD.Internal.Forward

Methods

properFraction :: Integral b => Forward a -> (b, Forward a) #

truncate :: Integral b => Forward a -> b #

round :: Integral b => Forward a -> b #

ceiling :: Integral b => Forward a -> b #

floor :: Integral b => Forward a -> b #

Show a => Show (Forward a) Source # 
Instance details

Defined in Numeric.AD.Internal.Forward

Methods

showsPrec :: Int -> Forward a -> ShowS #

show :: Forward a -> String #

showList :: [Forward a] -> ShowS #

Erf a => Erf (Forward a) Source # 
Instance details

Defined in Numeric.AD.Internal.Forward

Methods

erf :: Forward a -> Forward a #

erfc :: Forward a -> Forward a #

erfcx :: Forward a -> Forward a #

normcdf :: Forward a -> Forward a #

InvErf a => InvErf (Forward a) Source # 
Instance details

Defined in Numeric.AD.Internal.Forward

Methods

inverf :: Forward a -> Forward a #

inverfc :: Forward a -> Forward a #

invnormcdf :: Forward a -> Forward a #

Num a => Mode (Forward a) Source # 
Instance details

Defined in Numeric.AD.Internal.Forward

Associated Types

type Scalar (Forward a) :: Type Source #

Num a => Jacobian (Forward a) Source # 
Instance details

Defined in Numeric.AD.Internal.Forward

Associated Types

type D (Forward a) :: Type Source #

Methods

unary :: (Scalar (Forward a) -> Scalar (Forward a)) -> D (Forward a) -> Forward a -> Forward a Source #

lift1 :: (Scalar (Forward a) -> Scalar (Forward a)) -> (D (Forward a) -> D (Forward a)) -> Forward a -> Forward a Source #

lift1_ :: (Scalar (Forward a) -> Scalar (Forward a)) -> (D (Forward a) -> D (Forward a) -> D (Forward a)) -> Forward a -> Forward a Source #

binary :: (Scalar (Forward a) -> Scalar (Forward a) -> Scalar (Forward a)) -> D (Forward a) -> D (Forward a) -> Forward a -> Forward a -> Forward a Source #

lift2 :: (Scalar (Forward a) -> Scalar (Forward a) -> Scalar (Forward a)) -> (D (Forward a) -> D (Forward a) -> (D (Forward a), D (Forward a))) -> Forward a -> Forward a -> Forward a Source #

lift2_ :: (Scalar (Forward a) -> Scalar (Forward a) -> Scalar (Forward a)) -> (D (Forward a) -> D (Forward a) -> D (Forward a) -> (D (Forward a), D (Forward a))) -> Forward a -> Forward a -> Forward a Source #

type Scalar (Forward a) Source # 
Instance details

Defined in Numeric.AD.Internal.Forward

type Scalar (Forward a) = a
type D (Forward a) Source # 
Instance details

Defined in Numeric.AD.Internal.Forward

type D (Forward a) = Id a

auto :: Mode t => Scalar t -> t Source #

Embed a constant

Gradient

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

Compute the gradient of a function using forward mode AD.

Note, this performs O(n) worse than grad for n inputs, in exchange for better space utilization.

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

Compute the gradient and answer to a function using forward mode AD.

Note, this performs O(n) worse than grad' for n inputs, in exchange for better space utilization.

gradWith :: (Traversable f, Num a) => (a -> a -> b) -> (forall s. f (AD s (Forward a)) -> AD s (Forward a)) -> f a -> f b Source #

Compute the gradient of a function using forward mode AD and combine the result with the input using a user-specified function.

Note, this performs O(n) worse than gradWith for n inputs, in exchange for better space utilization.

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

Compute the gradient of a function using forward mode AD and the answer, and combine the result with the input using a user-specified function.

Note, this performs O(n) worse than gradWith' for n inputs, in exchange for better space utilization.

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

Jacobian

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

Compute the Jacobian using Forward mode AD. This must transpose the result, so jacobianT is faster and allows more result types.

>>> jacobian (\[x,y] -> [y,x,x+y,x*y,exp x * sin y]) [pi,1]
[[0.0,1.0],[1.0,0.0],[1.0,1.0],[1.0,3.141592653589793],[19.472221418841606,12.502969588876512]]

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

Compute the Jacobian using Forward mode AD along with the actual answer.

jacobianWith :: (Traversable f, Traversable g, Num a) => (a -> a -> b) -> (forall s. f (AD s (Forward a)) -> g (AD s (Forward a))) -> f a -> g (f b) Source #

Compute the Jacobian using Forward mode AD and combine the output with the input. This must transpose the result, so jacobianWithT is faster, and allows more result types.

jacobianWith' :: (Traversable f, Traversable g, Num a) => (a -> a -> b) -> (forall s. f (AD s (Forward a)) -> g (AD s (Forward a))) -> f a -> g (a, f b) Source #

Compute the Jacobian using Forward mode AD combined with the input using a user specified function, along with the actual answer.

Transposed Jacobian

jacobianT :: (Traversable f, Functor g, Num a) => (forall s. f (AD s (Forward a)) -> g (AD s (Forward a))) -> f a -> f (g a) Source #

A fast, simple, transposed Jacobian computed with forward-mode AD.

jacobianWithT :: (Traversable f, Functor g, Num a) => (a -> a -> b) -> (forall s. f (AD s (Forward a)) -> g (AD s (Forward a))) -> f a -> f (g b) Source #

A fast, simple, transposed Jacobian computed with Forward mode AD that combines the output with the input.

Hessian Product

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

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

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

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

Derivatives

diff :: Num a => (forall s. AD s (Forward a) -> AD s (Forward a)) -> a -> a Source #

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

>>> diff sin 0
1.0

diff' :: Num a => (forall s. AD s (Forward a) -> AD s (Forward a)) -> a -> (a, a) Source #

The diff' function calculates the result and first derivative of scalar-to-scalar function by Forward mode AD

diff' sin == sin &&& cos
diff' f = f &&& d f
>>> diff' sin 0
(0.0,1.0)
>>> diff' exp 0
(1.0,1.0)

diffF :: (Functor f, Num a) => (forall s. AD s (Forward a) -> f (AD s (Forward a))) -> a -> f a Source #

The diffF function calculates the first derivatives of scalar-to-nonscalar function by Forward mode AD

>>> diffF (\a -> [sin a, cos a]) 0
[1.0,-0.0]

diffF' :: (Functor f, Num a) => (forall s. AD s (Forward a) -> f (AD s (Forward a))) -> a -> f (a, a) Source #

The diffF' function calculates the result and first derivatives of a scalar-to-non-scalar function by Forward mode AD

>>> diffF' (\a -> [sin a, cos a]) 0
[(0.0,1.0),(1.0,-0.0)]

Directional Derivatives

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

Compute the directional derivative of a function given a zipped up Functor of the input values and their derivatives

du' :: (Functor f, Num a) => (forall s. f (AD s (Forward a)) -> AD s (Forward a)) -> f (a, a) -> (a, a) Source #

Compute the answer and directional derivative of a function given a zipped up Functor of the input values and their derivatives

duF :: (Functor f, Functor g, Num a) => (forall s. f (AD s (Forward a)) -> g (AD s (Forward a))) -> f (a, a) -> g a Source #

Compute a vector of directional derivatives for a function given a zipped up Functor of the input values and their derivatives.

duF' :: (Functor f, Functor g, Num a) => (forall s. f (AD s (Forward a)) -> g (AD s (Forward a))) -> f (a, a) -> g (a, a) Source #

Compute a vector of answers and directional derivatives for a function given a zipped up Functor of the input values and their derivatives.