Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
4 changed files
with
106 additions
and
42 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,14 +1,20 @@ | ||
|
||
var assert = require('assert'); | ||
var fann = require('../build/Release/fann'); | ||
var net = new fann.standard(1,10,1); | ||
|
||
console.log(net.activation_function(1, 0)); | ||
console.log(net.activation_function(1, 0, 'sin')); | ||
console.log(net.activation_function(1, 1, 'cos')); | ||
console.log(net.activation_function(1, 0)); | ||
console.log(net.activation_function(1, 1)); | ||
// default activation function | ||
assert.equal(net.activation_function(1, 0), 'sigmoid_stepwise'); | ||
|
||
// set custom activation function and return it | ||
assert.equal(net.activation_function(1, 0, 'sin'), 'sin'); | ||
assert.equal(net.activation_function(1, 1, 'cos'), 'cos'); | ||
|
||
// check if these activation functions are stored | ||
assert.equal(net.activation_function(1, 0), 'sin'); | ||
assert.equal(net.activation_function(1, 1), 'cos'); | ||
|
||
console.log(net.activation_function_hidden('sigmoid')); | ||
console.log(net.activation_function_output('elliot')); | ||
console.log(net.activation_function(1, 0)); | ||
console.log(net.activation_function(2, 0)); | ||
// activation functions for hidden and output layers | ||
assert.equal(net.activation_function_hidden('sigmoid'), 'sigmoid'); | ||
assert.equal(net.activation_function_output('elliot'), 'elliot'); | ||
assert.equal(net.activation_function(1, 0), 'sigmoid'); | ||
assert.equal(net.activation_function(2, 0), 'elliot'); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,28 +1,54 @@ | ||
|
||
var assert = require('assert'); | ||
var fann = require('../build/Release/fann'); | ||
var net = new fann.standard(1,10,1); | ||
|
||
console.log(fann); | ||
console.log(net); | ||
/* | ||
* Training algorithms | ||
*/ | ||
|
||
// wrong algorithm, shouldn't change | ||
net.training_algorithm = "back"; | ||
console.log(net.training_algorithm, net.training_algorithm == 'RPROP'); | ||
assert.equal(net.training_algorithm, 'rprop'); | ||
|
||
// but this should | ||
net.training_algorithm = "incremental"; | ||
console.log(net.training_algorithm, net.training_algorithm == 'INCREMENTAL'); | ||
assert.equal(net.training_algorithm, 'incremental'); | ||
|
||
// set first alg in the list | ||
net.training_algorithm = 1; | ||
console.log(net.training_algorithm, net.training_algorithm == 'BATCH'); | ||
assert.equal(net.training_algorithm, 'batch'); | ||
|
||
// should drop prefix | ||
net.training_algorithm = "FANN_TRAIN_INCREMENTAL"; | ||
console.log(net.training_algorithm, net.training_algorithm == 'INCREMENTAL'); | ||
assert.equal(net.training_algorithm, 'incremental'); | ||
|
||
/* | ||
* Learning rates | ||
*/ | ||
|
||
console.log(net.learning_rate, Math.abs(net.learning_rate-0.7) < 0.01); | ||
// should default to 0.7 | ||
assert(Math.abs(net.learning_rate-0.7) < 0.0001); | ||
|
||
// trying to change it | ||
net.learning_rate = '123'; | ||
console.log(net.learning_rate, net.learning_rate == 123); | ||
assert.equal(net.learning_rate, 123); | ||
|
||
// wrong rate, change to NaN | ||
net.learning_rate = 'hi!'; | ||
console.log(net.learning_rate, isNaN(net.learning_rate)); | ||
assert(isNaN(net.learning_rate)); | ||
|
||
/* | ||
* Learning momentum | ||
*/ | ||
|
||
console.log(net.learning_momentum, net.learning_momentum == 0); | ||
// should default to 0 | ||
assert.equal(net.learning_momentum, 0); | ||
|
||
// trying to change it | ||
net.learning_momentum = '123'; | ||
console.log(net.learning_momentum, net.learning_momentum == 123); | ||
assert.equal(net.learning_momentum, 123); | ||
|
||
// wrong momentum, change to NaN | ||
net.learning_momentum = 'hi!'; | ||
console.log(net.learning_momentum, isNaN(net.learning_rate)); | ||
assert(isNaN(net.learning_rate)); | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,19 +1,43 @@ | ||
|
||
var assert = require('assert'); | ||
var fann = require('../build/Release/fann'); | ||
var net = new fann.standard(1,10,1); | ||
|
||
console.log(fann.get_all_activation_functions()); | ||
console.log(net.get_all_activation_functions()); | ||
// activation functions | ||
var expected = [ | ||
'linear', | ||
'threshold', | ||
'threshold_symmetric', | ||
'sigmoid', | ||
'sigmoid_stepwise', | ||
'sigmoid_symmetric', | ||
'sigmoid_symmetric_stepwise', | ||
'gaussian', | ||
'gaussian_symmetric', | ||
'gaussian_stepwise', | ||
'elliot', | ||
'elliot_symmetric', | ||
'linear_piece', | ||
'linear_piece_symmetric', | ||
'sin_symmetric', | ||
'cos_symmetric', | ||
'sin', | ||
'cos' ] | ||
//console.log(fann.get_all_activation_functions()); | ||
assert.deepEqual(net.get_all_activation_functions(), expected); | ||
|
||
console.log(fann.get_all_training_algorithms()); | ||
console.log(net.get_all_training_algorithms()); | ||
var expected = [ 'incremental', 'batch', 'rprop', 'quickprop' ] | ||
//console.log(fann.get_all_training_algorithms()); | ||
assert.deepEqual(net.get_all_training_algorithms(), expected); | ||
|
||
console.log(fann.get_all_stop_functions()); | ||
console.log(net.get_all_stop_functions()); | ||
var expected = [ 'mse', 'bit' ] | ||
//console.log(fann.get_all_stop_functions()); | ||
assert.deepEqual(net.get_all_stop_functions(), expected); | ||
|
||
console.log(fann.get_all_error_functions()); | ||
console.log(net.get_all_error_functions()); | ||
var expected = [ 'linear', 'tanh' ] | ||
//console.log(fann.get_all_error_functions()); | ||
assert.deepEqual(net.get_all_error_functions(), expected); | ||
|
||
console.log(fann.get_all_network_types()); | ||
console.log(net.get_all_network_types()); | ||
var expected = [ 'layer', 'shortcut' ] | ||
//console.log(fann.get_all_network_types()); | ||
assert.deepEqual(net.get_all_network_types(), expected); | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,13 +1,21 @@ | ||
|
||
var assert = require('assert'); | ||
var fann = require('../build/Release/fann'); | ||
var net = new fann.shortcut([1,2,3,4]); | ||
|
||
console.log(net.get_num_input()); | ||
console.log(net.get_num_output()); | ||
console.log(net.get_total_neurons()); | ||
console.log(net.get_total_connections()); | ||
console.log(net.get_network_type()); | ||
// 1 input layer and 4 output | ||
assert.equal(net.get_num_input(), 1); | ||
assert.equal(net.get_num_output(), 4); | ||
|
||
// total 1+2+3+4 + 1 = 11 neurons | ||
assert.equal(net.get_total_neurons(), 11); | ||
|
||
// 44 connections, I don't remember why | ||
assert.equal(net.get_total_connections(), 44); | ||
|
||
// network type | ||
assert.equal(net.get_network_type(), 'shortcut'); | ||
|
||
console.log(net.get_layer_array()); | ||
console.log(net.get_bias_array()); | ||
// arrays | ||
assert.deepEqual(net.get_layer_array(), [1,2,3,4]); | ||
assert.deepEqual(net.get_bias_array(), [1,0,0,0]); | ||
|