[Haskell-cafe] Questions about Numeric.AD / Automatic differentiation
seanmatthews1 at gmail.com
Tue Nov 21 12:24:55 UTC 2017
After working through the other problems, that fills the last remaining
hole (at least for the moment).
On Tue, Nov 21, 2017 at 7:48 AM, Li-yao Xia <lysxia at gmail.com> wrote:
> Hi Sean,
> AD relies on overloading to instrument functions so they can be
> f :: Num a => m1 (m2 a) -> m3 a -> a
> By looking at the type of "grad", one can see that f will be specialized
> at type "Reverse s Double":
> f :: m1 (m2 (Reverse s Double)) -> m3 (Reverse s Double) -> Reverse s
> So if "x :: m1 (m2 Double)", you will need to apply "auto :: Double ->
> Reverse s Double" to lift x to the right type.
> df x theta = grad (f x') theta
> where x' = (fmap . fmap) auto x
> On 11/20/2017 05:05 PM, Sean Matthews wrote:
>> I'm having some problems with Numeric.AD (translation, things are not
>> working for reason that I don't understand). Note I don't have much
>> experience with this package, so these are newbie questions, thus
>> appropriate answers may involve pointing me to a document somewhere out
>> there on the net.
>> Anyway, here is my problem:
>> I have a function (call it f x theta) which I have defined purely in terms
>> of basic arithmetic functions (+/-/(/)/*/**) glued together using
>> applicative functor operations has type
>> f :: m1 (m2 Double) -> m3 Double -> Double
>> f x theta = ...
>> m1 m2 and m3 are all Traversable.
>> f is defined purely in terms of basic arithmetic operations,
>> glued together using standard applicative functor operations, and m1 m2
>> m3 are all pretty trivial record types (no recursion, even).
>> I would like to write
>> df x theta = grad (f x) theta
>> But it refuses to type, even though (admittedly quite a lot) simpler
>> versions do.
>> So what am I missing? Does AD not go through Applicative? That seems
>> unlikely to me.
>> Any advice / suggestions, etc. gratefully received.
>> Sean Matthews
>> Haskell-Cafe mailing list
>> To (un)subscribe, modify options or view archives go to:
>> Only members subscribed via the mailman list are allowed to post.
seanmatthews1 at gmail.com / +49 1515 800 1901
-------------- next part --------------
An HTML attachment was scrubbed...
More information about the Haskell-Cafe