Respond to sparkline PR change requests

This commit is contained in:
Sam Nolan 2022-04-08 11:02:41 +10:00
parent 53f4e56529
commit bf2f85a8ab
3 changed files with 10 additions and 14 deletions

View File

@ -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}))

View File

@ -168,20 +168,13 @@ let pdf = (f: float, t: t) => {
let inv = T.Integral.yToX
let cdf = T.Integral.xToY
let diff = (arr: array<float>): array<float> =>
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) => {

View File

@ -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<float>): array<float> =>
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<float> =>
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))