npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

vt-neural-network

v0.0.4

Published

A example neural network

Downloads

5

Readme

Neural Network in JavaScript

Implementantion of a Perceptron neural network in JavaScript. It is a simple implementation that can serve as an example for learning, not for production use. It does not use GPU and the only activation function implemented is a sigmoid function.

For a ready to use implementation please refer to BrainJS

Installation

npm install --save vt-neural-network

Usage

import { Network } from 'vt-neural-network'

// Define the layer structure
const layers = [
  2, // This is the input layer
  10, // Hidden layer 1
  10, // Hidden layer 2
  1 // Output
]

const network = new Network(layers)

// Start training
const numberOfIterations = 20000

// Training data for a "XOR" logic gate
const trainingData = [{
  input : [0,0],
  output: [0]
}, {
  input : [0,1],
  output: [1]
}, {
  input : [1,0],
  output: [1]
}, {
  input : [1,1],
  output: [0]
}]

for(var i = 0; i < numberOfIterations; i ++) {
  // Get a random training sample
  const trainingItem = trainingData[Math.floor((Math.random()*trainingData.length))]
  network.train(trainingItem.input, trainingItem.output);
}

// After training we can see if it works
// we call activate to set a input in the first layer
network.activate(trainingData[0].input)
const resultA = network.run()

network.activate(trainingData[1].input)
const resultB = network.run()

network.activate(trainingData[2].input)
const resultC = network.run()

network.activate(trainingData[3].input)
const resultD = network.run()
console.log('Expected 0 got', resultA[0])
console.log('Expected 1 got', resultB[0])
console.log('Expected 1 got', resultC[0])
console.log('Expected 0 got', resultD[0])

If you want to see other logic gates implementations, check the test folder.

API

  • network.setLearningRate(0.3): Adjust the learning rate of the network,
  • network.toJSON(): returns the structure of the network
  • network.layers: contains the different layers of the network
    • layer.neurons: contains the different neurons on each layer

How to develop the application?

npm install
npm run watch
# Open public/ directory in browser

Remove generated directory

If you would like to remove public/dist directory (created by Webpack):

npm run clear

If you would like to remove node_modules/ and remove public/dist/

npm run clear:all

Count LOC (Lines of Code)

If you would like to know how many lines of code you write:

npm run count

Analysis of bundle file weight

If you would like to check how much a bundle file weight:

npm run audit

Information of interest

Backpropagation

https://mattmazur.com/2015/03/17/a-step-by-step-backpropagation-example/

Neural networks

https://scrimba.com/g/gneuralnetworks https://franpapers.com/en/machine-learning-ai-en/2017-neural-network-implementation-in-javascript-by-an-example/ http://karpathy.github.io/neuralnets/