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

cervello

v0.2.2

Published

A simple machine learning lib written in Typescript

Downloads

9

Readme

Cervello

A simple machine learning lib written in Typescript.

Features

Installation

npm: npm install cervello --save

Linear Regression


import {Cervello} from "cervello"

let data = {inputs: [1,2,3,4,5,6], outputs: [1,2,3,4,5,6]}

let lr = new Cervello.LinearRegression().train(data)

let result = lr.predict(7)

console.log(result) // => 7
Import and export

Your can serialize Linear model and export it by export(), or you can load (a,b) of a trained linear model and use them as well.

// Export
let seralize = lr.export() // [a,b] => (ax + b) 

// Import/Load
lr.import([1.5, 2]) // which means => (y = 1.5x + 2)

Neural Network

import {Cervello} from "cervello"

// XOR Problem
let data = [{input: [0, 0], output: [0]},
            {input: [0, 1], output: [1]},
            {input: [1, 0], output: [1]},
            {input: [1, 1], output: [0]}]

let nn = new Cervello.NeuralNetwork().train(data)

let result = nn.predict([0,1])

console.log(result) // => [0.99]

You can specify which options you want to use such like hiddenLayers, iterations, neurons (units), Learning Rate and activation method.

Available options:
  • hiddenLayer: (numebr) : The number of hiddenLayer.
  • units: (number) : The number of neurons foreach hiddenLayer.
  • iteration: (number) : The number of iteration of (forward/back) probagation.
  • learningRate: (number) : The number of how faster could our net learn.
  • activator : (string) : activation method weather sigmoid or htan.
Other example (Digit recognition)
import {Cervello} from "cervello"

let one = number(
  '.....$.' +
  '..$$$$.' +
  '.....$.' +
  '.....$.' +
  '.....$.' +
  '.....$.' +
  '...$$$$'
)

let two = number(
  '$$$$$$$' +
  '......$' +
  '......$' +
  '$$$$$$$' +
  '$......' +
  '$......' +
  '$$$$$$$'
)

let three = number(
  '$$$$$$$' +
  '......$' +
  '......$' +
  '$$$$$$$' +
  '......$' +
  '......$' +
  '$$$$$$$'
)

let four = number(
  '$......' +
  '$.....$' +
  '$.....$' +
  '$$$$$$$' +
  '......$' +
  '......$' +
  '......$'
)

// Neural network options
let options = {hiddenLayer: 2, units: 4, iteration: 100000, activator: "sigmoid"}

// Init Neural Network.
let nn = new Cervello.NeuralNetwork(options)

// Train
nn.train([{input: one, output: results("1")},
          {input: two, output: results("2")},
          {input: three, output: results("3")},
          {input: four, output: results("4")}])

// Predict
let result = nn.predict(number(
  '.....$.' +
  '.$$$$$.' +
  '.....$.' +
  '.....$.' +
  '.....$.' +
  '.....$.' +
  '...$$$$'
))

console.log(result) // ~ [0.1]

// helpers
function number(string) {
  return string
    .trim()
    .split('')
    .map(function(symbol){
        if ('$' === symbol) return 1
        if ('.' === symbol) return 0
    })
}

function results(number) {
  if (number === '1') return [ 0.1 ]
  if (number === '2') return [ 0.3 ]
  if (number === '3') return [ 0.5 ]
  if (number === '4') return [ 0.7 ]
  return 0
}
Import and export

It's the same as Linear model, you can serialize the model wedges by export() that will return a serlized object of NN wedges.

// Export model
let serialized = nn.export() // => seralized object (string)

// Import model
nn.import(seralized)
Activation methods

Contributors

LICENSE

MIT