From acb0d3b9eeb0f61c1f912f75fdff214ad73be01d Mon Sep 17 00:00:00 2001 From: Quinn Dougherty Date: Sun, 26 Jun 2022 12:28:04 -0400 Subject: [PATCH] removed \`TwoScalars\` material --- .../Distributions/Scoring/TwoScalars_test.res | 90 ------------------- .../rescript/Distributions/GenericDist.res | 9 +- .../PointSetDist/PointSetDist_Scoring.res | 22 ----- 3 files changed, 1 insertion(+), 120 deletions(-) delete mode 100644 packages/squiggle-lang/__tests__/Distributions/Scoring/TwoScalars_test.res diff --git a/packages/squiggle-lang/__tests__/Distributions/Scoring/TwoScalars_test.res b/packages/squiggle-lang/__tests__/Distributions/Scoring/TwoScalars_test.res deleted file mode 100644 index a200212d..00000000 --- a/packages/squiggle-lang/__tests__/Distributions/Scoring/TwoScalars_test.res +++ /dev/null @@ -1,90 +0,0 @@ -open Jest -open Expect -open GenericDist_Fixtures -exception ScoreFailed - -describe("TwoScalars: scalar -> scalar -> score", () => { - test("score: infinity", () => { - let scalar1 = 1.0 // 100% of probability mass 1.0 - let scalar2 = 2.0 // 100% of probability mass to 2.0 - let score = PointSetDist_Scoring.TwoScalars.score(~estimate=scalar1, ~answer=scalar2) - switch score { - | Ok(x) => x->expect->toEqual(infinity) - | _ => raise(MixtureFailed) - } - }) - - test("score: 0.0", () => { - let scalar1 = 1.5 // 100% of probability mass 1.5 - let scalar2 = 1.5 // 100% of probability mass to 1.5 - let score = PointSetDist_Scoring.TwoScalars.score(~estimate=scalar1, ~answer=scalar2) - switch score { - | Ok(x) => x->expect->toEqual(0.0) - | _ => raise(MixtureFailed) - } - }) - - test("scoreWithPrior: minus infinity", () => { - let scalar1 = 1.5 // 100% of probability mass 1.5 - let scalar2 = 1.5 // 100% of probability mass to 1.5 - let scalar3 = 1.0 // 100% of probability mass to 1.0 - - let score = PointSetDist_Scoring.TwoScalars.scoreWithPrior( - ~estimate=scalar1, - ~answer=scalar2, - ~prior=scalar3, - ) - switch score { - | Ok(x) => x->expect->toEqual(-.infinity) - | _ => raise(MixtureFailed) - } - }) - - test("scoreWithPrior: 0.0", () => { - let scalar1 = 1.5 // 100% of probability mass 1.5 - let scalar2 = 1.5 // 100% of probability mass to 1.5 - let scalar3 = 1.5 // 100% of probability mass to 1.5 - - let score = PointSetDist_Scoring.TwoScalars.scoreWithPrior( - ~estimate=scalar1, - ~answer=scalar2, - ~prior=scalar3, - ) - switch score { - | Ok(x) => x->expect->toEqual(0.0) - | _ => raise(ScoreFailed) - } - }) - - test("scoreWithPrior: really dumb forecasters", () => { - let scalar1 = 1.0 // 100% of probability mass 1.0 - let scalar2 = 1.5 // 100% of probability mass to 1.5 - let scalar3 = 1.0 // 100% of probability mass to 1.0 - - let score = PointSetDist_Scoring.TwoScalars.scoreWithPrior( - ~estimate=scalar1, - ~answer=scalar2, - ~prior=scalar3, - ) - switch score { - | Ok(x) => x->expect->toEqual(infinity -. infinity) // "Error: Really dumb forecasters" - | _ => raise(ScoreFailed) - } - }) - - test("scoreWithPrior: 0.0", () => { - let scalar1 = 1.0 // 100% of probability mass 1.0 - let scalar2 = 1.0 // 100% of probability mass to 1.0 - let scalar3 = 1.0 // 100% of probability mass to 1.0 - - let score = PointSetDist_Scoring.TwoScalars.scoreWithPrior( - ~estimate=scalar1, - ~answer=scalar2, - ~prior=scalar3, - ) - switch score { - | Ok(x) => x->expect->toEqual(0.0) - | _ => raise(ScoreFailed) - } - }) -}) diff --git a/packages/squiggle-lang/src/rescript/Distributions/GenericDist.res b/packages/squiggle-lang/src/rescript/Distributions/GenericDist.res index b8aa680f..2c2108dd 100644 --- a/packages/squiggle-lang/src/rescript/Distributions/GenericDist.res +++ b/packages/squiggle-lang/src/rescript/Distributions/GenericDist.res @@ -190,14 +190,7 @@ module Score = { | (Score_Scalar(_), Score_Dist(_), None) => NotYetImplemented->Error | (Score_Scalar(_), Score_Dist(_), Some(Ok(PSScalar(_)))) => NotYetImplemented->Error | (Score_Scalar(_), _, Some(Ok(PSDist(_)))) => DistributionTypes.Unreachable->Error - | (Score_Scalar(esti'), Score_Scalar(answ'), None) => - {estimate: esti', answer: answ', prior: None} - ->PointSetDist_Scoring.ScalarEstimateScalarAnswer - ->Ok - | (Score_Scalar(esti'), Score_Scalar(answ'), Some(Ok(PSScalar(prior'')))) => - {estimate: esti', answer: answ', prior: prior''->Some} - ->PointSetDist_Scoring.ScalarEstimateScalarAnswer - ->Ok + | (Score_Scalar(_), Score_Scalar(_), _) => NotYetImplemented->Error | (_, _, Some(Error(err))) => err->Error } } diff --git a/packages/squiggle-lang/src/rescript/Distributions/PointSetDist/PointSetDist_Scoring.res b/packages/squiggle-lang/src/rescript/Distributions/PointSetDist/PointSetDist_Scoring.res index 56f67d17..b7806bfa 100644 --- a/packages/squiggle-lang/src/rescript/Distributions/PointSetDist/PointSetDist_Scoring.res +++ b/packages/squiggle-lang/src/rescript/Distributions/PointSetDist/PointSetDist_Scoring.res @@ -6,7 +6,6 @@ type abstractScoreArgs<'a, 'b> = {estimate: 'a, answer: 'b, prior: option<'a>} type scoreArgs = | DistEstimateDistAnswer(abstractScoreArgs) | DistEstimateScalarAnswer(abstractScoreArgs) - | ScalarEstimateScalarAnswer(abstractScoreArgs) let logFn = Js.Math.log // base e let minusScaledLogOfQuotient = (~esti, ~answ): result => { @@ -130,23 +129,6 @@ module WithScalarAnswer = { } } -module TwoScalars = { - // You will almost never want to use this. - let score = (~estimate: scalar, ~answer: scalar) => { - if Js.Math.abs_float(estimate -. answer) < MagicNumbers.Epsilon.ten { - 0.0->Ok - } else { - infinity->Ok // - log(0) - } - } - - let scoreWithPrior = (~estimate: scalar, ~answer: scalar, ~prior: scalar) => { - E.R.merge(score(~estimate, ~answer), score(~estimate=prior, ~answer))->E.R2.fmap(((s1, s2)) => - s1 -. s2 - ) // This will presently NaN if both are wrong: infinity-infinity. - } -} - let twoGenericDistsToTwoPointSetDists = (~toPointSetFn, estimate, answer): result< (pointSetDist, pointSetDist), 'e, @@ -165,8 +147,4 @@ let logScore = (args: scoreArgs, ~combineFn, ~integrateFn, ~toMixedFn): result< WithScalarAnswer.score(~estimate, ~answer) | DistEstimateScalarAnswer({estimate, answer, prior: Some(prior)}) => WithScalarAnswer.scoreWithPrior(~estimate, ~answer, ~prior) - | ScalarEstimateScalarAnswer({estimate, answer, prior: None}) => - TwoScalars.score(~estimate, ~answer) - | ScalarEstimateScalarAnswer({estimate, answer, prior: Some(prior)}) => - TwoScalars.scoreWithPrior(~estimate, ~answer, ~prior) }