intermediary commit while I check out something else
This commit is contained in:
parent
a99f52d781
commit
ba4ee1212d
|
@ -0,0 +1,83 @@
|
|||
open SymbolicDistTypes
|
||||
|
||||
module type ValidNormal = {
|
||||
let params: normal
|
||||
let distribution: validated<symbolicDist>
|
||||
}
|
||||
|
||||
let from90PercentCI = (low, high) => {
|
||||
let mean = E.A.Floats.mean([low, high])
|
||||
let stdev = (high -. low) /. (2.0 *. 1.644854)
|
||||
(mean, stdev)
|
||||
}
|
||||
|
||||
module Normal = (Validated: ValidNormal) => {
|
||||
let pdf = x => Jstat.Normal.pdf(x, Validated.params.mean, Validated.params.stdev)
|
||||
let cdf = x => Jstat.Normal.cdf(x, Validated.params.mean, Validated.params.stdev)
|
||||
|
||||
let from90PercentCI = (low, high) => {
|
||||
let mean = E.A.Floats.mean([low, high])
|
||||
let stdev = (high -. low) /. (2.0 *. 1.644854)
|
||||
normalConstr({mean: mean, stdev: stdev})
|
||||
}
|
||||
|
||||
let inv = p => Jstat.Normal.inv(p, Validated.params.mean, Validated.params.stdev)
|
||||
let sample = Jstat.Normal.sample(Validated.params.mean, Validated.params.stdev)
|
||||
let mean = Jstat.Normal.mean(Validated.params.mean, Validated.params.stdev)
|
||||
let toString = j`Normal(${Js.Float.toString(Validated.params.mean)},${Js.Float.toString(Validated.params.stdev)})`
|
||||
}
|
||||
|
||||
module NormalBinOps = (N1: ValidNormal, N2: ValidNormal) => {
|
||||
let add = {
|
||||
let mean = N1.params.mean +. N2.params.mean
|
||||
let stdev = sqrt(N1.params.stdev ** 2.0 +. N2.params.stdev ** 2.0)
|
||||
normalConstr({mean: mean, stdev: stdev})
|
||||
}
|
||||
|
||||
let subtract = {
|
||||
let mean = N1.params.mean -. N2.params.mean
|
||||
let stdev = sqrt(N1.params.stdev ** 2.0 +. N2.params.stdev ** 2.0)
|
||||
normalConstr({mean: mean, stdev: stdev})
|
||||
}
|
||||
|
||||
let operate: Operation.Algebraic.t => option<validated<symbolicDist>> = operation => {
|
||||
switch operation {
|
||||
| #Add => Some(add)
|
||||
| #Subtract => Some(subtract)
|
||||
| _ => None
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
module From90thPercentile = {
|
||||
let constr: (float, float) => validated<symbolicDist> = (low, high) => {
|
||||
let (mean, stdev) = from90PercentCI(low, high)
|
||||
module NormalValueValidated: ValidNormal = {
|
||||
let params = {mean: mean, stdev: stdev}
|
||||
let distribution = normalConstr(params)
|
||||
}
|
||||
module NormalValue = Normal(NormalValueValidated)
|
||||
NormalValue.from90PercentCI(low, high)
|
||||
}
|
||||
}
|
||||
|
||||
module T = {
|
||||
let minCdfValue = 1e-4
|
||||
let maxCdfValue = 1.0 -. 1e-4
|
||||
|
||||
let pdf = (x, dist) => {
|
||||
switch dist {
|
||||
| #Normal(_params) => {
|
||||
module NormalValueValidated: ValidNormal = {
|
||||
let params = _params
|
||||
let distribution = normalConstr(params)
|
||||
}
|
||||
module NormalValue = Normal(NormalValueValidated)
|
||||
switch NormalValueValidated.distribution {
|
||||
| Ok(symbdist) => NormalValue.pdf(x)
|
||||
| Error(invalidNormal) => 0.0
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user