Skip to content


Switch branches/tags

Name already in use

A tag already exists with the provided branch name. Many Git commands accept both tag and branch names, so creating this branch may cause unexpected behavior. Are you sure you want to create this branch?

Latest commit


Git stats


Failed to load latest commit information.
Latest commit message
Commit time


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]);



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().


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([-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.


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


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.


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


FANN compiled through Emscripten







No releases published


No packages published