summaryrefslogtreecommitdiff
path: root/test/MindTest.hs
diff options
context:
space:
mode:
Diffstat (limited to 'test/MindTest.hs')
-rw-r--r--test/MindTest.hs74
1 files changed, 74 insertions, 0 deletions
diff --git a/test/MindTest.hs b/test/MindTest.hs
index 65d5a84..cf5c50a 100644
--- a/test/MindTest.hs
+++ b/test/MindTest.hs
@@ -21,6 +21,8 @@ networkTests :: TestTree
networkTests = testGroup "network tests" $
[ testCase "create empty network" $
(createEmptyNetwork 3 2 1) @?= Network 3 [[], []] [[]]
+
+ -- neuron connections
, testCase "output network connection" $
let network = Network 3 [[], []] [[]]
in (connectNeurons network (Input 0) (Output 0) (negate 1.0))
@@ -57,4 +59,76 @@ networkTests = testGroup "network tests" $
let network = Network 3 [[], []] [[]]
in (connectNeurons network (Input 0) (Output 4) (negate 1.0))
@?= Nothing
+
+ -- network computations
+ , testCase "single input, single output" $
+ let
+ net = Network 1 [] [[Edge (Input 0, 2.0)]]
+ Just (output, state) = compute net [negate 0.5] []
+ in (output, state) @?=
+ ( [tanh (2.0 * (negate 0.5))]
+ , []
+ )
+ , testCase "multiple inputs, single output" $
+ let
+ net = Network 4 [] [
+ [ Edge (Input 0, negate 1.0)
+ , Edge (Input 1, negate 2.0)
+ , Edge (Input 2, 1.0)
+ , Edge (Input 3, 2.0)
+ ]]
+ Just (output, state) = compute net [1, 2, 3, 5] []
+ in (output, state) @?=
+ (
+ [tanh
+ ( (1 * (negate 1.0))
+ + (2 * (negate 2.0))
+ + (3 * 1.0)
+ + (5 * 2.0)
+ )
+ ]
+ , []
+ )
+ , testCase "multiple inputs, multiple outputs" $
+ let
+ net = Network 4 []
+ [ [ Edge (Input 0, 1.0)
+ , Edge (Input 1, negate 2.0)
+ ]
+ , [ Edge (Input 2, negate 1.0)
+ , Edge (Input 3, 1.0)
+ ]
+ ]
+ Just (output, state) = compute net [1, 2, 3, 5] []
+ in (output, state) @?=
+ (
+ [ tanh (2 - 1)
+ , tanh (5 - 3)
+ ]
+ , []
+ )
+ , testCase "hidden neurons" $
+ let
+ net = Network 4
+ -- hidden neurons
+ [ [ Edge (Input 0, negate 1.0)
+ , Edge (Input 1, 1.0)
+ ]
+ , [ Edge (Input 2, negate 1.0)
+ , Edge (Input 3, 1.0)
+ ]
+ ]
+ -- output neurons
+ [ [ Edge (Internal 0, negate 1.0)
+ , Edge (Internal 1, 1.0)
+ ]
+ ]
+ Just (output, state) = compute net [1, 2, 3, 5] [0, 0]
+ in (output, state) @?=
+ (
+ [ tanh ( (tanh (5-3)) - (tanh (2-1)) ) ]
+ , [ tanh (2-1)
+ , tanh (5-3)
+ ]
+ )
]