From fae22e68282336fc0d7f0efda236410a294b7eb5 Mon Sep 17 00:00:00 2001 From: sanine Date: Tue, 21 Nov 2023 14:16:38 -0600 Subject: add failing compute tests --- test/MindTest.hs | 74 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 74 insertions(+) (limited to 'test/MindTest.hs') 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) + ] + ) ] -- cgit v1.2.1