summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/Mind.hs19
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)