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

nearestneighbour

v0.1.1

Published

a general purpose nearest neighbour framework, an A.I. tool useful for machine learning and outcome estimation

Downloads

46

Readme

Issues Downloads Auto Test Status license Gitter chat

NearestNeighbour is a method of looking up best matches. Best matches of what? Of your data of course, using your distance function. If you have a list of robotic motions , previous limb location and speed along with current limb speed and the torque that was applied then you can use NearestNeighbour to look up the best guess torque needed to make the current state transition into a target state. If you have a list of books and their ranking in several dimensions such as romance level, word count, and popularity. You can use NearestNeighbour to find the best matches for a person based on their preferences of romance level, word count, etc.

You can improve the accuracy of NearestNeighbour by providing it with more data. The data can be anything you want so long as it works with your distance function. Don't have a distance function? No problem, I made a cartisian distance checker for you that works with objects that have one or more key:number entries. If you don't specify a distance function then the cartisian distance checker is used.

Amazon (used to) suggest related books and items to customers using NearestNeighbour (or something very similar to it) and built a huge online empire on the upsales from doing so. Play with NearestNeighbour a bit and you'll quickly see how you could get really accurate upsales lists based on someones previous shopping history and what other people shop for.

Section Links : Construction , Execution , Examples , FAQ , Related , and References

Construction

Create a NearestNeighbour

Create a default NearestNeighbour calculator from the constructor like so:

var nearestNeighbour = require('nearestneighbour')()

Set the configuration options like so:

var config = {
	objects : [ object1 , object2 , object3 ],
	number : 2  // the number of results
}
# in two steps
var nearestNeighbour = require('nearestneighbour')()
nearestNeighbour.config(config)

# or as a one liner
var nearestNeighbour = require('nearestneighbour')(config)

Update Objects

You can change or add to the list of objects like so

var nearestNeighbour = require('nearestneighbour')(config)
nearestNeighbour.setObjects( [ object1 , object2 , object3 ] )
nearestNeighbour.add( object4 )

Execution

Execution is a one liner and returns a list of nearest neighbours

var resultList = nearestNeighbour.nearest( searchObject )

Configuration

The full configuration is as follows

var config = {
	objects 			: [ /* list of objects */ ],
	number				: theNumberOfResultsYouWant,
	distanceFunction	: yourDistanceFunction
}

You can set the configuration wholely or just change one aspect using the .config function like so:

# change the number of results to 5
nearestNeighbour.config({number:5})

Example

This is a very simple example that finds the object with the closest match.

var neighbour = require('nearestneighbour')({ 
	objects : [ { a : -10 } , { a : 3 } ],
	number : 1
})
console.log( neighbour.nearest({ a : 1 })[0] )
# returns { a : 3 }
neighbour.add( { a : 2 } )
console.log( neighbour.nearest({ a : 1 })[0] )
# returns { a : 2 }

FAQ

Each object in objects can be any object you want. If you are using the default distance function the object must have at a minimum the same keys as the keys in the searchObject. Additionally, the values of the keys in the searchObject and the objects must be Numbers.

Related AI Projects

This is part of a set of related projects.

References