Installations
npm install ml-distance
Score
99
Supply Chain
100
Quality
82.3
Maintenance
100
Vulnerability
100
License
Developer
Developer Guide
Module System
CommonJS
Min. Node Version
Typescript Support
Yes
Node Version
16.20.0
NPM Version
8.19.4
Statistics
68 Stars
125 Commits
4 Forks
15 Watching
5 Branches
9 Contributors
Updated on 26 Nov 2024
Languages
TypeScript (97.03%)
JavaScript (2.97%)
Total Downloads
Cumulative downloads
Total Downloads
19,329,312
Last day
-3.6%
47,406
Compared to previous day
Last week
-0.7%
258,099
Compared to previous week
Last month
7.2%
1,143,477
Compared to previous month
Last year
298%
15,389,113
Compared to previous year
Daily Downloads
Weekly Downloads
Monthly Downloads
Yearly Downloads
ml-distance
Maintained by Zakodium
Distance functions to compare vectors.
Installation
$ npm i ml-distance
Methods
Distances
euclidean(p, q)
Returns the euclidean distance between vectors p and q
$d(p,q)=\sqrt{\sum\limits_{i=1}^{n}(p_i-q_i)^2}$
manhattan(p, q)
Returns the city block distance between vectors p and q
$d(p,q)=\sum\limits_{i=1}^{n}{\left|p_i-q_i\right|}$
minkowski(p, q, d)
Returns the Minkowski distance between vectors p and q for order d
chebyshev(p, q)
Returns the Chebyshev distance between vectors p and q
$d(p,q)=\max\limits_i(|p_i-q_i|)$
sorensen(p, q)
Returns the Sørensen distance between vectors p and q
$d(p,q)=\frac{\sum\limits_{i=1}^{n}{\left|p_i-q_i\right|}}{\sum\limits_{i=1}^{n}{p_i+q_i}}$
gower(p, q)
Returns the Gower distance between vectors p and q
$d(p,q)=\frac{\sum\limits_{i=1}^{n}{\left|p_i-q_i\right|}}{n}$
soergel(p, q)
Returns the Soergel distance between vectors p and q
$d(p,q)=\frac{\sum\limits_{i=1}^{n}{\left|p_i-q_i\right|}}{max(p_i,q_i)}$
kulczynski(p, q)
Returns the Kulczynski distance between vectors p and q
$d(p,q)=\frac{\sum\limits_{i=1}^{n}{\left|p_i-q_i\right|}}{min(p_i,q_i)}$
canberra(p, q)
Returns the Canberra distance between vectors p and q
$d(p,q)=\sum\limits_{i=1}^{n}\frac{\left|{p_i-q_i}\right|}{p_i+q_i}$
lorentzian(p, q)
Returns the Lorentzian distance between vectors p and q
$d(p,q)=\sum\limits_{i=1}^{n}\ln(\left|{p_i-q_i}\right|+1)$
intersection(p, q)
Returns the Intersection distance between vectors p and q
$d(p,q)=1-\sum\limits_{i=1}^{n}min(p_i,q_i)$
waveHedges(p, q)
Returns the Wave Hedges distance between vectors p and q
$d(p,q)=\sum\limits_{i=1}^{n}\left(1-\frac{min(p_i,q_i)}{max(p_i,q_i)}\right)$
czekanowski(p, q)
Returns the Czekanowski distance between vectors p and q
$d(p,q)=1-\frac{2\sum\limits_{i=1}^{n}{min(p_i,q_i)}}{\sum\limits_{i=1}^{n}{p_i+q_i}}$
motyka(p, q)
Returns the Motyka distance between vectors p and q
$d(p,q)=1-\frac{\sum\limits_{i=1}^{n}{min(p_i,q_i)}}{\sum\limits_{i=1}^{n}{p_i+q_i}}$
Note: distance between 2 identical vectors is 0.5 !
ruzicka(p, q)
Returns the Ruzicka similarity between vectors p and q
$d(p,q)=\frac{\sum\limits_{i=1}^{n}{max(p_i,q_i)}}{\sum\limits_{i=1}^{n}{min(p_i,q_i)}}$
tanimoto(p, q, [bitVector])
Returns the Tanimoto distance between vectors p and q, and accepts the bitVector use, see the test case for an example
innerProduct(p, q)
Returns the Inner Product similarity between vectors p and q
$s(p,q)=\sum\limits_{i=1}^{n}{p_i\cdot{q_i}}$
harmonicMean(p, q)
Returns the Harmonic mean similarity between vectors p and q
$d(p,q)=2\sum\limits_{i=1}^{n}\frac{p_i\cdot{q_i}}{p_i+q_i}$
cosine(p, q)
Returns the Cosine similarity between vectors p and q
$d(p,q)=\frac{\sum\limits_{i=1}^{n}{p_i\cdot{q_i}}}{\sum\limits_{i=1}^{n}{p_i^2}\sum\limits_{i=1}^{n}{q_i^2}}$
kumarHassebrook(p, q)
Returns the Kumar-Hassebrook similarity between vectors p and q
$d(p,q)=\frac{\sum\limits_{i=1}^{n}{p_i\cdot{q_i}}}{\sum\limits_{i=1}^{n}{p_i^2}+\sum\limits_{i=1}^{n}{q_i^2}-\sum\limits_{i=1}^{n}{p_i\cdot{q_i}}}$
jaccard(p, q)
Returns the Jaccard distance between vectors p and q
$d(p,q)=1-\frac{\sum\limits_{i=1}^{n}{p_i\cdot{q_i}}}{\sum\limits_{i=1}^{n}{p_i^2}+\sum\limits_{i=1}^{n}{q_i^2}-\sum\limits_{i=1}^{n}{p_i\cdot{q_i}}}$
dice(p,q)
Returns the Dice distance between vectors p and q
$d(p,q)=1-\frac{\sum\limits_{i=1}^{n}{(p_i-q_i)^2}}{\sum\limits_{i=1}^{n}{p_i^2}+\sum\limits_{i=1}^{n}{q_i^2}}$
fidelity(p, q)
Returns the Fidelity similarity between vectors p and q
$d(p,q)=\sum\limits_{i=1}^{n}{\sqrt{p_i\cdot{q_i}}}$
bhattacharyya(p, q)
Returns the Bhattacharyya distance between vectors p and q
$d(p,q)=-\ln\left(\sum\limits_{i=1}^{n}{\sqrt{p_i\cdot{q_i}}}\right)$
hellinger(p, q)
Returns the Hellinger distance between vectors p and q
$d(p,q)=2\cdot\sqrt{1-\sum\limits_{i=1}^{n}{\sqrt{p_i\cdot{q_i}}}}$
matusita(p, q)
Returns the Matusita distance between vectors p and q
$d(p,q)=\sqrt{2-2\cdot\sum\limits_{i=1}^{n}{\sqrt{p_i\cdot{q_i}}}}$
squaredChord(p, q)
Returns the Squared-chord distance between vectors p and q
$d(p,q)=\sum\limits_{i=1}^{n}{(\sqrt{p_i}-\sqrt{q_i})^2}$
squaredEuclidean(p, q)
Returns the squared euclidean distance between vectors p and q
$d(p,q)=\sum\limits_{i=1}^{n}{(p_i-q_i)^2}$
pearson(p, q)
Returns the Pearson distance between vectors p and q
$d(p,q)=\sum\limits_{i=1}^{n}{\frac{(p_i-q_i)^2}{q_i}}$
neyman(p, q)
Returns the Neyman distance between vectors p and q
$d(p,q)=\sum\limits_{i=1}^{n}{\frac{(p_i-q_i)^2}{p_i}}$
squared(p, q)
Returns the Squared distance between vectors p and q
$d(p,q)=\sum\limits_{i=1}^{n}{\frac{(p_i-q_i)^2}{p_i+q_i}}$
probabilisticSymmetric(p, q)
Returns the Probabilistic Symmetric distance between vectors p and q
$d(p,q)=2\cdot\sum\limits_{i=1}^{n}{\frac{(p_i-q_i)^2}{p_i+q_i}}$
divergence(p, q)
Returns the Divergence distance between vectors p and q
$d(p,q)=2\cdot\sum\limits_{i=1}^{n}{\frac{(p_i-q_i)^2}{(p_i+q_i)^2}}$
clark(p, q)
Returns the Clark distance between vectors p and q
$d(p,q)=\sqrt{\sum\limits_{i=1}^{n}{\left(\frac{\left|p_i-q_i\right|}{(p_i+q_i)}\right)^2}}$
additiveSymmetric(p, q)
Returns the Additive Symmetric distance between vectors p and q
$d(p,q)=\sum\limits_{i=1}^{n}{\frac{(p_i-q_i)^2\cdot(p_i+q_i)}{p_i\cdot{q_i}}}$
kullbackLeibler(p, q)
Returns the Kullback-Leibler distance between vectors p and q
$d(p,q)=\sum\limits_{i=1}^{n}{p_i\cdot\ln\frac{p_i}{q_i}}$
jeffreys(p, q)
Returns the Jeffreys distance between vectors p and q
$d(p,q)=\sum\limits_{i=1}^{n}{\left((p_i-q_i)\ln\frac{p_i}{q_i}\right)}$
kdivergence(p, q)
Returns the K divergence distance between vectors p and q
$d(p,q)=\sum\limits_{i=1}^{n}{\left(p_i\cdot\ln\frac{2p_i}{p_i+q_i}\right)}$
topsoe(p, q)
Returns the Topsøe distance between vectors p and q
$d(p,q)=\sum\limits_{i=1}^{n}{\left(p_i\cdot\ln\frac{2p_i}{p_i+q_i}+q_i\cdot\ln\frac{2q_i}{p_i+q_i}\right)}$
jensenShannon(p, q)
Returns the Jensen-Shannon distance between vectors p and q
$d(p,q)=\frac{1}{2}\left[\sum\limits_{i=1}^{n}{p_i\cdot\ln\frac{2p_i}{p_i+q_i}}+\sum\limits_{i=1}^{n}{q_i\cdot\ln\frac{2q_i}{p_i+q_i}}\right]$
jensenDifference(p, q)
Returns the Jensen difference distance between vectors p and q
$d(p,q)=\sum\limits_{i=1}^{n}{\left[\frac{p_i\ln{p_i}+q_i\ln{q_i}}{2}-\left(\frac{p_i+q_i}{2}\right)\ln\left(\frac{p_i+q_i}{2}\right)\right]}$
taneja(p, q)
Returns the Taneja distance between vectors p and q
$d(p,q)=\sum\limits_{i=1}^{n}{\left[\frac{p_i+q_i}{2}\ln\left(\frac{p_i+q_i}{2\sqrt{p_i\cdot{q_i}}}\right)\right]}$
kumarJohnson(p, q)
Returns the Kumar-Johnson distance between vectors p and q
$d(p,q)=\sum\limits_{i=1}^{n}{\frac{\left(p_i^2-q_i^2\right)^2}{2(p_i\cdot{q_i})^{3/2}}}$
avg(p, q)
Returns the average of city block and Chebyshev distances between vectors p and q
$d(p,q)=\frac{\sum\limits_{i=1}^{n}{\left|p_i-q_i\right|}+\max\limits_i(|p_i-q_i|)}{2}$
Similarities
intersection(p, q)
Returns the Intersection similarity between vectors p and q
czekanowski(p, q)
Returns the Czekanowski similarity between vectors p and q
motyka(p, q)
Returns the Motyka similarity between vectors p and q
kulczynski(p, q)
Returns the Kulczynski similarity between vectors p and q
squaredChord(p, q)
Returns the Squared-chord similarity between vectors p and q
jaccard(p, q)
Returns the Jaccard similarity between vectors p and q
dice(p, q)
Returns the Dice similarity between vectors p and q
tanimoto(p, q, [bitVector])
Returns the Tanimoto similarity between vectors p and q, and accepts the bitVector use, see the test case for an example
tree(a,b, from, to, [options])
Refer to ml-tree-similarity
Contributing
A new metric should normally be in its own file in the src/dist directory. There should be a corresponding test file in test/dist.
The metric should be then added in the exports of src/index.js with a relatively small but understandable name (use camelCase).
It should also be added to this README with either a link to the formula or an inline description.
Authors
License
No vulnerabilities found.
Reason
no dangerous workflow patterns detected
Reason
no binaries found in the repo
Reason
0 existing vulnerabilities detected
Reason
license file detected
Details
- Info: project has a license file: LICENSE:0
- Info: FSF or OSI recognized license: MIT License: LICENSE:0
Reason
4 commit(s) and 0 issue activity found in the last 90 days -- score normalized to 3
Reason
Found 6/29 approved changesets -- score normalized to 2
Reason
detected GitHub workflow tokens with excessive permissions
Details
- Warn: no topLevel permission defined: .github/workflows/nodejs.yml:1
- Warn: no topLevel permission defined: .github/workflows/release.yml:1
- Warn: no topLevel permission defined: .github/workflows/typedoc.yml:1
- Info: no jobLevel write permissions found
Reason
dependency not pinned by hash detected -- score normalized to 0
Details
- Warn: GitHub-owned GitHubAction not pinned by hash: .github/workflows/typedoc.yml:12: update your workflow using https://app.stepsecurity.io/secureworkflow/mljs/distance/typedoc.yml/main?enable=pin
- Warn: GitHub-owned GitHubAction not pinned by hash: .github/workflows/typedoc.yml:13: update your workflow using https://app.stepsecurity.io/secureworkflow/mljs/distance/typedoc.yml/main?enable=pin
- Warn: third-party GitHubAction not pinned by hash: .github/workflows/typedoc.yml:19: update your workflow using https://app.stepsecurity.io/secureworkflow/mljs/distance/typedoc.yml/main?enable=pin
- Warn: third-party GitHubAction not pinned by hash: .github/workflows/typedoc.yml:24: update your workflow using https://app.stepsecurity.io/secureworkflow/mljs/distance/typedoc.yml/main?enable=pin
- Warn: npmCommand not pinned by hash: .github/workflows/typedoc.yml:18
- Info: 0 out of 2 GitHub-owned GitHubAction dependencies pinned
- Info: 0 out of 2 third-party GitHubAction dependencies pinned
- Info: 0 out of 1 npmCommand dependencies pinned
Reason
no effort to earn an OpenSSF best practices badge detected
Reason
project is not fuzzed
Details
- Warn: no fuzzer integrations found
Reason
security policy file not detected
Details
- Warn: no security policy file detected
- Warn: no security file to analyze
- Warn: no security file to analyze
- Warn: no security file to analyze
Reason
SAST tool is not run on all commits -- score normalized to 0
Details
- Warn: 0 commits out of 7 are checked with a SAST tool
Score
4.3
/10
Last Scanned on 2024-11-18
The Open Source Security Foundation is a cross-industry collaboration to improve the security of open source software (OSS). The Scorecard provides security health metrics for open source projects.
Learn More