feat: Fix remaining scoring errors with Quinn

Value::0.3 to 0.9
This commit is contained in:
NunoSempere 2022-06-20 16:39:48 -04:00
parent 4b1c226173
commit 93f5b4ba2a
2 changed files with 111 additions and 6 deletions

View File

@ -14,7 +14,7 @@ describe("WithScalarAnswer: discrete -> discrete -> float", () => {
let pointC = mkDelta(1.0)
let pointD = mkDelta(0.0)
test("score: agrees with analytical answer when finite", () => {
test("WithScalarAnswer.score: agrees with analytical answer when finite", () => {
let prediction' = [(pointA, 0.25), (pointB, 0.25), (pointC, 0.25), (pointD, 0.25)]->mixture->run
let prediction = switch prediction' {
| Dist(PointSet(a'')) => a''
@ -29,7 +29,7 @@ describe("WithScalarAnswer: discrete -> discrete -> float", () => {
}
})
test("score: agrees with analytical answer when finite", () => {
test("WithScalarAnswer.score: agrees with analytical answer when finite", () => {
let prediction' = [(pointA, 0.75), (pointB, 0.25)]->mixture->run
let prediction = switch prediction' {
| Dist(PointSet(a'')) => a''
@ -43,7 +43,7 @@ describe("WithScalarAnswer: discrete -> discrete -> float", () => {
}
})
test("scoreWithPrior: ", () => {
test("WithScalarAnswer.scoreWithPrior: ", () => {
let prior' = [(pointA, 0.5), (pointB, 0.5)]->mixture->run
let prediction' = [(pointA, 0.75), (pointB, 0.25)]->mixture->run
@ -70,7 +70,91 @@ describe("WithScalarAnswer: discrete -> discrete -> float", () => {
})
})
// WithDistAnswer
describe("TwoScalars: float -> float -> float", () => {
test("TwoScalars.score: ", () => {
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("TwoScalars.score: ", () => {
let scalar1 = 1.5 // 100% of probability mass 1.0
let scalar2 = 1.5 // 100% of probability mass to 2.0
let score = PointSetDist_Scoring.TwoScalars.score(~estimate=scalar1, ~answer=scalar2)
switch score {
| Ok(x) => x->expect->toEqual(0.0)
| _ => raise(MixtureFailed)
}
})
test("TwoScalars.scoreWithPrior: ", () => {
let scalar1 = 1.5 // 100% of probability mass 1.0
let scalar2 = 1.5 // 100% of probability mass to 2.0
let scalar3 = 1.0 // 100% of probability mass to 2.0
let score = PointSetDist_Scoring.TwoScalars.scoreWithPrior(
~estimate=scalar1,
~answer=scalar2,
~prior=scalar3,
)
switch score {
| Ok(x) => x->expect->toEqual(-.infinity)
| _ => raise(MixtureFailed)
}
})
test("TwoScalars.scoreWithPrior: ", () => {
let scalar1 = 1.5 // 100% of probability mass 1.0
let scalar2 = 1.5 // 100% of probability mass to 2.0
let scalar3 = 1.5 // 100% of probability mass to 2.0
let score = PointSetDist_Scoring.TwoScalars.scoreWithPrior(
~estimate=scalar1,
~answer=scalar2,
~prior=scalar3,
)
switch score {
| Ok(x) => x->expect->toEqual(0.0)
| _ => raise(MixtureFailed)
}
})
test("TwoScalars.scoreWithPrior: ", () => {
let scalar1 = 1.0 // 100% of probability mass 1.0
let scalar2 = 1.5 // 100% of probability mass to 2.0
let scalar3 = 1.0 // 100% of probability mass to 2.0
let score = PointSetDist_Scoring.TwoScalars.scoreWithPrior(
~estimate=scalar1,
~answer=scalar2,
~prior=scalar3,
)
switch score {
| Ok(x) => x->expect->toEqual("Error: Really dumb forecasters") // unclear what this case should give; could be smth else, or undefined
| _ => raise(MixtureFailed)
}
})
test("TwoScalars.scoreWithPrior: ", () => {
let scalar1 = 1.0 // 100% of probability mass 1.0
let scalar2 = 1.0 // 100% of probability mass to 2.0
let scalar3 = 1.0 // 100% of probability mass to 2.0
let score = PointSetDist_Scoring.TwoScalars.scoreWithPrior(
~estimate=scalar1,
~answer=scalar2,
~prior=scalar3,
)
switch score {
| Ok(x) => x->expect->toEqual(0.0)
| _ => raise(MixtureFailed)
}
})
})
/*
describe("WithScalarAnswer: discrete -> discrete -> float", () => {
})

View File

@ -129,7 +129,7 @@ module WithScalarAnswer = {
s1 -. s2
)
/*
let _scoreWithPrior = (
let _scoreWithPrior = (
~estimatePdf: float => float,
~answer: scalar,
~priorPdf: float => float,
@ -141,6 +141,7 @@ module WithScalarAnswer = {
} else if numerator == 0.0 || priorDensityOfAnswer == 0.0 {
infinity->Ok
} else {
//
}
}
@ -157,11 +158,30 @@ module WithScalarAnswer = {
| Mixed(prio) => Mixed.T.xToY(x, prio)->sum
}
_scoreWithPrior(~estimatePdf, ~answer, ~priorPdf)
*/
*/
}
}
// For mixed discrete answer
// (prediction, answer) => sum(answer.map(a => a.probability * WithScalarAnswer.score(prediction, a.value)))
module TwoScalars = {
// You will almost never want to use this.
let score = (~estimate: scalar, ~answer: scalar) => {
if estimate == answer {
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
)
// unclear what this should give if both are wrong: infinity-infinity. Maybe some warning??
}
/*
let score = (~estimate: scalar, ~answer: scalar) =>
if answer == 0.0 {
0.0->Ok
@ -179,6 +199,7 @@ module TwoScalars = {
} else {
minusScaledLogOfQuotient(~esti=estimate /. prior, ~answ=answer)
}
*/
}
let twoGenericDistsToTwoPointSetDists = (~toPointSetFn, estimate, answer): result<