简体   繁体   English

Haskell-将数组的每个元素与另一个参数一起传递给函数

[英]Haskell - Passing each element of array with another parameter to function

I'm pretty new to Haskell, and have been trying to solve this for a while. 我对Haskell来说还很陌生,并且已经尝试解决了一段时间。

I have a function: 我有一个功能:

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)

I am needing to pass each (nodes layer) and the childLayer to function calculateNodeError 我需要通过每个(nodes layer)childLayer起作用calculateNodeError

The rest of the code (which isn't much) can be found here if you need: https://github.com/kennycason/haskell_nn/ 如果需要,可以在这里找到其余的代码(不是很多): https : //github.com/kennycason/haskell_nn/

Thanks a lot. 非常感谢。

干得好

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

这是另一种解决方案。

map ((flip calculateNodeError) childLayer) (nodes layer)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 Haskell:为函数列表参数中的每个元素执行函数 - Haskell: Perform function for each element in function list parameter haskell 中是否有一个函数来确定列表中的每个元素是否在另一个列表中? - Is there a function in haskell to determine if each element in a list is in another list? 将函数作为参数传递并返回函数 - Haskell - Passing a function as a parameter and returning a function - Haskell 将每个函数应用于列表Haskell的每个元素 - Apply each function to each element of a list Haskell Haskell:调用列表中每个元素的函数 - Haskell: Call a function with each element in a list 如何在Haskell的列表中的每个元素上应用函数? - How to apply a function on each element in a list in Haskell? 在Haskell中将列表作为参数传递 - Passing a list as Parameter in Haskell 如何在haskell中将列表中的每个元素与另一个列表中的每个元素相除 - How to divide every element in a list with each element in another list in haskell 将打印文本的函数作为参数传递,在 Haskell 中的新状态之后执行它 - Passing as parameter a function that prints a text, executing it after new state in Haskell 将函数应用于列表中的每个元素到另一个列表中的每个元素-Haskell - Apply a function to every element in a list to every element in another list - Haskell
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM