Created
May 16, 2022 16:01
-
-
Save quinn-dougherty/e8e11a9620ee91f85189e61bbca0f019 to your computer and use it in GitHub Desktop.
Squiggle records as argument interface draft one
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| let rec dispatchToGenericOutput = ( | |
| call: ExpressionValue.functionCall, | |
| env: DistributionOperation.env, | |
| ): option<DistributionOperation.outputType> => { | |
| let (fnName, args) = call | |
| switch (fnName, args) { | |
| ... | |
| | ("klDivergence", [EvDistribution(a), EvDistribution(b)]) => | |
| Some(DistributionOperation.run(FromDist(ToScore(KLDivergence(b)), a), ~env)) | |
| | ( | |
| "logScoreWithPointResolution", | |
| [EvDistribution(prediction), EvNumber(answer), EvDistribution(prior)], | |
| ) | |
| | ( | |
| "logScoreWithPointResolution", | |
| [EvDistribution(prediction), EvDistribution(Symbolic(#Float(answer))), EvDistribution(prior)], | |
| ) => | |
| DistributionOperation.run(FromDist(ToScore(LogScore(answer, prior->Some)), prediction), ~env)->Some | |
| | ("logScoreWithPointResolution", [EvDistribution(prediction), EvNumber(answer)]) | |
| | ( | |
| "logScoreWithPointResolution", | |
| [EvDistribution(prediction), EvDistribution(Symbolic(#Float(answer)))], | |
| ) => | |
| DistributionOperation.run(FromDist(ToScore(LogScore(answer, None)), prediction), ~env)->Some | |
| | ("logScore", [EvRecord(r)]) => | |
| [ | |
| recurRecordArgs( | |
| "logScoreWithPointResolution", | |
| ["estimate", "answerNum", "prior"], | |
| r, | |
| env, | |
| ), | |
| recurRecordArgs("klDivergence", ["estimate", "answerDist"], r, env), | |
| recurRecordArgs("logScoreWithPointResolution", ["estimate", "answerNum"], r, env), | |
| ]->E.A.O.firstSome | |
| ... | |
| } | |
| and recurRecordArgs = ( | |
| fnName: string, | |
| argNames: array<string>, | |
| args: ExpressionValue.record, | |
| env: DistributionOperation.env, | |
| ): option<DistributionOperation.outputType> => | |
| // argNames -> E.A2.fmap(x => Js.Dict.get(args, x)) -> E.A.O.arrSomeToSomeArr -> E.O.bind(a => dispatchToGenericOutput((fnName, a), _environment)) | |
| argNames | |
| ->E.A2.fmap(x => Js.Dict.unsafeGet(args, x)) | |
| ->(a => dispatchToGenericOutput((fnName, a), env)) | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment