rescript format on DistPlus.res

This commit is contained in:
Quinn Dougherty 2022-04-11 00:59:47 -04:00
parent 983dc1f08b
commit 19d5fa109b

View File

@ -1,116 +1,87 @@
open PointSetTypes; open PointSetTypes
@genType @genType
type t = PointSetTypes.distPlus; type t = PointSetTypes.distPlus
let pointSetDistIntegral = pointSetDist => PointSetDist.T.Integral.get(pointSetDist); let pointSetDistIntegral = pointSetDist => PointSetDist.T.Integral.get(pointSetDist)
let make = let make = (~pointSetDist, ~squiggleString, ()): t => {
( let integral = pointSetDistIntegral(pointSetDist)
~pointSetDist, {pointSetDist: pointSetDist, integralCache: integral, squiggleString: squiggleString}
~squiggleString, }
(),
)
: t => {
let integral = pointSetDistIntegral(pointSetDist);
{pointSetDist, integralCache: integral, squiggleString};
};
let update = let update = (~pointSetDist=?, ~integralCache=?, ~squiggleString=?, t: t) => {
(
~pointSetDist=?,
~integralCache=?,
~squiggleString=?,
t: t,
) => {
pointSetDist: E.O.default(t.pointSetDist, pointSetDist), pointSetDist: E.O.default(t.pointSetDist, pointSetDist),
integralCache: E.O.default(t.integralCache, integralCache), integralCache: E.O.default(t.integralCache, integralCache),
squiggleString: E.O.default(t.squiggleString, squiggleString), squiggleString: E.O.default(t.squiggleString, squiggleString),
}; }
let updateShape = (pointSetDist, t) => { let updateShape = (pointSetDist, t) => {
let integralCache = pointSetDistIntegral(pointSetDist); let integralCache = pointSetDistIntegral(pointSetDist)
update(~pointSetDist, ~integralCache, t); update(~pointSetDist, ~integralCache, t)
}; }
let toPointSetDist = ({pointSetDist, _}: t) => pointSetDist; let toPointSetDist = ({pointSetDist, _}: t) => pointSetDist
let pointSetDistFn = (fn, {pointSetDist}: t) => fn(pointSetDist); let pointSetDistFn = (fn, {pointSetDist}: t) => fn(pointSetDist)
module T = module T = Distributions.Dist({
Distributions.Dist({ type t = PointSetTypes.distPlus
type t = PointSetTypes.distPlus; type integral = PointSetTypes.distPlus
type integral = PointSetTypes.distPlus; let toPointSetDist = toPointSetDist
let toPointSetDist = toPointSetDist; let toContinuous = pointSetDistFn(PointSetDist.T.toContinuous)
let toContinuous = pointSetDistFn(PointSetDist.T.toContinuous); let toDiscrete = pointSetDistFn(PointSetDist.T.toDiscrete)
let toDiscrete = pointSetDistFn(PointSetDist.T.toDiscrete);
let normalize = (t: t): t => { let normalize = (t: t): t => {
let normalizedShape = t |> toPointSetDist |> PointSetDist.T.normalize; let normalizedShape = t |> toPointSetDist |> PointSetDist.T.normalize
t |> updateShape(normalizedShape); t |> updateShape(normalizedShape)
}; }
let truncate = (leftCutoff, rightCutoff, t: t): t => { let truncate = (leftCutoff, rightCutoff, t: t): t => {
let truncatedShape = let truncatedShape = t |> toPointSetDist |> PointSetDist.T.truncate(leftCutoff, rightCutoff)
t
|> toPointSetDist
|> PointSetDist.T.truncate(leftCutoff, rightCutoff);
t |> updateShape(truncatedShape); t |> updateShape(truncatedShape)
}; }
let xToY = (f, t: t) => let xToY = (f, t: t) => t |> toPointSetDist |> PointSetDist.T.xToY(f)
t
|> toPointSetDist
|> PointSetDist.T.xToY(f);
let minX = pointSetDistFn(PointSetDist.T.minX); let minX = pointSetDistFn(PointSetDist.T.minX)
let maxX = pointSetDistFn(PointSetDist.T.maxX); let maxX = pointSetDistFn(PointSetDist.T.maxX)
let toDiscreteProbabilityMassFraction = let toDiscreteProbabilityMassFraction = pointSetDistFn(
pointSetDistFn(PointSetDist.T.toDiscreteProbabilityMassFraction); PointSetDist.T.toDiscreteProbabilityMassFraction,
)
// This bit is kind of awkward, could probably use rethinking. // This bit is kind of awkward, could probably use rethinking.
let integral = (t: t) => let integral = (t: t) => updateShape(Continuous(t.integralCache), t)
updateShape(Continuous(t.integralCache), t);
let updateIntegralCache = (integralCache: option<PointSetTypes.continuousShape>, t) => let updateIntegralCache = (integralCache: option<PointSetTypes.continuousShape>, t) =>
update(~integralCache=E.O.default(t.integralCache, integralCache), t); update(~integralCache=E.O.default(t.integralCache, integralCache), t)
let downsample = (i, t): t => let downsample = (i, t): t => updateShape(t |> toPointSetDist |> PointSetDist.T.downsample(i), t)
updateShape(t |> toPointSetDist |> PointSetDist.T.downsample(i), t);
// todo: adjust for limit, maybe? // todo: adjust for limit, maybe?
let mapY = let mapY = (
(
~integralSumCacheFn=previousIntegralSum => None, ~integralSumCacheFn=previousIntegralSum => None,
~integralCacheFn=previousIntegralCache => None, ~integralCacheFn=previousIntegralCache => None,
~fn, ~fn,
{pointSetDist, _} as t: t, {pointSetDist, _} as t: t,
) ): t => PointSetDist.T.mapY(~integralSumCacheFn, ~fn, pointSetDist) |> updateShape(_, t)
: t =>
PointSetDist.T.mapY(~integralSumCacheFn, ~fn, pointSetDist)
|> updateShape(_, t);
// get the total of everything // get the total of everything
let integralEndY = (t: t) => { let integralEndY = (t: t) => {
PointSetDist.T.Integral.sum( PointSetDist.T.Integral.sum(toPointSetDist(t))
toPointSetDist(t), }
);
};
// TODO: Fix this below, obviously. Adjust for limits // TODO: Fix this below, obviously. Adjust for limits
let integralXtoY = (f, t: t) => { let integralXtoY = (f, t: t) => {
PointSetDist.T.Integral.xToY( PointSetDist.T.Integral.xToY(f, toPointSetDist(t))
f, }
toPointSetDist(t),
)
};
// TODO: This part is broken when there is a limit, if this is supposed to be taken into account. // TODO: This part is broken when there is a limit, if this is supposed to be taken into account.
let integralYtoX = (f, t: t) => { let integralYtoX = (f, t: t) => {
PointSetDist.T.Integral.yToX(f, toPointSetDist(t)); PointSetDist.T.Integral.yToX(f, toPointSetDist(t))
}; }
let mean = (t: t) => { let mean = (t: t) => {
PointSetDist.T.mean(t.pointSetDist); PointSetDist.T.mean(t.pointSetDist)
}; }
let variance = (t: t) => PointSetDist.T.variance(t.pointSetDist); let variance = (t: t) => PointSetDist.T.variance(t.pointSetDist)
}); })