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.
Create a NearestNeighbour
Create a default NearestNeighbour calculator from the constructor like so:
var nearestNeighbour =
Set the configuration options like so:
var config =objects : object1 object2 object3number : 2 // the number of results# in two stepsvar nearestNeighbour =nearestNeighbour# or as a one linervar nearestNeighbour = config
You can change or add to the list of objects like so
var nearestNeighbour = confignearestNeighbournearestNeighbour
Execution is a one liner and returns a list of nearest neighbours
var resultList = nearestNeighbour
The full configuration is as follows
var config =objects : /* list of objects */number : theNumberOfResultsYouWantdistanceFunction : yourDistanceFunction
You can set the configuration wholely or just change one aspect using the .config function like so:
# change the number of results to 5nearestNeighbour
This is a very simple example that finds the object with the closest match.
var neighbour =objects : a : -10 a : 3number : 1console# returns a : 3neighbourconsole# returns a : 2
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.