Code Monkey home page Code Monkey logo

fann.js's Introduction

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.

fann.js's People

Contributors

louisstow avatar

Watchers

James Cloos avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.