From 2d83cbf2238065ed24f3e6ca8fec65f32cfc16f4 Mon Sep 17 00:00:00 2001 From: Christian Hodgden Date: Thu, 15 Feb 2024 13:09:21 +0000 Subject: adding activation function tests added sigmoid and relu. Relu currently fails because of -0. need to update src code. --- test/reports/coverage.txt | 18 ++++++------ test/unit_tests/.activationFunctions.test.js.swp | Bin 0 -> 12288 bytes test/unit_tests/activationFunctions.test.js | 35 ++++++++++++++++------- 3 files changed, 34 insertions(+), 19 deletions(-) create mode 100644 test/unit_tests/.activationFunctions.test.js.swp diff --git a/test/reports/coverage.txt b/test/reports/coverage.txt index 56ff222..0d16f8e 100644 --- a/test/reports/coverage.txt +++ b/test/reports/coverage.txt @@ -1,9 +1,9 @@ -------------------------|---------|----------|---------|---------|---------------------- -File | % Stmts | % Branch | % Funcs | % Lines | Uncovered Line #s -------------------------|---------|----------|---------|---------|---------------------- -All files | 49.58 | 100 | 34.37 | 50.86 | - activationFunctions.js | 68 | 100 | 11.11 | 70.83 | 11,15,19,23,27,31,36 - binaryConverter.js | 100 | 100 | 100 | 100 | - layer.js | 8.82 | 100 | 0 | 9.09 | 7-53 - nnetwork.js | 12 | 100 | 0 | 13.04 | 6-35 -------------------------|---------|----------|---------|---------|---------------------- +------------------------|---------|----------|---------|---------|------------------- +File | % Stmts | % Branch | % Funcs | % Lines | Uncovered Line #s +------------------------|---------|----------|---------|---------|------------------- +All files | 53.71 | 100 | 50 | 54.31 | + activationFunctions.js | 88 | 100 | 66.66 | 87.5 | 23,27,31 + binaryConverter.js | 100 | 100 | 100 | 100 | + layer.js | 8.82 | 100 | 0 | 9.09 | 7-53 + nnetwork.js | 12 | 100 | 0 | 13.04 | 6-35 +------------------------|---------|----------|---------|---------|------------------- diff --git a/test/unit_tests/.activationFunctions.test.js.swp b/test/unit_tests/.activationFunctions.test.js.swp new file mode 100644 index 0000000..efad333 Binary files /dev/null and b/test/unit_tests/.activationFunctions.test.js.swp differ diff --git a/test/unit_tests/activationFunctions.test.js b/test/unit_tests/activationFunctions.test.js index e00140f..231544b 100644 --- a/test/unit_tests/activationFunctions.test.js +++ b/test/unit_tests/activationFunctions.test.js @@ -4,23 +4,38 @@ const math = require('mathjs'); describe('Test Activation Function module', () => { let result; + let targetResult; let testVector; let testMatrix; beforeEach(() => { testVector = [-2, -1, 0, 1, 2]; testVector = math.matrix(testVector); - testMatrix = math.matrix([testVector, testVector]); + testMatrix = math.matrix([testVector, testVector]); + }); + + test('Sigmoid Function', () => { + result = activationFunctionList['sigmoid'].gx(testVector); + expect(result._data[2]).toEqual(0.5); + + result = activationFunctionList['sigmoid'].dg_dx(testVector); + expect(result._data[2]).toEqual(0.25); }); - - test.todo('Sigmoid Function'); - // result = activationFunctionList['sigmoid'].gx(testVector); - // result = activationFunctionList['sigmoid'].dg_dx(testVector); - - test.todo('RELU Function'); - // result = activationFunctionList['relu'].gx(testMatrix); - // result = activationFunctionList['relu'].dg_dx(testMatrix); - + + test('RELU Function', () => { + targetResult = [0, 0, 0, 1, 2]; + targetResult = math.matrix(targetResult); + result = activationFunctionList['relu'].gx(testVector); + console.log(result); + console.log(targetResult); + expect(result).toEqual(targetResult); + + targetResult = [0, 0, 0, 1, 1]; + targetResult = math.matrix(targetResult); + result = activationFunctionList['relu'].dg_dx(testVector); + expect(result).toEqual(targetResult); + }); + test.todo('Identity Function'); // result = activationFunctionList['identity'].gx(testMatrix); // result = activationFunctionList['identity'].dg_dx(testMatrix); -- cgit v1.2.3