From 8a96a388474dc24bcb9e5b5ec402a74d60912fcd Mon Sep 17 00:00:00 2001 From: Michele Abruzzese <33634641+michezio@users.noreply.github.com> Date: Tue, 5 Jun 2018 13:29:16 +0200 Subject: [PATCH] mod constructor args to be self documented modified the arguments of the constructor to be self-documenting and added documentation to explain the cloning constructor --- lib/nn.js | 18 +++++++++++------- 1 file changed, 11 insertions(+), 7 deletions(-) diff --git a/lib/nn.js b/lib/nn.js index 3ba7edc..0cb4527 100644 --- a/lib/nn.js +++ b/lib/nn.js @@ -19,9 +19,13 @@ let tanh = new ActivationFunction( class NeuralNetwork { - // TODO: document what a, b, c are - constructor(a, b, c) { - if (a instanceof NeuralNetwork) { + /* + * if first argument is a NeuralNetwork the constructor clones it + * USAGE: cloned_nn = new NeuralNetwork(to_clone_nn); + */ + constructor(in_nodes, hid_nodes, out_nodes) { + if (in_nodes instanceof NeuralNetwork) { + let a = in_nodes; this.input_nodes = a.input_nodes; this.hidden_nodes = a.hidden_nodes; this.output_nodes = a.output_nodes; @@ -32,9 +36,9 @@ class NeuralNetwork { this.bias_h = a.bias_h.copy(); this.bias_o = a.bias_o.copy(); } else { - this.input_nodes = a; - this.hidden_nodes = b; - this.output_nodes = c; + this.input_nodes = in_nodes; + this.hidden_nodes = hid_nodes; + this.output_nodes = out_nodes; this.weights_ih = new Matrix(this.hidden_nodes, this.input_nodes); this.weights_ho = new Matrix(this.output_nodes, this.hidden_nodes); @@ -171,4 +175,4 @@ class NeuralNetwork { -} \ No newline at end of file +}