diff --git a/.github/workflows/typedoc.yml b/.github/workflows/typedoc.yml index 7c9601f..4e792c7 100644 --- a/.github/workflows/typedoc.yml +++ b/.github/workflows/typedoc.yml @@ -6,24 +6,10 @@ on: types: [published] jobs: - deploy: - runs-on: ubuntu-latest - steps: - - uses: actions/checkout@v3 - - uses: actions/setup-node@v3 - with: - node-version: 16.x - - name: Install dependencies - run: npm install - - name: Build documentation - uses: zakodium/typedoc-action@v2 - with: - entry: src/index.ts - - - name: Deploy to GitHub pages - uses: JamesIves/github-pages-deploy-action@releases/v4 - with: - token: ${{ secrets.BOT_TOKEN }} - branch: gh-pages - folder: docs - clean: true + typedoc: + # Documentation: https://github.com/zakodium/workflows#typedoc + uses: zakodium/workflows/.github/workflows/typedoc.yml@typedoc-v1 + with: + entry: 'src/index.ts' + secrets: + github-token: ${{ secrets.BOT_TOKEN }} diff --git a/.gitignore b/.gitignore index 64a1852..bf7761e 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,4 @@ +.claude .idea node_modules lib @@ -5,6 +6,4 @@ coverage .DS_Store -lib-esm - docs diff --git a/.npmrc b/.npmrc index 43c97e7..9951b11 100644 --- a/.npmrc +++ b/.npmrc @@ -1 +1,2 @@ package-lock=false +ignore-scripts=true diff --git a/.prettierignore b/.prettierignore new file mode 100644 index 0000000..b728abd --- /dev/null +++ b/.prettierignore @@ -0,0 +1,3 @@ +CHANGELOG.md +coverage +lib diff --git a/.prettierrc b/.prettierrc.json similarity index 100% rename from .prettierrc rename to .prettierrc.json diff --git a/README.md b/README.md index 8a86e92..d4098e4 100644 --- a/README.md +++ b/README.md @@ -1,20 +1,20 @@ # ml-distance

- + Zakodium logo - +

Maintained by Zakodium

- + [![NPM version][npm-image]][npm-url] [![Node.js CI](https://github.com/mljs/distance/actions/workflows/nodejs.yml/badge.svg)](https://github.com/mljs/distance/actions/workflows/nodejs.yml) [![Test coverage][codecov-image]][codecov-url] [![npm download][download-image]][download-url] - +

Distance functions to compare vectors. @@ -23,6 +23,22 @@ Distance functions to compare vectors. `$ npm i ml-distance` +This package is ESM-only. CommonJS consumers need Node.js >= 20.19, >= 22.12, or +any 24.x or later to `require()` it, or should migrate to `import`. + +## Usage + +```js +import { distance, similarity } from 'ml-distance'; + +const p = [0, 1, 2, 3, 4]; +const q = [4, 3, 2, 1, 0]; + +distance.euclidean(p, q); // 6.324555320336759 +distance.manhattan(p, q); // 12 +similarity.cosine(p, q); // 0.3333333333333333 +``` + ## Methods ### Distances @@ -65,13 +81,13 @@ $d(p,q)=\frac{\sum\limits_{i=1}^{n}{\left|p_i-q_i\right|}}{n}$ Returns the [Soergel distance](http://www.orgchm.bas.bg/~vmonev/SimSearch.pdf) 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)}$ +$d(p,q)=\frac{\sum\limits_{i=1}^{n}{\left|p_i-q_i\right|}}{\sum\limits_{i=1}^{n}{max(p_i,q_i)}}$ - `kulczynski(p, q)` Returns the [Kulczynski distance](http://www.naun.org/main/NAUN/ijmmas/mmmas-49.pdf) 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)}$ +$d(p,q)=\frac{\sum\limits_{i=1}^{n}{\left|p_i-q_i\right|}}{\sum\limits_{i=1}^{n}{min(p_i,q_i)}}$ - `canberra(p, q)` @@ -113,9 +129,9 @@ Note: distance between 2 identical vectors is 0.5 ! - `ruzicka(p, q)` -Returns the [Ruzicka similarity](http://www.naun.org/main/NAUN/ijmmas/mmmas-49.pdf) between vectors p and q +Returns the [Ruzicka similarity](http://www.naun.org/main/NAUN/ijmmas/mmmas-49.pdf) between vectors p and q. The matching distance is `soergel`. -$d(p,q)=\frac{\sum\limits_{i=1}^{n}{max(p_i,q_i)}}{\sum\limits_{i=1}^{n}{min(p_i,q_i)}}$ +$s(p,q)=\frac{\sum\limits_{i=1}^{n}{min(p_i,q_i)}}{\sum\limits_{i=1}^{n}{max(p_i,q_i)}}$ - `tanimoto(p, q, [bitVector])` @@ -133,18 +149,6 @@ Returns the [Harmonic mean similarity](http://www.naun.org/main/NAUN/ijmmas/mmma $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](http://www.naun.org/main/NAUN/ijmmas/mmmas-49.pdf) between vectors p and q - -$d(p,q)=\frac{\sum\limits_{i=1}^{n}{p_i\cdot{q_i}}}{\sqrt{\sum\limits_{i=1}^{n}{p_i^2}}\sqrt{\sum\limits_{i=1}^{n}{q_i^2}}}$ - -- `kumarHassebrook(p, q)` - -Returns the [Kumar-Hassebrook similarity](http://www.naun.org/main/NAUN/ijmmas/mmmas-49.pdf) 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](http://www.naun.org/main/NAUN/ijmmas/mmmas-49.pdf) between vectors p and q @@ -155,7 +159,7 @@ $d(p,q)=1-\frac{\sum\limits_{i=1}^{n}{p_i\cdot{q_i}}}{\sum\limits_{i=1}^{n}{p_i^ Returns the [Dice distance](http://www.naun.org/main/NAUN/ijmmas/mmmas-49.pdf) 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}}$ +$d(p,q)=\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)` @@ -311,9 +315,21 @@ Returns the [Kulczynski similarity](http://www.naun.org/main/NAUN/ijmmas/mmmas-4 Returns the [Squared-chord similarity](http://www.naun.org/main/NAUN/ijmmas/mmmas-49.pdf) between vectors p and q -- `jaccard(p, q)` +- `cosine(p, q)` + +Returns the [Cosine similarity](http://www.naun.org/main/NAUN/ijmmas/mmmas-49.pdf) between vectors p and q + +$s(p,q)=\frac{\sum\limits_{i=1}^{n}{p_i\cdot{q_i}}}{\sqrt{\sum\limits_{i=1}^{n}{p_i^2}}\sqrt{\sum\limits_{i=1}^{n}{q_i^2}}}$ + +- `kumarHassebrook(p, q)` + +Returns the [Kumar-Hassebrook similarity](http://www.naun.org/main/NAUN/ijmmas/mmmas-49.pdf) between vectors p and q + +$s(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}}}$ + +- `pearson(p, q)` -Returns the [Jaccard similarity](http://www.naun.org/main/NAUN/ijmmas/mmmas-49.pdf) between vectors p and q +Returns the [Pearson correlation](https://en.wikipedia.org/wiki/Pearson_correlation_coefficient) between vectors p and q, i.e. the cosine similarity of the mean-centred vectors - `dice(p, q)` @@ -329,8 +345,8 @@ Refer to [ml-tree-similarity](https://github.com/mljs/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). +A new metric should normally be in its own file in the `src/distances` (or `src/similarities`) directory. There should be a corresponding test file in the neighbouring `__tests__` directory. +The metric should be then added in the exports of `src/distances.ts` (or `src/similarities.ts`) 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 diff --git a/babel.config.js b/babel.config.js deleted file mode 100644 index f5f790b..0000000 --- a/babel.config.js +++ /dev/null @@ -1,4 +0,0 @@ -module.exports = { - presets: ['@babel/preset-typescript'], - plugins: ['@babel/plugin-transform-modules-commonjs'], -}; diff --git a/eslint.config.js b/eslint.config.js new file mode 100644 index 0000000..6063d16 --- /dev/null +++ b/eslint.config.js @@ -0,0 +1,4 @@ +import { defineConfig, globalIgnores } from 'eslint/config'; +import ts from 'eslint-config-cheminfo-typescript'; + +export default defineConfig(globalIgnores(['coverage', 'lib']), ts); diff --git a/eslint.config.mjs b/eslint.config.mjs deleted file mode 100644 index 98e4421..0000000 --- a/eslint.config.mjs +++ /dev/null @@ -1,9 +0,0 @@ -import cheminfo from 'eslint-config-cheminfo-typescript'; - -export default [ - ...cheminfo, - { - languageOptions: {}, - rules: {} - } -] \ No newline at end of file diff --git a/package.json b/package.json index b05bb0e..b458f0c 100644 --- a/package.json +++ b/package.json @@ -2,28 +2,26 @@ "name": "ml-distance", "version": "4.0.1", "description": "Distance and similarity functions to compare vectors", - "main": "lib/index.js", - "module": "./lib-esm/index.js", + "type": "module", + "exports": { + ".": "./lib/index.js" + }, "files": [ - "src", "lib", - "lib-esm" + "src" ], - "types": "./lib/index.d.ts", "scripts": { "check-types": "tsc --noEmit", - "clean": "rimraf lib lib-esm", - "eslint": "eslint src", - "eslint-fix": "npm run eslint -- --fix", + "clean": "rimraf coverage lib", + "eslint": "eslint .", + "eslint-fix": "eslint . --fix", "prepack": "npm run tsc", - "prettier": "prettier --check src", - "prettier-write": "prettier --write src", - "test": "npm run test-coverage && npm run eslint && npm run prettier && npm run check-types", - "test-only": "vitest run", - "test-coverage": "vitest run --coverage", - "tsc": "npm run clean && npm run tsc-cjs && npm run tsc-esm", - "tsc-cjs": "tsc --project tsconfig.cjs.json", - "tsc-esm": "tsc --project tsconfig.esm.json" + "prettier": "prettier --check .", + "prettier-write": "prettier --write .", + "test": "npm run test-only && npm run check-types && npm run eslint && npm run prettier", + "test-only": "vitest run --coverage", + "tsc": "npm run clean && npm run tsc-build", + "tsc-build": "tsc --project tsconfig.build.json" }, "repository": { "type": "git", @@ -49,23 +47,21 @@ "url": "https://github.com/mljs/distance/issues" }, "homepage": "https://github.com/mljs/distance", - "devDependencies": { - "@babel/plugin-transform-modules-commonjs": "^7.25.7", - "@babel/preset-typescript": "^7.25.7", - "@types/node": "^22.7.6", - "@vitest/coverage-v8": "^2.1.3", - "cheminfo-types": "^1.8.0", - "eslint": "^9.12.0", - "eslint-config-cheminfo-typescript": "^16.0.0", - "esm": "^3.2.25", - "prettier": "^3.3.3", - "rimraf": "^6.0.1", - "typescript": "^5.6.3", - "vitest": "^2.1.3" - }, "dependencies": { - "ml-array-mean": "^1.1.6", - "ml-distance-euclidean": "^2.0.0", + "cheminfo-types": "^1.15.0", + "ml-array-mean": "^2.0.0", + "ml-distance-euclidean": "^3.0.1", "ml-tree-similarity": "^1.0.0" + }, + "devDependencies": { + "@types/node": "^26.1.1", + "@vitest/coverage-v8": "^4.1.10", + "@zakodium/tsconfig": "^1.0.5", + "eslint": "^9.39.5", + "eslint-config-cheminfo-typescript": "^22.1.0", + "prettier": "^3.9.6", + "rimraf": "^6.1.3", + "typescript": "^6.0.3", + "vitest": "^4.1.10" } } diff --git a/scripts/similarity.js b/scripts/similarity.js index a247e66..e19cf4c 100644 --- a/scripts/similarity.js +++ b/scripts/similarity.js @@ -1,4 +1,4 @@ -import { distance } from '../src'; +import { distance } from '../src/index.ts'; let results = []; @@ -16,9 +16,7 @@ let v11 = [-0.6, 0.7]; for (let algorithm in distance) { if (algorithm.match(/fidelity|harmonicMean|innerProduct|ruzicka/)) continue; - if (algorithm.match(/minkowski/)) { - if (algorithm.match(/motyka/)) continue; - } // does not give a 0 with identical vector + if (algorithm.match(/minkowski/) && algorithm.match(/motyka/)) continue; // does not give a 0 with identical vector let result = { algorithm }; let callback = distance[algorithm]; result.self = callback(v1, v1); diff --git a/src/.npmignore b/src/.npmignore index d7a3323..76cf446 100644 --- a/src/.npmignore +++ b/src/.npmignore @@ -1,2 +1,3 @@ __tests__ +.DS_Store .npmignore diff --git a/src/distances.ts b/src/distances.ts index 01eac57..bad8042 100644 --- a/src/distances.ts +++ b/src/distances.ts @@ -1,81 +1,81 @@ export * from 'ml-distance-euclidean'; -export * from './distances/additiveSymmetric'; +export * from './distances/additiveSymmetric.ts'; -export * from './distances/avg'; +export * from './distances/avg.ts'; -export * from './distances/bhattacharyya'; +export * from './distances/bhattacharyya.ts'; -export * from './distances/canberra'; +export * from './distances/canberra.ts'; -export * from './distances/chebyshev'; +export * from './distances/chebyshev.ts'; -export * from './distances/clark'; +export * from './distances/clark.ts'; -export * from './distances/czekanowski'; +export * from './distances/czekanowski.ts'; -export * from './distances/dice'; +export * from './distances/dice.ts'; -export * from './distances/divergence'; +export * from './distances/divergence.ts'; -export * from './distances/fidelity'; +export * from './distances/fidelity.ts'; -export * from './distances/gower'; +export * from './distances/gower.ts'; -export * from './distances/harmonicMean'; +export * from './distances/harmonicMean.ts'; -export * from './distances/hellinger'; +export * from './distances/hellinger.ts'; -export * from './distances/innerProduct'; +export * from './distances/innerProduct.ts'; -export * from './distances/intersection'; +export * from './distances/intersection.ts'; -export * from './distances/jaccard'; +export * from './distances/jaccard.ts'; -export * from './distances/jeffreys'; +export * from './distances/jeffreys.ts'; -export * from './distances/jensenDifference'; +export * from './distances/jensenDifference.ts'; -export * from './distances/jensenShannon'; +export * from './distances/jensenShannon.ts'; -export * from './distances/kdivergence'; +export * from './distances/kdivergence.ts'; -export * from './distances/kulczynski'; +export * from './distances/kulczynski.ts'; -export * from './distances/kullbackLeibler'; +export * from './distances/kullbackLeibler.ts'; -export * from './distances/kumarJohnson'; +export * from './distances/kumarJohnson.ts'; -export * from './distances/lorentzian'; +export * from './distances/lorentzian.ts'; -export * from './distances/manhattan'; +export * from './distances/manhattan.ts'; -export * from './distances/matusita'; +export * from './distances/matusita.ts'; -export * from './distances/minkowski'; +export * from './distances/minkowski.ts'; -export * from './distances/motyka'; +export * from './distances/motyka.ts'; -export * from './distances/neyman'; +export * from './distances/neyman.ts'; -export * from './distances/pearson'; +export * from './distances/pearson.ts'; -export * from './distances/probabilisticSymmetric'; +export * from './distances/probabilisticSymmetric.ts'; -export * from './distances/ruzicka'; +export * from './distances/ruzicka.ts'; -export * from './distances/soergel'; +export * from './distances/soergel.ts'; -export * from './distances/sorensen'; +export * from './distances/sorensen.ts'; -export * from './distances/squared'; +export * from './distances/squared.ts'; -export * from './distances/squaredChord'; +export * from './distances/squaredChord.ts'; -export * from './distances/taneja'; +export * from './distances/taneja.ts'; -export * from './distances/tanimoto'; +export * from './distances/tanimoto.ts'; -export * from './distances/topsoe'; +export * from './distances/topsoe.ts'; -export * from './distances/waveHedges'; +export * from './distances/waveHedges.ts'; diff --git a/src/distances/__tests__/additiveSymmetric.test.ts b/src/distances/__tests__/additiveSymmetric.test.ts index 13d6d76..1c1ea63 100644 --- a/src/distances/__tests__/additiveSymmetric.test.ts +++ b/src/distances/__tests__/additiveSymmetric.test.ts @@ -1,16 +1,14 @@ -import { describe, it, expect } from 'vitest'; +import { expect, test } from 'vitest'; -import { distance } from '../..'; +import { distance } from '../../index.ts'; const v1 = [3, 1, 4, 6, 2]; const v2 = [3, 6, 9, 4, 3]; -describe('Aditive Symmetric distance', () => { - it('should return 0 with itself', () => { - expect(distance.additiveSymmetric(v1, v1)).toBe(0); - }); +test('should return 0 with itself', () => { + expect(distance.additiveSymmetric(v1, v1)).toBe(0); +}); - it('should be correct', () => { - expect(distance.additiveSymmetric(v1, v2)).toBeCloseTo(40.694444, 4); - }); +test('should be correct', () => { + expect(distance.additiveSymmetric(v1, v2)).toBeCloseTo(40.694444, 4); }); diff --git a/src/distances/__tests__/avg.test.ts b/src/distances/__tests__/avg.test.ts index 4c4be54..3ec5fee 100644 --- a/src/distances/__tests__/avg.test.ts +++ b/src/distances/__tests__/avg.test.ts @@ -1,16 +1,14 @@ -import { describe, it, expect } from 'vitest'; +import { expect, test } from 'vitest'; -import { distance } from '../..'; +import { distance } from '../../index.ts'; const v1 = [0, 1, 4, 6, 2]; const v2 = [3, 6, 9, 4, 3]; -describe('AVG distance', () => { - it('should return 0 with itself', () => { - expect(distance.avg(v1, v1)).toBe(0); - }); +test('should return 0 with itself', () => { + expect(distance.avg(v1, v1)).toBe(0); +}); - it('should be correct', () => { - expect(distance.avg(v1, v2)).toBe(10.5); - }); +test('should be correct', () => { + expect(distance.avg(v1, v2)).toBe(10.5); }); diff --git a/src/distances/__tests__/bhattacharyya.test.ts b/src/distances/__tests__/bhattacharyya.test.ts index f6dc27f..305cd81 100644 --- a/src/distances/__tests__/bhattacharyya.test.ts +++ b/src/distances/__tests__/bhattacharyya.test.ts @@ -1,12 +1,10 @@ -import { describe, it, expect } from 'vitest'; +import { expect, test } from 'vitest'; -import { distance } from '../..'; +import { distance } from '../../index.ts'; const v1 = [0.2, 0.4, 0.3, 0.1]; const v2 = [0.3, 0.2, 0.3, 0.2]; -describe('Bhattacharyya similarity', () => { - it('should be correct', () => { - expect(distance.bhattacharyya(v1, v2)).toBe(0.031270832649666964); - }); +test('should be correct', () => { + expect(distance.bhattacharyya(v1, v2)).toBe(0.031270832649666964); }); diff --git a/src/distances/__tests__/canberra.test.ts b/src/distances/__tests__/canberra.test.ts index 9e53cc9..0421aac 100644 --- a/src/distances/__tests__/canberra.test.ts +++ b/src/distances/__tests__/canberra.test.ts @@ -1,16 +1,14 @@ -import { describe, it, expect } from 'vitest'; +import { expect, test } from 'vitest'; -import { distance } from '../..'; +import { distance } from '../../index.ts'; const v1 = [0, 1, 4, 6, 2]; const v2 = [3, 6, 9, 4, 3]; -describe('Canberra distance', () => { - it('should return 0 with itself', () => { - expect(distance.canberra(v2, v2)).toBe(0); - }); +test('should return 0 with itself', () => { + expect(distance.canberra(v2, v2)).toBe(0); +}); - it('should be correct', () => { - expect(distance.canberra(v1, v2)).toBe(2.4989010989010993); - }); +test('should be correct', () => { + expect(distance.canberra(v1, v2)).toBe(2.4989010989010993); }); diff --git a/src/distances/__tests__/chebyshev.test.ts b/src/distances/__tests__/chebyshev.test.ts index d94c756..4a648fb 100644 --- a/src/distances/__tests__/chebyshev.test.ts +++ b/src/distances/__tests__/chebyshev.test.ts @@ -1,16 +1,14 @@ -import { describe, it, expect } from 'vitest'; +import { expect, test } from 'vitest'; -import { distance } from '../..'; +import { distance } from '../../index.ts'; const v1 = [0, 1, 4, 6, 2]; const v2 = [3, 6, 9, 4, 3]; -describe('Chebyshev distance', () => { - it('should return 0 with itself', () => { - expect(distance.chebyshev(v1, v1)).toBe(0); - }); +test('should return 0 with itself', () => { + expect(distance.chebyshev(v1, v1)).toBe(0); +}); - it('should be correct', () => { - expect(distance.chebyshev(v1, v2)).toBe(5); - }); +test('should be correct', () => { + expect(distance.chebyshev(v1, v2)).toBe(5); }); diff --git a/src/distances/__tests__/clark.test.ts b/src/distances/__tests__/clark.test.ts index 0885a8f..a052644 100644 --- a/src/distances/__tests__/clark.test.ts +++ b/src/distances/__tests__/clark.test.ts @@ -1,16 +1,14 @@ -import { describe, it, expect } from 'vitest'; +import { expect, test } from 'vitest'; -import { distance } from '../..'; +import { distance } from '../../index.ts'; const v1 = [3, 1, 4, 6, 2]; const v2 = [3, 6, 9, 4, 3]; -describe('Clark distance', () => { - it('should return 0 with itself', () => { - expect(distance.clark(v1, v1)).toBe(0); - }); +test('should return 0 with itself', () => { + expect(distance.clark(v1, v1)).toBe(0); +}); - it('should be correct', () => { - expect(distance.clark(v1, v2)).toBeCloseTo(0.85914671, 5); - }); +test('should be correct', () => { + expect(distance.clark(v1, v2)).toBeCloseTo(0.85914671, 5); }); diff --git a/src/distances/__tests__/czekanowski.test.ts b/src/distances/__tests__/czekanowski.test.ts index fe7e53b..076e7ed 100644 --- a/src/distances/__tests__/czekanowski.test.ts +++ b/src/distances/__tests__/czekanowski.test.ts @@ -1,20 +1,18 @@ -import { describe, it, expect } from 'vitest'; +import { expect, test } from 'vitest'; -import { distance } from '../..'; +import { distance } from '../../index.ts'; const v1 = [0.2, 0.4, 0.3, 0.1]; const v2 = [0.3, 0.2, 0.3, 0.2]; -describe('Czekanowski distance', () => { - it('should return 0 with itself', () => { - expect(distance.czekanowski(v1, v1)).toBe(0); - }); +test('should return 0 with itself', () => { + expect(distance.czekanowski(v1, v1)).toBe(0); +}); - it('should be correct', () => { - expect(distance.czekanowski(v1, v2)).toBe(0.20000000000000007); - expect(distance.czekanowski(v1, v2)).toBeCloseTo( - distance.sorensen(v1, v2), - 5, - ); - }); +test('should be correct', () => { + expect(distance.czekanowski(v1, v2)).toBe(0.20000000000000007); + expect(distance.czekanowski(v1, v2)).toBeCloseTo( + distance.sorensen(v1, v2), + 5, + ); }); diff --git a/src/distances/__tests__/dice.test.ts b/src/distances/__tests__/dice.test.ts index d98bd82..08d24ac 100644 --- a/src/distances/__tests__/dice.test.ts +++ b/src/distances/__tests__/dice.test.ts @@ -1,16 +1,14 @@ -import { describe, it, expect } from 'vitest'; +import { expect, test } from 'vitest'; -import { distance } from '../..'; +import { distance } from '../../index.ts'; const v1 = [0.2, 0.4, 0.3, 0.1]; const v2 = [0.3, 0.2, 0.3, 0.2]; -describe('Dice distance', () => { - it('should return 0 with itself', () => { - expect(distance.dice(v1, v1)).toBe(0); - }); +test('should return 0 with itself', () => { + expect(distance.dice(v1, v1)).toBe(0); +}); - it('should be correct', () => { - expect(distance.dice(v1, v2)).toBe(6 / 56); - }); +test('should be correct', () => { + expect(distance.dice(v1, v2)).toBe(6 / 56); }); diff --git a/src/distances/__tests__/divergence.test.ts b/src/distances/__tests__/divergence.test.ts index 8737175..1c0cbe8 100644 --- a/src/distances/__tests__/divergence.test.ts +++ b/src/distances/__tests__/divergence.test.ts @@ -1,16 +1,14 @@ -import { describe, it, expect } from 'vitest'; +import { expect, test } from 'vitest'; -import { distance } from '../..'; +import { distance } from '../../index.ts'; const v1 = [3, 1, 4, 6, 2]; const v2 = [3, 6, 9, 4, 3]; -describe('Divergence distance', () => { - it('should return 0 with itself', () => { - expect(distance.divergence(v1, v1)).toBe(0); - }); +test('should return 0 with itself', () => { + expect(distance.divergence(v1, v1)).toBe(0); +}); - it('should be correct', () => { - expect(distance.divergence(v1, v2)).toBe(1.4762661514309867); - }); +test('should be correct', () => { + expect(distance.divergence(v1, v2)).toBe(1.4762661514309867); }); diff --git a/src/distances/__tests__/fidelity.test.ts b/src/distances/__tests__/fidelity.test.ts index e53f9b6..a555afd 100644 --- a/src/distances/__tests__/fidelity.test.ts +++ b/src/distances/__tests__/fidelity.test.ts @@ -1,12 +1,10 @@ -import { describe, it, expect } from 'vitest'; +import { expect, test } from 'vitest'; -import { distance } from '../..'; +import { distance } from '../../index.ts'; const v1 = [0.2, 0.4, 0.3, 0.1]; const v2 = [0.3, 0.2, 0.3, 0.2]; -describe('Fidelity similarity', () => { - it('should be correct', () => { - expect(distance.fidelity(v1, v2)).toBe(0.9692130429902465); - }); +test('should be correct', () => { + expect(distance.fidelity(v1, v2)).toBe(0.9692130429902465); }); diff --git a/src/distances/__tests__/gower.test.ts b/src/distances/__tests__/gower.test.ts index 28dddcb..f887389 100644 --- a/src/distances/__tests__/gower.test.ts +++ b/src/distances/__tests__/gower.test.ts @@ -1,16 +1,14 @@ -import { describe, it, expect } from 'vitest'; +import { expect, test } from 'vitest'; -import { distance } from '../..'; +import { distance } from '../../index.ts'; const v1 = [0, 1, 4, 6, 2]; const v2 = [3, 6, 9, 4, 3]; -describe('Gower distance', () => { - it('should return 0 with itself', () => { - expect(distance.gower(v1, v1)).toBe(0); - }); +test('should return 0 with itself', () => { + expect(distance.gower(v1, v1)).toBe(0); +}); - it('should be correct', () => { - expect(distance.gower(v1, v2)).toBe(16 / 5); - }); +test('should be correct', () => { + expect(distance.gower(v1, v2)).toBe(16 / 5); }); diff --git a/src/distances/__tests__/harmonicMean.test.ts b/src/distances/__tests__/harmonicMean.test.ts index 0f6c23f..2b490fc 100644 --- a/src/distances/__tests__/harmonicMean.test.ts +++ b/src/distances/__tests__/harmonicMean.test.ts @@ -1,12 +1,10 @@ -import { describe, it, expect } from 'vitest'; +import { expect, test } from 'vitest'; -import { distance } from '../..'; +import { distance } from '../../index.ts'; const v1 = [0.2, 0.4, 0.3, 0.1]; const v2 = [0.3, 0.2, 0.3, 0.2]; -describe('Harmonic Mean similarity', () => { - it('should be correct', () => { - expect(distance.harmonicMean(v1, v2)).toBe(0.94); - }); +test('should be correct', () => { + expect(distance.harmonicMean(v1, v2)).toBe(0.94); }); diff --git a/src/distances/__tests__/hellinger.test.ts b/src/distances/__tests__/hellinger.test.ts index b59afaa..b301bb8 100644 --- a/src/distances/__tests__/hellinger.test.ts +++ b/src/distances/__tests__/hellinger.test.ts @@ -1,12 +1,10 @@ -import { describe, it, expect } from 'vitest'; +import { expect, test } from 'vitest'; -import { distance } from '../..'; +import { distance } from '../../index.ts'; const v1 = [0.2, 0.4, 0.3, 0.1]; const v2 = [0.3, 0.2, 0.3, 0.2]; -describe('Hellinger distance', () => { - it('should be correct', () => { - expect(distance.hellinger(v1, v2)).toBe(0.3509242482915852); - }); +test('should be correct', () => { + expect(distance.hellinger(v1, v2)).toBe(0.3509242482915852); }); diff --git a/src/distances/__tests__/innerProduct.test.ts b/src/distances/__tests__/innerProduct.test.ts index c465ecd..5be8d59 100644 --- a/src/distances/__tests__/innerProduct.test.ts +++ b/src/distances/__tests__/innerProduct.test.ts @@ -1,12 +1,10 @@ -import { describe, it, expect } from 'vitest'; +import { expect, test } from 'vitest'; -import { distance } from '../..'; +import { distance } from '../../index.ts'; const v1 = [0.2, 0.4, 0.3, 0.1]; const v2 = [0.3, 0.2, 0.3, 0.2]; -describe('Inner Product similarity', () => { - it('should be correct', () => { - expect(distance.innerProduct(v1, v2)).toBe(0.25); - }); +test('should be correct', () => { + expect(distance.innerProduct(v1, v2)).toBe(0.25); }); diff --git a/src/distances/__tests__/intersection.test.ts b/src/distances/__tests__/intersection.test.ts index 2dffed3..155da8d 100644 --- a/src/distances/__tests__/intersection.test.ts +++ b/src/distances/__tests__/intersection.test.ts @@ -1,20 +1,18 @@ -import { describe, it, expect } from 'vitest'; +import { expect, test } from 'vitest'; -import { distance } from '../..'; +import { distance } from '../../index.ts'; const v1 = [0.2, 0.4, 0.3, 0.1]; const v2 = [0.3, 0.2, 0.3, 0.2]; -describe('Intersection distance', () => { - it('should return 0 with itself', () => { - expect(distance.intersection(v2, v2)).toBe(0); - }); +test('should return 0 with itself', () => { + expect(distance.intersection(v2, v2)).toBe(0); +}); - it('should be correct', () => { - expect(distance.intersection(v1, v2)).toBe(0.20000000000000007); - expect(distance.intersection(v1, v2)).toBeCloseTo( - distance.manhattan(v1, v2) / 2, - 5, - ); - }); +test('should be correct', () => { + expect(distance.intersection(v1, v2)).toBe(0.20000000000000007); + expect(distance.intersection(v1, v2)).toBeCloseTo( + distance.manhattan(v1, v2) / 2, + 5, + ); }); diff --git a/src/distances/__tests__/jaccard.test.ts b/src/distances/__tests__/jaccard.test.ts index 34f1a1d..45e8326 100644 --- a/src/distances/__tests__/jaccard.test.ts +++ b/src/distances/__tests__/jaccard.test.ts @@ -1,13 +1,11 @@ -import { describe, it, expect } from 'vitest'; +import { expect, test } from 'vitest'; -import { distance } from '../..'; +import { distance } from '../../index.ts'; const v1 = [0.2, 0.4, 0.3, 0.1]; const v2 = [0.3, 0.2, 0.3, 0.2]; -describe('Jaccard distance', () => { - it('should be correct', () => { - expect(distance.jaccard(v1, v1)).toBe(0); - expect(distance.jaccard(v1, v2)).toBeCloseTo(6 / 31, 10); - }); +test('should be correct', () => { + expect(distance.jaccard(v1, v1)).toBe(0); + expect(distance.jaccard(v1, v2)).toBeCloseTo(6 / 31, 10); }); diff --git a/src/distances/__tests__/jeffreys.test.ts b/src/distances/__tests__/jeffreys.test.ts index 3d6ab0c..a12caa5 100644 --- a/src/distances/__tests__/jeffreys.test.ts +++ b/src/distances/__tests__/jeffreys.test.ts @@ -1,12 +1,10 @@ -import { describe, it, expect } from 'vitest'; +import { expect, test } from 'vitest'; -import { distance } from '../..'; +import { distance } from '../../index.ts'; const v1 = [0.2, 0.4, 0.3, 0.1]; const v2 = [0.3, 0.2, 0.3, 0.2]; -describe('Jeffreys similarity', () => { - it('should be correct', () => { - expect(distance.jeffreys(v1, v2)).toBe(0.2484906649788); - }); +test('should be correct', () => { + expect(distance.jeffreys(v1, v2)).toBe(0.2484906649788); }); diff --git a/src/distances/__tests__/jensenDifference.test.ts b/src/distances/__tests__/jensenDifference.test.ts index 9e539b8..5d12286 100644 --- a/src/distances/__tests__/jensenDifference.test.ts +++ b/src/distances/__tests__/jensenDifference.test.ts @@ -1,12 +1,10 @@ -import { describe, it, expect } from 'vitest'; +import { expect, test } from 'vitest'; -import { distance } from '../..'; +import { distance } from '../../index.ts'; const v1 = [0.2, 0.4, 0.3, 0.1]; const v2 = [0.3, 0.2, 0.3, 0.2]; -describe('Jensen difference distance', () => { - it('should be correct', () => { - expect(distance.jensenDifference(v1, v2)).toBe(0.030518733906981843); - }); +test('should be correct', () => { + expect(distance.jensenDifference(v1, v2)).toBe(0.030518733906981843); }); diff --git a/src/distances/__tests__/jensenShannon.test.ts b/src/distances/__tests__/jensenShannon.test.ts index b27bb12..153654f 100644 --- a/src/distances/__tests__/jensenShannon.test.ts +++ b/src/distances/__tests__/jensenShannon.test.ts @@ -1,12 +1,10 @@ -import { describe, it, expect } from 'vitest'; +import { expect, test } from 'vitest'; -import { distance } from '../..'; +import { distance } from '../../index.ts'; const v1 = [0.2, 0.4, 0.3, 0.1]; const v2 = [0.3, 0.2, 0.3, 0.2]; -describe('Jensen-Shannon distance', () => { - it('should be correct', () => { - expect(distance.jensenShannon(v1, v2)).toBe(0.0305187339069818); - }); +test('should be correct', () => { + expect(distance.jensenShannon(v1, v2)).toBe(0.0305187339069818); }); diff --git a/src/distances/__tests__/kdivergence.test.ts b/src/distances/__tests__/kdivergence.test.ts index f8f396a..abbe55a 100644 --- a/src/distances/__tests__/kdivergence.test.ts +++ b/src/distances/__tests__/kdivergence.test.ts @@ -1,12 +1,10 @@ -import { describe, it, expect } from 'vitest'; +import { expect, test } from 'vitest'; -import { distance } from '../..'; +import { distance } from '../../index.ts'; const v1 = [0.2, 0.4, 0.3, 0.1]; const v2 = [0.3, 0.2, 0.3, 0.2]; -describe('K divergence distance', () => { - it('should be correct', () => { - expect(distance.kdivergence(v1, v2)).toBe(0.029897607907053952); - }); +test('should be correct', () => { + expect(distance.kdivergence(v1, v2)).toBe(0.029897607907053952); }); diff --git a/src/distances/__tests__/kulczynski.test.ts b/src/distances/__tests__/kulczynski.test.ts index 283920f..1aba19f 100644 --- a/src/distances/__tests__/kulczynski.test.ts +++ b/src/distances/__tests__/kulczynski.test.ts @@ -1,16 +1,14 @@ -import { describe, it, expect } from 'vitest'; +import { expect, test } from 'vitest'; -import { distance } from '../..'; +import { distance } from '../../index.ts'; const v1 = [0, 1, 4, 6, 2]; const v2 = [3, 6, 9, 4, 3]; -describe('Kulczynski distance', () => { - it('should return 0 with itself', () => { - expect(distance.kulczynski(v1, v1)).toBe(0); - }); +test('should return 0 with itself', () => { + expect(distance.kulczynski(v1, v1)).toBe(0); +}); - it('should be correct', () => { - expect(distance.kulczynski(v1, v2)).toBe(16 / 11); - }); +test('should be correct', () => { + expect(distance.kulczynski(v1, v2)).toBe(16 / 11); }); diff --git a/src/distances/__tests__/kullbackLeibler.test.ts b/src/distances/__tests__/kullbackLeibler.test.ts index cdcdd99..4b7ddbf 100644 --- a/src/distances/__tests__/kullbackLeibler.test.ts +++ b/src/distances/__tests__/kullbackLeibler.test.ts @@ -1,12 +1,10 @@ -import { describe, it, expect } from 'vitest'; +import { expect, test } from 'vitest'; -import { distance } from '../..'; +import { distance } from '../../index.ts'; const v1 = [0.2, 0.4, 0.3, 0.1]; const v2 = [0.3, 0.2, 0.3, 0.2]; -describe('Kullback-Leibler similarity', () => { - it('should be correct', () => { - expect(distance.kullbackLeibler(v1, v2)).toBe(0.12685113254635072); - }); +test('should be correct', () => { + expect(distance.kullbackLeibler(v1, v2)).toBe(0.12685113254635072); }); diff --git a/src/distances/__tests__/kumarJohnson.test.ts b/src/distances/__tests__/kumarJohnson.test.ts index 5f2dca4..c9bb5de 100644 --- a/src/distances/__tests__/kumarJohnson.test.ts +++ b/src/distances/__tests__/kumarJohnson.test.ts @@ -1,12 +1,10 @@ -import { describe, it, expect } from 'vitest'; +import { expect, test } from 'vitest'; -import { distance } from '../..'; +import { distance } from '../../index.ts'; const v1 = [0.2, 0.4, 0.3, 0.1]; const v2 = [0.3, 0.2, 0.3, 0.2]; -describe('Kumar-Johnson distance', () => { - it('should be correct', () => { - expect(distance.kumarJohnson(v1, v2)).toBe(0.5623488044808911); - }); +test('should be correct', () => { + expect(distance.kumarJohnson(v1, v2)).toBe(0.5623488044808911); }); diff --git a/src/distances/__tests__/lorentzian.test.ts b/src/distances/__tests__/lorentzian.test.ts index b6addd6..718d6ad 100644 --- a/src/distances/__tests__/lorentzian.test.ts +++ b/src/distances/__tests__/lorentzian.test.ts @@ -1,16 +1,14 @@ -import { describe, it, expect } from 'vitest'; +import { expect, test } from 'vitest'; -import { distance } from '../..'; +import { distance } from '../../index.ts'; const v1 = [0, 1, 4, 6, 2]; const v2 = [3, 6, 9, 4, 3]; -describe('lorentzian distance', () => { - it('should return 0 with itself', () => { - expect(distance.lorentzian(v1, v1)).toBe(0); - }); +test('should return 0 with itself', () => { + expect(distance.lorentzian(v1, v1)).toBe(0); +}); - it('should be correct', () => { - expect(distance.lorentzian(v1, v2)).toBeCloseTo(Math.log(864), 5); - }); +test('should be correct', () => { + expect(distance.lorentzian(v1, v2)).toBeCloseTo(Math.log(864), 5); }); diff --git a/src/distances/__tests__/manhattan.test.ts b/src/distances/__tests__/manhattan.test.ts index b667eff..0b7c589 100644 --- a/src/distances/__tests__/manhattan.test.ts +++ b/src/distances/__tests__/manhattan.test.ts @@ -1,16 +1,14 @@ -import { describe, it, expect } from 'vitest'; +import { expect, test } from 'vitest'; -import { distance } from '../..'; +import { distance } from '../../index.ts'; const v1 = [0, 1, 4, 6, 2]; const v2 = [3, 6, 9, 4, 3]; -describe('City block distance', () => { - it('should return 0 with itself', () => { - expect(distance.manhattan(v1, v1)).toBe(0); - }); +test('should return 0 with itself', () => { + expect(distance.manhattan(v1, v1)).toBe(0); +}); - it('should be correct', () => { - expect(distance.manhattan(v1, v2)).toBe(16); - }); +test('should be correct', () => { + expect(distance.manhattan(v1, v2)).toBe(16); }); diff --git a/src/distances/__tests__/matusita.test.ts b/src/distances/__tests__/matusita.test.ts index 1a9e137..6fd81b1 100644 --- a/src/distances/__tests__/matusita.test.ts +++ b/src/distances/__tests__/matusita.test.ts @@ -1,12 +1,10 @@ -import { describe, it, expect } from 'vitest'; +import { expect, test } from 'vitest'; -import { distance } from '../..'; +import { distance } from '../../index.ts'; const v1 = [0.2, 0.4, 0.3, 0.1]; const v2 = [0.3, 0.2, 0.3, 0.2]; -describe('matusita similarity', () => { - it('should be correct', () => { - expect(distance.matusita(v1, v2)).toBe(0.24814091564977162); - }); +test('should be correct', () => { + expect(distance.matusita(v1, v2)).toBe(0.24814091564977162); }); diff --git a/src/distances/__tests__/minkowski.test.ts b/src/distances/__tests__/minkowski.test.ts index f7e7ea4..42103aa 100644 --- a/src/distances/__tests__/minkowski.test.ts +++ b/src/distances/__tests__/minkowski.test.ts @@ -1,20 +1,18 @@ -import { describe, it, expect } from 'vitest'; +import { expect, test } from 'vitest'; -import { distance } from '../..'; +import { distance } from '../../index.ts'; const v1 = [0, 1, 4, 6, 2]; const v2 = [3, 6, 9, 4, 3]; -describe('Minkowski distance', () => { - it('should return 0 with itself', () => { - expect(distance.minkowski(v1, v1, 1)).toBe(0); - expect(distance.minkowski(v1, v1, 2)).toBe(0); - expect(distance.minkowski(v1, v1, 5)).toBe(0); - }); +test('should return 0 with itself', () => { + expect(distance.minkowski(v1, v1, 1)).toBe(0); + expect(distance.minkowski(v1, v1, 2)).toBe(0); + expect(distance.minkowski(v1, v1, 5)).toBe(0); +}); - it('should be correct', () => { - expect(distance.minkowski(v1, v2, 1)).toBe(distance.manhattan(v1, v2)); - expect(distance.minkowski(v1, v2, 2)).toBe(distance.euclidean(v1, v2)); - expect(distance.minkowski(v1, v2, 5)).toBe(6526 ** (1 / 5)); - }); +test('should be correct', () => { + expect(distance.minkowski(v1, v2, 1)).toBe(distance.manhattan(v1, v2)); + expect(distance.minkowski(v1, v2, 2)).toBe(distance.euclidean(v1, v2)); + expect(distance.minkowski(v1, v2, 5)).toBe(6526 ** (1 / 5)); }); diff --git a/src/distances/__tests__/motyka.test.ts b/src/distances/__tests__/motyka.test.ts index c85e338..ecf27c0 100644 --- a/src/distances/__tests__/motyka.test.ts +++ b/src/distances/__tests__/motyka.test.ts @@ -1,16 +1,14 @@ -import { describe, it, expect } from 'vitest'; +import { expect, test } from 'vitest'; -import { distance } from '../..'; +import { distance } from '../../index.ts'; const v1 = [0.2, 0.4, 0.3, 0.1]; const v2 = [0.3, 0.2, 0.3, 0.2]; -describe('Motyka distance', () => { - it('should return 0.5 with itself', () => { - expect(distance.motyka(v1, v1)).toBe(0.5); - }); +test('should return 0.5 with itself', () => { + expect(distance.motyka(v1, v1)).toBe(0.5); +}); - it('should be correct', () => { - expect(distance.motyka(v1, v2)).toBe(0.6000000000000001); - }); +test('should be correct', () => { + expect(distance.motyka(v1, v2)).toBe(0.6000000000000001); }); diff --git a/src/distances/__tests__/neyman.test.ts b/src/distances/__tests__/neyman.test.ts index a6e7543..3283dbf 100644 --- a/src/distances/__tests__/neyman.test.ts +++ b/src/distances/__tests__/neyman.test.ts @@ -1,16 +1,14 @@ -import { describe, it, expect } from 'vitest'; +import { expect, test } from 'vitest'; -import { distance } from '../..'; +import { distance } from '../../index.ts'; const v1 = [3, 1, 4, 6, 2]; const v2 = [3, 6, 9, 4, 3]; -describe('Pearson distance', () => { - it('should return 0 with itself', () => { - expect(distance.pearson(v1, v1)).toBe(0); - }); +test('should return 0 with itself', () => { + expect(distance.pearson(v1, v1)).toBe(0); +}); - it('should be correct', () => { - expect(distance.pearson(v1, v2)).toBe(8.277777777777779); - }); +test('should be correct', () => { + expect(distance.pearson(v1, v2)).toBe(8.277777777777779); }); diff --git a/src/distances/__tests__/pearson.test.ts b/src/distances/__tests__/pearson.test.ts index 2374f59..e707904 100644 --- a/src/distances/__tests__/pearson.test.ts +++ b/src/distances/__tests__/pearson.test.ts @@ -1,12 +1,10 @@ -import { describe, it, expect } from 'vitest'; +import { expect, test } from 'vitest'; -import { distance } from '../..'; +import { distance } from '../../index.ts'; const v1 = [0, 1, 4, 6, 2]; const v2 = [3, 6, 9, 4, 3]; -describe('Pearson distance', () => { - it('should be correct', () => { - expect(distance.pearson(v1, v2)).toBe(11.277777777777779); - }); +test('should be correct', () => { + expect(distance.pearson(v1, v2)).toBe(11.277777777777779); }); diff --git a/src/distances/__tests__/probabilisticSymmetric.test.ts b/src/distances/__tests__/probabilisticSymmetric.test.ts index 979b724..ff54e4c 100644 --- a/src/distances/__tests__/probabilisticSymmetric.test.ts +++ b/src/distances/__tests__/probabilisticSymmetric.test.ts @@ -1,19 +1,17 @@ -import { describe, it, expect } from 'vitest'; +import { expect, test } from 'vitest'; -import { distance } from '../..'; +import { distance } from '../../index.ts'; const v1 = [3, 1, 4, 6, 2]; const v2 = [3, 6, 9, 4, 3]; -describe('Probabilistic Symmetric distance', () => { - it('should return 0 with itself', () => { - expect(distance.probabilisticSymmetric(v1, v1)).toBe(0); - }); +test('should return 0 with itself', () => { + expect(distance.probabilisticSymmetric(v1, v1)).toBe(0); +}); - it('should be correct', () => { - expect(distance.probabilisticSymmetric(v1, v2)).toBe(12.18901098901099); - expect(distance.probabilisticSymmetric(v1, v2)).toBe( - 2 * distance.squared(v1, v2), - ); - }); +test('should be correct', () => { + expect(distance.probabilisticSymmetric(v1, v2)).toBe(12.18901098901099); + expect(distance.probabilisticSymmetric(v1, v2)).toBe( + 2 * distance.squared(v1, v2), + ); }); diff --git a/src/distances/__tests__/ruzicka.test.ts b/src/distances/__tests__/ruzicka.test.ts index 21d45f5..661d767 100644 --- a/src/distances/__tests__/ruzicka.test.ts +++ b/src/distances/__tests__/ruzicka.test.ts @@ -1,12 +1,38 @@ -import { describe, it, expect } from 'vitest'; +import { expect, test } from 'vitest'; -import { distance } from '../..'; +import { distance } from '../../index.ts'; const v1 = [0.2, 0.4, 0.3, 0.1]; const v2 = [0.3, 0.2, 0.3, 0.2]; -describe('Ruzicka similarity', () => { - it('should be correct', () => { - expect(distance.ruzicka(v1, v2)).toBe(2 / 3); - }); +test('should be correct', () => { + expect(distance.ruzicka(v1, v2)).toBe(2 / 3); +}); + +test('should be 1 for identical vectors, not 0 as a distance would be', () => { + expect(distance.ruzicka(v1, v1)).toBe(1); + expect(distance.soergel(v1, v1)).toBe(0); +}); + +test('should grow as the vectors get more similar', () => { + const far = distance.ruzicka([1, 0], [0, 1]); + const near = distance.ruzicka([1, 0], [0.9, 0.1]); + + expect(far).toBe(0); + expect(near).toBeCloseTo(0.818181, 5); + expect(near).toBeGreaterThan(far); +}); + +test('should be the complement of the soergel distance', () => { + expect(1 - distance.ruzicka(v1, v2)).toBeCloseTo( + distance.soergel(v1, v2), + 10, + ); +}); + +test('should be the complement of the tanimoto distance', () => { + expect(1 - distance.ruzicka(v1, v2)).toBeCloseTo( + distance.tanimoto(v1, v2), + 10, + ); }); diff --git a/src/distances/__tests__/soergel.test.ts b/src/distances/__tests__/soergel.test.ts index 4454c29..4ffb5cb 100644 --- a/src/distances/__tests__/soergel.test.ts +++ b/src/distances/__tests__/soergel.test.ts @@ -1,16 +1,14 @@ -import { describe, it, expect } from 'vitest'; +import { expect, test } from 'vitest'; -import { distance } from '../..'; +import { distance } from '../../index.ts'; const v1 = [0, 1, 4, 6, 2]; const v2 = [3, 6, 9, 4, 3]; -describe('Soergel distance', () => { - it('should return 0 with itself', () => { - expect(distance.soergel(v1, v1)).toBe(0); - }); +test('should return 0 with itself', () => { + expect(distance.soergel(v1, v1)).toBe(0); +}); - it('should be correct', () => { - expect(distance.soergel(v1, v2)).toBe(16 / 27); - }); +test('should be correct', () => { + expect(distance.soergel(v1, v2)).toBe(16 / 27); }); diff --git a/src/distances/__tests__/sorensen.test.ts b/src/distances/__tests__/sorensen.test.ts index 9c67b96..4a0b8aa 100644 --- a/src/distances/__tests__/sorensen.test.ts +++ b/src/distances/__tests__/sorensen.test.ts @@ -1,16 +1,14 @@ -import { describe, it, expect } from 'vitest'; +import { expect, test } from 'vitest'; -import { distance } from '../..'; +import { distance } from '../../index.ts'; const v1 = [0, 1, 4, 6, 2]; const v2 = [3, 6, 9, 4, 3]; -describe('Sørensen distance', () => { - it('should return 0 with itself', () => { - expect(distance.sorensen(v1, v1)).toBe(0); - }); +test('should return 0 with itself', () => { + expect(distance.sorensen(v1, v1)).toBe(0); +}); - it('should be correct', () => { - expect(distance.sorensen(v1, v2)).toBe(16 / 38); - }); +test('should be correct', () => { + expect(distance.sorensen(v1, v2)).toBe(16 / 38); }); diff --git a/src/distances/__tests__/squared.test.ts b/src/distances/__tests__/squared.test.ts index 3991060..e34f817 100644 --- a/src/distances/__tests__/squared.test.ts +++ b/src/distances/__tests__/squared.test.ts @@ -1,16 +1,14 @@ -import { describe, it, expect } from 'vitest'; +import { expect, test } from 'vitest'; -import { distance } from '../..'; +import { distance } from '../../index.ts'; const v1 = [3, 1, 4, 6, 2]; const v2 = [3, 6, 9, 4, 3]; -describe('Squared distance', () => { - it('should return 0 with itself', () => { - expect(distance.squared(v1, v1)).toBe(0); - }); +test('should return 0 with itself', () => { + expect(distance.squared(v1, v1)).toBe(0); +}); - it('should be correct', () => { - expect(distance.squared(v1, v2)).toBe(6.094505494505495); - }); +test('should be correct', () => { + expect(distance.squared(v1, v2)).toBe(6.094505494505495); }); diff --git a/src/distances/__tests__/squaredChord.test.ts b/src/distances/__tests__/squaredChord.test.ts index c2bb189..d437261 100644 --- a/src/distances/__tests__/squaredChord.test.ts +++ b/src/distances/__tests__/squaredChord.test.ts @@ -1,12 +1,10 @@ -import { describe, it, expect } from 'vitest'; +import { expect, test } from 'vitest'; -import { distance } from '../..'; +import { distance } from '../../index.ts'; const v1 = [0.2, 0.4, 0.3, 0.1]; const v2 = [0.3, 0.2, 0.3, 0.2]; -describe('Squared-Chord distance', () => { - it('should be correct', () => { - expect(distance.squaredChord(v1, v2)).toBe(0.06157391401950735); - }); +test('should be correct', () => { + expect(distance.squaredChord(v1, v2)).toBe(0.06157391401950735); }); diff --git a/src/distances/__tests__/taneja.test.ts b/src/distances/__tests__/taneja.test.ts index 5346047..0f2d22b 100644 --- a/src/distances/__tests__/taneja.test.ts +++ b/src/distances/__tests__/taneja.test.ts @@ -1,12 +1,10 @@ -import { describe, it, expect } from 'vitest'; +import { expect, test } from 'vitest'; -import { distance } from '../..'; +import { distance } from '../../index.ts'; const v1 = [0.2, 0.4, 0.3, 0.1]; const v2 = [0.3, 0.2, 0.3, 0.2]; -describe('Taneja distance', () => { - it('should be correct', () => { - expect(distance.taneja(v1, v2)).toBe(0.031603932337718146); - }); +test('should be correct', () => { + expect(distance.taneja(v1, v2)).toBe(0.031603932337718146); }); diff --git a/src/distances/__tests__/tanimoto.test.ts b/src/distances/__tests__/tanimoto.test.ts index 4e8df8a..68b9880 100644 --- a/src/distances/__tests__/tanimoto.test.ts +++ b/src/distances/__tests__/tanimoto.test.ts @@ -1,6 +1,6 @@ -import { describe, it, expect } from 'vitest'; +import { expect, test } from 'vitest'; -import { distance } from '../..'; +import { distance } from '../../index.ts'; const v1 = [0.2, 0.4, 0.3, 0.1]; const v2 = [0.3, 0.2, 0.3, 0.2]; @@ -14,15 +14,13 @@ bv2[0] = 1; bv2[1] = 1; bv2[2] = 1; -describe('Tanimoto distance', () => { - it('should return 0 with itself', () => { - expect(distance.tanimoto(v1, v1)).toBe(0); - expect(distance.tanimoto(bv1, bv1, true)).toBe(0); - }); +test('should return 0 with itself', () => { + expect(distance.tanimoto(v1, v1)).toBe(0); + expect(distance.tanimoto(bv1, bv1, true)).toBe(0); +}); - it('should be correct', () => { - expect(distance.tanimoto(v1, v2)).toBe(0.33333333333333337); - expect(distance.tanimoto(v1, v2)).toBe(distance.soergel(v1, v2)); - expect(distance.tanimoto(bv1, bv2, true)).toBeCloseTo(0.333, 1); - }); +test('should be correct', () => { + expect(distance.tanimoto(v1, v2)).toBe(0.33333333333333337); + expect(distance.tanimoto(v1, v2)).toBe(distance.soergel(v1, v2)); + expect(distance.tanimoto(bv1, bv2, true)).toBeCloseTo(0.333, 1); }); diff --git a/src/distances/__tests__/topsoe.test.ts b/src/distances/__tests__/topsoe.test.ts index 06356f7..1b3532e 100644 --- a/src/distances/__tests__/topsoe.test.ts +++ b/src/distances/__tests__/topsoe.test.ts @@ -1,12 +1,10 @@ -import { describe, it, expect } from 'vitest'; +import { expect, test } from 'vitest'; -import { distance } from '../..'; +import { distance } from '../../index.ts'; const v1 = [0.2, 0.4, 0.3, 0.1]; const v2 = [0.3, 0.2, 0.3, 0.2]; -describe('Topsøe distance', () => { - it('should be correct', () => { - expect(distance.topsoe(v1, v2)).toBe(0.0610374678139636); - }); +test('should be correct', () => { + expect(distance.topsoe(v1, v2)).toBe(0.0610374678139636); }); diff --git a/src/distances/__tests__/waveHedges.test.ts b/src/distances/__tests__/waveHedges.test.ts index e1a5f2b..b000251 100644 --- a/src/distances/__tests__/waveHedges.test.ts +++ b/src/distances/__tests__/waveHedges.test.ts @@ -1,16 +1,14 @@ -import { describe, it, expect } from 'vitest'; +import { expect, test } from 'vitest'; -import { distance } from '../..'; +import { distance } from '../../index.ts'; const v1 = [0.2, 0.4, 0.3, 0.1]; const v2 = [0.3, 0.2, 0.3, 0.2]; -describe('Wave Hedges distance', () => { - it('should return 0 with itself', () => { - expect(distance.waveHedges(v1, v1)).toBe(0); - }); +test('should return 0 with itself', () => { + expect(distance.waveHedges(v1, v1)).toBe(0); +}); - it('should be correct', () => { - expect(distance.waveHedges(v1, v2)).toBe(4 / 3); - }); +test('should be correct', () => { + expect(distance.waveHedges(v1, v2)).toBe(4 / 3); }); diff --git a/src/distances/additiveSymmetric.ts b/src/distances/additiveSymmetric.ts index 1e1ffce..45d4e30 100644 --- a/src/distances/additiveSymmetric.ts +++ b/src/distances/additiveSymmetric.ts @@ -1,4 +1,4 @@ -import { NumberArray } from 'cheminfo-types'; +import type { NumberArray } from 'cheminfo-types'; /** *Returns the Additive Symmetric distance between vectors a and b * @link [Additive Symmetric algorithm](https://www.naun.org/main/NAUN/ijmmas/mmmas-49.pdf) diff --git a/src/distances/avg.ts b/src/distances/avg.ts index 8434584..bcce2a5 100644 --- a/src/distances/avg.ts +++ b/src/distances/avg.ts @@ -1,4 +1,4 @@ -import { NumberArray } from 'cheminfo-types'; +import type { NumberArray } from 'cheminfo-types'; /** * Returns the average of city block and Chebyshev distances between vectors a and b diff --git a/src/distances/bhattacharyya.ts b/src/distances/bhattacharyya.ts index 5d3fc2e..25b209d 100644 --- a/src/distances/bhattacharyya.ts +++ b/src/distances/bhattacharyya.ts @@ -1,8 +1,8 @@ -import { NumberArray } from 'cheminfo-types'; +import type { NumberArray } from 'cheminfo-types'; /** - *Returns the Bhattacharyy distance between vectors a and b - * @link [Bhattacharyy algorithm](https://www.naun.org/main/NAUN/ijmmas/mmmas-49.pdf) + *Returns the Bhattacharyya distance between vectors a and b + * @link [Bhattacharyya algorithm](https://www.naun.org/main/NAUN/ijmmas/mmmas-49.pdf) * @param a - first vector * @param b - second vector */ diff --git a/src/distances/canberra.ts b/src/distances/canberra.ts index 718babb..aa1ab3e 100644 --- a/src/distances/canberra.ts +++ b/src/distances/canberra.ts @@ -1,4 +1,4 @@ -import { NumberArray } from 'cheminfo-types'; +import type { NumberArray } from 'cheminfo-types'; /** * Returns the Canberra distance between vectors a and b * @link [Canberra algorithm](https://en.wikipedia.org/wiki/Canberra_distance) diff --git a/src/distances/chebyshev.ts b/src/distances/chebyshev.ts index 2ff8f36..1e8111a 100644 --- a/src/distances/chebyshev.ts +++ b/src/distances/chebyshev.ts @@ -1,4 +1,4 @@ -import { NumberArray } from 'cheminfo-types'; +import type { NumberArray } from 'cheminfo-types'; /** *Returns the Chebyshev distance between vectors a and b diff --git a/src/distances/clark.ts b/src/distances/clark.ts index e9499fe..faea766 100644 --- a/src/distances/clark.ts +++ b/src/distances/clark.ts @@ -1,4 +1,4 @@ -import { NumberArray } from 'cheminfo-types'; +import type { NumberArray } from 'cheminfo-types'; /** *Returns the Clark distance between vectors a and b * @link [Clark algorithm](https://www.naun.org/main/NAUN/ijmmas/mmmas-49.pdf) diff --git a/src/distances/czekanowski.ts b/src/distances/czekanowski.ts index 807889b..07f54e1 100644 --- a/src/distances/czekanowski.ts +++ b/src/distances/czekanowski.ts @@ -1,6 +1,6 @@ -import { NumberArray } from 'cheminfo-types'; +import type { NumberArray } from 'cheminfo-types'; -import { czekanowski as czekanowskiSimilarity } from '../similarities/czekanowski'; +import { czekanowski as czekanowskiSimilarity } from '../similarities/czekanowski.ts'; /** *Returns the Czekanowski distance between vectors a and b * @link [Czekanowski algorithm](https://www.naun.org/main/NAUN/ijmmas/mmmas-49.pdf) diff --git a/src/distances/dice.ts b/src/distances/dice.ts index 3780274..7696bc1 100644 --- a/src/distances/dice.ts +++ b/src/distances/dice.ts @@ -1,4 +1,4 @@ -import { NumberArray } from 'cheminfo-types'; +import type { NumberArray } from 'cheminfo-types'; /** *Returns the Dice distance between vectors a and b * @link [Dice algorithm](https://www.naun.org/main/NAUN/ijmmas/mmmas-49.pdf) diff --git a/src/distances/divergence.ts b/src/distances/divergence.ts index 5c91725..1b62dd4 100644 --- a/src/distances/divergence.ts +++ b/src/distances/divergence.ts @@ -1,4 +1,4 @@ -import { NumberArray } from 'cheminfo-types'; +import type { NumberArray } from 'cheminfo-types'; /** *Returns the Divergence distance between vectors a and b * @link [Divergence algorithm](https://www.naun.org/main/NAUN/ijmmas/mmmas-49.pdf) diff --git a/src/distances/fidelity.ts b/src/distances/fidelity.ts index 7a4a041..ef7a235 100644 --- a/src/distances/fidelity.ts +++ b/src/distances/fidelity.ts @@ -1,4 +1,4 @@ -import { NumberArray } from 'cheminfo-types'; +import type { NumberArray } from 'cheminfo-types'; /** *Returns the Fidelity similarity between vectors a and b * @link [Fidelity Similarity algorithm](https://www.naun.org/main/NAUN/ijmmas/mmmas-49.pdf) diff --git a/src/distances/gower.ts b/src/distances/gower.ts index 42d7397..c2750c1 100644 --- a/src/distances/gower.ts +++ b/src/distances/gower.ts @@ -1,4 +1,4 @@ -import { NumberArray } from 'cheminfo-types'; +import type { NumberArray } from 'cheminfo-types'; /** *Returns the Gower distance between vectors a and b * @link [Gower algorithm](https://stat.ethz.ch/education/semesters/ss2012/ams/slides/v4.2.pdf) diff --git a/src/distances/harmonicMean.ts b/src/distances/harmonicMean.ts index 1b37b1d..dde08dd 100644 --- a/src/distances/harmonicMean.ts +++ b/src/distances/harmonicMean.ts @@ -1,4 +1,4 @@ -import { NumberArray } from 'cheminfo-types'; +import type { NumberArray } from 'cheminfo-types'; /** *Returns the Harmonic mean similarity between vectors a and b * @link [Harmonic Mean Similarity algorithm](https://www.naun.org/main/NAUN/ijmmas/mmmas-49.pdf) diff --git a/src/distances/hellinger.ts b/src/distances/hellinger.ts index e25888c..bcf3ce0 100644 --- a/src/distances/hellinger.ts +++ b/src/distances/hellinger.ts @@ -1,4 +1,4 @@ -import { NumberArray } from 'cheminfo-types'; +import type { NumberArray } from 'cheminfo-types'; /** *Returns the Hellinger distance between vectors a and b * @link [Hellinger algorithm](https://www.naun.org/main/NAUN/ijmmas/mmmas-49.pdf) diff --git a/src/distances/innerProduct.ts b/src/distances/innerProduct.ts index 861f595..cb4b5e6 100644 --- a/src/distances/innerProduct.ts +++ b/src/distances/innerProduct.ts @@ -1,4 +1,4 @@ -import { NumberArray } from 'cheminfo-types'; +import type { NumberArray } from 'cheminfo-types'; /** *Returns the Inner Product similarity between vectors a and b * @link [Inner Product Similarity algorithm](https://www.naun.org/main/NAUN/ijmmas/mmmas-49.pdf) diff --git a/src/distances/intersection.ts b/src/distances/intersection.ts index 4d80f1e..431b39f 100644 --- a/src/distances/intersection.ts +++ b/src/distances/intersection.ts @@ -1,4 +1,4 @@ -import { NumberArray } from 'cheminfo-types'; +import type { NumberArray } from 'cheminfo-types'; /** *Returns the Intersection distance between vectors a and b * @link [Intersection algorithm](https://www.naun.org/main/NAUN/ijmmas/mmmas-49.pdf) diff --git a/src/distances/jaccard.ts b/src/distances/jaccard.ts index 9543d1b..1bab8e8 100644 --- a/src/distances/jaccard.ts +++ b/src/distances/jaccard.ts @@ -1,6 +1,6 @@ -import { NumberArray } from 'cheminfo-types'; +import type { NumberArray } from 'cheminfo-types'; -import { kumarHassebrook } from '../similarities/kumarHassebrook'; +import { kumarHassebrook } from '../similarities/kumarHassebrook.ts'; /** *Returns Jaccard distance between vectors a and b * @link [Jaccard algorithm](https://www.naun.org/main/NAUN/ijmmas/mmmas-49.pdf) diff --git a/src/distances/jeffreys.ts b/src/distances/jeffreys.ts index 16e74ab..cdaec4e 100644 --- a/src/distances/jeffreys.ts +++ b/src/distances/jeffreys.ts @@ -1,4 +1,4 @@ -import { NumberArray } from 'cheminfo-types'; +import type { NumberArray } from 'cheminfo-types'; /** *Returns the Jeffreys distance between vectors a and b * @link [Jeffreys algorithm](https://www.naun.org/main/NAUN/ijmmas/mmmas-49.pdf) diff --git a/src/distances/jensenDifference.ts b/src/distances/jensenDifference.ts index 9e51a8b..6beaf95 100644 --- a/src/distances/jensenDifference.ts +++ b/src/distances/jensenDifference.ts @@ -1,4 +1,4 @@ -import { NumberArray } from 'cheminfo-types'; +import type { NumberArray } from 'cheminfo-types'; /** *Returns the Jensen difference distance between vectors a and b * @link [Jensen difference algorithm](https://www.naun.org/main/NAUN/ijmmas/mmmas-49.pdf) diff --git a/src/distances/jensenShannon.ts b/src/distances/jensenShannon.ts index ecdcf41..ededd6e 100644 --- a/src/distances/jensenShannon.ts +++ b/src/distances/jensenShannon.ts @@ -1,4 +1,4 @@ -import { NumberArray } from 'cheminfo-types'; +import type { NumberArray } from 'cheminfo-types'; /** *Returns the Jensen-Shannon distance between vectors a and b * @link [Jensen-Shannon algorithm](https://www.naun.org/main/NAUN/ijmmas/mmmas-49.pdf) diff --git a/src/distances/kdivergence.ts b/src/distances/kdivergence.ts index 2c6ad42..915dcb9 100644 --- a/src/distances/kdivergence.ts +++ b/src/distances/kdivergence.ts @@ -1,4 +1,4 @@ -import { NumberArray } from 'cheminfo-types'; +import type { NumberArray } from 'cheminfo-types'; /** *Returns the K divergence distance between vectors a and b * @link [K divergence algorithm](https://www.naun.org/main/NAUN/ijmmas/mmmas-49.pdf) diff --git a/src/distances/kulczynski.ts b/src/distances/kulczynski.ts index ff032c8..7e2fe67 100644 --- a/src/distances/kulczynski.ts +++ b/src/distances/kulczynski.ts @@ -1,4 +1,4 @@ -import { NumberArray } from 'cheminfo-types'; +import type { NumberArray } from 'cheminfo-types'; /** * Returns the Kulczynski distance between vectors a and b * @link [Kulczynski algorithm](https://www.naun.org/main/NAUN/ijmmas/mmmas-49.pdf) diff --git a/src/distances/kullbackLeibler.ts b/src/distances/kullbackLeibler.ts index 3784051..0df38bb 100644 --- a/src/distances/kullbackLeibler.ts +++ b/src/distances/kullbackLeibler.ts @@ -1,6 +1,6 @@ -import { NumberArray } from 'cheminfo-types'; +import type { NumberArray } from 'cheminfo-types'; /** - *Returns the Jensen-Shannon distance between vectors a and b + *Returns the Kullback-Leibler distance between vectors a and b * @link [Kullback-Leibler algorithm](https://www.naun.org/main/NAUN/ijmmas/mmmas-49.pdf) * @param a - first vector * @param b - second vector diff --git a/src/distances/kumarJohnson.ts b/src/distances/kumarJohnson.ts index 370022f..208309f 100644 --- a/src/distances/kumarJohnson.ts +++ b/src/distances/kumarJohnson.ts @@ -1,4 +1,4 @@ -import { NumberArray } from 'cheminfo-types'; +import type { NumberArray } from 'cheminfo-types'; /** *Returns the Kumar-Johnson distance between vectors a and b * @link [Kumar-Johnson algorithm](https://www.naun.org/main/NAUN/ijmmas/mmmas-49.pdf) diff --git a/src/distances/lorentzian.ts b/src/distances/lorentzian.ts index 530c561..18e7a8f 100644 --- a/src/distances/lorentzian.ts +++ b/src/distances/lorentzian.ts @@ -1,4 +1,4 @@ -import { NumberArray } from 'cheminfo-types'; +import type { NumberArray } from 'cheminfo-types'; /** *Returns the Lorentzian distance between vectors a and b * @link [Lorentzian algorithm](https://stat.ethz.ch/education/semesters/ss2012/ams/slides/v4.2.pdf) diff --git a/src/distances/manhattan.ts b/src/distances/manhattan.ts index 7fd339c..3908595 100644 --- a/src/distances/manhattan.ts +++ b/src/distances/manhattan.ts @@ -1,4 +1,4 @@ -import { NumberArray } from 'cheminfo-types'; +import type { NumberArray } from 'cheminfo-types'; /** *Returns the Manhattan distance between vectors a and b * @link [Manhattan algorithm](https://www.naun.org/main/NAUN/ijmmas/mmmas-49.pdf) diff --git a/src/distances/matusita.ts b/src/distances/matusita.ts index abef480..7891c26 100644 --- a/src/distances/matusita.ts +++ b/src/distances/matusita.ts @@ -1,4 +1,4 @@ -import { NumberArray } from 'cheminfo-types'; +import type { NumberArray } from 'cheminfo-types'; /** *Returns the Matusita distance between vectors a and b * @link [Matusita algorithm](https://www.naun.org/main/NAUN/ijmmas/mmmas-49.pdf) diff --git a/src/distances/minkowski.ts b/src/distances/minkowski.ts index 026d67c..e0639c4 100644 --- a/src/distances/minkowski.ts +++ b/src/distances/minkowski.ts @@ -1,4 +1,4 @@ -import { NumberArray } from 'cheminfo-types'; +import type { NumberArray } from 'cheminfo-types'; /** * Returns the Minkowski distance between vectors a and b for order p * @link [Minkowski algorithm](https://en.wikipedia.org/wiki/Minkowski_distance) diff --git a/src/distances/motyka.ts b/src/distances/motyka.ts index 6bb2d31..b7f1b40 100644 --- a/src/distances/motyka.ts +++ b/src/distances/motyka.ts @@ -1,4 +1,4 @@ -import { NumberArray } from 'cheminfo-types'; +import type { NumberArray } from 'cheminfo-types'; /** *Returns the Motyka distance between vectors a and b * @link [Motyka algorithm](https://www.naun.org/main/NAUN/ijmmas/mmmas-49.pdf) diff --git a/src/distances/neyman.ts b/src/distances/neyman.ts index 8a64224..e406bd1 100644 --- a/src/distances/neyman.ts +++ b/src/distances/neyman.ts @@ -1,4 +1,4 @@ -import { NumberArray } from 'cheminfo-types'; +import type { NumberArray } from 'cheminfo-types'; /** *Returns the Neyman distance between vectors a and b * @link [Neyman algorithm](https://www.naun.org/main/NAUN/ijmmas/mmmas-49.pdf) diff --git a/src/distances/pearson.ts b/src/distances/pearson.ts index 890d0b3..60ce11e 100644 --- a/src/distances/pearson.ts +++ b/src/distances/pearson.ts @@ -1,4 +1,4 @@ -import { NumberArray } from 'cheminfo-types'; +import type { NumberArray } from 'cheminfo-types'; /** *Returns the Pearson distance between vectors a and b * @link [Pearson algorithm](https://www.naun.org/main/NAUN/ijmmas/mmmas-49.pdf) diff --git a/src/distances/probabilisticSymmetric.ts b/src/distances/probabilisticSymmetric.ts index 9d8c70d..5d310f0 100644 --- a/src/distances/probabilisticSymmetric.ts +++ b/src/distances/probabilisticSymmetric.ts @@ -1,4 +1,4 @@ -import { NumberArray } from 'cheminfo-types'; +import type { NumberArray } from 'cheminfo-types'; /** *Returns the Probabilistic Symmetric distance between vectors a and b * @link [Probabilistic Symmetric algorithm](https://www.naun.org/main/NAUN/ijmmas/mmmas-49.pdf) diff --git a/src/distances/ruzicka.ts b/src/distances/ruzicka.ts index 8622189..3554691 100644 --- a/src/distances/ruzicka.ts +++ b/src/distances/ruzicka.ts @@ -1,6 +1,6 @@ -import { NumberArray } from 'cheminfo-types'; +import type { NumberArray } from 'cheminfo-types'; /** - *Returns the Ruzicka distance between vectors a and b + *Returns the Ruzicka similarity between vectors a and b * @link [Ruzicka algorithm](https://www.naun.org/main/NAUN/ijmmas/mmmas-49.pdf) * @param a - first vector * @param b - second vector diff --git a/src/distances/soergel.ts b/src/distances/soergel.ts index e58d470..ef00338 100644 --- a/src/distances/soergel.ts +++ b/src/distances/soergel.ts @@ -1,4 +1,4 @@ -import { NumberArray } from 'cheminfo-types'; +import type { NumberArray } from 'cheminfo-types'; /** * Returns the Soergel distance between vectors a and b diff --git a/src/distances/sorensen.ts b/src/distances/sorensen.ts index 6a962f5..c13cb3c 100644 --- a/src/distances/sorensen.ts +++ b/src/distances/sorensen.ts @@ -1,4 +1,4 @@ -import { NumberArray } from 'cheminfo-types'; +import type { NumberArray } from 'cheminfo-types'; /** *Returns the Sorensen distance between vectors a and b diff --git a/src/distances/squared.ts b/src/distances/squared.ts index e609011..3565dae 100644 --- a/src/distances/squared.ts +++ b/src/distances/squared.ts @@ -1,4 +1,4 @@ -import { NumberArray } from 'cheminfo-types'; +import type { NumberArray } from 'cheminfo-types'; /** *Returns the squared distance between vectors a and b * @link [Squared algorithm](https://www.naun.org/main/NAUN/ijmmas/mmmas-49.pdf) diff --git a/src/distances/squaredChord.ts b/src/distances/squaredChord.ts index 6dac5b3..b62e45d 100644 --- a/src/distances/squaredChord.ts +++ b/src/distances/squaredChord.ts @@ -1,4 +1,4 @@ -import { NumberArray } from 'cheminfo-types'; +import type { NumberArray } from 'cheminfo-types'; /** *Returns the Squared Chord distance between vectors a and b * @link [Squared Chord algorithm](https://www.naun.org/main/NAUN/ijmmas/mmmas-49.pdf) diff --git a/src/distances/taneja.ts b/src/distances/taneja.ts index dc69365..12a0df3 100644 --- a/src/distances/taneja.ts +++ b/src/distances/taneja.ts @@ -1,4 +1,4 @@ -import { NumberArray } from 'cheminfo-types'; +import type { NumberArray } from 'cheminfo-types'; /** *Returns the Taneja distance between vectors a and b * @link [Taneja algorithm](https://www.naun.org/main/NAUN/ijmmas/mmmas-49.pdf) diff --git a/src/distances/tanimoto.ts b/src/distances/tanimoto.ts index 6906640..a0b1260 100644 --- a/src/distances/tanimoto.ts +++ b/src/distances/tanimoto.ts @@ -1,6 +1,6 @@ -import { NumberArray } from 'cheminfo-types'; +import type { NumberArray } from 'cheminfo-types'; -import { tanimoto as tanimotoS } from '../similarities/tanimoto'; +import { tanimoto as tanimotoS } from '../similarities/tanimoto.ts'; /** *Returns the Tanimoto distance between vectors p and q, and accepts the bitVector use, see the test case for an example * @link [Tanimoto algorithm](https://www.naun.org/main/NAUN/ijmmas/mmmas-49.pdf) diff --git a/src/distances/topsoe.ts b/src/distances/topsoe.ts index eb61b07..3df7cd4 100644 --- a/src/distances/topsoe.ts +++ b/src/distances/topsoe.ts @@ -1,4 +1,4 @@ -import { NumberArray } from 'cheminfo-types'; +import type { NumberArray } from 'cheminfo-types'; /** *Returns the Topsoe distance between vectors a and b * @link [Topsoe algorithm](https://www.naun.org/main/NAUN/ijmmas/mmmas-49.pdf) diff --git a/src/distances/waveHedges.ts b/src/distances/waveHedges.ts index fb897d6..86ceae1 100644 --- a/src/distances/waveHedges.ts +++ b/src/distances/waveHedges.ts @@ -1,10 +1,9 @@ -import { NumberArray } from 'cheminfo-types'; +import type { NumberArray } from 'cheminfo-types'; /** - *Returns the Wave Hedges distance between vectors p and q, and accepts the bitVector use, see the test case for an example + *Returns the Wave Hedges distance between vectors a and b * @link [Wave Hedges algorithm](https://www.naun.org/main/NAUN/ijmmas/mmmas-49.pdf) * @param a - first vector * @param b - second vector - * @param bitvector - bitVector */ export function waveHedges(a: NumberArray, b: NumberArray): number { let ans = 0; diff --git a/src/index.ts b/src/index.ts index ea00c12..d12e0dd 100644 --- a/src/index.ts +++ b/src/index.ts @@ -1,2 +1,2 @@ -export * as distance from './distances'; -export * as similarity from './similarities'; +export * as distance from './distances.ts'; +export * as similarity from './similarities.ts'; diff --git a/src/similarities.ts b/src/similarities.ts index c14e6f9..320c627 100644 --- a/src/similarities.ts +++ b/src/similarities.ts @@ -1,22 +1,22 @@ -export * from './similarities/cosine'; +export * from './similarities/cosine.ts'; -export * from './similarities/czekanowski'; +export * from './similarities/czekanowski.ts'; -export * from './similarities/dice'; +export * from './similarities/dice.ts'; -export * from './similarities/intersection'; +export * from './similarities/intersection.ts'; -export * from './similarities/kulczynski'; +export * from './similarities/kulczynski.ts'; -export * from './similarities/motyka'; +export * from './similarities/motyka.ts'; -export * from './similarities/pearson'; +export * from './similarities/pearson.ts'; -export * from './similarities/squaredChord'; +export * from './similarities/squaredChord.ts'; -export * from './similarities/tanimoto'; +export * from './similarities/tanimoto.ts'; -export * from './similarities/kumarHassebrook'; +export * from './similarities/kumarHassebrook.ts'; // @ts-expect-error ml-tree-similarity is not typed export * as tree from 'ml-tree-similarity'; diff --git a/src/similarities/__tests__/cosine.test.ts b/src/similarities/__tests__/cosine.test.ts index 9c96637..3f4dcbd 100644 --- a/src/similarities/__tests__/cosine.test.ts +++ b/src/similarities/__tests__/cosine.test.ts @@ -1,13 +1,11 @@ -import { describe, it, expect } from 'vitest'; +import { expect, test } from 'vitest'; -import { similarity } from '../..'; +import { similarity } from '../../index.ts'; const v1 = [0.2, 0.4, 0.3, 0.1]; const v2 = [0.3, 0.2, 0.3, 0.2]; -describe('Cosine similarity', () => { - it('should be correct', () => { - expect(similarity.cosine(v1, v1)).toBeCloseTo(1, 5); - expect(similarity.cosine(v1, v2)).toBe(0.8951435925492909); - }); +test('should be correct', () => { + expect(similarity.cosine(v1, v1)).toBeCloseTo(1, 5); + expect(similarity.cosine(v1, v2)).toBe(0.8951435925492909); }); diff --git a/src/similarities/__tests__/czekanowski.test.ts b/src/similarities/__tests__/czekanowski.test.ts index dcaa77b..b85a0a2 100644 --- a/src/similarities/__tests__/czekanowski.test.ts +++ b/src/similarities/__tests__/czekanowski.test.ts @@ -1,20 +1,18 @@ -import { describe, it, expect } from 'vitest'; +import { expect, test } from 'vitest'; -import { distance, similarity } from '../..'; +import { distance, similarity } from '../../index.ts'; const v1 = [0.2, 0.4, 0.3, 0.1]; const v2 = [0.3, 0.2, 0.3, 0.2]; -describe('Czekanowski similarity', () => { - it('should return 0 with itself', () => { - expect(similarity.czekanowski(v1, v1)).toBe(1); - }); +test('should return 0 with itself', () => { + expect(similarity.czekanowski(v1, v1)).toBe(1); +}); - it('should be correct', () => { - expect(similarity.czekanowski(v1, v2)).toBe(0.7999999999999999); - expect(similarity.czekanowski(v1, v2)).toBeCloseTo( - 1 - distance.sorensen(v1, v2), - 5, - ); - }); +test('should be correct', () => { + expect(similarity.czekanowski(v1, v2)).toBe(0.7999999999999999); + expect(similarity.czekanowski(v1, v2)).toBeCloseTo( + 1 - distance.sorensen(v1, v2), + 5, + ); }); diff --git a/src/similarities/__tests__/dice.test.ts b/src/similarities/__tests__/dice.test.ts index c27016d..c4e0d61 100644 --- a/src/similarities/__tests__/dice.test.ts +++ b/src/similarities/__tests__/dice.test.ts @@ -1,12 +1,10 @@ -import { describe, it, expect } from 'vitest'; +import { expect, test } from 'vitest'; -import { similarity } from '../..'; +import { similarity } from '../../index.ts'; const v1 = [0.2, 0.4, 0.3, 0.1]; const v2 = [0.3, 0.2, 0.3, 0.2]; -describe('Dice similarity', () => { - it('should be correct', () => { - expect(similarity.dice(v1, v2)).toBe(50 / 56); - }); +test('should be correct', () => { + expect(similarity.dice(v1, v2)).toBe(50 / 56); }); diff --git a/src/similarities/__tests__/intersection.test.ts b/src/similarities/__tests__/intersection.test.ts index 38a3c02..e7728ae 100644 --- a/src/similarities/__tests__/intersection.test.ts +++ b/src/similarities/__tests__/intersection.test.ts @@ -1,20 +1,18 @@ -import { describe, it, expect } from 'vitest'; +import { expect, test } from 'vitest'; -import { distance, similarity } from '../..'; +import { distance, similarity } from '../../index.ts'; const v1 = [0.2, 0.4, 0.3, 0.1]; const v2 = [0.3, 0.2, 0.3, 0.2]; -describe('Intersection similarity', () => { - it('should return 0 with itself', () => { - expect(similarity.intersection(v2, v2)).toBe(1); - }); +test('should return 0 with itself', () => { + expect(similarity.intersection(v2, v2)).toBe(1); +}); - it('should be correct', () => { - expect(similarity.intersection(v1, v2)).toBeCloseTo(0.8, 4); - expect(similarity.intersection(v1, v2)).toBeCloseTo( - 1 - distance.manhattan(v1, v2) / 2, - 4, - ); - }); +test('should be correct', () => { + expect(similarity.intersection(v1, v2)).toBeCloseTo(0.8, 4); + expect(similarity.intersection(v1, v2)).toBeCloseTo( + 1 - distance.manhattan(v1, v2) / 2, + 4, + ); }); diff --git a/src/similarities/__tests__/kulczynski.test.ts b/src/similarities/__tests__/kulczynski.test.ts index 3897afd..7f256f6 100644 --- a/src/similarities/__tests__/kulczynski.test.ts +++ b/src/similarities/__tests__/kulczynski.test.ts @@ -1,12 +1,10 @@ -import { describe, it, expect } from 'vitest'; +import { expect, test } from 'vitest'; -import { similarity } from '../..'; +import { similarity } from '../../index.ts'; const v1 = [0.2, 0.4, 0.3, 0.1]; const v2 = [0.3, 0.2, 0.3, 0.2]; -describe('Kulczynski similarity', () => { - it('should be correct', () => { - expect(similarity.kulczynski(v1, v2)).toBe(1.9999999999999996); - }); +test('should be correct', () => { + expect(similarity.kulczynski(v1, v2)).toBe(1.9999999999999996); }); diff --git a/src/similarities/__tests__/kumarHassebrook.test.ts b/src/similarities/__tests__/kumarHassebrook.test.ts index a359388..4d13e3a 100644 --- a/src/similarities/__tests__/kumarHassebrook.test.ts +++ b/src/similarities/__tests__/kumarHassebrook.test.ts @@ -1,13 +1,11 @@ -import { describe, it, expect } from 'vitest'; +import { expect, test } from 'vitest'; -import { similarity } from '../..'; +import { similarity } from '../../index.ts'; const v1 = [0.2, 0.4, 0.3, 0.1]; const v2 = [0.3, 0.2, 0.3, 0.2]; -describe('Kumar-Hassebrook similarity', () => { - it('should be correct', () => { - expect(similarity.kumarHassebrook(v1, v1)).toBe(1); - expect(similarity.kumarHassebrook(v1, v2)).toBe(0.8064516129032256); - }); +test('should be correct', () => { + expect(similarity.kumarHassebrook(v1, v1)).toBe(1); + expect(similarity.kumarHassebrook(v1, v2)).toBe(0.8064516129032256); }); diff --git a/src/similarities/__tests__/motyka.test.ts b/src/similarities/__tests__/motyka.test.ts index 0afc366..7936e18 100644 --- a/src/similarities/__tests__/motyka.test.ts +++ b/src/similarities/__tests__/motyka.test.ts @@ -1,16 +1,14 @@ -import { describe, it, expect } from 'vitest'; +import { expect, test } from 'vitest'; -import { similarity } from '../..'; +import { similarity } from '../../index.ts'; const v1 = [0.2, 0.4, 0.3, 0.1]; const v2 = [0.3, 0.2, 0.3, 0.2]; -describe('Motyka similarity', () => { - it('should return 0.5 with itself', () => { - expect(similarity.motyka(v1, v1)).toBe(0.5); - }); +test('should return 0.5 with itself', () => { + expect(similarity.motyka(v1, v1)).toBe(0.5); +}); - it('should be correct', () => { - expect(similarity.motyka(v1, v2)).toBeCloseTo(0.4, 3); - }); +test('should be correct', () => { + expect(similarity.motyka(v1, v2)).toBeCloseTo(0.4, 3); }); diff --git a/src/similarities/__tests__/pearson.test.ts b/src/similarities/__tests__/pearson.test.ts index 67b2131..66c47cd 100644 --- a/src/similarities/__tests__/pearson.test.ts +++ b/src/similarities/__tests__/pearson.test.ts @@ -1,13 +1,11 @@ -import { describe, it, expect } from 'vitest'; +import { expect, test } from 'vitest'; -import { similarity } from '../..'; +import { similarity } from '../../index.ts'; const v1 = [0, 1, 2, 3]; const v2 = [0, 1, 2, 1]; -describe('Pearson correlation', () => { - it('should be correct', () => { - expect(similarity.pearson(v1, v1)).toBeCloseTo(1, 8); - expect(similarity.pearson(v1, v2)).toBeCloseTo(0.6324555320336759, 8); - }); +test('should be correct', () => { + expect(similarity.pearson(v1, v1)).toBeCloseTo(1, 8); + expect(similarity.pearson(v1, v2)).toBeCloseTo(0.6324555320336759, 8); }); diff --git a/src/similarities/__tests__/squaredChord.test.ts b/src/similarities/__tests__/squaredChord.test.ts index 09c98b2..05bc0b0 100644 --- a/src/similarities/__tests__/squaredChord.test.ts +++ b/src/similarities/__tests__/squaredChord.test.ts @@ -1,12 +1,10 @@ -import { describe, it, expect } from 'vitest'; +import { expect, test } from 'vitest'; -import { similarity } from '../..'; +import { similarity } from '../../index.ts'; const v1 = [0.2, 0.4, 0.3, 0.1]; const v2 = [0.3, 0.2, 0.3, 0.2]; -describe('Squared-Chord similarity', () => { - it('should be correct', () => { - expect(similarity.squaredChord(v1, v2)).toBe(0.9384260859804927); - }); +test('should be correct', () => { + expect(similarity.squaredChord(v1, v2)).toBe(0.9384260859804927); }); diff --git a/src/similarities/__tests__/tanimoto.test.ts b/src/similarities/__tests__/tanimoto.test.ts index f0b9069..ee10dca 100644 --- a/src/similarities/__tests__/tanimoto.test.ts +++ b/src/similarities/__tests__/tanimoto.test.ts @@ -1,6 +1,6 @@ -import { describe, it, expect } from 'vitest'; +import { expect, test } from 'vitest'; -import { similarity } from '../..'; +import { similarity } from '../../index.ts'; const v1 = [0.2, 0.4, 0.3, 0.1]; const v2 = [0.3, 0.2, 0.3, 0.2]; @@ -14,14 +14,12 @@ bv2[0] = 1; bv2[1] = 1; bv2[2] = 1; -describe('Tanimoto similarity', () => { - it('should return 1 with itself', () => { - expect(similarity.tanimoto(v1, v1)).toBe(1); - expect(similarity.tanimoto(bv1, bv1, true)).toBe(1); - }); +test('should return 1 with itself', () => { + expect(similarity.tanimoto(v1, v1)).toBe(1); + expect(similarity.tanimoto(bv1, bv1, true)).toBe(1); +}); - it('should be correct', () => { - expect(similarity.tanimoto(v1, v2)).toBeCloseTo(0.666, 2); - expect(similarity.tanimoto(bv1, bv2, true)).toBeCloseTo(0.666, 2); - }); +test('should be correct', () => { + expect(similarity.tanimoto(v1, v2)).toBeCloseTo(0.666, 2); + expect(similarity.tanimoto(bv1, bv2, true)).toBeCloseTo(0.666, 2); }); diff --git a/src/similarities/__tests__/tree.test.ts b/src/similarities/__tests__/tree.test.ts index 672ba5e..f732dd5 100644 --- a/src/similarities/__tests__/tree.test.ts +++ b/src/similarities/__tests__/tree.test.ts @@ -1,6 +1,6 @@ -import { describe, it, expect } from 'vitest'; +import { expect, test } from 'vitest'; -import { similarity } from '../..'; +import { similarity } from '../../index.ts'; const a = [ [1, 2, 3, 4, 5, 6, 7], @@ -11,15 +11,10 @@ const b = [ [0.3, 4, 0.7, 0.3, 5, 0.2, 0.3], ]; -describe('Tree similarity', () => { - it('should be correct', () => { - expect(similarity.tree.treeSimilarity(a, b, 1, 7)).toBeCloseTo(0.65335, 3); - }); +test('should be correct', () => { + expect(similarity.tree.treeSimilarity(a, b, 1, 7)).toBeCloseTo(0.65335, 3); +}); - it('exports tree', () => { - expect(similarity.tree.createTree(a, a, 1, 7).center).toBeCloseTo( - 4.3714, - 3, - ); - }); +test('exports tree', () => { + expect(similarity.tree.createTree(a, a, 1, 7).center).toBeCloseTo(4.3714, 3); }); diff --git a/src/similarities/cosine.ts b/src/similarities/cosine.ts index 20ecb62..3857896 100644 --- a/src/similarities/cosine.ts +++ b/src/similarities/cosine.ts @@ -1,6 +1,6 @@ -import { NumberArray } from 'cheminfo-types'; +import type { NumberArray } from 'cheminfo-types'; /** - * Returns the average of cosine distances between vectors a and b + * Returns the cosine similarity between vectors a and b * @param a - first vector * @param b - second vector */ diff --git a/src/similarities/czekanowski.ts b/src/similarities/czekanowski.ts index f42e3a8..7ca8039 100644 --- a/src/similarities/czekanowski.ts +++ b/src/similarities/czekanowski.ts @@ -1,4 +1,4 @@ -import { NumberArray } from 'cheminfo-types'; +import type { NumberArray } from 'cheminfo-types'; /** *Returns the Czekanowski similarity between vectors a and b * @link [Czekanowski similarity](https://www.naun.org/main/NAUN/ijmmas/mmmas-49.pdf) diff --git a/src/similarities/dice.ts b/src/similarities/dice.ts index 8e24d0b..6f743a9 100644 --- a/src/similarities/dice.ts +++ b/src/similarities/dice.ts @@ -1,6 +1,6 @@ -import { NumberArray } from 'cheminfo-types'; +import type { NumberArray } from 'cheminfo-types'; -import { dice as diceD } from '../distances/dice'; +import { dice as diceD } from '../distances/dice.ts'; /** *Returns the Dice similarity between vectors a and b * @link [Dice similarity algorithm](https://www.naun.org/main/NAUN/ijmmas/mmmas-49.pdf) diff --git a/src/similarities/intersection.ts b/src/similarities/intersection.ts index 1de0c8f..4b20fb6 100644 --- a/src/similarities/intersection.ts +++ b/src/similarities/intersection.ts @@ -1,8 +1,8 @@ -import { NumberArray } from 'cheminfo-types'; +import type { NumberArray } from 'cheminfo-types'; -import { intersection as intersectionD } from '../distances/intersection'; +import { intersection as intersectionD } from '../distances/intersection.ts'; /** - *Returns the Intersection similarity distance between vectors a and b + *Returns the Intersection similarity between vectors a and b * @link [Intersection similarity algorithm](https://www.naun.org/main/NAUN/ijmmas/mmmas-49.pdf) * @param a - first vector * @param b - second vector diff --git a/src/similarities/kulczynski.ts b/src/similarities/kulczynski.ts index a169a4e..c65c907 100644 --- a/src/similarities/kulczynski.ts +++ b/src/similarities/kulczynski.ts @@ -1,6 +1,6 @@ -import { NumberArray } from 'cheminfo-types'; +import type { NumberArray } from 'cheminfo-types'; -import { kulczynski as kulczynskiD } from '../distances/kulczynski'; +import { kulczynski as kulczynskiD } from '../distances/kulczynski.ts'; /** *Returns the Kulczynski similarity between vectors a and b * @link [Kulczinski algorithm](https://www.naun.org/main/NAUN/ijmmas/mmmas-49.pdf) diff --git a/src/similarities/kumarHassebrook.ts b/src/similarities/kumarHassebrook.ts index bb39b2a..c2bba35 100644 --- a/src/similarities/kumarHassebrook.ts +++ b/src/similarities/kumarHassebrook.ts @@ -1,4 +1,4 @@ -import { NumberArray } from 'cheminfo-types'; +import type { NumberArray } from 'cheminfo-types'; /** *Returns Kumar-Hassebrook similarity between vectors a and b * @link [Kumar-Hassebrook Similarity algorithm](https://www.naun.org/main/NAUN/ijmmas/mmmas-49.pdf) diff --git a/src/similarities/motyka.ts b/src/similarities/motyka.ts index 7f6e768..cd8c26a 100644 --- a/src/similarities/motyka.ts +++ b/src/similarities/motyka.ts @@ -1,6 +1,6 @@ -import { NumberArray } from 'cheminfo-types'; +import type { NumberArray } from 'cheminfo-types'; -import { motyka as motykaD } from '../distances/motyka'; +import { motyka as motykaD } from '../distances/motyka.ts'; /** *Returns the Motyka similarity between vectors a and b * @link [Motyka algorithm](https://www.naun.org/main/NAUN/ijmmas/mmmas-49.pdf) diff --git a/src/similarities/pearson.ts b/src/similarities/pearson.ts index 5be093e..59d7e4c 100644 --- a/src/similarities/pearson.ts +++ b/src/similarities/pearson.ts @@ -1,8 +1,14 @@ -import { NumberArray } from 'cheminfo-types'; +import type { NumberArray } from 'cheminfo-types'; import mean from 'ml-array-mean'; -import { cosine } from './cosine'; +import { cosine } from './cosine.ts'; +/** + * Returns the Pearson correlation between vectors a and b, i.e. the cosine + * similarity of the mean-centred vectors + * @param a - first vector + * @param b - second vector + */ export function pearson(a: NumberArray, b: NumberArray): number { const avgA = mean(a); const avgB = mean(b); diff --git a/src/similarities/squaredChord.ts b/src/similarities/squaredChord.ts index 151d269..5bd131a 100644 --- a/src/similarities/squaredChord.ts +++ b/src/similarities/squaredChord.ts @@ -1,8 +1,8 @@ -import { NumberArray } from 'cheminfo-types'; +import type { NumberArray } from 'cheminfo-types'; -import { squaredChord as squaredChordD } from '../distances/squaredChord'; +import { squaredChord as squaredChordD } from '../distances/squaredChord.ts'; /** - *Returns the Squared-chord distance between vectors a and b + *Returns the Squared-chord similarity between vectors a and b * @link [Squared-chord algorithm](https://www.naun.org/main/NAUN/ijmmas/mmmas-49.pdf) * @param a - first vector * @param b - second vector diff --git a/src/similarities/tanimoto.ts b/src/similarities/tanimoto.ts index 2526ddd..371d1c8 100644 --- a/src/similarities/tanimoto.ts +++ b/src/similarities/tanimoto.ts @@ -1,4 +1,4 @@ -import { NumberArray } from 'cheminfo-types'; +import type { NumberArray } from 'cheminfo-types'; /** *Returns the Tanimoto similarity between vectors p and q, and accepts the bitVector use, see the test case for an example * @link [Tanimoto similarity algorithm](https://www.naun.org/main/NAUN/ijmmas/mmmas-49.pdf) diff --git a/tsconfig.build.json b/tsconfig.build.json new file mode 100644 index 0000000..d55545e --- /dev/null +++ b/tsconfig.build.json @@ -0,0 +1,8 @@ +{ + "extends": "./tsconfig.json", + "compilerOptions": { + "rootDir": "src" + }, + "include": ["src"], + "exclude": ["**/__tests__", "**/*.test.*"] +} diff --git a/tsconfig.cjs.json b/tsconfig.cjs.json deleted file mode 100644 index 3b9e100..0000000 --- a/tsconfig.cjs.json +++ /dev/null @@ -1,9 +0,0 @@ -{ - "extends": "./tsconfig.json", - "compilerOptions": { - "module": "commonjs", - "declaration": true, - "declarationMap": true - }, - "exclude": ["./src/**/__tests__"] -} diff --git a/tsconfig.esm.json b/tsconfig.esm.json deleted file mode 100644 index 050b45d..0000000 --- a/tsconfig.esm.json +++ /dev/null @@ -1,7 +0,0 @@ -{ - "extends": "./tsconfig.cjs.json", - "compilerOptions": { - "module": "es2020", - "outDir": "lib-esm" - } -} diff --git a/tsconfig.json b/tsconfig.json index 3a01755..4028baf 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -1,13 +1,10 @@ { + "extends": "@zakodium/tsconfig", "compilerOptions": { - "allowJs": true, - "esModuleInterop": true, - "moduleResolution": "node", - "skipLibCheck": true, + // the numeric loops index with a counter bounded by `length` + "noUncheckedIndexedAccess": false, "outDir": "lib", - "sourceMap": true, - "strict": true, - "target": "es2020" + "types": ["node"] }, - "include": ["./src/**/*"] + "include": ["src", "vite*.ts"] } diff --git a/vitest.config.ts b/vitest.config.ts new file mode 100644 index 0000000..e0e8ea4 --- /dev/null +++ b/vitest.config.ts @@ -0,0 +1,13 @@ +import { defineConfig } from 'vitest/config'; + +export default defineConfig({ + test: { + coverage: { + include: ['src/**/*.ts'], + provider: 'v8', + }, + snapshotFormat: { + maxOutputLength: Number.MAX_SAFE_INTEGER, + }, + }, +});