squiggle/src/distPlus/distribution/Distributions.re

72 lines
2.2 KiB
ReasonML
Raw Normal View History

module type dist = {
type t;
2020-03-18 20:50:01 +00:00
type integral;
let minX: t => float;
let maxX: t => float;
2020-06-27 04:29:21 +00:00
let mapY:
(~knownIntegralSumFn: float => option(float)=?, float => float, t) => t;
2020-02-23 13:27:52 +00:00
let xToY: (float, t) => DistTypes.mixedPoint;
let toShape: t => DistTypes.shape;
let toContinuous: t => option(DistTypes.continuousShape);
let toDiscrete: t => option(DistTypes.discreteShape);
let normalize: t => t;
let normalizedToContinuous: t => option(DistTypes.continuousShape);
let normalizedToDiscrete: t => option(DistTypes.discreteShape);
let toDiscreteProbabilityMassFraction: t => float;
let downsample: (~cache: option(integral)=?, int, t) => t;
2020-06-27 04:29:21 +00:00
let truncate: (option(float), option(float), t) => t;
2020-02-22 10:17:51 +00:00
2020-02-22 10:10:10 +00:00
let integral: (~cache: option(integral), t) => integral;
let integralEndY: (~cache: option(integral), t) => float;
2020-02-22 10:17:51 +00:00
let integralXtoY: (~cache: option(integral), float, t) => float;
let integralYtoX: (~cache: option(integral), float, t) => float;
2020-04-19 20:04:50 +00:00
let mean: t => float;
let variance: t => float;
};
module Dist = (T: dist) => {
type t = T.t;
type integral = T.integral;
let minX = T.minX;
let maxX = T.maxX;
let integral = T.integral;
let xTotalRange = (t: t) => maxX(t) -. minX(t);
2020-03-28 14:17:47 +00:00
let mapY = T.mapY;
let xToY = T.xToY;
let downsample = T.downsample;
2020-02-22 16:24:54 +00:00
let toShape = T.toShape;
let toDiscreteProbabilityMassFraction = T.toDiscreteProbabilityMassFraction;
2020-02-22 16:24:54 +00:00
let toContinuous = T.toContinuous;
let toDiscrete = T.toDiscrete;
let normalize = T.normalize;
2020-06-27 04:29:21 +00:00
let truncate = T.truncate;
let normalizedToContinuous = T.normalizedToContinuous;
let normalizedToDiscrete = T.normalizedToDiscrete;
2020-04-19 20:04:50 +00:00
let mean = T.mean;
let variance = T.variance;
2020-03-18 21:46:43 +00:00
2020-02-22 10:17:51 +00:00
module Integral = {
type t = T.integral;
let get = T.integral;
let xToY = T.integralXtoY;
let yToX = T.integralYtoX;
let sum = T.integralEndY;
2020-02-22 10:17:51 +00:00
};
};
2020-06-27 04:29:21 +00:00
module Common = {
let combineIntegralSums =
(
combineFn: (float, float) => option(float),
t1KnownIntegralSum: option(float),
t2KnownIntegralSum: option(float),
) => {
switch (t1KnownIntegralSum, t2KnownIntegralSum) {
| (None, _)
| (_, None) => None
| (Some(s1), Some(s2)) => combineFn(s1, s2)
};
};
};