Skip to content

A zero-dependency Typescript library for computing pairwise distances

License

Notifications You must be signed in to change notification settings

seth-brown/furlong

Repository files navigation

furlong

n. a unit of distance equal to 220 yards

furlong is a zero dependency Node and Javascript library for computing pairwise distance metrics writting in Typescript.

Build Status

Installation

npm install furlong --save

Usage

furlong can be used with Node or with plain Javascript; it has no external dependencies. To use with Node, simply require it:

const { furlong } = require('furlong')

To use in Javascript, just import it:

import { furlong } from 'furlong'

Pairwise distance functions are computed using a distance method. furlong provides several built-in distance functions and also supports user defined functions. The provided distance functions include:

  • Euclidean distance
  • Manhattan (Taxicab) distance
  • Chebyshev distance
  • Bray Curtis distance
  • Canberra distance
  • Hamming distance
>>> furlong('euclidean').distance([0,0,0],[0,0,100])
100

Accessor functions can also be used for more complex data structures:

>>> const distanceFunc = furlong('chebyshev')
                     .x(d => d.foo)
                     .y(d => d.bar)

>>> const vectorA = [{'foo': 12},{'foo': 7},{'foo': 0}]
>>> const vectorB = [{'bar': 6},{'bar': 32},{'bar': 27}]
>>> distanceFunc
      .distance(vectorA, vectorB)
      .toFixed(2)
27

Custom distance functions can be used with furlong's accessors as well:

>>> const customDistanceFunc = (v1, v2) => 0
>>> furlong('hamming')
    .func(customDistanceFunc)
    .distance([0,0],[1,1])
0

Testing

  • Using npm:
    npm test

Release History

  • 0.1.0 Initial release
  • 0.2.0 Ported library to Typescript

About

A zero-dependency Typescript library for computing pairwise distances

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published