From 8fb358e84770f69606f7f27c40cfdf0ce57cd026 Mon Sep 17 00:00:00 2001 From: sanine Date: Tue, 21 Nov 2023 23:48:32 -0600 Subject: fix warnings and bug in connectNeurons --- src/Mind.hs | 19 ++++++++++--------- 1 file changed, 10 insertions(+), 9 deletions(-) (limited to 'src') diff --git a/src/Mind.hs b/src/Mind.hs index 70b7494..359293c 100644 --- a/src/Mind.hs +++ b/src/Mind.hs @@ -70,7 +70,7 @@ validSource (Network _ h _) (Internal x) = -- insert a new edge into a neuron list, possibly failing insertEdge :: [[Edge]] -> Int -> Edge -> Maybe [[Edge]] insertEdge ns i e - | (inRange (0, length ns) i) = let (front, es:back) = splitAt i ns + | (inRange (0, (length ns)-1) i) = let (front, es:back) = splitAt i ns in Just $ front ++ [e:es] ++ back | otherwise = Nothing @@ -88,6 +88,7 @@ type InputState = ([Float], [Float]) type NewState = [Maybe Float] +output :: Network -> [Float] -> [Float] -> NewState -> [Float] output net input state state'= let numOutput = length $ outputNeurons net @@ -109,8 +110,8 @@ newState net input state = updateValue :: NewState -> Int -> Float -> NewState -updateValue state' index value = - let (front, _:back) = splitAt index state' +updateValue state' i value = + let (front, _:back) = splitAt i state' in front ++ (Just value):back @@ -132,15 +133,15 @@ getValue net inputState state' (Output x) = foldEdges:: Network -> InputState -> NewState -> NeuronIndex -> [Edge] -> (Float, NewState) foldEdges net (input, state) state' sink edges = let - (total, ns) = foldl - (\(total, ns) (Edge (source, w)) -> + (t, ns) = foldl + (\(total, nss) (Edge (source, w)) -> let - (value, ns') = if (sink == source) + (value, nss') = if (sink == source) then (state !! (getNeuronIndex source), ns) - else getValue net (input, state) ns source + else getValue net (input, state) nss source total' = (w * value) + total - in (total', ns') + in (total', nss') ) (0, state') edges - in (tanh total, ns) + in (tanh t, ns) -- cgit v1.2.1