@explorable-viz/fluid 0.10.2 → 0.10.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,75 +1,86 @@
1
- let split [] = ([], []);
2
- split (x : xs) =
3
- let (ys, zs) = split xs in (x : zs, ys);
4
-
5
- let merge xs ys =
6
- match (xs, ys) as {
7
- ([], _) -> ys;
8
- (x : xs', []) -> xs;
9
- (x : xs', y : ys') ->
10
- if x < y
11
- then x : merge xs' ys
12
- else y : merge xs ys'
13
- };
14
-
15
- let mergesort xs =
16
- if length xs < 2
17
- then xs
18
- else
19
- let (ys, zs) = split xs in
20
- merge (mergesort ys) (mergesort zs);
21
-
22
- -- assume xs is sorted
23
- let findQuantile q p xs =
24
- let rank = (p / q) * (length xs - 1)
25
- in if rank == floor rank
26
- then nth rank xs
27
- else let x1 = floor rank;
28
- x2 = ceiling rank;
29
- left = nth x1 xs;
30
- right = nth x2 xs
31
- in left + (rank - x1) * (right - left);
32
-
33
- let findPercentile = findQuantile 100;
34
-
35
- let accumBins data Nil = [];
36
- accumBins data [l] = [];
37
- accumBins data (l : r : es) =
38
- let (ge, le) = splitOn (fun x -> x <= r) data
39
- in (le, r - l) : accumBins ge (r : es);
40
-
41
- let cut xs nbins =
42
- let low = minimum xs;
43
- binwidth = (maximum xs - low) / nbins;
44
- edges = [ low + (x * binwidth) | x <- enumFromTo 0 nbins ]
45
- in accumBins xs edges;
46
-
47
- let qcut xs qs =
48
- let (low, high) = (minimum xs, maximum xs);
49
- edges = append (low : [ findPercentile x xs | x <- qs], [high])
50
- in accumBins xs edges;
51
-
52
- let likelihoodLE xs target =
53
- length (filter (fun x -> x <= target) xs) / length xs;
54
-
55
- let likelihoodGE xs target =
56
- length (filter (fun x -> x >= target) xs) / length xs;
57
-
58
- let likelihoodMap table prob = (fromSome (find (fun x -> x.prob <= prob) table)).msg;
59
-
60
- let mkPercent num = numToStr (num * 100) ++ "%";
61
-
62
- let leqP n m =
63
- if n <= m
64
- then "less"
65
- else "more";
66
-
67
- let gradedLeqP n m =
68
- let ratio = n / m
69
- in if ratio <= 1.0
70
- then if ratio <=0.5
71
- then "much less"
72
- else "less"
73
- else if ratio >= 2.0
74
- then "much more"
75
- else "more";
1
+ def split([]): ([], [])
2
+ def split(x :| xs):
3
+ def (ys, zs): split(xs);
4
+
5
+ (x :| zs, ys);
6
+
7
+ def merge(xs, ys):
8
+ match (xs, ys):
9
+ case ([], _): ys
10
+ case (x :| xs', []): xs
11
+ case (x :| xs', y :| ys'):
12
+ if x < y: x :| merge(xs', ys)
13
+ else: y :| merge(xs, ys');
14
+
15
+ def mergesort(xs):
16
+ if length(xs) < 2: xs
17
+ else:
18
+ def (ys, zs): split(xs);
19
+
20
+ merge(mergesort(ys), mergesort(zs));
21
+
22
+ def findQuantile(q, p, xs):
23
+ def rank:
24
+ (p / q) * (length(xs) - 1);
25
+
26
+ if rank == floor(rank): nth(rank, xs)
27
+ else:
28
+ def x1: floor(rank)
29
+ def x2: ceiling(rank)
30
+ def left: nth(x1, xs)
31
+ def right: nth(x2, xs);
32
+
33
+ left + (rank - x1) * (right - left);
34
+
35
+ def findPercentile: findQuantile(100);
36
+
37
+ def accumBins(data, Nil): []
38
+ def accumBins(data, [l]): []
39
+ def accumBins(data, l :| r :| es):
40
+ def (ge, le):
41
+ splitOn((lambda x: x <= r), data);
42
+
43
+ (le, r - l) :| accumBins(ge, r :| es);
44
+
45
+ def cut(xs, nbins):
46
+ def low: minimum(xs)
47
+ def binwidth:
48
+ (maximum(xs) - low) / nbins
49
+ def edges:
50
+ [low + x * binwidth for x in enumFromTo(0, nbins)];
51
+
52
+ accumBins(xs, edges);
53
+
54
+ def qcut(xs, qs):
55
+ def (low, high):
56
+ (minimum(xs), maximum(xs))
57
+ def edges:
58
+ append((low :| [findPercentile(x, xs) for x in qs], [high]));
59
+
60
+ accumBins(xs, edges);
61
+
62
+ def likelihoodLE(xs, target):
63
+ length(filter((lambda x: x <= target), xs)) / length(xs);
64
+
65
+ def likelihoodGE(xs, target):
66
+ length(filter((lambda x: x >= target), xs)) / length(xs);
67
+
68
+ def likelihoodMap(table, prob):
69
+ fromSome(find((lambda x: x.prob <= prob), table)).msg;
70
+
71
+ def mkPercent(num):
72
+ numToStr(num * 100) ++ "%";
73
+
74
+ def leqP(n, m):
75
+ if n <= m: "less"
76
+ else: "more";
77
+
78
+ def gradedLeqP(n, m):
79
+ def ratio: n / m;
80
+
81
+ if ratio <= 1.0:
82
+ if ratio <= 0.5: "much less"
83
+ else: "less"
84
+ else:
85
+ if ratio >= 2.0: "much more"
86
+ else: "more";