-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathmath.ts
31 lines (25 loc) · 1006 Bytes
/
math.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
export function SIGMOID_3PL(z: number, steepness = 1, midpoint = 0, supremum = 1) {
return supremum / (1 + Math.exp(-steepness * (z - midpoint)))
}
export function LOGIT_3PL(z: number, steepness = 1, midpoint = 0, supremum = 1) {
// return Math.log(z / (1 - z))
return -1 * steepness ** -1 * Math.log(supremum / z - 1) + midpoint
}
export function roundNumber(num: number, decimalPlaces: number | null | undefined = 2): number {
if (decimalPlaces === undefined || decimalPlaces === null || decimalPlaces < 0) return num
return Number(num.toFixed(decimalPlaces))
}
export function cartesian(...args: any[][]): any[][] {
const r: any[][] = []
const max = args.length - 1
function helper(arr: any[], i: number) {
for (let j = 0, l = args[i]!.length; j < l; j++) {
const a = arr.slice(0) // clone arr
a.push(args[i]![j])
if (i == max) r.push(a)
else helper(a, i + 1)
}
}
helper([], 0)
return r
}