From 62993dd59bbbfcdb07dbb5836d359fad6334f23e Mon Sep 17 00:00:00 2001 From: TinWoodman92 Date: Thu, 8 Feb 2024 16:09:56 -0600 Subject: initial commit --- test/unit_tests/activationFunctions.test.js | 23 ++++++++++++++++++++ test/unit_tests/binaryConverter.test.js | 33 +++++++++++++++++++++++++++++ test/unit_tests/layer.test.js | 15 +++++++++++++ test/unit_tests/nnetwork.test.js | 17 +++++++++++++++ 4 files changed, 88 insertions(+) create mode 100644 test/unit_tests/activationFunctions.test.js create mode 100644 test/unit_tests/binaryConverter.test.js create mode 100644 test/unit_tests/layer.test.js create mode 100644 test/unit_tests/nnetwork.test.js (limited to 'test') diff --git a/test/unit_tests/activationFunctions.test.js b/test/unit_tests/activationFunctions.test.js new file mode 100644 index 0000000..b7fd570 --- /dev/null +++ b/test/unit_tests/activationFunctions.test.js @@ -0,0 +1,23 @@ +console.log('Hello from activationFunctions.test.js'); + +console.log(activationFunctionList); + +let result; +let testVector = [-2, -1, 0, 1, 2]; +testVector = math.matrix(testVector); +let testMatrix = math.matrix([testVector, testVector]); + +result = activationFunctionList['sigmoid'].gx(testVector); +console.log(result); +result = activationFunctionList['sigmoid'].dg_dx(testVector); +console.log(result); + +result = activationFunctionList['relu'].gx(testMatrix); +console.log(result); +result = activationFunctionList['relu'].dg_dx(testMatrix); +console.log(result); + +result = activationFunctionList['identity'].gx(testMatrix); +console.log(result); +result = activationFunctionList['identity'].dg_dx(testMatrix); +console.log(result); diff --git a/test/unit_tests/binaryConverter.test.js b/test/unit_tests/binaryConverter.test.js new file mode 100644 index 0000000..b6fb503 --- /dev/null +++ b/test/unit_tests/binaryConverter.test.js @@ -0,0 +1,33 @@ +const BinaryConverter = require('../../src/binaryConverter'); +const math = require('mathjs'); + +//import BinaryConverter from 'binaryConverter'; + +describe('Test BinaryConversion module', () => { + + let testConverter; + let testVector; + let testInteger; + + beforeEach(() => { + testConverter = new BinaryConverter(2); + testInteger = 2; + testVector = math.matrix([1, 0]); + }); + + + test('convert integer to binary array', () => { + testConverter.integer = testInteger; + expect(testConverter.inputActivation).toEqual(testVector); + }); + + test('convert binary array to integer', () => { + testConverter.inputActivation = testVector; + expect(testConverter.integer).toEqual(testInteger); + }); + + test.todo('Random array initializes correct integer'); + +}); + + diff --git a/test/unit_tests/layer.test.js b/test/unit_tests/layer.test.js new file mode 100644 index 0000000..37402d3 --- /dev/null +++ b/test/unit_tests/layer.test.js @@ -0,0 +1,15 @@ +console.log('Hello from layer.test.js'); + +let testLayer = new Layer(2, 3, 'relu'); +let testConv = new BinaryConverter(2); + +console.log(testLayer); +console.log(testConv.randomInput()); + +console.log(testLayer.forwardPropogation(testConv.inputActivation)); + +testLayer = new Layer(2, 3, 'sigmoid'); +console.log(testLayer.forwardPropogation(testConv.inputActivation)); + +testLayer = new Layer(2, 3, 'identity'); +console.log(testLayer.forwardPropogation(testConv.inputActivation)); diff --git a/test/unit_tests/nnetwork.test.js b/test/unit_tests/nnetwork.test.js new file mode 100644 index 0000000..efc3f6e --- /dev/null +++ b/test/unit_tests/nnetwork.test.js @@ -0,0 +1,17 @@ +console.log('Hello from nnetwork.test.js'); + +let testConv = new BinaryConverter(2); +let nodeCounts = [testConv._inputDigits, 3, testConv._outputDigits]; +let afns = ['identity', 'relu', 'identity']; + +let testNNetwork = new NNetwork(nodeCounts, afns, 0.1); + +console.log(testConv.randomInput()); +console.log(testNNetwork.forwardPropogation(testConv.inputActivation)); +console.log(testNNetwork.backPropogation(testConv.inputActivation, testConv.outputActivation)); + +console.log(testConv.randomInput()); +console.log(testNNetwork.forwardPropogation(testConv.inputActivation)); +console.log(testNNetwork.backPropogation(testConv.inputActivation, testConv.outputActivation)); + +testNNetwork.gradientDescent(); \ No newline at end of file -- cgit v1.2.3