Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

set-distance

Package Overview
Dependencies
Maintainers
1
Versions
3
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

set-distance

Finds measure of similarity/distance between two input sets.

  • 1.0.2
  • latest
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
23
increased by109.09%
Maintainers
1
Weekly downloads
 
Created
Source

set-distance

Finds similarity/distance between two input sets.
Algorithms implemented:
1). Sorensen-Dice Coefficient.
2). Jaccard Index.
3). Ochiai Coefficient.
4). Overlap Coefficient.
5). Levenshtein/Edit Distance.
6). Euclidean Distance.

Installation

npm install set-distance --save
bower install set-distance --save

Usage

Javascript

var Distance = require('set-distance');
//SorensenDice Coefficient
var sc = new Distance.SorensenDice(['S', 'A', 'T', 'U', 'R', 'D', 'A', 'Y'], ['S', 'U', 'N', 'D', 'A', 'Y']).getCoefficient();
console.log(sc);
//Output: 0.7142857142857143

//Jaccard Index
var jc = new Distance.Jaccard(['S', 'A', 'T', 'U', 'R', 'D', 'A', 'Y'], ['S', 'U', 'N', 'D', 'A', 'Y']).getCoefficient();
console.log(jc);
//Output: 0.5555555555555556

//Ochiai Coefficient
var oc = new Distance.Ochiai(['S', 'A', 'T', 'U', 'R', 'D', 'A', 'Y'], ['S', 'U', 'N', 'D', 'A', 'Y']).getCoefficient();
console.log(oc);
//Output: 0.7216878364870323

//Overlap Coefficient
var ov = new Distance.Overlap(['S', 'A', 'T', 'U', 'R', 'D', 'A', 'Y'], ['S', 'U', 'N', 'D', 'A', 'Y']).getCoefficient();
console.log(ov);
//Output: 0.8333333333333334

//Levenshtein/Edit Distance
var ld = new Distance.Levenshtein(['S', 'A', 'T', 'U', 'R', 'D', 'A', 'Y'], ['S', 'U', 'N', 'D', 'A', 'Y']).getCoefficient();
console.log(ld);
//Output: 3

//Euclidean Distance
var ed = new Distance.Euclidean([50, 60], [20, 25]).getDistance(); // Here cartesian co-ordinates given in both arrays. Eg.: cartestian co-ordinates p1=50, p2=60 given in first list. And cartesian co-ordinates q1=20, q2=25 given in second list. Thus array1 in this case holds caretsian co-ordinates of "p" and array2 holds caretsian co-ordinates of "q".
console.log(ed);
//Output: 46.0977

TypeScript

import * as Distance from 'set-distance';
//SorensenDice Coefficient
var sc = new Distance.SorensenDice(['S', 'A', 'T', 'U', 'R', 'D', 'A', 'Y'], ['S', 'U', 'N', 'D', 'A', 'Y']).getCoefficient();
console.log(sc);
//Output: 0.7142857142857143

//Jaccard Index
var jc = new Distance.Jaccard(['S', 'A', 'T', 'U', 'R', 'D', 'A', 'Y'], ['S', 'U', 'N', 'D', 'A', 'Y']).getCoefficient();
console.log(jc);
//Output: 0.5555555555555556

//Ochiai Coefficient
var oc = new Distance.Ochiai(['S', 'A', 'T', 'U', 'R', 'D', 'A', 'Y'], ['S', 'U', 'N', 'D', 'A', 'Y']).getCoefficient();
console.log(oc);
//Output: 0.7216878364870323

//Overlap Coefficient
var ov = new Distance.Overlap(['S', 'A', 'T', 'U', 'R', 'D', 'A', 'Y'], ['S', 'U', 'N', 'D', 'A', 'Y']).getCoefficient();
console.log(ov);
//Output: 0.8333333333333334

//Levenshtein/Edit Distance
var ld = new Distance.Levenshtein(['S', 'A', 'T', 'U', 'R', 'D', 'A', 'Y'], ['S', 'U', 'N', 'D', 'A', 'Y']).getCoefficient();
console.log(ld);
//Output: 3

//Euclidean Distance
var ed = new Distance.Euclidean([50, 60], [20, 25]).getDistance(); // Here cartesian co-ordinates given in both arrays. Eg.: cartestian co-ordinates p1=50, p2=60 given in first list. And cartesian co-ordinates q1=20, q2=25 given in second list. Thus array1 in this case holds caretsian co-ordinates of "p" and array2 holds caretsian co-ordinates of "q".
console.log(ed);
//Output: 46.0977

Keywords

FAQs

Package last updated on 10 Sep 2022

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc