Giter VIP home page Giter VIP logo

bray-curtis's Introduction

bray-curtis

Nearest neighbor using bray curtis dissimilarity.

wercker status

This is a Bray Curtis implementation for nearest neighbor. More information can be found here.

"The Bray–Curtis dissimilarity is bound between 0 and 1, where 0 means the two sites have the same composition (that is they share all the species), and 1 means the two sites do not share any species."

Note: This implementation actually uses the Bray-Curtis index. This means the values are bound between 0 and 100, and 0 means the two sites do not share any species. This is implemented like so:

dissimilarity = dissimilarity * 100; // interpret dissimilarity as a percentage
var similarity = 100 - dissimilarity; // change dissimilarity to similarity (Bray-Curtis index)

methods

var BrayCurtis = require('bray-curtis');

var nn = BrayCurtis(vectors)

Create a new Bray Curtis nearest neighbor instance. vector is an an array (neighbors) of arrays (neighbor features).

var neighbors = nn.knn(subject, k);

Returns the k most nearest neighbors to subject (the target neighbor). k default is 10.

Resulting neighbors is a sorted, (most similar first) array where each object has the following properties:

  • vector - the neighbor vector
  • d - the "Bray-Curtis index" score. ie. similarity score.

example

var BrayCurtis = require('bray-curtis');
var vectors = [
  [26, 4, 13, 11, 0],
  [0, 10, 9, 8, 0],
  [0, 0, 15, 3, 0],
  [13, 5, 3, 10, 7],
  [31, 21, 13, 16, 5],
  [9, 6, 0, 11, 2],
  [32, 26, 0, 23, 0],
  [32, 21, 0, 10, 2],
  [24, 17, 0, 25, 6],
  [16, 3, 12, 20, 2],
  [11, 0, 7, 8, 0],
  [24, 37, 5, 18, 1]
  ];
var nn = new BrayCurtis(vectors);

var subject = [32, 26, 0, 23, 0];
var mostSimilar = [32, 21, 0, 10, 2];

var neighbors = nn.knn(subject, 2);
var neighbor = neighbors[1]; // the subject itself should always be returned as the first element because the item will be most similar to itself, so we get the second element
neighbors[0].d.should.eql(100);
neighbor.vector.should.eql(mostSimilar);

License

(The MIT License)

Copyright (c) 2014 Nick Poorman [email protected]

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.

bray-curtis's People

Contributors

nickpoorman avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.