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 🙏

© 2026 – Pkg Stats / Ryan Hefner

@leoni4/neat-js

v1.0.1

Published

NEAT Neural Network Implementation in TypeScript

Readme

🧬 NEAT.js

A TypeScript implementation of the NEAT (NeuroEvolution of Augmenting Topologies) algorithm for evolving neural networks.

🎮 Live Demo

Try the interactive demo: https://leoni4.github.io/neat-js/

The demo showcases NEAT solving various problems including XOR, parity functions, and classification tasks with real-time visualization of the neural network evolution.

Installation

npm install @leoni4/neat-js

Usage

Basic Library Usage

import { Neat } from '@leoni4/neat-js';

// Create a NEAT instance
const neat = new Neat(
    2, // input nodes
    1, // output nodes
    1000, // population size
);

// Training data (XOR example)
const inputs = [
    [0, 0],
    [1, 1],
    [1, 0],
    [0, 1],
];
const outputs = [[0], [0], [1], [1]];

const solved = neat.fit(inputs, outputs, {
    verbose: 1,
});

console.log('solved in:', solved.epochs);

Manual Library Usage

Could be helpfull with non linear score determination, or complex environment

import { Neat } from '@leoni4/neat-js';

// Create a NEAT instance same as above
const neat = new Neat(2, 1, 1000);

// Training data (XOR example) ... same as above
const inputs = [
    [0, 0],
    [1, 1],
    [1, 0],
    [0, 1],
];
const outputs = [[0], [0], [1], [1]];

let finalError = 1; // just for the demo
let counter = 0;
// Evolution loop
for (let epoch = 0; epoch < 1000; epoch++) {
    // Evaluate each client
    for (const client of neat.clients) {
        let error = 0;
        inputs.forEach((input, i) => {
            const output = client.calculate(input)[0];
            error += Math.abs(output - outputs[i][0]);
        });
        error = error / inputs.length;

        // calculate error and score of the client
        client.error = error;
        client.score = 1 - client.error;

        if (finalError > error) {
            finalError = error;
        }
    }
    counter++;
    // Evolve to next generation
    neat.evolve();

    if (epoch % 10 === 0) console.log('Epoch:', epoch, ' Error:', finalError);

    if (finalError < 0.01) break;
}

console.log('Total epochs:', counter, ' Final Error:', finalError);
// ... rest of the logic

Development

Running the Demo

Clone the repository and run the demo locally:

git clone https://github.com/leoni4/neat-js.git
cd neat-js
npm install
npm start

The demo will start a Vite development server at http://localhost:3000 with a visual demonstration of the NEAT algorithm solving the selected problem.

Available Scripts

  • npm start - Start the Vite development server with demo
  • npm run build - Build the library for production
  • npm run build:demo - Build the demo for production
  • npm test - Run tests
  • npm run test:watch - Run tests in watch mode
  • npm run lint - Lint the codebase
  • npm run typecheck - Run TypeScript type checking

API

Core Classes

  • Neat - Main NEAT algorithm class
  • Client - Individual neural network in the population
  • Genome - Genetic representation of a neural network
  • Species - Group of similar genomes

Data Structures

  • RandomHashSet - Efficient random selection from a set
  • RandomSelector - Weighted random selection

Contributing

  1. Fork the repository
  2. Create a feature branch
  3. Make your changes with tests
  4. Ensure all tests pass: npm test
  5. Submit a pull request

License

MIT

Repository

https://github.com/leoni4/neat-js