2013-06-04 50 views
1

我對Haskell來說很新,並且一直試圖解決這個問題。Haskell - 將另一個參數的每個元素傳遞給函數

我有一個函數:

sumNodeError :: Node -> Layer -> Double 
sumNodeError node childLayer = foldl (+) 0 (listProduct (weights node) (errors childLayer)) 

calculateNodeError :: Node -> Layer -> Double 
calculateNodeError node childLayer = (sumNodeError node childLayer) * (value node) * (1.0 - (value node)) 

-- problem is in this function 
calculateErrors :: Layer -> Layer -> Layer 
calculateErrors layer childLayer = Layer (nodes layer) 
             (map calculateNodeError (nodes layer) childLayer) -- problem, need to map each of the nodes in the layer, and the childLayer to calculateNodeError 
             (teacherSignals layer) 
             (learningRate layer) 

我需要通過每個(nodes layer)childLayer運作calculateNodeError

的代碼的其餘部分(不太多),可以在這裏找到,如果你需要:https://github.com/kennycason/haskell_nn/

非常感謝。

回答

5

在這裏你去

(map (\n -> calculateNodeError n childLayer) (nodes layer)) 
+0

非常感謝,這工作,我甚至不知道我可以編寫這樣的功能! :) –

2

這裏是另一種解決方案。

map ((flip calculateNodeError) childLayer) (nodes layer) 
相關問題