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
|
| ToDist(Normalize) => dist->GenericDist.normalize->Dist
|
||||||
| ToScore(LogScore(answer, prior)) =>
|
| 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))
|
->E.R2.fmap(s => Float(s))
|
||||||
->OutputLocal.fromResult
|
->OutputLocal.fromResult
|
||||||
| ToBool(IsNormalized) => dist->GenericDist.isNormalized->Bool
|
| ToBool(IsNormalized) => dist->GenericDist.isNormalized->Bool
|
||||||
|
|
|
@ -92,7 +92,7 @@ module DistributionOperation = {
|
||||||
| ToString
|
| ToString
|
||||||
| ToSparkline(int)
|
| ToSparkline(int)
|
||||||
|
|
||||||
type genericDistOrScalar = GDist(genericDist) | GScalar(float)
|
type genericDistOrScalar = Score_Dist(genericDist) | Score_Scalar(float)
|
||||||
|
|
||||||
type toScore = LogScore(genericDistOrScalar, option<genericDistOrScalar>)
|
type toScore = LogScore(genericDistOrScalar, option<genericDistOrScalar>)
|
||||||
|
|
||||||
|
@ -165,35 +165,35 @@ module Constructors = {
|
||||||
let inspect = (dist): t => FromDist(ToDist(Inspect), dist)
|
let inspect = (dist): t => FromDist(ToDist(Inspect), dist)
|
||||||
module LogScore = {
|
module LogScore = {
|
||||||
let distEstimateDistAnswer = (estimate, answer): t => FromDist(
|
let distEstimateDistAnswer = (estimate, answer): t => FromDist(
|
||||||
ToScore(LogScore(GDist(answer), None)),
|
ToScore(LogScore(Score_Dist(answer), None)),
|
||||||
estimate,
|
estimate,
|
||||||
)
|
)
|
||||||
let distEstimateDistAnswerWithPrior = (estimate, answer, prior): t => FromDist(
|
let distEstimateDistAnswerWithPrior = (estimate, answer, prior): t => FromDist(
|
||||||
ToScore(LogScore(GDist(answer), Some(prior))),
|
ToScore(LogScore(Score_Dist(answer), Some(prior))),
|
||||||
estimate,
|
estimate,
|
||||||
)
|
)
|
||||||
let distEstimateScalarAnswer = (estimate, answer): t => FromDist(
|
let distEstimateScalarAnswer = (estimate, answer): t => FromDist(
|
||||||
ToScore(LogScore(GScalar(answer), None)),
|
ToScore(LogScore(Score_Scalar(answer), None)),
|
||||||
estimate,
|
estimate,
|
||||||
)
|
)
|
||||||
let distEstimateScalarAnswerWithPrior = (estimate, answer, prior): t => FromDist(
|
let distEstimateScalarAnswerWithPrior = (estimate, answer, prior): t => FromDist(
|
||||||
ToScore(LogScore(GScalar(answer), Some(prior))),
|
ToScore(LogScore(Score_Scalar(answer), Some(prior))),
|
||||||
estimate,
|
estimate,
|
||||||
)
|
)
|
||||||
let scalarEstimateDistAnswer = (estimate, answer): t => FromFloat(
|
let scalarEstimateDistAnswer = (estimate, answer): t => FromFloat(
|
||||||
ToScore(LogScore(GDist(answer), None)),
|
ToScore(LogScore(Score_Dist(answer), None)),
|
||||||
estimate,
|
estimate,
|
||||||
)
|
)
|
||||||
let scalarEstimateDistAnswerWithPrior = (estimate, answer, prior): t => FromFloat(
|
let scalarEstimateDistAnswerWithPrior = (estimate, answer, prior): t => FromFloat(
|
||||||
ToScore(LogScore(GDist(answer), Some(prior))),
|
ToScore(LogScore(Score_Dist(answer), Some(prior))),
|
||||||
estimate,
|
estimate,
|
||||||
)
|
)
|
||||||
let scalarEstimateScalarAnswer = (estimate, answer): t => FromFloat(
|
let scalarEstimateScalarAnswer = (estimate, answer): t => FromFloat(
|
||||||
ToScore(LogScore(GScalar(answer), None)),
|
ToScore(LogScore(Score_Scalar(answer), None)),
|
||||||
estimate,
|
estimate,
|
||||||
)
|
)
|
||||||
let scalarEstimateScalarAnswerWithPrior = (estimate, answer, prior): t => FromFloat(
|
let scalarEstimateScalarAnswerWithPrior = (estimate, answer, prior): t => FromFloat(
|
||||||
ToScore(LogScore(GScalar(answer), Some(prior))),
|
ToScore(LogScore(Score_Scalar(answer), Some(prior))),
|
||||||
estimate,
|
estimate,
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
|
@ -121,31 +121,13 @@ let toPointSet = (
|
||||||
|
|
||||||
module Score = {
|
module Score = {
|
||||||
type genericDistOrScalar = DistributionTypes.DistributionOperation.genericDistOrScalar
|
type genericDistOrScalar = DistributionTypes.DistributionOperation.genericDistOrScalar
|
||||||
type psDistOrScalar = PSDist(PointSetTypes.pointSetDist) | PSScalar(float)
|
type pointSet_ScoreDistOrScalar = PSDist(PointSetTypes.pointSetDist) | PSScalar(float)
|
||||||
|
|
||||||
let argsMake = (
|
let argsMake = (
|
||||||
~esti: genericDistOrScalar,
|
~esti: genericDistOrScalar,
|
||||||
~answ: genericDistOrScalar,
|
~answ: genericDistOrScalar,
|
||||||
~prior: option<genericDistOrScalar>,
|
~prior: option<genericDistOrScalar>,
|
||||||
): result<PointSetDist_Scoring.scoreArgs, error> => {
|
): 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 =>
|
let toPointSetFn = t =>
|
||||||
toPointSet(
|
toPointSet(
|
||||||
t,
|
t,
|
||||||
|
@ -156,52 +138,53 @@ module Score = {
|
||||||
)
|
)
|
||||||
let prior': option<result<pointSet_ScoreDistOrScalar, error>> = switch prior {
|
let prior': option<result<pointSet_ScoreDistOrScalar, error>> = switch prior {
|
||||||
| None => None
|
| None => None
|
||||||
| Some(Score_Dist(d)) => toPointSetFn(d)->E.R.bind(x => x->D->Ok)->Some
|
| Some(Score_Dist(d)) => toPointSetFn(d)->E.R.bind(x => x->PSDist->Ok)->Some
|
||||||
| Some(Score_Scalar(s)) => s->S->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),
|
(PointSetTypes.pointSetDist, PointSetTypes.pointSetDist),
|
||||||
error,
|
error,
|
||||||
> => E.R.merge(toPointSetFn(esti'), toPointSetFn(answ'))
|
> => E.R.merge(toPointSetFn(esti'), toPointSetFn(answ'))
|
||||||
switch (esti, answ, prior') {
|
switch (esti, answ, prior') {
|
||||||
| (Score_Dist(esti'), Score_Dist(answ'), None) =>
|
| (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
|
{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'')) =>
|
twoDists(~toPointSetFn, esti', answ')->E.R2.fmap(((esti'', answ'')) =>
|
||||||
{estimate: esti'', answer: answ'', prior: Some(prior'')}
|
{estimate: esti'', answer: answ'', prior: Some(prior'')}
|
||||||
->PointSetDist_Scoring.DistEstimateDistAnswer
|
->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) =>
|
| (Score_Dist(esti'), Score_Scalar(answ'), None) =>
|
||||||
toPointSetFn(esti')->E.R.bind(esti'' =>
|
toPointSetFn(esti')->E.R.bind(esti'' =>
|
||||||
{estimate: esti'', answer: answ', prior: None}
|
{estimate: esti'', answer: answ', prior: None}
|
||||||
->PointSetDist_Scoring.DistEstimateScalarAnswer
|
->PointSetDist_Scoring.DistEstimateScalarAnswer
|
||||||
->Ok
|
->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'' =>
|
toPointSetFn(esti')->E.R.bind(esti'' =>
|
||||||
{estimate: esti'', answer: answ', prior: Some(prior'')}
|
{estimate: esti'', answer: answ', prior: Some(prior'')}
|
||||||
->PointSetDist_Scoring.DistEstimateScalarAnswer
|
->PointSetDist_Scoring.DistEstimateScalarAnswer
|
||||||
|
-> Ok
|
||||||
)
|
)
|
||||||
| (Score_Scalar(esti'), Score_Dist(answ'), None) =>
|
| (Score_Scalar(esti'), Score_Dist(answ'), None) =>
|
||||||
toPointSetFn(answ')->E.R.bind(answ'' =>
|
toPointSetFn(answ')->E.R.bind(answ'' =>
|
||||||
{estimate: esti', answer: answ'', prior: None}
|
{estimate: esti', answer: answ'', prior: None}
|
||||||
->PointSetDist_Scoring.ScalarEstimateDistAnswer
|
->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'' =>
|
toPointSetFn(answ')->E.R.bind(answ'' =>
|
||||||
{estimate: esti', answer: answ'', prior: Some(prior'')}
|
{estimate: esti', answer: answ'', prior: Some(prior'')}
|
||||||
->PointSetDist_Scoring.ScalarEstimateDistAnswer
|
->PointSetDist_Scoring.ScalarEstimateDistAnswer->Ok
|
||||||
)
|
)
|
||||||
| (GScalar(_), _, Some(Ok(PSDist(_)))) => DistributionTypes.Unreachable->Error
|
| (Score_Scalar(_), _, Some(Ok(PSDist(_)))) => DistributionTypes.Unreachable->Error
|
||||||
| (GScalar(esti'), GScalar(answ'), None) =>
|
| (Score_Scalar(esti'), Score_Scalar(answ'), None) =>
|
||||||
{estimate: esti', answer: answ', prior: None}
|
{estimate: esti', answer: answ', prior: None}
|
||||||
->PointSetDist_Scoring.ScalarEstimateScalarAnswer
|
->PointSetDist_Scoring.ScalarEstimateScalarAnswer
|
||||||
->Ok
|
->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}
|
{estimate: esti', answer: answ', prior: prior''->Some}
|
||||||
->PointSetDist_Scoring.ScalarEstimateScalarAnswer
|
->PointSetDist_Scoring.ScalarEstimateScalarAnswer
|
||||||
->Ok
|
->Ok
|
||||||
|
|
|
@ -132,7 +132,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 {
|
||||||
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, ()))
|
E.R.merge(toPointSetFn(estimate, ()), toPointSetFn(answer, ()))
|
||||||
|
|
||||||
let logScore = (args: scoreArgs, ~combineFn, ~integrateFn, ~toMixedFn): result<
|
let logScore = (args: scoreArgs, ~combineFn, ~integrateFn, ~toMixedFn): result<
|
||||||
|
|
|
@ -214,12 +214,12 @@ let dispatchToGenericOutput = (
|
||||||
| ("normalize", [EvDistribution(dist)]) => Helpers.toDistFn(Normalize, dist, ~env)
|
| ("normalize", [EvDistribution(dist)]) => Helpers.toDistFn(Normalize, dist, ~env)
|
||||||
| ("klDivergence", [EvDistribution(estimate), EvDistribution(answer)]) =>
|
| ("klDivergence", [EvDistribution(estimate), EvDistribution(answer)]) =>
|
||||||
Some(
|
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)]) =>
|
| ("klDivergence", [EvDistribution(estimate), EvDistribution(answer), EvDistribution(prior)]) =>
|
||||||
Some(
|
Some(
|
||||||
DistributionOperation.run(
|
DistributionOperation.run(
|
||||||
FromDist(ToScore(LogScore(GDist(answer), Some(GDist(prior)))), estimate),
|
FromDist(ToScore(LogScore(Score_Dist(answer), Some(Score_Dist(prior)))), estimate),
|
||||||
~env,
|
~env,
|
||||||
),
|
),
|
||||||
)
|
)
|
||||||
|
|
Loading…
Reference in New Issue
Block a user