1

I'm pretty new to Haskell, and have been trying to solve this for a while.

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

The rest of the code (which isn't much) can be found here if you need: https://github.com/kennycason/haskell_nn/

Thanks a lot.

2 Answers 2

5

Here you go

(map (\n -> calculateNodeError n childLayer) (nodes layer) )
Sign up to request clarification or add additional context in comments.

1 Comment

Many thanks, that worked, I wasn't even aware that I could compose the function like that! :)
2

Here is another solution.

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

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.