merged 592
This commit is contained in:
parent
74fe0296e0
commit
18733f2d09
|
@ -146,7 +146,7 @@ let rec run = (~env, functionCallInfo: functionCallInfo): outputType => {
|
|||
}
|
||||
| ToDist(Normalize) => dist->GenericDist.normalize->Dist
|
||||
| ToScore(LogScore(answer, prior)) =>
|
||||
GenericDist.Score.logScore(~estimate=GDist(dist), ~answer, ~prior)
|
||||
GenericDist.Score.logScore(~estimate=Score_Dist(dist), ~answer, ~prior)
|
||||
->E.R2.fmap(s => Float(s))
|
||||
->OutputLocal.fromResult
|
||||
| ToBool(IsNormalized) => dist->GenericDist.isNormalized->Bool
|
||||
|
|
|
@ -92,7 +92,7 @@ module DistributionOperation = {
|
|||
| ToString
|
||||
| ToSparkline(int)
|
||||
|
||||
type genericDistOrScalar = GDist(genericDist) | GScalar(float)
|
||||
type genericDistOrScalar = Score_Dist(genericDist) | Score_Scalar(float)
|
||||
|
||||
type toScore = LogScore(genericDistOrScalar, option<genericDistOrScalar>)
|
||||
|
||||
|
@ -165,35 +165,35 @@ module Constructors = {
|
|||
let inspect = (dist): t => FromDist(ToDist(Inspect), dist)
|
||||
module LogScore = {
|
||||
let distEstimateDistAnswer = (estimate, answer): t => FromDist(
|
||||
ToScore(LogScore(GDist(answer), None)),
|
||||
ToScore(LogScore(Score_Dist(answer), None)),
|
||||
estimate,
|
||||
)
|
||||
let distEstimateDistAnswerWithPrior = (estimate, answer, prior): t => FromDist(
|
||||
ToScore(LogScore(GDist(answer), Some(prior))),
|
||||
ToScore(LogScore(Score_Dist(answer), Some(prior))),
|
||||
estimate,
|
||||
)
|
||||
let distEstimateScalarAnswer = (estimate, answer): t => FromDist(
|
||||
ToScore(LogScore(GScalar(answer), None)),
|
||||
ToScore(LogScore(Score_Scalar(answer), None)),
|
||||
estimate,
|
||||
)
|
||||
let distEstimateScalarAnswerWithPrior = (estimate, answer, prior): t => FromDist(
|
||||
ToScore(LogScore(GScalar(answer), Some(prior))),
|
||||
ToScore(LogScore(Score_Scalar(answer), Some(prior))),
|
||||
estimate,
|
||||
)
|
||||
let scalarEstimateDistAnswer = (estimate, answer): t => FromFloat(
|
||||
ToScore(LogScore(GDist(answer), None)),
|
||||
ToScore(LogScore(Score_Dist(answer), None)),
|
||||
estimate,
|
||||
)
|
||||
let scalarEstimateDistAnswerWithPrior = (estimate, answer, prior): t => FromFloat(
|
||||
ToScore(LogScore(GDist(answer), Some(prior))),
|
||||
ToScore(LogScore(Score_Dist(answer), Some(prior))),
|
||||
estimate,
|
||||
)
|
||||
let scalarEstimateScalarAnswer = (estimate, answer): t => FromFloat(
|
||||
ToScore(LogScore(GScalar(answer), None)),
|
||||
ToScore(LogScore(Score_Scalar(answer), None)),
|
||||
estimate,
|
||||
)
|
||||
let scalarEstimateScalarAnswerWithPrior = (estimate, answer, prior): t => FromFloat(
|
||||
ToScore(LogScore(GScalar(answer), Some(prior))),
|
||||
ToScore(LogScore(Score_Scalar(answer), Some(prior))),
|
||||
estimate,
|
||||
)
|
||||
}
|
||||
|
|
|
@ -121,31 +121,13 @@ let toPointSet = (
|
|||
|
||||
module Score = {
|
||||
type genericDistOrScalar = DistributionTypes.DistributionOperation.genericDistOrScalar
|
||||
type psDistOrScalar = PSDist(PointSetTypes.pointSetDist) | PSScalar(float)
|
||||
type pointSet_ScoreDistOrScalar = PSDist(PointSetTypes.pointSetDist) | PSScalar(float)
|
||||
|
||||
let argsMake = (
|
||||
~esti: genericDistOrScalar,
|
||||
~answ: genericDistOrScalar,
|
||||
~prior: option<genericDistOrScalar>,
|
||||
): result<PointSetDist_Scoring.scoreArgs, error> => {
|
||||
// <<<<<<< HEAD
|
||||
// let toPointSetFn = toPointSet(
|
||||
// ~xyPointLength=MagicNumbers.Environment.defaultXYPointLength,
|
||||
// ~sampleCount=MagicNumbers.Environment.defaultSampleCount,
|
||||
// ~xSelection=#ByWeight,
|
||||
// )
|
||||
// let twoDists = PointSetDist_Scoring.twoGenericDistsToTwoPointSetDists
|
||||
// let prior': option<result<psDistOrScalar, error>> = switch prior {
|
||||
// | None => None
|
||||
// | Some(GDist(d)) => toPointSetFn(d, ())->E.R2.fmap(x => x->PSDist)->Some
|
||||
// | Some(GScalar(s)) => s->PSScalar->Ok->Some
|
||||
// }
|
||||
// switch (esti, answ, prior') {
|
||||
// | (GDist(esti'), GDist(answ'), None) =>
|
||||
// twoDists(~toPointSetFn, esti', answ')->E.R2.fmap(((esti'', answ'')) =>
|
||||
// {estimate: esti'', answer: answ'', prior: None}
|
||||
// ->PointSetDist_Scoring.DistEstimateDistAnswer
|
||||
// =======
|
||||
let toPointSetFn = t =>
|
||||
toPointSet(
|
||||
t,
|
||||
|
@ -156,52 +138,53 @@ module Score = {
|
|||
)
|
||||
let prior': option<result<pointSet_ScoreDistOrScalar, error>> = switch prior {
|
||||
| None => None
|
||||
| Some(Score_Dist(d)) => toPointSetFn(d)->E.R.bind(x => x->D->Ok)->Some
|
||||
| Some(Score_Scalar(s)) => s->S->Ok->Some
|
||||
| Some(Score_Dist(d)) => toPointSetFn(d)->E.R.bind(x => x->PSDist->Ok)->Some
|
||||
| Some(Score_Scalar(s)) => s->PSScalar->Ok->Some
|
||||
}
|
||||
let twoDists = (esti': t, answ': t): result<
|
||||
let twoDists = (~toPointSetFn, esti': t, answ': t): result<
|
||||
(PointSetTypes.pointSetDist, PointSetTypes.pointSetDist),
|
||||
error,
|
||||
> => E.R.merge(toPointSetFn(esti'), toPointSetFn(answ'))
|
||||
switch (esti, answ, prior') {
|
||||
| (Score_Dist(esti'), Score_Dist(answ'), None) =>
|
||||
twoDists(esti', answ')->E.R2.fmap(((esti'', answ'')) =>
|
||||
twoDists(~toPointSetFn, esti', answ')->E.R2.fmap(((esti'', answ'')) =>
|
||||
{estimate: esti'', answer: answ'', prior: None}->PointSetDist_Scoring.DistEstimateDistAnswer
|
||||
// >>>>>>> origin/scoring-cleanup-refactor
|
||||
)
|
||||
| (GDist(esti'), GDist(answ'), Some(Ok(PSDist(prior'')))) =>
|
||||
| (Score_Dist(esti'), Score_Dist(answ'), Some(Ok(PSDist(prior'')))) =>
|
||||
twoDists(~toPointSetFn, esti', answ')->E.R2.fmap(((esti'', answ'')) =>
|
||||
{estimate: esti'', answer: answ'', prior: Some(prior'')}
|
||||
->PointSetDist_Scoring.DistEstimateDistAnswer
|
||||
)
|
||||
| (Score_Dist(_), _, Some(Ok(S(_)))) => DistributionTypes.Unreachable->Error
|
||||
| (Score_Dist(_), _, Some(Ok(PSScalar(_)))) => DistributionTypes.Unreachable->Error
|
||||
| (Score_Dist(esti'), Score_Scalar(answ'), None) =>
|
||||
toPointSetFn(esti')->E.R.bind(esti'' =>
|
||||
{estimate: esti'', answer: answ', prior: None}
|
||||
->PointSetDist_Scoring.DistEstimateScalarAnswer
|
||||
->Ok
|
||||
)
|
||||
| (Score_Dist(esti'), Score_Scalar(answ'), Some(Ok(D(prior'')))) =>
|
||||
| (Score_Dist(esti'), Score_Scalar(answ'), Some(Ok(PSDist(prior'')))) =>
|
||||
toPointSetFn(esti')->E.R.bind(esti'' =>
|
||||
{estimate: esti'', answer: answ', prior: Some(prior'')}
|
||||
->PointSetDist_Scoring.DistEstimateScalarAnswer
|
||||
-> Ok
|
||||
)
|
||||
| (Score_Scalar(esti'), Score_Dist(answ'), None) =>
|
||||
toPointSetFn(answ')->E.R.bind(answ'' =>
|
||||
{estimate: esti', answer: answ'', prior: None}
|
||||
->PointSetDist_Scoring.ScalarEstimateDistAnswer
|
||||
-> Ok
|
||||
)
|
||||
| (Score_Scalar(esti'), Score_Dist(answ'), Some(Ok(S(prior'')))) =>
|
||||
| (Score_Scalar(esti'), Score_Dist(answ'), Some(Ok(PSScalar(prior'')))) =>
|
||||
toPointSetFn(answ')->E.R.bind(answ'' =>
|
||||
{estimate: esti', answer: answ'', prior: Some(prior'')}
|
||||
->PointSetDist_Scoring.ScalarEstimateDistAnswer
|
||||
->PointSetDist_Scoring.ScalarEstimateDistAnswer->Ok
|
||||
)
|
||||
| (GScalar(_), _, Some(Ok(PSDist(_)))) => DistributionTypes.Unreachable->Error
|
||||
| (GScalar(esti'), GScalar(answ'), None) =>
|
||||
| (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
|
||||
| (GScalar(esti'), GScalar(answ'), Some(Ok(PSScalar(prior'')))) =>
|
||||
| (Score_Scalar(esti'), Score_Scalar(answ'), Some(Ok(PSScalar(prior'')))) =>
|
||||
{estimate: esti', answer: answ', prior: prior''->Some}
|
||||
->PointSetDist_Scoring.ScalarEstimateScalarAnswer
|
||||
->Ok
|
||||
|
|
|
@ -132,7 +132,7 @@ module WithScalarAnswer = {
|
|||
} else if numerator == 0.0 || priorDensityOfAnswer == 0.0 {
|
||||
infinity->Ok
|
||||
} else {
|
||||
minusScaledLogOfQuot(~esti=numerator, ~answ=priorDensityOfAnswer)
|
||||
minusScaledLogOfQuotient(~esti=numerator, ~answ=priorDensityOfAnswer)
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -172,7 +172,7 @@ module TwoScalars = {
|
|||
}
|
||||
}
|
||||
|
||||
let twoGenericDistsToTwoPointSetDists = (~toPointSetFn, estimate, answer): result<(t, t), 'e> =>
|
||||
let twoGenericDistsToTwoPointSetDists = (~toPointSetFn, estimate, answer): result<(pointSetDist, pointSetDist), 'e> =>
|
||||
E.R.merge(toPointSetFn(estimate, ()), toPointSetFn(answer, ()))
|
||||
|
||||
let logScore = (args: scoreArgs, ~combineFn, ~integrateFn, ~toMixedFn): result<
|
||||
|
|
|
@ -214,12 +214,12 @@ let dispatchToGenericOutput = (
|
|||
| ("normalize", [EvDistribution(dist)]) => Helpers.toDistFn(Normalize, dist, ~env)
|
||||
| ("klDivergence", [EvDistribution(estimate), EvDistribution(answer)]) =>
|
||||
Some(
|
||||
DistributionOperation.run(FromDist(ToScore(LogScore(GDist(answer), None)), estimate), ~env),
|
||||
DistributionOperation.run(FromDist(ToScore(LogScore(Score_Dist(answer), None)), estimate), ~env),
|
||||
)
|
||||
| ("klDivergence", [EvDistribution(estimate), EvDistribution(answer), EvDistribution(prior)]) =>
|
||||
Some(
|
||||
DistributionOperation.run(
|
||||
FromDist(ToScore(LogScore(GDist(answer), Some(GDist(prior)))), estimate),
|
||||
FromDist(ToScore(LogScore(Score_Dist(answer), Some(Score_Dist(prior)))), estimate),
|
||||
~env,
|
||||
),
|
||||
)
|
||||
|
|
Loading…
Reference in New Issue
Block a user