From 1339b0c3a45f2ae410d57cb99e69994c89447247 Mon Sep 17 00:00:00 2001 From: mantikoros Date: Sun, 8 May 2022 15:42:01 -0400 Subject: [PATCH] normpdf variance mislabeled --- common/calculate-dpm.ts | 6 ++++-- common/normal.ts | 9 ++++++--- 2 files changed, 10 insertions(+), 5 deletions(-) diff --git a/common/calculate-dpm.ts b/common/calculate-dpm.ts index 0b0961c3..908af4d2 100644 --- a/common/calculate-dpm.ts +++ b/common/calculate-dpm.ts @@ -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 diff --git a/common/normal.ts b/common/normal.ts index 3d21af4b..32010215 100644 --- a/common/normal.ts +++ b/common/normal.ts @@ -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