ml-fnn
Advanced tools
Comparing version 0.0.2 to 0.0.3
{ | ||
"name": "ml-fnn", | ||
"version": "0.0.2", | ||
"version": "0.0.3", | ||
"description": "feedforward neural networks library", | ||
@@ -5,0 +5,0 @@ "main": "src/index.js", |
@@ -22,3 +22,3 @@ # Feedforward Neural Network | ||
### train(trainingSet, predictions, learningRate, momentum) | ||
### train(trainingSet, predictions, iterations, learningRate, momentum) | ||
@@ -32,2 +32,3 @@ Train the Neural Network with a given training set, predictions, learning rate and a | ||
* `predictions` - A matrix of predictions with the same size of rows of the trainingSet. | ||
* `iterations` - Maximum number of iterations of the algorithm. | ||
* `learningRate` - The learning rate (number). | ||
@@ -34,0 +35,0 @@ * `momentum` - The regularization term (number). |
@@ -86,13 +86,9 @@ "use strict"; | ||
var layersNum = this.layers.length; | ||
var lengthLayers = this.layers.length; | ||
for(i = 0; i < layersNum; ++i) { | ||
error = this.layers[layersNum - i - 1].train(error, learningRate, momentum) | ||
for(i = 0; i < lengthLayers; ++i) { | ||
error = this.layers[lengthLayers - 1 - i].train(error, learningRate, momentum); | ||
} | ||
}; | ||
FeedforwardNeuralNetwork.prototype.flagFunction = function () { | ||
return 0; | ||
}; | ||
/** | ||
@@ -99,0 +95,0 @@ * Method that train the neural network with a given training set with corresponding |
@@ -30,6 +30,6 @@ "use strict"; | ||
(results[0][0] > results[0][1]).should.be.ok; | ||
(results[1][0] > results[1][1]).should.be.ok; | ||
(results[2][0] > results[2][1]).should.be.ok; | ||
(results[3][0] < results[3][1]).should.be.ok; | ||
(results[0][0]).should.be.greaterThan(results[0][1]); | ||
(results[1][0]).should.be.greaterThan(results[1][1]); | ||
(results[2][0]).should.be.greaterThan(results[2][1]); | ||
(results[3][0]).should.be.lessThan(results[3][1]); | ||
}); | ||
@@ -54,2 +54,31 @@ | ||
}); | ||
it('multiclass clasification', function () { | ||
var trainingSet = [[0, 0], [0, 1], [1, 0], [1, 1]]; | ||
var predictions = [[2], [0], [1], [0]]; | ||
var nn = new FeedforwardNeuralNetwork([2, 4, 1]); | ||
nn.train(trainingSet, predictions, 300, 0.5, 0.1); | ||
var result = nn.predict(trainingSet); | ||
result[0].should.be.approximately(2, 1e-1); | ||
result[1].should.be.approximately(0, 1e-1); | ||
result[2].should.be.approximately(1, 1e-1); | ||
result[3].should.be.approximately(0, 1e-1); | ||
}); | ||
it('big case', function () { | ||
var trainingSet = [[1, 1], [1, 2], [2, 1], [2, 2], [3, 1], [1, 3], [1, 4], [4, 1], | ||
[6, 1], [6, 2], [6, 3], [6, 4], [6, 5], [5, 5], [4, 5], [3, 5]]; | ||
var predictions = [[1, 0], [1, 0], [1, 0], [1, 0], [1, 0], [1, 0], [1, 0], [1, 0], | ||
[0, 1], [0, 1], [0, 1], [0, 1], [0, 1], [0, 1], [0, 1], [0, 1]]; | ||
var nn = new FeedforwardNeuralNetwork([2, 10, 2]); | ||
nn.train(trainingSet, predictions, 200, 0.1, 0.1); | ||
var result = nn.predict([[5, 4]]); | ||
result[0][0].should.be.lessThan(result[0][1]); | ||
}); | ||
}); |
18102
355
78