linting
This commit is contained in:
parent
597c6efc9b
commit
8b5e06954a
26 changed files with 532 additions and 186 deletions
|
|
@ -918,7 +918,9 @@ function shuffleArray<T>(array: T[]): T[] {
|
|||
* Helper function to calculate the average of an array of numbers
|
||||
*/
|
||||
function average(arr: number[]): number {
|
||||
if (arr.length === 0) {return 0;}
|
||||
if (arr.length === 0) {
|
||||
return 0;
|
||||
}
|
||||
return arr.reduce((a, b) => a + b, 0) / arr.length;
|
||||
}
|
||||
|
||||
|
|
@ -963,8 +965,12 @@ function erf(x: number): number {
|
|||
|
||||
function betaIncomplete(a: number, b: number, x: number): number {
|
||||
// Better approximation of incomplete beta function
|
||||
if (x === 0) {return 0;}
|
||||
if (x === 1) {return 1;}
|
||||
if (x === 0) {
|
||||
return 0;
|
||||
}
|
||||
if (x === 1) {
|
||||
return 1;
|
||||
}
|
||||
|
||||
// Use continued fraction approximation (Lentz's algorithm)
|
||||
const fpmin = 1e-30;
|
||||
|
|
@ -984,7 +990,9 @@ function betaIncomplete(a: number, b: number, x: number): number {
|
|||
function betaContinuedFraction(a: number, b: number, x: number): number {
|
||||
let c = 1;
|
||||
let d = 1 - ((a + b) * x) / (a + 1);
|
||||
if (Math.abs(d) < fpmin) {d = fpmin;}
|
||||
if (Math.abs(d) < fpmin) {
|
||||
d = fpmin;
|
||||
}
|
||||
d = 1 / d;
|
||||
let h = d;
|
||||
|
||||
|
|
@ -992,22 +1000,32 @@ function betaIncomplete(a: number, b: number, x: number): number {
|
|||
const m2 = 2 * m;
|
||||
const aa = (m * (b - m) * x) / ((a + m2 - 1) * (a + m2));
|
||||
d = 1 + aa * d;
|
||||
if (Math.abs(d) < fpmin) {d = fpmin;}
|
||||
if (Math.abs(d) < fpmin) {
|
||||
d = fpmin;
|
||||
}
|
||||
c = 1 + aa / c;
|
||||
if (Math.abs(c) < fpmin) {c = fpmin;}
|
||||
if (Math.abs(c) < fpmin) {
|
||||
c = fpmin;
|
||||
}
|
||||
d = 1 / d;
|
||||
h *= d * c;
|
||||
|
||||
const bb = (-(a + m) * (a + b + m) * x) / ((a + m2) * (a + m2 + 1));
|
||||
d = 1 + bb * d;
|
||||
if (Math.abs(d) < fpmin) {d = fpmin;}
|
||||
if (Math.abs(d) < fpmin) {
|
||||
d = fpmin;
|
||||
}
|
||||
c = 1 + bb / c;
|
||||
if (Math.abs(c) < fpmin) {c = fpmin;}
|
||||
if (Math.abs(c) < fpmin) {
|
||||
c = fpmin;
|
||||
}
|
||||
d = 1 / d;
|
||||
const del = d * c;
|
||||
h *= del;
|
||||
|
||||
if (Math.abs(del - 1) < eps) {break;}
|
||||
if (Math.abs(del - 1) < eps) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
return h;
|
||||
|
|
@ -1055,11 +1073,15 @@ function eigenDecomposition(matrix: number[][]): {
|
|||
const newLambda = Av.reduce((sum, val, i) => sum + val * v[i], 0);
|
||||
const norm = Math.sqrt(Av.reduce((sum, val) => sum + val * val, 0));
|
||||
|
||||
if (norm === 0) {break;}
|
||||
if (norm === 0) {
|
||||
break;
|
||||
}
|
||||
|
||||
v = Av.map(val => val / norm);
|
||||
|
||||
if (Math.abs(newLambda - lambda) < 1e-10) {break;}
|
||||
if (Math.abs(newLambda - lambda) < 1e-10) {
|
||||
break;
|
||||
}
|
||||
lambda = newLambda;
|
||||
}
|
||||
|
||||
|
|
@ -1215,8 +1237,12 @@ function arModel(y: number[], lag: number): { rss: number } {
|
|||
|
||||
function fCDF(f: number, df1: number, df2: number): number {
|
||||
// Approximation for F distribution CDF
|
||||
if (f <= 0) {return 0;}
|
||||
if (f === Infinity) {return 1;}
|
||||
if (f <= 0) {
|
||||
return 0;
|
||||
}
|
||||
if (f === Infinity) {
|
||||
return 1;
|
||||
}
|
||||
|
||||
const x = df2 / (df2 + df1 * f);
|
||||
return 1 - betaIncomplete(df2 / 2, df1 / 2, x);
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue