From 435c52c7330bcd49328a8facfc5a11b00e4a41bf Mon Sep 17 00:00:00 2001 From: sanine Date: Tue, 21 Nov 2023 23:41:38 -0600 Subject: implement self-connected computation --- src/Mind.hs | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) (limited to 'src') diff --git a/src/Mind.hs b/src/Mind.hs index cb78a1e..70b7494 100644 --- a/src/Mind.hs +++ b/src/Mind.hs @@ -121,21 +121,23 @@ getValue net inputState state' (Internal x) = in if isJust cached then (fromJust cached, state') else let - (value, ns) = foldEdges net inputState state' (internalNeurons net !! x) + (value, ns) = foldEdges net inputState state' (Internal x) (internalNeurons net !! x) nss = updateValue ns x value in (value, nss) getValue net inputState state' (Output x) = - foldEdges net inputState state' (outputNeurons net !! x) + foldEdges net inputState state' (Output x) (outputNeurons net !! x) -foldEdges:: Network -> InputState -> NewState -> [Edge] -> (Float, NewState) -foldEdges net (input, state) state' edges = +foldEdges:: Network -> InputState -> NewState -> NeuronIndex -> [Edge] -> (Float, NewState) +foldEdges net (input, state) state' sink edges = let (total, ns) = foldl (\(total, ns) (Edge (source, w)) -> let - (value, ns') = getValue net (input, state) ns source + (value, ns') = if (sink == source) + then (state !! (getNeuronIndex source), ns) + else getValue net (input, state) ns source total' = (w * value) + total in (total', ns') ) -- cgit v1.2.1