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 => {
|
): Internals.Types.outputs => {
|
||||||
Array.fast_sort(compare, samples)
|
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 length = samples |> E.A.length |> float_of_int
|
||||||
let discrete: PointSetTypes.discreteShape =
|
let discrete: PointSetTypes.discreteShape =
|
||||||
discretePart
|
discretePart
|
||||||
|
|
|
@ -475,42 +475,73 @@ module A = {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
module Sorted = {
|
module Floats = {
|
||||||
let min = first
|
let mean = Jstat.mean
|
||||||
let max = last
|
let geomean = Jstat.geomean
|
||||||
let range = (~min=min, ~max=max, a) =>
|
let mode = Jstat.mode
|
||||||
switch (min(a), max(a)) {
|
let variance = Jstat.variance
|
||||||
| (Some(min), Some(max)) => Some(max -. min)
|
let stdev = Jstat.stdev
|
||||||
| _ => None
|
let sum = Jstat.sum
|
||||||
}
|
let random = Js.Math.random_int
|
||||||
|
|
||||||
let floatCompare: (float, float) => int = compare
|
let floatCompare: (float, float) => int = compare
|
||||||
|
let sort = t => {
|
||||||
|
let r = t
|
||||||
|
r |> Array.fast_sort(floatCompare)
|
||||||
|
r
|
||||||
|
}
|
||||||
|
|
||||||
let binarySearchFirstElementGreaterIndex = (ar: array<'a>, el: 'a) => {
|
let isSorted = (ar: array<float>): bool =>
|
||||||
let el = Belt.SortArray.binarySearchBy(ar, el, floatCompare)
|
reduce(zip(ar, tail(ar)), true, (acc, (first, second)) => acc && first < second)
|
||||||
let el = el < 0 ? el * -1 - 1 : el
|
|
||||||
switch el {
|
//Passing true for the exclusive parameter excludes both endpoints of the range.
|
||||||
| e if e >= length(ar) => #overMax
|
//https://jstat.github.io/all.html
|
||||||
| e if e == 0 => #underMin
|
let percentile = (a, b) => Jstat.percentile(a, b, false)
|
||||||
| e => #firstHigher(e)
|
|
||||||
|
// 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 concat = (t1: array<'a>, t2: array<'a>) => {
|
let min = Js.Math.minMany_float
|
||||||
let ts = Belt.Array.concat(t1, t2)
|
let max = Js.Math.maxMany_float
|
||||||
ts |> Array.fast_sort(floatCompare)
|
|
||||||
ts
|
|
||||||
}
|
|
||||||
|
|
||||||
let concatMany = (t1: array<array<'a>>) => {
|
module Sorted = {
|
||||||
let ts = Belt.Array.concatMany(t1)
|
let min = first
|
||||||
ts |> Array.fast_sort(floatCompare)
|
let max = last
|
||||||
ts
|
let range = (~min=min, ~max=max, a) =>
|
||||||
}
|
switch (min(a), max(a)) {
|
||||||
|
| (Some(min), Some(max)) => Some(max -. min)
|
||||||
|
| _ => None
|
||||||
|
}
|
||||||
|
|
||||||
module Floats = {
|
let binarySearchFirstElementGreaterIndex = (ar: array<'a>, el: 'a) => {
|
||||||
let isSorted = (ar: array<float>): bool =>
|
let el = Belt.SortArray.binarySearchBy(ar, el, floatCompare)
|
||||||
reduce(zip(ar, tail(ar)), true, (acc, (first, second)) => acc && first < second)
|
let el = el < 0 ? el * -1 - 1 : el
|
||||||
|
switch el {
|
||||||
|
| e if e >= length(ar) => #overMax
|
||||||
|
| e if e == 0 => #underMin
|
||||||
|
| e => #firstHigher(e)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
let concat = (t1: array<'a>, t2: array<'a>) => Belt.Array.concat(t1, t2)->sort
|
||||||
|
|
||||||
|
let concatMany = (t1: array<array<'a>>) => Belt.Array.concatMany(t1)->sort
|
||||||
|
|
||||||
let makeIncrementalUp = (a, b) =>
|
let makeIncrementalUp = (a, b) =>
|
||||||
Array.make(b - a + 1, a) |> Array.mapi((i, c) => c + i) |> Belt.Array.map(_, float_of_int)
|
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 Sorted = Floats.Sorted;
|
||||||
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 A2 = {
|
module A2 = {
|
||||||
|
|
Loading…
Reference in New Issue
Block a user