我正在尝试压缩两个[[Float]]
数组,然后对每个元素执行计算。我认为生成的zip-ed数组将具有类型[([Float], [Float])]
。
但是我继续在Haskell告诉我的地方收到错误:
[1 of 1] Compiling Mod ( Mod.hs, interpreted )
NN.hs:38:42:
Couldn't match type ‘[Float]’ with ‘Float’
Expected type: [Float]
Actual type: [[Float]]
In the second argument of ‘zip’, namely ‘bs’
In the second argument of ‘map’, namely ‘(zip ws bs)’
Failed, modules loaded: none.
我似乎无法弄清楚MCVE,因为这就是(kinda / sorta)试图做的事情:
feedforward :: ([[Float]], [[Float]]) -> Float -> [Float]
feedforward (ws, bs) a = map (equation a) (zip ws bs)
where equation a (w, b) = (sum $ zipWith (*) w b) + a
但实际上编译了!而我的真实代码看起来像这样:
data NNetwork = NNetwork { nlayers :: Int
, sizes :: [Int]
, biases :: [[Float]]
, weights :: [[Float]] }
deriving (Show, Ord, Eq)
toFloat x = fromIntegral x :: Float
sig :: Float -> Float
sig a = 1 / (1 + exp (-a))
feedforward :: NNetwork -> Float -> [Float]
feedforward net a = map (eq22 a) (zip ws bs)
where bs = biases net
ws = weights net
dot a b = sum $ zipWith (*) a b
rep a b = replicate (length a) b
eq22 a (w, b) = sig $ (dot w (rep w a)) + b
然而无效!
- 提前致谢
答案 0 :(得分:2)
问题是:
eq22 :: Float -> ([Float], [Float]) -> Float
eq22 a (w, b) = sig $ (dot w (rep w a)) + b
除此之外,b
是[Float]
并用作Float
(请参阅+ b
)。你的意思是b
以上的某种功能吗?
此外,这些不是数组,而是列表。