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

imperfect-nn-comparison

v0.0.1

Published

Tools to compare a few different approaches to determining nearest neighbors.

Downloads

4

Readme

Imperfect Nearest Neighbor Comparison

This package contains some tools written while comparing different approaches to finding nearest neighbor points in a large dataset. It speeds up the process of generating data sets and then running nearest neighbor searches.

The approaches presently compared:

ANN

The approximate nearest neighbor (ANN) package is a C++ library. Here we're using a sample program that comes with the library distribution to run searches. See:

http://www.cs.umd.edu/~mount/ANN/

What does this do: it finds the nearest N neighbors to a designated point, approximately, in order of distance. It supposedly doesn't do well above about 20 dimensions.

To setup and run, edit /config/config.js for dimensions and number of rows, then:

node imperfect-nn-comparison ann setup
node imperfect-nn-comparison ann run

MySQL With Indexed Columns

You can perform a constrained search for nearest neighbors in SQL by building an indexed table for your data, one row per point, one column per dimension.

You should probably turn off the MySQL query cache before trying this to avoid potentially misleading results.

What does this do? It looks for all neighbors within a volume around the designated point. So it doesn't specifically find the nearest wherever it might be, nor does it order those it does find.

Not that ordering would be hard once you have the results. The hard part is how to know how big the volume should be, since you have to process all the results from the volume to figure out which are the nearest. This is very dependent on the nature of the data.

To setup and run, edit /config/config.js for dimensions and number of rows, then:

node imperfect-nn-comparison mysql setup
node imperfect-nn-comparison mysql run

Notes

These are obviously not apples-to-apples comparisons. The searches are of different forms and data is moved around in different ways: on disk, in memory, and so forth. The sample ANN program reads in data from a file and builds all of its data structures from scratch for each test, while MySQL is using some mix of file system and memory for its data and has already built its indexes before the test is run.

High Level Results

I ran some non-rigorous experiments on a small Digital Ocean virtual SSD drive server with 2G RAM and two CPUs. These notes are here for the purpose of steering expectations, and shouldn't be taken as being in any way accurate.

For 20 dimensions and 10,000 rows:

ANN: ~450-500ms to find 10 nearest neighbors. The time taken doesn't have much of a dependency on the number of nearest neighbors requested.

MySQL: ~40-100ms to find 0-500 close neighbors. Returning more results takes longer, but that's expected with a SQL client: it's looking at more indexes as the search volume is made larger.

For 20 dimensions and 100,000 rows:

ANN: ~4600-5000ms to find 10 nearest neighbors.

MySQL: ~140-200ms to find 0-500 close neighbors. Returning more results takes longer, as before.

For 20 dimensions and 1,000,000 rows:

ANN: ~50000-60000ms to find 10 nearest neighbors.

MySQL: ~900-1100ms to find 0-500 close neighbors. Returning more results takes longer, as before.