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

genetic-nodejs-multithread

v0.3.7

Published

Advanced genetic and evolutionary algorithm library

Downloads

5

Readme

Genetic-multithread.js

Advanced genetic and evolutionary algorithm library written in Javascript by Sub Protocol.

Changes from original version

This is a modified genetic repo optimized for nodejs with multi thread performance optimization. it uses experimental feature worker_threads This version only supports genetic with node js, doesn't support running in browser.

requires to run program with node --experimental-worker

Examples

example in nodejs node --experimental-worker examples/nodeJsFitting.js

Install

npm install genetic-nodejs-multithread

Population Functions

The genetic-js interface exposes a few simple concepts and primitives, you just fill in the details/features you want to use.

| Function | Return Type | Required | Description | ----------------------------------------- | ------------------------ | ---------- | ----------- | seed() | Individual | Yes | Called to create an individual, can be of any type (int, float, string, array, object) | fitness(individual) | Float | Yes | Computes a fitness score for an individual | mutate(individual) | Individual | Optional | Called when an individual has been selected for mutation | crossover(mother, father) | [Son, Daughter] | Optional | Called when two individuals are selected for mating. Two children should always returned | optimize(fitness, fitness) | Boolean | Yes | Determines if the first fitness score is better than the second. See Optimizer section below | select1(population) | Individual | Yes | See Selection section below | select2(population) | Individual | Optional | Selects a pair of individuals from a population. Selection | generation(pop, gen, stats) | Boolean | Optional | Called for each generation. Return false to terminate end algorithm (ie- if goal state is reached) | notification(pop, gen, stats, isFinished) | Void | Optional | Runs in the calling context. All functions other than this one are run in a web worker.

Optimizer

The optimizer specifies how to rank individuals against each other based on an arbitrary fitness score. For example, minimizing the sum of squared error for a regression curve Genetic.Optimize.Minimize would be used, as a smaller fitness score is indicative of better fit.

| Optimizer | Description | -------------------------- | ----------- | Genetic.Optimize.Minimizer | The smaller fitness score of two individuals is best | Genetic.Optimize.Maximizer | The greater fitness score of two individuals is best

Selection

An algorithm can be either genetic or evolutionary depending on which selection operations are used. An algorithm is evolutionary if it only uses a Single (select1) operator. If both Single and Pair-wise operations are used (and if crossover is implemented) it is genetic.

| Select Type | Required | Description | ------------------- | ----------- | ----------- | select1 (Single) | Yes | Selects a single individual for survival from a population | select2 (Pair-wise) | Optional | Selects two individuals from a population for mating/crossover

Selection Operators

| Single Selectors | Description | -------------------------------- | ----------- | Genetic.Select1.Tournament2 | Fittest of two random individuals | Genetic.Select1.Tournament3 | Fittest of three random individuals | Genetic.Select1.Fittest | Always selects the Fittest individual | Genetic.Select1.Random | Randomly selects an individual | Genetic.Select1.RandomLinearRank | Select random individual where probability is a linear function of rank | Genetic.Select1.Sequential | Sequentially selects an individual

| Pair-wise Selectors | Description | -------------------------------- | ----------- | Genetic.Select2.Tournament2 | Pairs two individuals, each the best from a random pair | Genetic.Select2.Tournament3 | Pairs two individuals, each the best from a random triplett | Genetic.Select2.Random | Randomly pairs two individuals | Genetic.Select2.RandomLinearRank | Pairs two individuals, each randomly selected from a linear rank | Genetic.Select2.Sequential | Selects adjacent pairs | Genetic.Select2.FittestRandom | Pairs the most fit individual with random individuals

var genetic = Genetic.create();

// more likely allows the most fit individuals to survive between generations
genetic.select1 = Genetic.Select1.RandomLinearRank;

// always mates the most fit individual with random individuals
genetic.select2 = Genetic.Select2.FittestRandom;

// ...

Configuration Parameters

| Parameter | Default | Range/Type | Description | --------------------- | -------- | ---------- | ----------- | size | 250 | Real Number | Population size | crossover | 0.9 | [0.0, 1.0] | Probability of crossover | mutation | 0.2 | [0.0, 1.0] | Probability of mutation | iterations | 100 | Real Number | Maximum number of iterations before finishing | fittestAlwaysSurvives | true | Boolean | Prevents losing the best fit between generations | skip | 0 | Real Number | Setting this higher throttles back how frequently genetic.notification gets called in the main thread. | workerPath | '' | String | NodeJS only, set a custom fitness worker path | workersCount | 0 | number | NodeJS only, set how many multi thread workers to use, set 0 to disable multi threading

Building

To clone, build, and test Genetic.js issue the following command:

git clone [email protected]:subprotocol/genetic-js.git && make distcheck

| Command | Description | --------------------- | ----------- | make | Automatically install dev-dependencies

Contributing

Feel free to open issues and send pull-requests.