Restructuring of E Sorted
This commit is contained in:
parent
20685ea8cb
commit
dde28e54f0
|
@ -263,4 +263,4 @@ let combineShapesContinuousDiscrete = (
|
|||
)
|
||||
}
|
||||
|
||||
let isOrdered = (a: XYShape.T.t): bool => E.A.Sorted.Floats.isSorted(a.xs)
|
||||
let isOrdered = (a: XYShape.T.t): bool => E.A.Floats.isSorted(a.xs)
|
||||
|
|
|
@ -85,7 +85,7 @@ let toPointSetDist = (
|
|||
(),
|
||||
): Internals.Types.outputs => {
|
||||
Array.fast_sort(compare, samples)
|
||||
let (continuousPart, discretePart) = E.A.Sorted.Floats.split(samples)
|
||||
let (continuousPart, discretePart) = E.A.Sorted.split(samples)
|
||||
let length = samples |> E.A.length |> float_of_int
|
||||
let discrete: PointSetTypes.discreteShape =
|
||||
discretePart
|
||||
|
|
|
@ -475,6 +475,51 @@ module A = {
|
|||
}
|
||||
}
|
||||
|
||||
module Floats = {
|
||||
let mean = Jstat.mean
|
||||
let geomean = Jstat.geomean
|
||||
let mode = Jstat.mode
|
||||
let variance = Jstat.variance
|
||||
let stdev = Jstat.stdev
|
||||
let sum = Jstat.sum
|
||||
let random = Js.Math.random_int
|
||||
|
||||
let floatCompare: (float, float) => int = compare
|
||||
let sort = t => {
|
||||
let r = t
|
||||
r |> Array.fast_sort(floatCompare)
|
||||
r
|
||||
}
|
||||
|
||||
let isSorted = (ar: array<float>): bool =>
|
||||
reduce(zip(ar, tail(ar)), true, (acc, (first, second)) => acc && first < second)
|
||||
|
||||
//Passing true for the exclusive parameter excludes both endpoints of the range.
|
||||
//https://jstat.github.io/all.html
|
||||
let percentile = (a, b) => Jstat.percentile(a, b, false)
|
||||
|
||||
// Gives an array with all the differences between values
|
||||
// diff([1,5,3,7]) = [4,-2,4]
|
||||
let diff = (arr: array<float>): array<float> =>
|
||||
Belt.Array.zipBy(arr, Belt.Array.sliceToEnd(arr, 1), (left, right) => right -. left)
|
||||
|
||||
exception RangeError(string)
|
||||
let range = (min: float, max: float, n: int): array<float> =>
|
||||
switch n {
|
||||
| 0 => []
|
||||
| 1 => [min]
|
||||
| 2 => [min, max]
|
||||
| _ if min == max => Belt.Array.make(n, min)
|
||||
| _ if n < 0 => raise(RangeError("n must be greater than 0"))
|
||||
| _ if min > max => raise(RangeError("Min value is less then max value"))
|
||||
| _ =>
|
||||
let diff = (max -. min) /. Belt.Float.fromInt(n - 1)
|
||||
Belt.Array.makeBy(n, i => min +. Belt.Float.fromInt(i) *. diff)
|
||||
}
|
||||
|
||||
let min = Js.Math.minMany_float
|
||||
let max = Js.Math.maxMany_float
|
||||
|
||||
module Sorted = {
|
||||
let min = first
|
||||
let max = last
|
||||
|
@ -484,8 +529,6 @@ module A = {
|
|||
| _ => None
|
||||
}
|
||||
|
||||
let floatCompare: (float, float) => int = compare
|
||||
|
||||
let binarySearchFirstElementGreaterIndex = (ar: array<'a>, el: 'a) => {
|
||||
let el = Belt.SortArray.binarySearchBy(ar, el, floatCompare)
|
||||
let el = el < 0 ? el * -1 - 1 : el
|
||||
|
@ -496,21 +539,9 @@ module A = {
|
|||
}
|
||||
}
|
||||
|
||||
let concat = (t1: array<'a>, t2: array<'a>) => {
|
||||
let ts = Belt.Array.concat(t1, t2)
|
||||
ts |> Array.fast_sort(floatCompare)
|
||||
ts
|
||||
}
|
||||
let concat = (t1: array<'a>, t2: array<'a>) => Belt.Array.concat(t1, t2)->sort
|
||||
|
||||
let concatMany = (t1: array<array<'a>>) => {
|
||||
let ts = Belt.Array.concatMany(t1)
|
||||
ts |> Array.fast_sort(floatCompare)
|
||||
ts
|
||||
}
|
||||
|
||||
module Floats = {
|
||||
let isSorted = (ar: array<float>): bool =>
|
||||
reduce(zip(ar, tail(ar)), true, (acc, (first, second)) => acc && first < second)
|
||||
let concatMany = (t1: array<array<'a>>) => Belt.Array.concatMany(t1)->sort
|
||||
|
||||
let makeIncrementalUp = (a, b) =>
|
||||
Array.make(b - a + 1, a) |> Array.mapi((i, c) => c + i) |> Belt.Array.map(_, float_of_int)
|
||||
|
@ -543,42 +574,7 @@ module A = {
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
module Floats = {
|
||||
let mean = Jstat.mean
|
||||
let geomean = Jstat.geomean
|
||||
let mode = Jstat.mode
|
||||
let variance = Jstat.variance
|
||||
let stdev = Jstat.stdev
|
||||
let sum = Jstat.sum
|
||||
let random = Js.Math.random_int
|
||||
|
||||
//Passing true for the exclusive parameter excludes both endpoints of the range.
|
||||
//https://jstat.github.io/all.html
|
||||
let percentile = (a, b) => Jstat.percentile(a, b, false)
|
||||
|
||||
// Gives an array with all the differences between values
|
||||
// diff([1,5,3,7]) = [4,-2,4]
|
||||
let diff = (arr: array<float>): array<float> =>
|
||||
Belt.Array.zipBy(arr, Belt.Array.sliceToEnd(arr, 1), (left, right) => right -. left)
|
||||
|
||||
exception RangeError(string)
|
||||
let range = (min: float, max: float, n: int): array<float> =>
|
||||
switch n {
|
||||
| 0 => []
|
||||
| 1 => [min]
|
||||
| 2 => [min, max]
|
||||
| _ if min == max => Belt.Array.make(n, min)
|
||||
| _ if n < 0 => raise(RangeError("n must be greater than 0"))
|
||||
| _ if min > max => raise(RangeError("Min value is less then max value"))
|
||||
| _ =>
|
||||
let diff = (max -. min) /. Belt.Float.fromInt(n - 1)
|
||||
Belt.Array.makeBy(n, i => min +. Belt.Float.fromInt(i) *. diff)
|
||||
}
|
||||
|
||||
let min = Js.Math.minMany_float
|
||||
let max = Js.Math.maxMany_float
|
||||
}
|
||||
module Sorted = Floats.Sorted;
|
||||
}
|
||||
|
||||
module A2 = {
|
||||
|
|
Loading…
Reference in New Issue
Block a user