給出了基於矢量一個非常簡單的矩陣的定義: import Numeric.AD
import qualified Data.Vector as V
newtype Mat a = Mat { unMat :: V.Vector a }
scale' f = Mat . V.map (*f) . unMat
add' a b = Mat $ V.zipWith (+) (unMat a)
我試圖在Haskell中使用automatic differentiation來處理非線性控制問題,但在使其運行時遇到一些問題。我基本上有一個cost函數,應該在初始狀態下對其進行優化。該類型是: data Reference a = Reference a deriving Functor
data Plant a = Plant a deriving Functor
optimize :
我試圖編譯從Numeric.AD以下小例子: import Numeric.AD
timeAndGrad f l = grad f l
main = putStrLn "hi"
,我碰到這個錯誤: test.hs:3:24:
Couldn't match expected type ‘f (Numeric.AD.Internal.Reverse.Reverse
下面的程序類型檢查: {-# LANGUAGE RankNTypes #-}
import Numeric.AD (grad)
newtype Fun = Fun (forall a. Num a => [a] -> a)
test1 [u, v] = (v - (u * u * u))
test2 [u, v] = ((u * u) + (v * v) - 1)
main =