summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/Mind.hs37
1 files changed, 20 insertions, 17 deletions
diff --git a/src/Mind.hs b/src/Mind.hs
index 359293c..d686e24 100644
--- a/src/Mind.hs
+++ b/src/Mind.hs
@@ -76,12 +76,15 @@ insertEdge ns i e
-- network computation
-compute :: Network -> [Float] -> [Float] -> Maybe ([Float], [Float])
-compute net input state =
- let
- s = newState net input state
- state' = map (Just) s
- in Just $ (output net input state state', s)
+compute :: Network -> [Float] -> [Float] -> Either String ([Float], [Float])
+compute net input state
+ | (length input) /= (numInput net) = Left $ "Bad input length: " ++ (show $ length input)
+ | (length state) /= (length $ internalNeurons net) = Left $ "Bad state length: " ++ (show $ length state)
+ | otherwise =
+ let
+ s = newState net input state
+ state' = map (Just) s
+ in Right $ (output net input state state', s)
type InputState = ([Float], [Float])
@@ -89,7 +92,7 @@ type NewState = [Maybe Float]
output :: Network -> [Float] -> [Float] -> NewState -> [Float]
-output net input state state'=
+output net input state state' =
let
numOutput = length $ outputNeurons net
in
@@ -97,16 +100,16 @@ output net input state state'=
newState :: Network -> [Float] -> [Float] -> [Float]
newState net input state =
- let numInternal = length $ internalNeurons net
- in fst $
- foldr
- (\x (r, ns) ->
- let (value, ns') = getValue net (input, state) ns (Internal x)
- in (value:r, ns')
- )
- ([], replicate numInternal Nothing)
- [0..numInternal-1]
-
+ let numInternal = length $ internalNeurons net
+ in fst $
+ foldr
+ (\x (r, ns) ->
+ let (value, ns') = getValue net (input, state) ns (Internal x)
+ in (value:r, ns')
+ )
+ ([], replicate numInternal Nothing)
+ [0..numInternal-1]
+
updateValue :: NewState -> Int -> Float -> NewState