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

@seracio/kohonen

v3.0.2

Published

A basic implementation of a Kohonen map in JavaScript

Downloads

5

Readme

kohonen Build Status

A basic implementation of a Kohonen map in JavaScript

Disclaimer: this is a toy implementation of the SOM algorithm, you should probably consider using a more solid library in R or Python.

Usage

Import lib

npm i d3-array d3-scale d3-random lodash ml-pca @seracio/kohonen --save

Then, in your JS script :

import { Kohonen, generateGrid } from '@seracio/kohonen';

API

Kohonen

The Kohonen class is the main class.

Constructor

| param name | definition | type | mandatory | default | | :-------------: | :---------------: | :------------: | :-------: | :-----: | | neurons | grid of neurons | Array | yes | | | data | dataset | Array of Array | yes | | | maxStep | step max to clamp | Number | no | 1000 | | maxLearningCoef | | Number | no | .4 | | minLearningCoef | | Number | no | .1 | | maxNeighborhood | | Number | no | 1 | | minNeighborhood | | Number | no | .3 |

// instanciate your Kohonen map
const k = new Kohonen({ data, neurons });

// you can use the grid helper to generate a grid with 10x10 hexagons
const k = new Kohonen({ data, neurons: generateGrid(10, 10) });

neurons parameter should be a flat array of { pos: [x,y] }. pos array being the coordinate on the grid.

data parameter is an array of the vectors you want to display. There is no need to standardize your data, that will be done internally by scaling each feature to the [0,1] range.

Basically the constructor do :

  • standardize the given data set
  • initialize random weights for neurons using PCA's largests eigenvectors
training method

| param name | definition | type | mandatory | default | | :--------: | :---------------------------------------------: | :------: | :-------: | :-----------------: | | log | func called after each step of learning process | Function | no | (neurons, step)=>{} |

k.training();

training method iterates on random vectors picked on normalized data. If a log function is provided as a parameter, it will receive instance neurons and step as params.

mapping method

mapping method returns grid position for each data provided on the constructor.

const myPositions = k.mapping();
umatrix method

umatrix method returns the U-Matrix of the grid (currently only with standardized vectors).

const umatrix = k.umatrix();
errors

There are some heavy calculations in those 2 methods ; if you use them in the training callback (log), it's better not to use it on every step.

k.topographicError();
k.quantizationError();

k.training((neurons, step) => {
    if (step % 20 === 0) {
        k.topographicError();
        k.quantizationError();
    }
});

Example

We've developed a full example on a dedicated repository

capture

(Re)sources