[Haskell-beginners] Automatic Differentiation

Jonas Béal jonas.beal at novadiscovery.com
Wed Aug 17 08:40:07 UTC 2016


Hello,

I have some questions about the Automatic Differentiation package in
Haskell (https://hackage.haskell.org/package/ad-4.3.2.1/docs/Numeric-AD.html
)
I need to compute the jacobian with that method and I have a type problem,
here a simplified example in order to focus on the error:

According to documentation I need to write "*jacobian function values*". So
I built the input *function. *Please notice this is important for me that
my function may depend on an external parameter (named factor here)
testFunctionForJacobian :: Fractional a => a -> [a] -> [a]
testFunctionForJacobian factor inputs = [(sum inputs) * factor]

Then, using *jacobian* function of Numeric.AD in terminal, as a test, it
works perfectly
>jacobian (testFunctionForJacobian 2) [1,2]
< [[2.0,2.0]]

No apparent type problem here
> :t (testFunctionForJacobian 2)
(testFunctionForJacobian 2) :: Fractional a => [a] -> [a]

But, I would like to insert that in a bigger function computing the jacobian
testJacobian :: Fractional a => a -> [a] -> [[a]]
testJacobian factor inputs = jacobian (testFunctionForJacobian factor)
inputs

This time it generates an error message about *factor*
Couldn't match expected type ‘Numeric.AD.Internal.Reverse.Reverse
<http://numeric.ad.internal.reverse.reverse/> s a’ with actual type ‘a’
‘a’ is a rigid type variable bound by the type signature for
testJacobian :: Fractional a => a -> [a] -> [[a]] s a’

All in all, my type seems implicitly correct in the terminal example but I
did not manage to write it explicitly in my function.

Here the *jacobian* function signature to help you answer me:






-- 
Jonas Béal

-- 
*This message is intended only for the personal and confidential use of the 
designated recipient(s) named above. If you are not the intended recipient 
of this message you are hereby notified that any review, dissemination, 
distribution or copying of this message is strictly prohibited. Email 
transmission cannot be guaranteed to be secure or error-free. Therefore, we 
do not represent that this information is complete or accurate and it 
should not be relied upon as such. All information is subject to change 
without notice.*
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.haskell.org/pipermail/beginners/attachments/20160817/2806c351/attachment.html>


More information about the Beginners mailing list