Skip to content
This repository has been archived by the owner on Mar 27, 2024. It is now read-only.

Commit

Permalink
Merge pull request #173 from AirGrid/release/v0.0.0-dev.40
Browse files Browse the repository at this point in the history
release: v0.0.0-dev.40 to MASTER
  • Loading branch information
ydennisy authored Feb 18, 2022
2 parents 2348f7e + 830f69e commit 7653842
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 10 deletions.
4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@airgrid/edgekit",
"version": "0.0.0-dev.39",
"version": "0.0.0-dev.40",
"homepage": "https://edgekit.org/",
"author": "AirGrid <https://airgrid.io>",
"license": "MIT",
Expand Down
23 changes: 16 additions & 7 deletions src/engine/filters/math.ts
Original file line number Diff line number Diff line change
@@ -1,19 +1,28 @@
export const dotProduct = (vectorA: number[], vectorB: number[]): number => {
return vectorA.reduce((acc, cur, idx) => acc + cur * vectorB[idx], 0);
};

const euclideanLength = (vector: number[]): number => {
return Math.sqrt(vector.reduce((acc, cur) => acc + Math.pow(cur, 2), 0));
};

const cosineScaler = (x: number): number => {
const MAX = 0.9;
const MIN = -0.5;
const scaled = (x - MIN) / (MAX - MIN);
if (scaled >= 1) return 1;
if (scaled <= 0) return 0;
return scaled;
};

export const dotProduct = (vectorA: number[], vectorB: number[]): number => {
return vectorA.reduce((acc, cur, idx) => acc + cur * vectorB[idx], 0);
};

export const cosineSimilarity = (
vectorA: number[],
vectorB: number[]
): number => {
return (
const cosineSim =
dotProduct(vectorA, vectorB) /
(euclideanLength(vectorA) * euclideanLength(vectorB))
);
(euclideanLength(vectorA) * euclideanLength(vectorB));
return cosineScaler(cosineSim);
};

export const sigmoid = (z: number): number => {
Expand Down

0 comments on commit 7653842

Please sign in to comment.