summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorChristian Hodgden <chrhodgden@gmail.com>2024-02-09 14:57:48 +0000
committerChristian Hodgden <chrhodgden@gmail.com>2024-02-09 14:57:48 +0000
commit118f623577d7e033fa6ddbbe3823d48ffde29c12 (patch)
tree52023be957d31919fe5aecde363886f997888cf6
parentd8e17c036eecadb17c6521fac23a5d956b8fd415 (diff)
added module imports and describe() method to layer testing
-rw-r--r--src/layer.js18
-rw-r--r--test/reports/coverage.txt5
-rw-r--r--test/unit_tests/layer.test.js29
3 files changed, 32 insertions, 20 deletions
diff --git a/src/layer.js b/src/layer.js
index 65b14ec..dac062a 100644
--- a/src/layer.js
+++ b/src/layer.js
@@ -1,4 +1,6 @@
-console.log('Hello from layer.js');
+const math = require('mathjs');
+const activationFunctionList = require('./activationFunctions');
+
class Layer {
constructor(inputCount, nodeCount, activationFunctionName) {
@@ -10,7 +12,7 @@ class Layer {
this.z = math.matrix(math.zeros([nodeCount]));
this.dc_dw_vectors = math.matrix(math.zeros(this.weights._size));
this.dc_db_vectors = math.matrix(math.zeros(this.biases._size));
- console.log('dc_db_vectors', this.dc_db_vectors);
+ //console.log('dc_db_vectors', this.dc_db_vectors);
}
forwardPropogation(activationInput) {
this.ai = activationInput;
@@ -30,18 +32,18 @@ class Layer {
let dc_dai = math.multiply(dz_dai, dc_db);
//store cost vectors for gradient descent
- console.log('dc_db_vectors', this.dc_db_vectors);
- console.log('dc_db', dc_db);
+ //console.log('dc_db_vectors', this.dc_db_vectors);
+ //console.log('dc_db', dc_db);
this.dc_db_vectors = math.concat(this.dc_db_vectors, dc_db, 0);
this.dc_dw_vectors = math.concat(this.dc_dw_vectors, dc_dw, 0);
- console.log('dc_db_vectors', this.dc_db_vectors);
+ //console.log('dc_db_vectors', this.dc_db_vectors);
return dc_dai;
}
gradientDescent(learningRate) {
- console.log(this.dc_dw_vectors);
- console.log(this.dc_db_vectors);
+ //console.log(this.dc_dw_vectors);
+ //console.log(this.dc_db_vectors);
let dc_dw_avg = math.mean(this.dc_dw_vectors, 0)
let dc_db_avg = math.mean(this.dc_db_vectors, 0)
@@ -51,3 +53,5 @@ class Layer {
this.dc_db_vectors = math.matrix([]);
}
};
+
+module.exports = Layer; \ No newline at end of file
diff --git a/test/reports/coverage.txt b/test/reports/coverage.txt
index dc96a2d..38557e5 100644
--- a/test/reports/coverage.txt
+++ b/test/reports/coverage.txt
@@ -1,7 +1,8 @@
------------------------|---------|----------|---------|---------|-------------------
File | % Stmts | % Branch | % Funcs | % Lines | Uncovered Line #s
------------------------|---------|----------|---------|---------|-------------------
-All files | 90.32 | 100 | 84.21 | 91.66 |
+All files | 82.29 | 100 | 87.5 | 81.72 |
activationFunctions.js | 100 | 100 | 100 | 100 |
- binaryConverter.js | 83.78 | 100 | 70 | 86.11 | 30-33,45
+ binaryConverter.js | 97.29 | 100 | 90 | 97.22 | 45
+ layer.js | 52.94 | 100 | 60 | 51.51 | 26-53
------------------------|---------|----------|---------|---------|-------------------
diff --git a/test/unit_tests/layer.test.js b/test/unit_tests/layer.test.js
index 37402d3..d7dcdb8 100644
--- a/test/unit_tests/layer.test.js
+++ b/test/unit_tests/layer.test.js
@@ -1,15 +1,22 @@
-console.log('Hello from layer.test.js');
+const BinaryConverter = require('../../src/binaryConverter');
+const Layer = require('../../src/layer');
+const math = require('mathjs');
-let testLayer = new Layer(2, 3, 'relu');
-let testConv = new BinaryConverter(2);
+describe('Test Layer module', () => {
-console.log(testLayer);
-console.log(testConv.randomInput());
+ let testLayer = new Layer(2, 3, 'relu');
+ let testConv = new BinaryConverter(2);
+
+ testConv.randomInput()
+ testLayer.forwardPropogation(testConv.inputActivation);
+
+ testLayer = new Layer(2, 3, 'sigmoid');
+ testLayer.forwardPropogation(testConv.inputActivation);
+
+ testLayer = new Layer(2, 3, 'identity');
+ testLayer.forwardPropogation(testConv.inputActivation);
+
+ test.todo('Layer Tests');
-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));