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

snes

v1.0.1

Published

separable Natural Evolutionary Strategy

Readme

snes

Separable Natural Evolution Strategy algorithm in JavaScript.

import SNES from "snes";

// creates an optimizer with settings
const optimizer = SNES({
  solutionLength, // number of parameters
  populationCount,
});

// an array to store your fitnesses for each population
const fitnesses = new Float32Array(populationCount);

// for each epoch...
const epochs = 100;
for (let i = 0; i < epochs; i++) {
  // ask for a set of solutions (flat array)
  const solutions = optimizer.ask();

  // compute the fitness for each
  for (let j = 0; j < populationCount; j++) {
    // note this returns a subarray (i.e. no copy)
    const params = optimizer.getSolutionAt(solutions, j);

    // compute the fitness, which is often -err
    fitnesses[j] = fitness(params);
  }

  // update the optimizer with all fitnesses
  optimizer.tell(fitnesses);
}

// The optimized 'mean' solution
console.log(optimizer.center);

See the examples directory for more.

Install

Use npm to install.

npm install snes --save

Usage

optimizer = SNES({ opts })

With options:

  • solutionLength number of parameters to optimize
  • populationCount number of candidate solutions to use
  • alpha (default=0.05) learning rate
  • state a 4-element Uint32Array random seed state
  • random (default=Math.random) randomizer for computing an initial opts.state if not specified; ignored if state is given
  • sigma the initial standard deviation, defaults to:
    • new Float32Array(solutionLength).fill(1)
  • center the initial mean, defaults to:
    • new Float32Array(solutionLength).fill(0)

solutions = optimizer.ask()

Returns a flat array of solutions, strided by solutionLength. The total size of this array will be solutionLength * populationCount.

subarray = optimizer.getSolutionAt(solutions, index)

From a flat array of solutions, gets a subarray at slot index. Since this is a view of the flat array, it is not a copy, and so any changes to the flat array will also be present in this view. You should use subarray.slice() if you want a copy.

optimizer.tell(fitnesses)

Updates the parameters based on the list of fitnesses, which is expected to be parallel to the solutions array given by the ask() function. The size of this array should be populationCount.

optimizer.center

The current mean of the optimizer, i.e. the optimization result. This may not always be the best performing candidate, for example compared to candidates from prior epochs.

other getters

  • optimizer.sigma (length solutionLength)
  • optimizer.gaussian (length populationCount * solutionLength)
  • optimizer.prng (you can use prng.next() and prng.nextGaussian() for random values)

References

License

MIT, see LICENSE.md for details.