Prior can't be a point
This commit is contained in:
parent
e9968288fd
commit
652394f535
|
@ -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=Score_Dist(dist), ~answer, ~prior)
|
||||
GenericDist.Score.logScore(~estimate=dist, ~answer, ~prior)
|
||||
->E.R2.fmap(s => Float(s))
|
||||
->OutputLocal.fromResult
|
||||
| #ToBool(IsNormalized) => dist->GenericDist.isNormalized->Bool
|
||||
|
|
|
@ -72,7 +72,7 @@ module Constructors: {
|
|||
~env: env,
|
||||
genericDist,
|
||||
genericDist,
|
||||
DistributionTypes.DistributionOperation.genericDistOrScalar,
|
||||
genericDist,
|
||||
) => result<float, error>
|
||||
@genType
|
||||
let distEstimateScalarAnswer: (~env: env, genericDist, float) => result<float, error>
|
||||
|
@ -81,7 +81,7 @@ module Constructors: {
|
|||
~env: env,
|
||||
genericDist,
|
||||
float,
|
||||
DistributionTypes.DistributionOperation.genericDistOrScalar,
|
||||
genericDist,
|
||||
) => result<float, error>
|
||||
}
|
||||
@genType
|
||||
|
|
|
@ -100,7 +100,7 @@ module DistributionOperation = {
|
|||
|
||||
type genericDistOrScalar = Score_Dist(genericDist) | Score_Scalar(float)
|
||||
|
||||
type toScore = LogScore(genericDistOrScalar, option<genericDistOrScalar>)
|
||||
type toScore = LogScore(genericDistOrScalar, option<genericDist>)
|
||||
|
||||
type fromFloat = [
|
||||
| #ToFloat(toFloat)
|
||||
|
|
|
@ -133,13 +133,11 @@ let toPointSet = (
|
|||
|
||||
module Score = {
|
||||
type genericDistOrScalar = DistributionTypes.DistributionOperation.genericDistOrScalar
|
||||
type pointSet_ScoreDistOrScalar = PSDist(PointSetTypes.pointSetDist) | PSScalar(float)
|
||||
|
||||
let argsMake = (
|
||||
~esti: genericDistOrScalar,
|
||||
~answ: genericDistOrScalar,
|
||||
~prior: option<genericDistOrScalar>,
|
||||
): result<PointSetDist_Scoring.scoreArgs, error> => {
|
||||
let argsMake = (~esti: t, ~answ: genericDistOrScalar, ~prior: option<t>): result<
|
||||
PointSetDist_Scoring.scoreArgs,
|
||||
error,
|
||||
> => {
|
||||
let toPointSetFn = t =>
|
||||
toPointSet(
|
||||
t,
|
||||
|
@ -148,21 +146,20 @@ module Score = {
|
|||
~xSelection=#ByWeight,
|
||||
(),
|
||||
)
|
||||
let prior': option<result<pointSet_ScoreDistOrScalar, error>> = switch prior {
|
||||
let prior': option<result<PointSetTypes.pointSetDist, error>> = switch prior {
|
||||
| None => None
|
||||
| Some(Score_Dist(d)) => toPointSetFn(d)->E.R.bind(x => x->PSDist->Ok)->Some
|
||||
| Some(Score_Scalar(s)) => s->PSScalar->Ok->Some
|
||||
| Some(d) => toPointSetFn(d)->Some
|
||||
}
|
||||
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) =>
|
||||
| (esti', Score_Dist(answ'), None) =>
|
||||
twoDists(~toPointSetFn, esti', answ')->E.R2.fmap(((esti'', answ'')) =>
|
||||
{estimate: esti'', answer: answ'', prior: None}->PointSetDist_Scoring.DistAnswer
|
||||
)
|
||||
| (Score_Dist(esti'), Score_Dist(answ'), Some(Ok(PSDist(prior'')))) =>
|
||||
| (esti', Score_Dist(answ'), Some(Ok(prior''))) =>
|
||||
twoDists(~toPointSetFn, esti', answ')->E.R2.fmap(((esti'', answ'')) =>
|
||||
{
|
||||
estimate: esti'',
|
||||
|
@ -170,8 +167,7 @@ module Score = {
|
|||
prior: Some(prior''),
|
||||
}->PointSetDist_Scoring.DistAnswer
|
||||
)
|
||||
| (Score_Dist(_), _, Some(Ok(PSScalar(_)))) => DistributionTypes.Unreachable->Error
|
||||
| (Score_Dist(esti'), Score_Scalar(answ'), None) =>
|
||||
| (esti', Score_Scalar(answ'), None) =>
|
||||
toPointSetFn(esti')->E.R2.fmap(esti'' =>
|
||||
{
|
||||
estimate: esti'',
|
||||
|
@ -179,7 +175,7 @@ module Score = {
|
|||
prior: None,
|
||||
}->PointSetDist_Scoring.ScalarAnswer
|
||||
)
|
||||
| (Score_Dist(esti'), Score_Scalar(answ'), Some(Ok(PSDist(prior'')))) =>
|
||||
| (esti', Score_Scalar(answ'), Some(Ok(prior''))) =>
|
||||
toPointSetFn(esti')->E.R2.fmap(esti'' =>
|
||||
{
|
||||
estimate: esti'',
|
||||
|
@ -187,19 +183,14 @@ module Score = {
|
|||
prior: Some(prior''),
|
||||
}->PointSetDist_Scoring.ScalarAnswer
|
||||
)
|
||||
| (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(_), Score_Scalar(_), _) => NotYetImplemented->Error
|
||||
| (_, _, Some(Error(err))) => err->Error
|
||||
}
|
||||
}
|
||||
|
||||
let logScore = (
|
||||
~estimate: genericDistOrScalar,
|
||||
~answer: genericDistOrScalar,
|
||||
~prior: option<genericDistOrScalar>,
|
||||
): result<float, error> =>
|
||||
let logScore = (~estimate: t, ~answer: genericDistOrScalar, ~prior: option<t>): result<
|
||||
float,
|
||||
error,
|
||||
> =>
|
||||
argsMake(~esti=estimate, ~answ=answer, ~prior)->E.R.bind(x =>
|
||||
x->PointSetDist.logScore->E.R2.errMap(y => DistributionTypes.OperationError(y))
|
||||
)
|
||||
|
|
|
@ -26,9 +26,9 @@ let toFloatOperation: (
|
|||
|
||||
module Score: {
|
||||
let logScore: (
|
||||
~estimate: DistributionTypes.DistributionOperation.genericDistOrScalar,
|
||||
~estimate: t,
|
||||
~answer: DistributionTypes.DistributionOperation.genericDistOrScalar,
|
||||
~prior: option<DistributionTypes.DistributionOperation.genericDistOrScalar>,
|
||||
~prior: option<t>,
|
||||
) => result<float, error>
|
||||
}
|
||||
|
||||
|
|
|
@ -19,7 +19,7 @@ module WithDistAnswer = {
|
|||
float,
|
||||
Operation.Error.t,
|
||||
> =>
|
||||
// We decided that negative infinity, not an error at answerElement = 0.0, is a desirable value.
|
||||
// We decided that 0.0, not an error at answerElement = 0.0, is a desirable value.
|
||||
if answerElement == 0.0 {
|
||||
Ok(0.0)
|
||||
} else if estimateElement == 0.0 {
|
||||
|
|
|
@ -231,10 +231,7 @@ let dispatchToGenericOutput = (call: IEV.functionCall, env: DistributionOperatio
|
|||
DistributionOperation.run(
|
||||
FromDist(
|
||||
#ToScore(
|
||||
LogScore(
|
||||
DistributionTypes.DistributionOperation.Score_Dist(answer),
|
||||
Some(DistributionTypes.DistributionOperation.Score_Dist(prior)),
|
||||
),
|
||||
LogScore(DistributionTypes.DistributionOperation.Score_Dist(answer), Some(prior)),
|
||||
),
|
||||
prediction,
|
||||
),
|
||||
|
@ -256,10 +253,7 @@ let dispatchToGenericOutput = (call: IEV.functionCall, env: DistributionOperatio
|
|||
DistributionOperation.run(
|
||||
FromDist(
|
||||
#ToScore(
|
||||
LogScore(
|
||||
DistributionTypes.DistributionOperation.Score_Scalar(answer),
|
||||
DistributionTypes.DistributionOperation.Score_Dist(prior)->Some,
|
||||
),
|
||||
LogScore(DistributionTypes.DistributionOperation.Score_Scalar(answer), prior->Some),
|
||||
),
|
||||
prediction,
|
||||
),
|
||||
|
|
Loading…
Reference in New Issue
Block a user