Skip to content

louisstow/fann.js

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

33 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

FANN.js

The FANN (Fast Artificial Neural Network) library compiled through Emscripten. This library contains some higher level bindings.

Much of the original documentation is still relevant. The noticable changes will be documented below. Note not all functions have a binding. You may see mention of Fixed vs Float mode, FANN.js uses Float mode.

How to use

FANN.js can be used almost like for like with the original library. These bindings provide an object oriented approach. For example take fann_print_connections(ann). In FANN.js this function is available on a Network instance as network.print_connections(). Notice the fann_ prefix isn't necessary nor is passing the neural network reference.

Before using the FANN library you should set a callback to window.FANN_ready.

FANN_ready = function () {
	// FANN.js is ready to use	
	var network = FANN.create([3, 3, 1]);
};

Demos

FANN.

Network create(neurons Array<Number>)

  • neurons the number of neurons in an array. The length of the array is the number of layers

Create a network with the provided structure. Returns an instance of the Network class. The neurons array argument specifies how many neurons are in that layer. The first index will be the input layer, the last index will be the output layer and anything between will be hidden layer(s).

var network = FANN.create([
	2, // Input layer: 2 neurons
	2, // Hidden layers (1): 2 neurons
	1  // Output layer: 1 neuron
]);

Network create(exported_network String)

  • exported_network String of a network exported through .export()

Create a network from a previously exported network as a string. This is useful when restoring a network.

TrainingData createTraining(Array data)

  • data a multidimensional array containing a set of inputs and desired outputs.

Create a TrainingData instance based on the provided data.

var tdata = FANN.createTraining([
    [[-1, -1], [-1]],
    [[ 1,  1], [-1]],
    [[-1,  1], [ 1]],
    [[ 1, -1], [ 1]]
]);

TrainingData createTraining(String data)

  • data a string of the training data. The required format is documented here.

Create a TrainingData instance based on the provided data. The string format will be the same as when exported via .export().

Network.

Array<Number> run(inputs Array<Number>)

  • inputs array of number inputs. Length should correspond to the amount of input neurons

Run the network with a set of inputs. Returns an array of the output neurons value.

var network = FANN.create([2, 2, 1]);
console.log(network.run([-1, 1]));

String export()

Returns a large string containing a snapshot of the network. You can store this string and restore a network based on the snapshot data using FANN.create().

Other functions

The following functions are available on a Network instance. The only difference between the original documented function is you do not need to pass the network reference as the first argument or use the fann_ prefix.

TrainingData.

String export()

Returns a large string containing a snapshot of the training data. You can store this string and create a TrainingData instance using FANN.createTraining().

Other functions

Constants

All of the enum and constants from the original library are available under the FANN. namespace. For example, FANN_TRAIN_INCREMENTAL becomes FANN.TRAIN_INCREMENTAL.

Compiling

After cloning, simply run ./build.sh build. The built file will be in the root directory as fann.js.

About

FANN compiled through Emscripten

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published