Hi cafe,<br><br>I'm trying to implement a Perceptron in Haskell and I found one in: <a href="http://jpmoresmau.blogspot.com/2007/05/perceptron-in-haskell.html">http://jpmoresmau.blogspot.com/2007/05/perceptron-in-haskell.html</a> (Thanks JP Moresmau) but there is one line I don't understand, I was wondering if someone could explain it to me. I know the theory behind a perceptron, my question is more about the Haskell syntax in that line I don't understand.<br>
<br>epoch :: [([Float],Float)] -> -- ^ Test Cases and Expected Values for each test case<br> [Float] -> -- ^ weights<br> ([Float],Float) -- ^ New weights, delta<br>epoch allInputs weights=<br>
let<br> f w (inputs,expected) = step inputs w expected -- I don't understand this line<br> newWeights = foldl f weights allInputs -- Neither this one<br> delta = (foldl (+) 0 (map abs (zipWith (-) newWeights weights))) / (fromIntegral $ length weights)<br>
in (newWeights,delta)<br><br>What is f and what is w? I really don't get it, Is like it is defining a function f which calls step unziping the input, taking one of the elements from the fst and it's corresponding snd and invoking step with that, along with w (which seems to be a list according to step's signature but I don't know where it comes from), and then applying fold to the weights and all the Inputs using that f function... But I don't get it!<br>
<br>Maybe if someone could rewrite that redefining f as an separate function and calling fold with that function I'll get it.<br><br>The input for epoch would be something like this:<br>epoch [([0,0],0),([0,1],0),([1,0],0),([1,1],1)] [-0,413,0.135]<br>
<br>and the output for that examples is:<br>([0.0,412.9],3.333537e-2)<br><br><br>Thanks a lot,<br><br>Hector Guilarte<br>