ad-4.5.6: Automatic Differentiation
Copyright(c) Edward Kmett 2010-2021
LicenseBSD3
Maintainerekmett@gmail.com
Stabilityexperimental
PortabilityGHC only
Safe HaskellSafe-Inferred
LanguageHaskell2010

Numeric.AD.Mode.Sparse

Description

Higher order derivatives via a "dual number tower".

Synopsis

Documentation

data AD s a Source #

Instances

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

Defined in Numeric.AD.Internal.Type

Associated Types

type Scalar (AD s a) Source #

Methods

isKnownConstant :: AD s a -> Bool Source #

asKnownConstant :: AD s a -> Maybe (Scalar (AD s a)) 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 #

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] #

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 #

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 #

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 #

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] #

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 #

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

Defined in Numeric.AD.Internal.Type

Methods

toRational :: AD s a -> Rational #

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 #

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 #

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 #

type Scalar (AD s a) Source # 
Instance details

Defined in Numeric.AD.Internal.Type

type Scalar (AD s a) = Scalar a

data Sparse a Source #

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

Instances

Instances details
Num a => Jacobian (Sparse a) Source # 
Instance details

Defined in Numeric.AD.Internal.Sparse

Associated Types

type D (Sparse a) Source #

Methods

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

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

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

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

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

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

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

Defined in Numeric.AD.Internal.Sparse

Associated Types

type Scalar (Sparse a) Source #

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

Defined in Numeric.AD.Internal.Sparse

Methods

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

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

toConstr :: Sparse a -> Constr #

dataTypeOf :: Sparse a -> DataType #

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

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

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

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

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

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

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

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

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

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

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

Defined in Numeric.AD.Internal.Sparse

Methods

minBound :: Sparse a #

maxBound :: Sparse a #

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

Defined in Numeric.AD.Internal.Sparse

Methods

succ :: Sparse a -> Sparse a #

pred :: Sparse a -> Sparse a #

toEnum :: Int -> Sparse a #

fromEnum :: Sparse a -> Int #

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

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

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

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

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

Defined in Numeric.AD.Internal.Sparse

Methods

pi :: Sparse a #

exp :: Sparse a -> Sparse a #

log :: Sparse a -> Sparse a #

sqrt :: Sparse a -> Sparse a #

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

logBase :: Sparse a -> Sparse a -> Sparse a #

sin :: Sparse a -> Sparse a #

cos :: Sparse a -> Sparse a #

tan :: Sparse a -> Sparse a #

asin :: Sparse a -> Sparse a #

acos :: Sparse a -> Sparse a #

atan :: Sparse a -> Sparse a #

sinh :: Sparse a -> Sparse a #

cosh :: Sparse a -> Sparse a #

tanh :: Sparse a -> Sparse a #

asinh :: Sparse a -> Sparse a #

acosh :: Sparse a -> Sparse a #

atanh :: Sparse a -> Sparse a #

log1p :: Sparse a -> Sparse a #

expm1 :: Sparse a -> Sparse a #

log1pexp :: Sparse a -> Sparse a #

log1mexp :: Sparse a -> Sparse a #

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

Defined in Numeric.AD.Internal.Sparse

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

Defined in Numeric.AD.Internal.Sparse

Methods

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

(-) :: Sparse a -> Sparse a -> Sparse a #

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

negate :: Sparse a -> Sparse a #

abs :: Sparse a -> Sparse a #

signum :: Sparse a -> Sparse a #

fromInteger :: Integer -> Sparse a #

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

Defined in Numeric.AD.Internal.Sparse

Methods

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

recip :: Sparse a -> Sparse a #

fromRational :: Rational -> Sparse a #

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

Defined in Numeric.AD.Internal.Sparse

Methods

toRational :: Sparse a -> Rational #

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

Defined in Numeric.AD.Internal.Sparse

Methods

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

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

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

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

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

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

Defined in Numeric.AD.Internal.Sparse

Methods

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

show :: Sparse a -> String #

showList :: [Sparse a] -> ShowS #

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

Defined in Numeric.AD.Internal.Sparse

Methods

erf :: Sparse a -> Sparse a #

erfc :: Sparse a -> Sparse a #

erfcx :: Sparse a -> Sparse a #

normcdf :: Sparse a -> Sparse a #

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

Defined in Numeric.AD.Internal.Sparse

Methods

inverf :: Sparse a -> Sparse a #

inverfc :: Sparse a -> Sparse a #

invnormcdf :: Sparse a -> Sparse a #

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

Defined in Numeric.AD.Internal.Sparse

Methods

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

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

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

Defined in Numeric.AD.Internal.Sparse

Methods

compare :: Sparse a -> Sparse a -> Ordering #

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

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

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

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

max :: Sparse a -> Sparse a -> Sparse a #

min :: Sparse a -> Sparse a -> Sparse a #

Num a => Grad (Sparse a) [a] (a, [a]) a Source # 
Instance details

Defined in Numeric.AD.Internal.Sparse

Methods

pack :: Sparse a -> [Sparse a] -> Sparse a Source #

unpack :: ([a] -> [a]) -> [a] Source #

unpack' :: ([a] -> (a, [a])) -> (a, [a]) Source #

Num a => Grads (Sparse a) (Cofree List a) a Source # 
Instance details

Defined in Numeric.AD.Internal.Sparse

Methods

packs :: Sparse a -> [Sparse a] -> Sparse a Source #

unpacks :: ([a] -> Cofree List a) -> Cofree List a Source #

Grads i o a => Grads (Sparse a -> i) (a -> o) a Source # 
Instance details

Defined in Numeric.AD.Internal.Sparse

Methods

packs :: (Sparse a -> i) -> [Sparse a] -> Sparse a Source #

unpacks :: ([a] -> Cofree List a) -> a -> o Source #

Grad i o o' a => Grad (Sparse a -> i) (a -> o) (a -> o') a Source # 
Instance details

Defined in Numeric.AD.Internal.Sparse

Methods

pack :: (Sparse a -> i) -> [Sparse a] -> Sparse a Source #

unpack :: ([a] -> [a]) -> a -> o Source #

unpack' :: ([a] -> (a, [a])) -> a -> o' Source #

type D (Sparse a) Source # 
Instance details

Defined in Numeric.AD.Internal.Sparse

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

Defined in Numeric.AD.Internal.Sparse

type Scalar (Sparse a) = a

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

Embed a constant

Sparse Gradients

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

The grad function calculates the gradient of a non-scalar-to-scalar function with sparse-mode AD in a single pass.

>>> grad (\[x,y,z] -> x*y+z) [1,2,3]
[2,1,1]
>>> grad (\[x,y] -> x**y) [0,2]
[0.0,NaN]

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

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

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

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

Sparse Jacobians (synonyms)

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

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

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

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

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

Sparse Hessians

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

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

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

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