mirror of
https://github.com/gnh1201/welsonjs.git
synced 2025-05-20 00:21:03 +00:00
Update extramath.js
This commit is contained in:
parent
21f3e7c2e7
commit
750a4f8f94
|
@ -26,25 +26,25 @@ function DTM() {
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
function cosineSim(A, B) {
|
function cos(A, B) {
|
||||||
var dotproduct = 0;
|
var dotproduct = 0;
|
||||||
var mA = 0;
|
var mA = 0;
|
||||||
var mB = 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]);
|
dotproduct += (A[i] * B[i]);
|
||||||
mA += (A[i] * A[i]);
|
mA += (A[i] * A[i]);
|
||||||
mB += (B[i] * B[i]);
|
mB += (B[i] * B[i]);
|
||||||
}
|
}
|
||||||
mA = Math.sqrt(mA);
|
mA = Math.sqrt(mA);
|
||||||
mB = Math.sqrt(mB);
|
mB = Math.sqrt(mB);
|
||||||
var similarity = (dotproduct) / ((mA)*(mB)) // here you needed extra brackets
|
var similarity = (dotproduct) / ((mA) * (mB))
|
||||||
return similarity;
|
return similarity;
|
||||||
}
|
}
|
||||||
|
|
||||||
exports.DTM = DTM;
|
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.AUTHOR = "catswords@protonmail.com";
|
||||||
exports.global = global;
|
exports.global = global;
|
||||||
exports.require = global.require;
|
exports.require = global.require;
|
||||||
|
|
Loading…
Reference in New Issue
Block a user