diff --git a/packages/squiggle-lang/__tests__/GenericDist/GenericDistSparkline_Test.res b/packages/squiggle-lang/__tests__/GenericDist/GenericDistSparkline_Test.res index 8c29f7e4..8b3a8542 100644 --- a/packages/squiggle-lang/__tests__/GenericDist/GenericDistSparkline_Test.res +++ b/packages/squiggle-lang/__tests__/GenericDist/GenericDistSparkline_Test.res @@ -1,11 +1,6 @@ open Jest open Expect -let env: DistributionOperation.env = { - sampleCount: 100, - xyPointLength: 100, -} - let normalDist: GenericDist_Types.genericDist = Symbolic(#Normal({mean: 5.0, stdev: 2.0})) let uniformDist: GenericDist_Types.genericDist = Symbolic(#Uniform({low: 9.0, high: 10.0})) let betaDist: GenericDist_Types.genericDist = Symbolic(#Beta({alpha: 2.0, beta: 5.0})) diff --git a/packages/squiggle-lang/src/rescript/Distributions/PointSetDist/PointSetDist.res b/packages/squiggle-lang/src/rescript/Distributions/PointSetDist/PointSetDist.res index 7cacd634..d5fa99b6 100644 --- a/packages/squiggle-lang/src/rescript/Distributions/PointSetDist/PointSetDist.res +++ b/packages/squiggle-lang/src/rescript/Distributions/PointSetDist/PointSetDist.res @@ -168,20 +168,13 @@ let pdf = (f: float, t: t) => { let inv = T.Integral.yToX let cdf = T.Integral.xToY -let diff = (arr: array): array => - Belt.Array.zipBy(arr, Belt.Array.sliceToEnd(arr, 1), (left, right) => right -. left) - -let rec rangeByFloat = (start : float, end: float, step: float) => - start > end ? - [] - : Belt.Array.concat([start], rangeByFloat(start +. step, end, step)) @genType let toSparkline = (buckets: int, t: t ): string => { let size : float = T.maxX(t) -. T.minX(t) let stepSize = size /. Belt.Int.toFloat(buckets) - let cdf = rangeByFloat(T.minX(t), T.maxX(t), stepSize) -> Belt.Array.map(val => cdf(val,t)) - Sparklines.create(diff(cdf), ()) + let cdfImage = E.A.rangeByFloat(~step=stepSize, T.minX(t), T.maxX(t)) -> Belt.Array.map(val => cdf(val,t)) + Sparklines.create(E.A.diff(cdfImage), ()) } let doN = (n, fn) => { diff --git a/packages/squiggle-lang/src/rescript/Utility/E.res b/packages/squiggle-lang/src/rescript/Utility/E.res index e36b6124..b3119da3 100644 --- a/packages/squiggle-lang/src/rescript/Utility/E.res +++ b/packages/squiggle-lang/src/rescript/Utility/E.res @@ -292,6 +292,14 @@ module A = { let rangeFloat = (~step=1, start, stop) => Belt.Array.rangeBy(start, stop, ~step) |> fmap(Belt.Int.toFloat) + let diff = (arr: array): array => + Belt.Array.zipBy(arr, Belt.Array.sliceToEnd(arr, 1), (left, right) => right -. left) + + let rec rangeByFloat = (~step: float=1.0, start : float, end: float) : array => + start > end ? + [] + : Belt.Array.concat([start], rangeByFloat(~step, start +. step, end)) + // This zips while taking the longest elements of each array. let zipMaxLength = (array1, array2) => { let maxLength = Int.max(length(array1), length(array2))