Response to CR

Value: [1e-4 to 4e-3]
This commit is contained in:
Quinn Dougherty 2022-05-03 10:15:48 -04:00
parent 20adc4e25a
commit 5d6de7b487
4 changed files with 21 additions and 19 deletions

View File

@ -61,18 +61,13 @@ let lognormalMake = SymbolicDist.Lognormal.make
let triangularMake = SymbolicDist.Triangular.make
let floatMake = SymbolicDist.Float.make
let normalMakeR = (mean, stdev) =>
E.R.fmap(s => DistributionTypes.Symbolic(s), SymbolicDist.Normal.make(mean, stdev))
let betaMakeR = (alpha, beta) =>
E.R.fmap(s => DistributionTypes.Symbolic(s), SymbolicDist.Beta.make(alpha, beta))
let exponentialMakeR = rate =>
E.R.fmap(s => DistributionTypes.Symbolic(s), SymbolicDist.Exponential.make(rate))
let uniformMakeR = (low, high) =>
E.R.fmap(s => DistributionTypes.Symbolic(s), SymbolicDist.Uniform.make(low, high))
let cauchyMakeR = (local, rate) =>
E.R.fmap(s => DistributionTypes.Symbolic(s), SymbolicDist.Cauchy.make(local, rate))
let lognormalMakeR = (mu, sigma) =>
E.R.fmap(s => DistributionTypes.Symbolic(s), SymbolicDist.Lognormal.make(mu, sigma))
let fmapGenDist = symbdistres => E.R.fmap(s => DistributionTypes.Symbolic(s), symbdistres)
let normalMakeR = (mean, stdev) => fmapGenDist(SymbolicDist.Normal.make(mean, stdev))
let betaMakeR = (alpha, beta) => fmapGenDist(SymbolicDist.Beta.make(alpha, beta))
let exponentialMakeR = rate => fmapGenDist(SymbolicDist.Exponential.make(rate))
let uniformMakeR = (low, high) => fmapGenDist(SymbolicDist.Uniform.make(low, high))
let cauchyMakeR = (local, rate) => fmapGenDist(SymbolicDist.Cauchy.make(local, rate))
let lognormalMakeR = (mu, sigma) => fmapGenDist(SymbolicDist.Lognormal.make(mu, sigma))
let triangularMakeR = (low, mode, high) =>
E.R.fmap(s => DistributionTypes.Symbolic(s), SymbolicDist.Triangular.make(low, mode, high))
fmapGenDist(SymbolicDist.Triangular.make(low, mode, high))
// let floatMakeR = x =>E.R.fmap(s => DistributionTypes.Symbolic(s), SymbolicDist.Float.make(x))

View File

@ -233,6 +233,5 @@ module T = Dist({
combinePointwise(~fn=PointSetDist_Scoring.LogScoring.logScore, base, reference) |> E.R2.bind(
integralEndYResult,
)
// |> (r => Ok(r))
}
})

View File

@ -1,8 +1,14 @@
module LogScoring = {
let logFn = Js.Math.log
let subtraction = (a, b) => Ok(a -. b)
let logScore = (a: float, b: float): result<float, Operation.Error.t> => Ok(
logFn(Js.Math.abs_float(a /. b)),
)
let logScore = (a: float, b: float): result<float, Operation.Error.t> =>
if a == 0.0 {
Error(Operation.Error.NegativeInfinityError)
} else if b == 0.0 {
Error(Operation.Error.DivideByZeroError)
} else {
let quot = a /. b
quot < 0.0 ? Error(OperationError.ComplexNumberError) : Ok(logFn(quot))
}
let multiply = (a: float, b: float): result<float, Operation.Error.t> => Ok(a *. b)
}

View File

@ -53,6 +53,7 @@ type operationError =
| DivisionByZeroError
| ComplexNumberError
| InfinityError
| NegativeInfinityError
@genType
module Error = {
@ -63,7 +64,8 @@ module Error = {
switch err {
| DivisionByZeroError => "Cannot divide by zero"
| ComplexNumberError => "Operation returned complex result"
| InfinityError => "Operation returned + or - infinity"
| InfinityError => "Operation returned positive infinity"
| NegativeInfinityError => "Operation returned negative infinity"
}
}
@ -89,7 +91,7 @@ let logarithm = (a: float, b: float): result<float, Error.t> =>
} else if a > 0.0 && b > 0.0 {
Ok(log(a) /. log(b))
} else if a == 0.0 {
Error(InfinityError)
Error(NegativeInfinityError)
} else {
Error(ComplexNumberError)
}