Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 6 additions & 6 deletions lib/matrix.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,14 @@ class Matrix {
this.data = Array(this.rows).fill().map(() => Array(this.cols).fill(0));
}

copy() {
let m = new Matrix(this.rows, this.cols);
for (let i = 0; i < this.rows; i++) {
for (let j = 0; j < this.cols; j++) {
m.data[i][j] = this.data[i][j];
static copy(matrix) {
let matrixCopy = new Matrix(matrix.rows, matrix.cols);
for (let i = 0; i < matrix.rows; i++) {
for (let j = 0; j < matrix.cols; j++) {
matrixCopy.data[i][j] = matrix.data[i][j];
}
}
return m;
return matrixCopy;
}

static fromArray(arr) {
Expand Down
2 changes: 1 addition & 1 deletion lib/matrix.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -381,7 +381,7 @@ test('matrix copy', () => {
let m = new Matrix(5, 5);
m.randomize();

let n = m.copy();
let n = Matrix.copy(m);

expect(n).toEqual({
rows: m.rows,
Expand Down
9 changes: 4 additions & 5 deletions lib/nn.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,11 +30,10 @@ class NeuralNetwork {
this.hidden_nodes = a.hidden_nodes;
this.output_nodes = a.output_nodes;

this.weights_ih = a.weights_ih.copy();
this.weights_ho = a.weights_ho.copy();

this.bias_h = a.bias_h.copy();
this.bias_o = a.bias_o.copy();
this.weights_ih = Matrix.copy(a.weights_ih);
this.weights_ho = Matrix.copy(a.weights_ho);
this.bias_h = Matrix.copy(a.bias_h);
this.bias_o = Matrix.copy(a.bias_o);
} else {
this.input_nodes = in_nodes;
this.hidden_nodes = hid_nodes;
Expand Down