fixed up types and working on utils lib

This commit is contained in:
Boki 2025-06-19 09:47:57 -04:00
parent 25d9f2dd85
commit da75979574
17 changed files with 1093 additions and 901 deletions

View file

@ -65,7 +65,10 @@ export function pearsonCorrelation(x: number[], y: number[]): CorrelationResult
const n = x.length;
const sumX = x.reduce((a, b) => a + b, 0);
const sumY = y.reduce((a, b) => a + b, 0);
const sumXY = x.reduce((sum, xi, i) => sum + xi * y[i], 0);
const sumXY = x.reduce((sum, xi, i) => {
const yi = y[i];
return yi !== undefined ? sum + xi * yi : sum;
}, 0);
const sumX2 = x.reduce((sum, xi) => sum + xi * xi, 0);
const sumY2 = y.reduce((sum, yi) => sum + yi * yi, 0);
@ -127,13 +130,20 @@ export function kendallTau(x: number[], y: number[]): CorrelationResult {
for (let i = 0; i < n - 1; i++) {
for (let j = i + 1; j < n; j++) {
const xDiff = x[i] - x[j];
const yDiff = y[i] - y[j];
const xi = x[i];
const xj = x[j];
const yi = y[i];
const yj = y[j];
if (xi !== undefined && xj !== undefined && yi !== undefined && yj !== undefined) {
const xDiff = xi - xj;
const yDiff = yi - yj;
if (xDiff * yDiff > 0) {
concordant++;
} else if (xDiff * yDiff < 0) {
discordant++;
if (xDiff * yDiff > 0) {
concordant++;
} else if (xDiff * yDiff < 0) {
discordant++;
}
}
}
}