diff options
author | sanine <sanine.not@pm.me> | 2023-11-21 23:48:32 -0600 |
---|---|---|
committer | sanine <sanine.not@pm.me> | 2023-11-21 23:48:32 -0600 |
commit | 8fb358e84770f69606f7f27c40cfdf0ce57cd026 (patch) | |
tree | 89652659b124f3112d12645cda5da31d2669d3c8 /src/Mind.hs | |
parent | 435c52c7330bcd49328a8facfc5a11b00e4a41bf (diff) |
fix warnings and bug in connectNeurons
Diffstat (limited to 'src/Mind.hs')
-rw-r--r-- | src/Mind.hs | 19 |
1 files changed, 10 insertions, 9 deletions
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) |