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.
- 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 - 1) distinct nth partial derivatives of a function with k inputs.
(Num a, Bounded a) => Bounded (Sparse a) # | |
(Num a, Enum a) => Enum (Sparse a) # | |
(Num a, Eq a) => Eq (Sparse a) # | |
Floating a => Floating (Sparse a) # | |
Fractional a => Fractional (Sparse a) # | |
Data a => Data (Sparse a) Source # | |
Num a => Num (Sparse a) # | |
(Num a, Ord a) => Ord (Sparse a) # | |
Real a => Real (Sparse a) # | |
RealFloat a => RealFloat (Sparse a) # | |
RealFrac a => RealFrac (Sparse a) # | |
Show a => Show (Sparse a) Source # | |
Erf a => Erf (Sparse a) # | |
InvErf a => InvErf (Sparse a) # | |
Num a => Mode (Sparse a) Source # | |
Num a => Jacobian (Sparse a) Source # | |
Num a => Grad (Sparse a) [a] (a, [a]) a Source # | |
Num a => Grads (Sparse a) (Cofree [] a) a Source # | |
Grads i o a => Grads (Sparse a -> i) (a -> o) a Source # | |
Grad i o o' a => Grad (Sparse a -> i) (a -> o) (a -> o') a Source # | |
type Scalar (Sparse a) Source # | |
type D (Sparse a) Source # | |
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 #
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.