Added delta function to produce delta distributions

This commit is contained in:
Ozzie Gooen 2022-05-01 09:00:56 -04:00
parent ed5b7e63f2
commit 18af09ab04
3 changed files with 11 additions and 2 deletions

View File

@ -219,6 +219,12 @@ module Uniform = {
module Float = {
type t = float
let make = t => #Float(t)
let makeSafe = t =>
if E.Float.isFinite(t) {
Ok(#Float(t))
} else {
Error("Float must be finite")
}
let pdf = (x, t: t) => x == t ? 1.0 : 0.0
let cdf = (x, t: t) => x >= t ? 1.0 : 0.0
let inv = (p, t: t) => p < t ? 0.0 : 1.0

View File

@ -179,10 +179,12 @@ let dispatchToGenericOutput = (call: ExpressionValue.functionCall): option<
> => {
let (fnName, args) = call
switch (fnName, args) {
| ("exponential" as fnName, [EvNumber(f1)]) =>
| ("exponential" as fnName, [EvNumber(f)]) =>
SymbolicConstructors.oneFloat(fnName)
->E.R.bind(r => r(f1))
->E.R.bind(r => r(f))
->SymbolicConstructors.symbolicResultToOutput
| ("delta", [EvNumber(f)]) =>
SymbolicDist.Float.makeSafe(f)->SymbolicConstructors.symbolicResultToOutput
| (
("normal" | "uniform" | "beta" | "lognormal" | "cauchy" | "to") as fnName,
[EvNumber(f1), EvNumber(f2)],

View File

@ -198,6 +198,7 @@ module Float = {
let with3DigitsPrecision = Js.Float.toPrecisionWithPrecision(_, ~digits=3)
let toFixed = Js.Float.toFixed
let toString = Js.Float.toString
let isFinite = Js.Float.isFinite
}
module I = {