Copyright | (c) Edward Kmett 2010-2015 |
---|---|
License | BSD3 |
Maintainer | ekmett@gmail.com |
Stability | experimental |
Portability | GHC only |
Safe Haskell | None |
Language | Haskell2010 |
Unsafe and often partial combinators intended for internal usage.
Handle with care.
Synopsis
- newtype Monomial = Monomial (IntMap Int)
- emptyMonomial :: Monomial
- addToMonomial :: Int -> Monomial -> Monomial
- indices :: Monomial -> [Int]
- data Sparse a
- apply :: (Traversable f, Num a) => (f (Sparse a) -> b) -> f a -> b
- vars :: (Traversable f, Num a) => f a -> f (Sparse a)
- d :: (Traversable f, Num a) => f b -> Sparse a -> f a
- d' :: (Traversable f, Num a) => f a -> Sparse a -> (a, f a)
- ds :: (Traversable f, Num a) => f b -> Sparse a -> Cofree f a
- skeleton :: Traversable f => f a -> f Int
- spartial :: Num a => [Int] -> Sparse a -> Maybe a
- partial :: Num a => [Int] -> Sparse a -> a
- vgrad :: Grad i o o' a => i -> o
- vgrad' :: Grad i o o' a => i -> o'
- vgrads :: Grads i o a => i -> o
- class Num a => Grad i o o' a | i -> a o o', o -> a i o', o' -> a i o where
- class Num a => Grads i o a | i -> a o, o -> a i where
- terms :: Monomial -> [(Integer, Monomial, Monomial)]
- primal :: Num a => Sparse a -> a
Documentation
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
skeleton :: Traversable f => f a -> f Int Source #
class Num a => Grad i o o' a | i -> a o o', o -> a i o', o' -> a i o where Source #
class Num a => Grads i o a | i -> a o, o -> a i where 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 Zero
s as much as possible.
The number of terms in the sum for order mi as of differentiation has
terms, so this is *much* more efficient
than the naive recursive differentiation with sum
(map
(+1) as)2^
terms.
The coefficients sum
asa
, which collect equivalent derivatives, are suitable products
of binomial coefficients.