normpdf variance mislabeled

This commit is contained in:
mantikoros 2022-05-08 15:42:01 -04:00
parent 3658c6eee0
commit 1339b0c3a4
2 changed files with 10 additions and 5 deletions

View File

@ -38,7 +38,7 @@ export function getNumericBets(
contract: NumericContract,
bucket: string,
betAmount: number,
std = 0.01
variance = 0.01
) {
const { bucketCount } = contract
const bucketNumber = parseInt(bucket)
@ -46,7 +46,9 @@ export function getNumericBets(
const mean = bucketNumber / bucketCount
const allDensities = buckets.map((i) => normpdf(i / bucketCount, mean, std))
const allDensities = buckets.map((i) =>
normpdf(i / bucketCount, mean, variance)
)
const densitySum = _.sum(allDensities)
const rawBetAmounts = allDensities

View File

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