main.bend
mlbend-select@0.1.0.0 · 79 lines · 9 definitions
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17import Base
18import mlbend-split@0.1.1.0/main.bend as Split
19
20
21
22type Fold is Data:
23 Fold{test: List<&2, Nat>, train: List<&2, Nat>}
24
25
26
27
28law select_covers:
29 for labels: List<&2, Nat>
30 for +orders: List<&2, List<&2, Nat>>
31 for +k: Nat
32 for +i: Nat
33 {Split.count_rows(Split.folds_from(labels, orders, k, i)) == List.length(&2, Nat, labels) : Nat}
34
35
36def fold_of(+fs: List<&2, Nat>, +f: Nat) -> Fold:
37 Fold{Split.test_of(fs, f), Split.train_of(fs, f)}
38
39
40def fold_size(fs: List<&2, Nat>, f: Nat) -> Nat:
41 List.length(&2, Nat, Split.test_of(fs, f))
42
43
44def fold_sizes_go(+fs: List<&2, Nat>, k: Nat, +acc: List<&2, Nat>) -> List<&2, Nat>:
45 match k:
46 case 0n:
47 acc
48 case 1n++rest:
49 fold_sizes_go(fs, rest, Con{fold_size(fs, rest), acc})
50
51
52def fold_sizes(fs: List<&2, Nat>, k: Nat) -> List<&2, Nat>:
53 fold_sizes_go(fs, k, Nil{})
54
55
56def folds(labels: List<&2, Nat>, seed: U32, k: Nat) -> List<&2, Nat>:
57 Split.folds(labels, seed, k)
58
59
60def folds_go(+fs: List<&2, Nat>, k: Nat, +acc: List<&2, Fold>) -> List<&2, Fold>:
61 match k:
62 case 0n:
63 acc
64 case 1n++rest:
65 folds_go(fs, rest, Con{fold_of(fs, rest), acc})
66
67
68
69def folds_of(labels: List<&2, Nat>, seed: U32, +k: Nat) -> List<&2, Fold>:
70 folds_go(Split.folds(labels, seed, k), k, Nil{})
71
72
73def select_covers(labels, orders, k, i):
74 match labels:
75 case Nil{}:
76 {==}
77 case Con{h, +t}:
78 %select_covers(t, orders, k, Nat.add(i, 1n)) : {1n+Split.count_rows(Split.folds_from(t, orders, k, Nat.add(i, 1n))) == 1n+_ : Nat}
79 {==}