manifold/common/normal.ts
2022-05-06 15:39:02 -04:00

10 lines
223 B
TypeScript

export function normpdf(x: number, mean = 0, std = 1) {
if (std === 0) {
return x === mean ? Infinity : 0
}
return Math.exp((-0.5 * Math.pow(x - mean, 2)) / std) / Math.sqrt(TAU * std)
}
const TAU = Math.PI * 2