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

gene-pool

v0.0.4

Published

Genetic algorithms in a given gene pool

Downloads

5

Readme

gene-pool

Genetic algorithms in a given gene pool

Usage

// 初始化
var population = new GenePool(opts);
// 繁衍三代
population.next();
population.next();
population.next();
// 初始化
var population = new GenePool(opts);
// 在大约两秒时间内尽可能繁衍迭代
population.timeout(2000, function(err, results) {
    console.log(results);
});

Opts

  • N: 个体基因数
  • K: 种群规模(种群稳定时的数量)
  • genes: 基因
  • weights: 基因权重,影响出现的可能性大小(可选)
  • mutationRate: 基因突变率,大约有多少比例的基因需要突变
  • birthRate: 出生率

Demo

Demo 是一个以五色总亮度作为 fitness 的一个测试。 黑框表示是突变出来的基因。

opts.K = 5;
opts.N = 5;
opts.mutationRate = 0.1;
opts.birthRate = 1;

http://zenozeng.github.io/gene-pool/demo/

Why

有时候,我们需要在一个不小的数据集中取一个不大组合。 但由于组合的关系,需要的计算量可能不小, 比如从 length 为 40 里的 array 随意取 5 个元素来组合。 那么就有 658008 种可能性, 而我们要的只是比如里面 TOP 100。 显然完全计算fitness然后sort是非常有压力了,那么就用遗传算法。

一些假设前提

只是为了计算,而非生物学正确。

  • 一个个体必须含有N个基因库中的不相重复的基因

  • 随机变异只发生在给定基因库

  • 产生子代时,从亲代整个群体随机获取基因

  • 基因相同但基因顺序不同的个体视为相同

  • 为保证最终产生数目竟可能 >= K,这个库的做法是先出生再定向选择,而往常的做法可能是用存活率的概念,然后再补满。

License

The MIT License (MIT)

Copyright (c) 2014 Zeno Zeng

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.