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

genprojs

v0.0.12

Published

Simple Genetic Programming Framework for Javascript

Downloads

6

Readme

GenProJS

A simple basic genetic programming framework for NodeJS.

https://www.npmjs.com/package/genprojs

Sample usage: https://github.com/twinfifty/genprojs-sample/blob/master/sample1.js

Currently still under development

Requirements

Install

npm install genprojs

Usage

var genpro = require('genprojs');

var result = genpro.run(
    functions,
    variables,
    trainingData,
    testingData,
    options
);

Parameters:

  • functions: List of available functions/operators to be used, wrapped in GenProJS.Operation prototype
  • variables: List of variables to be used, wrapped in GenProJS.Variable prototype
  • trainingData: Array of JSON objects for training
  • testingData: Array of JSON objects for testing
  • options: See options section below

Returns a JSON object with properties:

  • population: final population from latest generation
  • history: list of average population fitness by generation
  • stat: some statistics: max, min, and average fitness score, and maxIndividual (best individual out of population)
  • goals: list of individuals who met the goal function (if enabled)

Operation

GenProJS uses a wrapper prototype called Operation for all of its functions. These following operations are provided out of the box:

  • add
  • subtract
  • multiply
  • divide
  • increment
  • decrement
  • power
  • sqrt

To access these operations:

var Genpro = require('genprojs');

var add = GenPro.BasicMathOperations.add;
var subtract = GenPro.BasicMathOperations.subtract;

var availableFunctions = [add, subtract];

/*....ommitted code...*/

var result = genpro.run(
    availableFunctions,
    variables,
    trainingData,
    testingData,
    options
);

To create new function:

var Genpro = require('genprojs');
var Operation = Genpro.Operation;

var newFn = new Operation(fn, operationType, displayFn, name:optional);

Parameters:

  • fn: The actual function
  • operationType: Currently suppors either "UNARY" or "BINARY"
  • displayFn: display function, i.e. toString function
  • name-optional: the name of the function

Example from the add function:

var Genpro = require('genprojs');
var Operation = Genpro.Operation;

var add = new Operation(
    (...args) => {
        return Array.prototype.reduce.call(args, (acc, elem) => {
            return acc + elem;
        });
    }, 
    "BINARY", 
    (...args) => {
        return '(' + Array.prototype.reduce.call(args, (acc, elem) => {
            return acc + ' + ' + elem;
        }) + ')';
    }
);

Variable

Like operation, the variables used in GenProJS requires them to be wrapped in GenProJS.Variable prototype.

Example:

var Genpro = require('genprojs');
var Variable = Genpro.Variable;

var aVariable = new Variable('a');
var variables = ['x', 'y', 'z'].map(key => new Variable(key)); // returns an array of Variable objects
variables.push(aVariable);

/*....ommitted code...*/

var result = genpro.run(
    functions,
    variables,
    trainingData,
    testingData,
    options
);

Data

GenProJS expects the data to be an array of JSON objects, with all input variables specified. Additionally, an expected output property may also be included in the JSON object.

Example:

var trainingData = [
    {
        x: 20,
        y: 30,
        z: 50,
        output: 100
    },
    {
        x: 120,
        y: 130,
        z: 150,
        output: 400
    },
    {
        x: 2,
        y: 3,
        z: 5,
        output: 10
    }
]

Options

  • fitnessFn REQUIRED: the fitness function to be used
  • populationSize: population size (default: 100)
  • minDepth: minimum program depth (default: 1, i.e. one operation, e.g. a + b)
  • maxDepth: maximum program depth (default: 3)
  • crossoverProbability: crossover probability(default: 0.70)
  • mutationProbability: mutation probability (default: 0.005)
  • maxIteration: maximum number of iterations (default: 2000)
  • operationProbability: used in generating initial population, probability that a node will be an operation instead of a variable (default: 0.75)

Fitness Function

Fitness Function, or fitnessFn, is required. Currently, GenProJS expects a maximizing fitness function. fitnessFn requires four parameters:

  • individual: the individual chromosome being evaluated
  • functions: available functions
  • variables: variables
  • data: data to be calculated by the program (see data above)

Example of a fitnessFn:

var Genpro = require('genprojs');
var Chromosome = Genpro.Chromosome;

var fitnessFn = (individual, functions, variables, data) => {
    // iterate through each row in data and sum
    let fitnessValSum = data.reduce((sum, vt) => {
        let val = Chromosome.val(individual, functions, variables, vt);
        return sum + val;
    }, 0);
    fitnessVal = fitnessValSum / data.length;
    // return average
    return fitnessVal;
};


var options {
    fitnessFn: fitnessFn
};

/*...code omitted...*/

var result = genpro.run(
    functions,
    variables,
    trainingData,
    testingData,
    options
);