Update extramath.js

This commit is contained in:
Namhyeon Go 2022-11-06 21:41:10 +09:00 committed by GitHub
parent 21f3e7c2e7
commit 750a4f8f94
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -26,25 +26,25 @@ function DTM() {
};
}
function cosineSim(A, B) {
function cos(A, B) {
var dotproduct = 0;
var mA = 0;
var mB = 0;
for (i = 0; i < A.length; i++) { // here you missed the i++
for (i = 0; i < A.length; i++) {
dotproduct += (A[i] * B[i]);
mA += (A[i] * A[i]);
mB += (B[i] * B[i]);
}
mA = Math.sqrt(mA);
mB = Math.sqrt(mB);
var similarity = (dotproduct) / ((mA)*(mB)) // here you needed extra brackets
var similarity = (dotproduct) / ((mA) * (mB))
return similarity;
}
exports.DTM = DTM;
exports.cosineSim = cosineSim;
exports.cos = cos;
exports.VERSIONINFO = "ExtraMath module (extramath.js) version 0.0.1";
exports.VERSIONINFO = "ExtraMath module (extramath.js) version 0.0.2";
exports.AUTHOR = "catswords@protonmail.com";
exports.global = global;
exports.require = global.require;