feat: Fix remaining scoring errors with Quinn
Value::0.3 to 0.9
This commit is contained in:
parent
4b1c226173
commit
93f5b4ba2a
|
@ -14,7 +14,7 @@ describe("WithScalarAnswer: discrete -> discrete -> float", () => {
|
||||||
let pointC = mkDelta(1.0)
|
let pointC = mkDelta(1.0)
|
||||||
let pointD = mkDelta(0.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' = [(pointA, 0.25), (pointB, 0.25), (pointC, 0.25), (pointD, 0.25)]->mixture->run
|
||||||
let prediction = switch prediction' {
|
let prediction = switch prediction' {
|
||||||
| Dist(PointSet(a'')) => a''
|
| 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' = [(pointA, 0.75), (pointB, 0.25)]->mixture->run
|
||||||
let prediction = switch prediction' {
|
let prediction = switch prediction' {
|
||||||
| Dist(PointSet(a'')) => a''
|
| 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 prior' = [(pointA, 0.5), (pointB, 0.5)]->mixture->run
|
||||||
let prediction' = [(pointA, 0.75), (pointB, 0.25)]->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", () => {
|
describe("WithScalarAnswer: discrete -> discrete -> float", () => {
|
||||||
})
|
})
|
||||||
|
|
|
@ -141,6 +141,7 @@ module WithScalarAnswer = {
|
||||||
} else if numerator == 0.0 || priorDensityOfAnswer == 0.0 {
|
} else if numerator == 0.0 || priorDensityOfAnswer == 0.0 {
|
||||||
infinity->Ok
|
infinity->Ok
|
||||||
} else {
|
} else {
|
||||||
|
//
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -161,7 +162,26 @@ module WithScalarAnswer = {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// For mixed discrete answer
|
||||||
|
// (prediction, answer) => sum(answer.map(a => a.probability * WithScalarAnswer.score(prediction, a.value)))
|
||||||
|
|
||||||
module TwoScalars = {
|
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) =>
|
let score = (~estimate: scalar, ~answer: scalar) =>
|
||||||
if answer == 0.0 {
|
if answer == 0.0 {
|
||||||
0.0->Ok
|
0.0->Ok
|
||||||
|
@ -179,6 +199,7 @@ module TwoScalars = {
|
||||||
} else {
|
} else {
|
||||||
minusScaledLogOfQuotient(~esti=estimate /. prior, ~answ=answer)
|
minusScaledLogOfQuotient(~esti=estimate /. prior, ~answ=answer)
|
||||||
}
|
}
|
||||||
|
*/
|
||||||
}
|
}
|
||||||
|
|
||||||
let twoGenericDistsToTwoPointSetDists = (~toPointSetFn, estimate, answer): result<
|
let twoGenericDistsToTwoPointSetDists = (~toPointSetFn, estimate, answer): result<
|
||||||
|
|
Loading…
Reference in New Issue
Block a user