moved dists to distributions subdir and added threither

This commit is contained in:
Quinn Dougherty 2022-02-27 22:58:46 -05:00
parent 4ebb11182f
commit 809ea9e225
17 changed files with 76 additions and 3 deletions

View File

@ -0,0 +1,33 @@
type distribution =
| SymbolicDist(SymbolicDistTypes.symbolicDist)
| PointSetDist(PointSetTypes.pointSetDist)
| SampleSetDist(SampleSet.Internals.Types.outputs)
module Distributions = {
module D = E.Threither(
{type tau = SymbolicDistTypes.symbolicDist},
{type tau = PointSetTypes.pointSetDist},
{type tau = SampleSet.Internals.Types.outputs}
)
}
type distinputs =
| Symb(SymbolicDistTypes.symbolicDist)
| PS(PointSetTypes.pointSetDist)
| SS(SampleSet.Internals.Types.outputs)
module type theDist = {
let t: distribution
}
module TheDistribution = (Thedist: theDist) => {
let t = Thedist.t
let thedistribution: distinputs = switch t {
| SymbolicDist(symbdist) => Symb(symbdist)
| PointSetDist(pointsetdist) => PS(pointsetdist)
| SampleSetDist(samplesetdist) => SS(samplesetdist)
}
}

View File

@ -48,8 +48,7 @@ let toPointSetDist = ({pointSetDist, _}: t) => pointSetDist;
let pointSetDistFn = (fn, {pointSetDist}: t) => fn(pointSetDist);
module T =
Distributions.Dist({
module Thedist: Distributions.dist = {
type t = PointSetTypes.distPlus;
type integral = PointSetTypes.distPlus;
let toPointSetDist = toPointSetDist;
@ -127,4 +126,6 @@ module T =
PointSetDist.T.mean(t.pointSetDist);
};
let variance = (t: t) => PointSetDist.T.variance(t.pointSetDist);
});
}
module T = Distributions.Dist(Thedist);

View File

@ -1,5 +1,6 @@
open SymbolicDistTypes
// TODO: make module enumeration in the same order as the variant enumeration in SymbolicDistTypes
module Normal = {
type t = normal
let make = (mean, stdev): symbolicDist => #Normal({mean: mean, stdev: stdev})

View File

@ -47,3 +47,13 @@ type analyticalSimplificationResult = [
| #Error(string)
| #NoSolution
]
type params =
| NormalParams(normal)
| BetaParams(beta)
| LognormalParams(lognormal)
| UniformParams(uniform)
| ExponentialParams(exponential)
| CauchyParams(cauchy)
| TriangularParams(triangular)
| FloatParams(float)

View File

@ -441,3 +441,31 @@ module JsArray = {
|> Js.Array.map(Rationale.Option.toExn("Warning: This should not have happened"))
let filter = Js.Array.filter
}
module type Tau = {
type tau
}
module Threither = (Tau1: Tau, Tau2: Tau, Tau3: Tau) => {
type either3 = First(Tau1.tau) | Second(Tau2.tau) | Third(Tau3.tau)
let fmap1 = (~fn: Tau1.tau => 'a, ~x: either3) => switch x {
| First(y) => First(fn(y))
| Second(y) => Second(y)
| Third(y) => Third(y)
}
let fmap2 = (~fn: Tau2.tau => 'a, ~x: either3) => switch x {
| First(y) => First(y)
| Second(y) => Second(fn(y))
| Third(y) => Third(y)
}
let fmap3 = (~fn: Tau3.tau => 'a, ~x: either3) => switch x {
| First(y) => First(y)
| Second(y) => Second(y)
| Third(y) => Third(fn(y))
}
let trifmap = (~fn1: Tau1.tau => 'a, ~fn2: Tau2.tau => 'b, ~fn3: Tau3.tau => 'c, ~x: either3) => switch x {
| First(y) => First(fn1(y))
| Second(y) => Second(fn2(y))
| Third(y) => Third(fn3(y))
}
}