ad-4.4.1: Automatic Differentiation

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

Numeric.AD.Internal.Sparse

Description

Unsafe and often partial combinators intended for internal usage.

Handle with care.

Synopsis

Documentation

newtype Monomial Source #

Constructors

Monomial (IntMap Int) 

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.

Constructors

Sparse !a (IntMap (Sparse a)) 
Zero 
Instances
(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] #

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

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 #

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 #

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 :: (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 => 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 #

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

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

Defined in Numeric.AD.Internal.Sparse

Methods

toRational :: Sparse a -> Rational #

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

Defined in Numeric.AD.Internal.Sparse

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 => Mode (Sparse a) Source # 
Instance details

Defined in Numeric.AD.Internal.Sparse

Associated Types

type Scalar (Sparse a) :: Type Source #

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

Defined in Numeric.AD.Internal.Sparse

Associated Types

type D (Sparse a) :: Type 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 => 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 [] a) a Source # 
Instance details

Defined in Numeric.AD.Internal.Sparse

Methods

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

unpacks :: ([a] -> Cofree [] a) -> Cofree [] 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 [] 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 Scalar (Sparse a) Source # 
Instance details

Defined in Numeric.AD.Internal.Sparse

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

Defined in Numeric.AD.Internal.Sparse

type D (Sparse a) = Sparse a

apply :: (Traversable f, Num a) => (f (Sparse a) -> b) -> f a -> b Source #

vars :: (Traversable f, Num a) => f a -> f (Sparse a) Source #

d :: (Traversable f, Num a) => f b -> Sparse a -> f a Source #

d' :: (Traversable f, Num a) => f a -> Sparse a -> (a, f a) Source #

ds :: (Traversable f, Num a) => f b -> Sparse a -> Cofree f a Source #

skeleton :: Traversable f => f a -> f Int Source #

spartial :: Num a => [Int] -> Sparse a -> Maybe a Source #

partial :: Num a => [Int] -> Sparse a -> a Source #

vgrad :: Grad i o o' a => i -> o Source #

vgrad' :: Grad i o o' a => i -> o' Source #

vgrads :: Grads i o a => i -> o Source #

class Num a => Grad i o o' a | i -> a o o', o -> a i o', o' -> a i o where Source #

Methods

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

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

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

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

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 #

class Num a => Grads i o a | i -> a o, o -> a i where Source #

Methods

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

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

Instances
Num a => Grads (Sparse a) (Cofree [] a) a Source # 
Instance details

Defined in Numeric.AD.Internal.Sparse

Methods

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

unpacks :: ([a] -> Cofree [] a) -> Cofree [] 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 [] a) -> a -> o Source #

terms :: Monomial -> [(Integer, Monomial, Monomial)] Source #

The value of the derivative of (f*g) of order mi is

sum [a * primal (partialS (indices b) f) * primal (partialS (indices c) g) | (a,b,c) <- terms mi ]

It is a bit more complicated in mul below, since we build the whole tree of derivatives and want to prune the tree with Zeros as much as possible. The number of terms in the sum for order mi as of differentiation has sum (map (+1) as) terms, so this is *much* more efficient than the naive recursive differentiation with 2^sum as terms. The coefficients a, which collect equivalent derivatives, are suitable products of binomial coefficients.

primal :: Num a => Sparse a -> a Source #