Skip to content
TypeScript Neural Network Library
Branch: master
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
examples
src
tests
thinking
.editorconfig
.gitignore
.npmignore
LICENSE
README.md
package.json
tsconfig.json
tslint.json
webpack.config.js
yarn.lock

README.md

Synaps

TypeScript Neural Network Library

Installation

  • In the browser

    <script type="text/javascript" src="https://unpkg.com/synaps"></script>
  • In Node.js

    $ npm install synaps
    

    and

    const synaps = require("synaps").default;

    or in es6 or TypeScript

    import synaps from "synaps";

Usage

  • Creating a new instance

    • Neural network with 3 input neurons and 1 output neuron

      let network = new synaps.Network.Type.FeedForward(3, [], 1);
    • Neural network with 4 input neurons, 3 hidden neurons and 2 output neurons

      let network = new synaps.Network.Type.FeedForward(4, [ 3 ], 2);
    • Neural network with 6 input neurons, two hidden layers with 4 and 2 neurons, and 3 output neurons

      let network = new synaps.Network.Type.FeedForward(6, [ 4, 2 ], 3);
  • Passing any number of additional options to the network

    // pass an object containing the desired options as the fourth parameter
    let network = new synaps.Network.Type.FeedForward(3, [ 4 ], 1, {
        seed: 501935,
        learningRate: 0.3,
        hiddenLayerActivationFunction: new synaps.Activation.HyperbolicTangent(),
        outputLayerActivationFunction: new synaps.Activation.BinaryStep()
    });
  • Available activation functions

    new synaps.Activation.ArcTangent();
    new synaps.Activation.BinaryStep();
    new synaps.Activation.GaussianFunction();
    new synaps.Activation.HyperbolicTangent();
    new synaps.Activation.Identity();
    new synaps.Activation.LogisticFunction();
    new synaps.Activation.RectifiedLinearUnit();
    new synaps.Activation.RectifiedLinearUnit(0.01);
    new synaps.Activation.SinusoidFunction();
  • Training the network using supervised batch ("all-at-once") learning

    // the first parameter is the array of inputs and the second parameter is the array of desired outputs
    // the third parameter is the optional number of iterations and the fourth parameter is the optional error threshold
    let error = network.trainBatch(
        [
            [0, 0, 1],
            [0, 1, 1],
            [1, 0, 1],
            [1, 1, 1]
        ],
        [
            [ 0 ],
            [ 1 ],
            [ 1 ],
            [ 0 ]
        ],
        60000,
        0.005
    );
  • Training the network using supervised online ("single-pattern") learning

    // the first parameter is the input and the second parameter is the desired output
    let error = network.train([0, 0, 1], [ 0 ]);
  • Asking the network to predict some output from a supplied input pattern

    // the single parameter is the input to process
    network.predict([ 0, 0, 1 ])
  • Saving the network with all its properties to a JSON string

    let jsonStr = JSON.stringify(network);
  • Restoring the network with all its properties from a JSON string

    let network = synaps.Network.Type.FeedForward.fromJson(jsonStr);

Development

  • Prerequisites

    $ npm install
    
  • Lint the js files

    $ npm lint
    

    or to fix some errors automatically

    $ npm lint:fix
    
  • Build the js files

    $ npm build
    
  • Running the Node.js examples

    $ node examples/node.js
    

Contributing

All contributions are welcome! If you wish to contribute, please create an issue first so that your feature, problem or question can be discussed.

Socials Links

You can’t perform that action at this time.