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

neuron-fiber

v2.0.44

Published

Downloads

8

Readme

A high level util of neural net in javascript

NPM version build status

Getting Started

Follow these steps:

  1. Install
  2. Usage
  3. API
  4. Algorithm
  5. Review Example Code

Install

$ npm install neuron-fiber --save

Usage

Nodejs environment


import { NeuronNet, NeuronLayer } from 'neuron-fiber'

Browser environment


import { NeuronNet, NeuronLayer } from 'neuron-fiber/dest/browser/index.esm.js'


const number0 = '*****' 
              + '*   *'
              + '*   *'
              + '*****' 

/**
 *  Imagine looks like number: 1
 */
const number1 = '*    ' 
              + '*    '
              + '*    '
              + '*    '

/**
 *  Imagine looks like number: 2
 */
const number2 = '*****' 
              + '  ** '
              + ' **  '
              + '*****' 


/**
 *  Imagine looks like number: 7
 */
const number3 = '**   ' 
              + ' *   '
              + ' *   '
              + '     ' 

/**
 *  Imagine looks like number: 7  from different position
 */

const number4 = '     ' 
              + '   **'
              + '    *'
              + '    *' 

/**
 *  Imagine looks like number: 7
 */
const number5 = ' **  ' 
              + '  *  '
              + '  *  '
              + '     '


function stringToArray(string){
  return string.replace(/\*/g,1).replace(/\s/g,0).split('')
}

// Flattern inputs
const inputs = [stringToArray(number0), 
               stringToArray(number1), 
               stringToArray(number2),
               stringToArray(number3),
               stringToArray(number4),
               stringToArray(number5)
              ]


const outputs = [[1,0,0],
                 [0,1,0],  
                 [0,0,1],
                 [0,1,1],
                 [0,1,1],
                 [0,1,1]]  

// Map outputs to one hot vector
function resultMap(result){
  const n = JSON.stringify(result[0].map(item=>{
    return Math.round(item)
  }))
  switch(n){
    case '[1,0,0]': // [1,0,0] >>> number: 0
      return 0
    case '[0,1,0]': // [0,1,0] >>> number: 1
      return 1
    case '[0,0,1]': // [0,0,1] >>> number: 2
      return 2
    case '[0,1,1]': // [0,1,1] >>> number: 7
      return 7
    default:
      return null
  }
}

// Build neural net
const neuronNet = new NeuronNet(inputs, outputs, 20000)

neuronNet
  .link(new NeuronLayer(15,'sigmoid'))
  .link(new NeuronLayer(20,'sigmoid'))
  .link(new NeuronLayer(15,'sigmoid'))
  .link(new NeuronLayer(8,'sigmoid'))
  .link(new NeuronLayer(5,'sigmoid'))
  .link(new NeuronLayer(outputs[0].length,'sigmoid'))

// Begin to train
neuronNet.train()

// Summary all params of neural layers
neuronNet.summary()

const data1 = '*****' 
            + '*** *'
            + '*   *'
            + '*****' 

const data2 = '     '
            + ' **  '
            + '  *  '
            + '  *  '

// Export neural net params
neuronNet.export()


// Predict data
const result1 = neuronNet.predict([stringToArray(data1)])

const result2 = neuronNet.predict([stringToArray(data2)])

// Result 0
console.log('result1:'+resultMap(result1)) 

// Result 7
console.log('result2:'+resultMap(result2)) 

API

new NeuronNet(inputs, outputs, iteration)

  • inputs:the data sample of inputs
  • outputs:the data sample of outputs
  • iteration:the number of training times

.link(options)

The options is a object obtain a layer of neural layer

.train()

Begin to train and modify the weight of each neural layer

.predict(input)

This will return results

  • input: The data should to be predicted

.export(fileName)

  • fileName: (default 'neural-params.json') The model will export .json into project root in nodejs environment(In browser will download a json file)

.summary()

The infomation about every layer print

.loadModel(options)

options

  • params: The model what using export to make up
  • path(nodejs environment only): The model file's path(.json,.text,*)

new NeuronLayer(neuronNumber,activatorType)

  • neuronNumber: the amount of neurons in this neural layer
  • activatorType: 'sigmoid'

Algorithm

  • Sigmoid
  • Softmax(WIP)
  • ReLU(WIP)
  • Tanh(WIP)

License

MIT. © 2017 lau stone