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

ts-neuroevolution

v2.0.0

Published

Neuroevolution library in TypeScript

Downloads

11

Readme

Neuroevolution in Typescript

  

Run Test npm

Neuroevolution

Neuroevolution, or neuro-evolution, is a form of machine learning that uses evolutionary algorithms to train artificial neural networks.

It is most commonly applied in artificial life, computer games, and evolutionary robotics. A main benefit is that neuroevolution can be applied more widely than supervised learning algorithms, which require a syllabus of correct input-output pairs. In contrast, neuroevolution requires only a measure of a network's performance at a task. For example, the outcome of a game (i.e. whether one player won or lost) can be easily measured without providing labeled examples of desired strategies.

Originals

Ts-Neuroevolution is a TypeScript library version of xviniette Neuroevolution.

Installation

CDN:

<script src="https://unpkg.com/ts-neuroevolution/dist/neuroevolution.js"></script>

NPM:

npm install --save ts-neuroevolution

Configuration

export interface INeuroevolutionConfig {
  /**
   * Network structure
   * 
   * @default - [1, [2], 1]
   * @var number[] - [input, hidden, output]
   */
  network?: (number | number[])[];

  /**
   * Population by generation
   * 
   * @default - 50
   * @var number
   */
  population?: number;

  /**
   * Best network kepts unchange for next generation
   * 
   * @default - 0.2
   * @var number - 0.0 - 1.0
   */
  elitism?: number;

  /**
   * Mix trained networks with randomized networks for next generation
   * 
   * @default - 0.2
   * @var number - 0.0 - 1.0
   */
  randomBehaviour?: number;

  /**
   * Perform mutation on some genomes during breed
   * 
   * @default - 0.1
   * @var number - 0.0 - 1.0
   */
  mutationRate?: number;

  /**
   * Number of generation to be saved. 
   * Set to -1 to only keep the latest generation
   * 
   * @default - 0
   * @var number - -1 - n
   */
  historic?: number; // Latest generations saved.

  /**
   * ...
   * 
   * @default - false
   * @var boolean
   */
  lowHistoric?: boolean;

  /**
   * Sort the best score. AI will rely on best networks
   * -1 = descending. The highest the better
   * 1 = ascending. The lowest the better
   * 
   * @default - -1
   * @var number - -1, 1
   */
  scoreSort?: number;

  /**
   * Number of child to produce during breed
   * 
   * @default - 1
   * @var number
   */
  nbChild?: number;

  /**
   * Probability of making an absolute copy of a genomes during breed
   * 
   * @default - 0.5
   * @var number - 0.0 - 1.0
   */
  crossoverFactor?: number;
}

Recommended and Required Configurations

// tsconfig.json
{
  "compilerOptions": {
    "target": "ES6", // Recomended. ES Module or Higher
    "module": "ES6", // Recomended. ES Module or Higher
    "moduleResolution": "node", // Optional
    "typeRoots": [
      "./node_modules"
    ],

    // Optionals
    "esModuleInterop": true,
    "forceConsistentCasingInFileNames": true,
    "strict": true,
    "skipLibCheck": true
  }
}

Usage

import { Neuroevolution } from 'neuroevolution-typescript';

const config = {
    ...
}

// Create an instance 
const instance: Neuroevolution = new Neuroevolution(config);

// Generate new generation
// Will return an array of generation
// The array length is based on population
const generations = instance.nextGeneration();


const input = [0,1,1];
const expected = 1;

// Do compute

for(let i = 0; i < instance.options.population; i++) {
// Will return a prediction number ranging 0 to 1
    let result = generations[i].compute(input);
    
    // Tell if is right or wrong
    instance.networkScore(generations[i], Math.ceil(result[0]) === expected);
}

// Optional
// Repeat the process from generating generations

Exporting and Importing

// Must have atleast 1 generation completed before exporting trained data

// Your trained data including the configurations
// Will export the last generation
const data = instance.exportData();

const otherNeuvol = new Neuroevolution();

// Import pretrained data


// Note: Configuration from exported data will be use

// Import first before calling
// Neuroevolution.nextGeneration() function otherwise will not work correctly
otherNeuvol.importData(data);


otherNeuvol = instance.nextGeneration();

Examples

FlappyLearning - An Implementation of Ts-Neuroevolution with Webpack.

Tip: You can also use xviniette FlappyLearning version and replace the Neuroevolution with this ts-neuroevolution CDN version

Resources

Deep Neuroevolution: Genetic Algorithms are a Competitive Alternative for Training Deep Neural Networks for Reinforcement Learning

Scripts

Start development mode

npm start, npm run dev

Serve Ouput/dist folder

npm run serve

Will serve http://localhost:8080

Linting

npm run lint - Run lint

npm run lint:fix - Run lint and fix lines that linter can fix

Test

You can directly run npm test without npm run build:test

since jest will automatically compile Typescript to JavaScript

Builds

  • npm run build - Build all (except declarations and testing kit)
  • npm run build:umd - Build Browser Version. Output file 'neuroevolution.js'
  • npm run build:node - Build ES Node Module Version. Output file 'main.js'
  • npm run build:tsc - Build Declaration Files. Required for ES Node Modules

Building for NPM package steps

  • npm ci
  • npm run build - Build both umd and node version
  • npm run bud:tsc - Build TyoeScript types

Formating

npm run prettier-format - Start formating code from ./src and ./tests using Prettier

License

Under MIT License