1.0.4 • Published 2 years ago

calculate-cos-distance v1.0.4

Weekly downloads
-
License
MIT
Repository
github
Last release
2 years ago

calculate-cos-distance-js

This little package will help you calculate cos distance between two vectors.

npm i calculate-cos-distance

Usage

cosDistance(vector1, vector2 [, precision])

Calculates distance between vector1 and vector2, both of them must be arrays of the same length

precision is the argument that defines precision of returned number (default = 5)

const { cosDistance } = require("calculate-cos-distance");

console.log(cosDistance([1, 2, 3], [3, 2, 1])) // 0.71428;
console.log(cosDistance([10, -2, 3], [4, 10.23, 1])) // 0.19947;
console.log(cosDistance([10, -2, 3], [4, 10.23, 1], 10)) // 0.1994690265;

or

import { cosDistance } from "calculate-cos-distance";

console.log(cosDistance([1, 2, 3], [3, 2, 1])) // 0.71428;
console.log(cosDistance([10, -2, 3], [4, 10.23, 1])) // 0.19947;
console.log(cosDistance([10, -2, 3], [4, 10.23, 1], 10)) // 0.1994690265;

API

You can use functions that is implemented in lhis library:

dotProduct(vector1, vector2) will calculate dot product of two vectors vectorLen(vector) will calculate vector length of passed vector

const { dotProduct, vectorLen } = require("calculate-cos-distance");

dotProduct([1, 2, 3], [3, 2, 1]);
vectorLen([1, 2, 3]);
1.0.4

2 years ago

1.0.3

2 years ago

1.0.2

2 years ago

1.0.1

2 years ago

1.0.0

2 years ago