@mark1russell7/rigor-generators 0.1.16 → 0.1.18
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.
- package/README.md +51 -0
- package/build/covering.d.ts +54 -0
- package/build/covering.d.ts.map +1 -0
- package/build/covering.js +187 -0
- package/build/covering.js.map +1 -0
- package/build/designs.d.ts.map +1 -1
- package/build/designs.js +25 -9
- package/build/designs.js.map +1 -1
- package/build/index.d.ts +3 -1
- package/build/index.js +3 -1
- package/build/shrink.d.ts +45 -0
- package/build/shrink.d.ts.map +1 -0
- package/build/shrink.js +130 -0
- package/build/shrink.js.map +1 -0
- package/package.json +7 -3
package/README.md
CHANGED
|
@@ -143,6 +143,57 @@ The parameters of a dimension come from `r.fork("dimension:" + name)`. The same
|
|
|
143
143
|
|
|
144
144
|
For the mean of a sum of 3 inputs from 50 points, the Latin hypercube gives 0.00042 of the variance of the random design. A test holds the ratio below 1/1000.
|
|
145
145
|
|
|
146
|
+
### Shrink a point that fails
|
|
147
|
+
|
|
148
|
+
`shrinkPoint` finds a smaller point of a family that still fails. Give it the family, the point and a function that gives `true` for a failure:
|
|
149
|
+
|
|
150
|
+
```ts
|
|
151
|
+
import { shrinkPoint } from "@mark1russell7/rigor-generators";
|
|
152
|
+
|
|
153
|
+
const shrunk = shrinkPoint(family, points[17]!, (point) => !check(point));
|
|
154
|
+
// shrunk.point, shrunk.steps, shrunk.checks, shrunk.exhausted
|
|
155
|
+
```
|
|
156
|
+
|
|
157
|
+
- The target of each dimension is the value of its range nearest to 0 (`shrinkTarget`).
|
|
158
|
+
- In each round, each dimension first tries its target. Then a bisection on the scale of the dimension finds the edge of the failure.
|
|
159
|
+
- A bisection of a double stops within `tolerance` of the range (default `SHRINK_TOLERANCE`, 1e-6). A log dimension uses the range of its logarithm.
|
|
160
|
+
- The rounds continue until no dimension moves, or until `maxChecks` checks (default `SHRINK_CHECKS`, 1000). Then `exhausted` is `true`.
|
|
161
|
+
- `steps` records each move: the dimension, the value before and the value after. The keys of the point that are not dimensions stay.
|
|
162
|
+
- The shrink has no random draws. The same point and the same function give the same result.
|
|
163
|
+
- `shrinkPointAsync` takes a function that gives a promise, for example a check in a child process.
|
|
164
|
+
|
|
165
|
+
A first point that does not fail is a `RangeError`. A value out of its range, or a value that is not an integer in an integer dimension, is also a `RangeError`.
|
|
166
|
+
|
|
167
|
+
## Covering arrays
|
|
168
|
+
|
|
169
|
+
A covering array of strength `t` has few rows, but each combination of `t` values of `t` different dimensions is in one row or more.
|
|
170
|
+
The default strength is 2, so each pair of values is in a row. A test of each row then finds each fault that 2 values cause together.
|
|
171
|
+
|
|
172
|
+
```ts
|
|
173
|
+
import { coveringRows, random, tupleCoverage } from "@mark1russell7/rigor-generators";
|
|
174
|
+
|
|
175
|
+
const dimensions = { shape: ["rect", "circle", "polygon"], count: [1, 10, 100], edges: ["none", "few", "many"], spacing: [0, 4] };
|
|
176
|
+
const rows = coveringRows(dimensions, random(1).fork("pairwise"));
|
|
177
|
+
// 9 rows hold the 45 pairs. The full product has 54 rows.
|
|
178
|
+
tupleCoverage(rows, dimensions).share; // 1
|
|
179
|
+
```
|
|
180
|
+
|
|
181
|
+
- `coveringArray(levels, r, options)` gives the index of a level of each dimension. `coveringRows(dimensions, r, options)` gives the values by name.
|
|
182
|
+
- The option `strength` sets `t`. With fewer dimensions than `t`, the array is the full product.
|
|
183
|
+
- The algorithm is a greedy AETG. It makes `candidates` rows (the default is 50) for each row that it keeps.
|
|
184
|
+
- The arrays are small, but not always the smallest. The row count is at least the product of the `t` largest counts of levels.
|
|
185
|
+
- The draws come from `r`. The same dimensions, options and seed give the same rows.
|
|
186
|
+
- `tupleCoverage(rows, dimensions, t)` gives the share of the combinations that some rows hold, and the list of the missing combinations. It compares the values as text.
|
|
187
|
+
- More than `COVERING_LIMIT` (10 million) combinations is a `RangeError`, not a long run.
|
|
188
|
+
|
|
189
|
+
### Moves from the copies
|
|
190
|
+
|
|
191
|
+
| Copy | Move |
|
|
192
|
+
| --- | --- |
|
|
193
|
+
| `pairwise(dimensions, seed)` of `packages/joint` in `layout-contract` | `coveringRows(dimensions, random(seed).fork("pairwise"))` gives the same rows. A test holds a record of the copy. One dimension gives a row for each value, not no rows. |
|
|
194
|
+
| `coverage(cells, dimensions)` of `packages/joint` in `layout-contract` | `tupleCoverage(cells, dimensions)`. The field `pairs` becomes `tuples`. A missing pair has the same key. |
|
|
195
|
+
| `allPairs` and `pairsOf` of `bench/law-cover.ts` in `packing` | `tupleCoverage`. The key of a pair changes from `area:x+aspect:y` to `area=x&aspect=y`. |
|
|
196
|
+
|
|
146
197
|
## The input of `fnv1a32`
|
|
147
198
|
|
|
148
199
|
The option `input` of `fnv1a32` selects the units that the hash reads. Use it to replace a local copy of FNV-1a with the same hashes.
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Covering arrays: few rows that still hold each combination of `t` values of `t` different dimensions.
|
|
3
|
+
* With the strength 2, each pair of values of 2 dimensions is in one row or more (a pairwise array).
|
|
4
|
+
*/
|
|
5
|
+
import { Random } from "./random.js";
|
|
6
|
+
/** The default count of candidate rows for each row that `coveringArray` keeps. */
|
|
7
|
+
export declare const COVERING_CANDIDATES = 50;
|
|
8
|
+
/** The largest count of combinations of values that one array covers. A larger array is an error, not a long run. */
|
|
9
|
+
export declare const COVERING_LIMIT = 1e7;
|
|
10
|
+
/** The options of `coveringArray` and `coveringRows`. */
|
|
11
|
+
export interface CoveringOptions {
|
|
12
|
+
/** The strength `t`: each `t` values of `t` different dimensions are in one row or more. The default is 2. */
|
|
13
|
+
readonly strength?: number;
|
|
14
|
+
/** The count of candidate rows for each row that the array keeps. The default is `COVERING_CANDIDATES`. */
|
|
15
|
+
readonly candidates?: number;
|
|
16
|
+
}
|
|
17
|
+
/** The coverage of a set of rows over some dimensions. */
|
|
18
|
+
export interface Coverage {
|
|
19
|
+
/** The count of the combinations of `t` values of `t` different dimensions. */
|
|
20
|
+
readonly tuples: number;
|
|
21
|
+
/** The count of the combinations that one row or more holds. */
|
|
22
|
+
readonly covered: number;
|
|
23
|
+
/** `covered` divided by `tuples`. Dimensions with no combination give 1. */
|
|
24
|
+
readonly share: number;
|
|
25
|
+
/** The combinations that no row holds, as `<dimension>=<value>&<dimension>=<value>`, in the order of the dimensions. */
|
|
26
|
+
readonly missing: readonly string[];
|
|
27
|
+
}
|
|
28
|
+
/**
|
|
29
|
+
* This function gives a covering array of strength `t` over dimensions with `levels[i]` levels each. Each row has the index
|
|
30
|
+
* of one level of each dimension. With fewer dimensions than `t`, the array covers each combination of all the dimensions.
|
|
31
|
+
* Thus no dimensions give one empty row, as the product of no sets has one item.
|
|
32
|
+
*
|
|
33
|
+
* The algorithm is a greedy AETG. Each row starts at a level with the most open combinations. The array makes `candidates`
|
|
34
|
+
* rows, and it keeps the row that covers the most new combinations. Each candidate takes the dimensions in a random order.
|
|
35
|
+
* Each dimension takes the level that covers the most new combinations with the dimensions before it.
|
|
36
|
+
* The random draws come from `r`, thus the same levels, options and seed give the same rows.
|
|
37
|
+
*
|
|
38
|
+
* This function throws a `RangeError` for a dimension with no level, for bad options, and for more than `COVERING_LIMIT` combinations.
|
|
39
|
+
*/
|
|
40
|
+
export declare function coveringArray(levels: readonly number[], r: Random, options?: CoveringOptions): number[][];
|
|
41
|
+
/**
|
|
42
|
+
* This function gives a covering array over named dimensions: each row has one value of each dimension. The values of a
|
|
43
|
+
* dimension are its levels, in their order. The options and the draws are those of `coveringArray`. The value of each name
|
|
44
|
+
* in a row has the type of the levels of its dimension. Thus dimensions of different types can be in one call.
|
|
45
|
+
*/
|
|
46
|
+
export declare function coveringRows<D extends Readonly<Record<string, readonly unknown[]>>>(dimensions: D, r: Random, options?: CoveringOptions): { [K in keyof D]: D[K][number]; }[];
|
|
47
|
+
/**
|
|
48
|
+
* This function gives the coverage of some rows over named dimensions, with the strength `t` (the default is 2). A row holds a
|
|
49
|
+
* combination when it has each of its values. The function compares the values as text with `String`, and it ignores the
|
|
50
|
+
* fields of a row that are not dimensions. With fewer dimensions than `t`, the combinations are those of all the dimensions.
|
|
51
|
+
* Thus no dimensions give one empty combination, with the key `""`.
|
|
52
|
+
*/
|
|
53
|
+
export declare function tupleCoverage(rows: readonly Readonly<Record<string, unknown>>[], dimensions: Readonly<Record<string, readonly unknown[]>>, strength?: number): Coverage;
|
|
54
|
+
//# sourceMappingURL=covering.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"covering.d.ts","names":[],"sources":["../src/covering.ts"],"mappings":";;;;;;qBAOa;;qBAGA;;iBAGI;;WAEN;;WAEA;;;iBAIM;;WAEN;;WAEA;;WAEA;;WAEA;;;;;;;;;;;;;;wBA2CK,cAAc,2BAA2B,GAAG,QAAQ,UAAS;;;;;;wBA8G7D,aAAa,UAAU,SAAS,qCAAqC,YAAY,GAAG,GAAG,QAAQ,UAAS,qBAA0B,WAAW,IAAI,EAAE;;;;;;;wBAgBnJ,cAAc,eAAe,SAAS,4BAA4B,YAAY,SAAS,qCAAqC,oBAAe"}
|
|
@@ -0,0 +1,187 @@
|
|
|
1
|
+
// src/covering.ts
|
|
2
|
+
/** The default count of candidate rows for each row that `coveringArray` keeps. */
|
|
3
|
+
const COVERING_CANDIDATES = 50;
|
|
4
|
+
/** The largest count of combinations of values that one array covers. A larger array is an error, not a long run. */
|
|
5
|
+
const COVERING_LIMIT = 1e7;
|
|
6
|
+
const isWhole = (value, least) => typeof value === "number" && Number.isSafeInteger(value) && value >= least;
|
|
7
|
+
/** This function gives each set of `t` indices from 0 to `k - 1`, each set in increasing order, the sets in lexical order. */
|
|
8
|
+
function combinations(k, t) {
|
|
9
|
+
const out = [];
|
|
10
|
+
const pick = [];
|
|
11
|
+
const walk = (from) => {
|
|
12
|
+
if (pick.length === t) {
|
|
13
|
+
out.push([...pick]);
|
|
14
|
+
return;
|
|
15
|
+
}
|
|
16
|
+
for (let i = from; i <= k - (t - pick.length); i++) {
|
|
17
|
+
pick.push(i);
|
|
18
|
+
walk(i + 1);
|
|
19
|
+
pick.pop();
|
|
20
|
+
}
|
|
21
|
+
};
|
|
22
|
+
walk(0);
|
|
23
|
+
return out;
|
|
24
|
+
}
|
|
25
|
+
/** This function checks the options and gives the strength for `k` dimensions: the given strength, or `k` when there are fewer dimensions. */
|
|
26
|
+
function strengthOf(k, options) {
|
|
27
|
+
const strength = options.strength ?? 2;
|
|
28
|
+
if (!isWhole(strength, 1)) throw new RangeError(`covering: the strength is a whole number of 1 or more, not ${String(strength)}.`);
|
|
29
|
+
return Math.min(strength, k);
|
|
30
|
+
}
|
|
31
|
+
/**
|
|
32
|
+
* This function gives a covering array of strength `t` over dimensions with `levels[i]` levels each. Each row has the index
|
|
33
|
+
* of one level of each dimension. With fewer dimensions than `t`, the array covers each combination of all the dimensions.
|
|
34
|
+
* Thus no dimensions give one empty row, as the product of no sets has one item.
|
|
35
|
+
*
|
|
36
|
+
* The algorithm is a greedy AETG. Each row starts at a level with the most open combinations. The array makes `candidates`
|
|
37
|
+
* rows, and it keeps the row that covers the most new combinations. Each candidate takes the dimensions in a random order.
|
|
38
|
+
* Each dimension takes the level that covers the most new combinations with the dimensions before it.
|
|
39
|
+
* The random draws come from `r`, thus the same levels, options and seed give the same rows.
|
|
40
|
+
*
|
|
41
|
+
* This function throws a `RangeError` for a dimension with no level, for bad options, and for more than `COVERING_LIMIT` combinations.
|
|
42
|
+
*/
|
|
43
|
+
function coveringArray(levels, r, options = {}) {
|
|
44
|
+
for (const [i, size] of levels.entries()) if (!isWhole(size, 1)) throw new RangeError(`coveringArray: dimension ${i} has ${String(size)} levels, not a whole number of 1 or more.`);
|
|
45
|
+
const t = strengthOf(levels.length, options);
|
|
46
|
+
const candidates = options.candidates ?? 50;
|
|
47
|
+
if (!isWhole(candidates, 1)) throw new RangeError(`coveringArray: candidates is a whole number of 1 or more, not ${String(candidates)}.`);
|
|
48
|
+
const k = levels.length;
|
|
49
|
+
if (k === 0) return [[]];
|
|
50
|
+
const combos = combinations(k, t);
|
|
51
|
+
const comboOf = new Map(combos.map((combo, index) => [combo.join(","), index]));
|
|
52
|
+
const sizes = combos.map((combo) => combo.reduce((product, d) => product * levels[d], 1));
|
|
53
|
+
const total = sizes.reduce((sum, size) => sum + size, 0);
|
|
54
|
+
if (total > 1e7) throw new RangeError(`coveringArray: ${total} combinations of values, more than ${COVERING_LIMIT}.`);
|
|
55
|
+
const open = sizes.map((size) => new Uint8Array(size).fill(1));
|
|
56
|
+
const openBy = levels.map((size, d) => new Array(size).fill(combos.reduce((sum, combo, c) => sum + (combo.includes(d) ? sizes[c] / levels[d] : 0), 0)));
|
|
57
|
+
let left = total;
|
|
58
|
+
const indexOf = (combo, row) => combo.reduce((index, d) => index * levels[d] + row[d], 0);
|
|
59
|
+
const bestLevel = (f, row, done, choose) => {
|
|
60
|
+
const sets = combinations(done.length, t - 1).map((rest) => {
|
|
61
|
+
const combo = [...rest.map((i) => done[i]), f].sort((a, b) => a - b);
|
|
62
|
+
return {
|
|
63
|
+
flags: open[comboOf.get(combo.join(","))],
|
|
64
|
+
combo
|
|
65
|
+
};
|
|
66
|
+
});
|
|
67
|
+
let top = -1;
|
|
68
|
+
let tops = [];
|
|
69
|
+
for (let v = 0; v < levels[f]; v++) {
|
|
70
|
+
row[f] = v;
|
|
71
|
+
let n = 0;
|
|
72
|
+
for (const { flags, combo } of sets) n += flags[indexOf(combo, row)];
|
|
73
|
+
if (n > top) {
|
|
74
|
+
top = n;
|
|
75
|
+
tops = [];
|
|
76
|
+
}
|
|
77
|
+
if (n === top) tops.push(v);
|
|
78
|
+
}
|
|
79
|
+
return [choose(tops), top];
|
|
80
|
+
};
|
|
81
|
+
const rows = [];
|
|
82
|
+
while (left > 0) {
|
|
83
|
+
let most = -1;
|
|
84
|
+
let starts = [];
|
|
85
|
+
for (let d = 0; d < k; d++) for (let v = 0; v < levels[d]; v++) {
|
|
86
|
+
if (openBy[d][v] > most) {
|
|
87
|
+
most = openBy[d][v];
|
|
88
|
+
starts = [];
|
|
89
|
+
}
|
|
90
|
+
if (openBy[d][v] === most) starts.push([d, v]);
|
|
91
|
+
}
|
|
92
|
+
let best = [];
|
|
93
|
+
let bestGain = -1;
|
|
94
|
+
for (let c = 0; c < candidates; c++) {
|
|
95
|
+
const [first, level] = r.pick(starts);
|
|
96
|
+
const row = new Array(k).fill(-1);
|
|
97
|
+
row[first] = level;
|
|
98
|
+
const done = [first];
|
|
99
|
+
let gain = t === 1 ? open[comboOf.get(String(first))][level] : 0;
|
|
100
|
+
for (const f of r.shuffle([...Array(k).keys()].filter((d) => d !== first))) {
|
|
101
|
+
const [chosen, top] = bestLevel(f, row, done, (ties) => r.pick(ties));
|
|
102
|
+
row[f] = chosen;
|
|
103
|
+
gain += top;
|
|
104
|
+
done.push(f);
|
|
105
|
+
}
|
|
106
|
+
if (gain > bestGain) {
|
|
107
|
+
best = row;
|
|
108
|
+
bestGain = gain;
|
|
109
|
+
}
|
|
110
|
+
}
|
|
111
|
+
if (bestGain === 0) {
|
|
112
|
+
const c = open.findIndex((flags) => flags.includes(1));
|
|
113
|
+
let index = open[c].indexOf(1);
|
|
114
|
+
best = new Array(k).fill(-1);
|
|
115
|
+
for (const d of [...combos[c]].reverse()) {
|
|
116
|
+
best[d] = index % levels[d];
|
|
117
|
+
index = Math.floor(index / levels[d]);
|
|
118
|
+
}
|
|
119
|
+
const done = [...combos[c]];
|
|
120
|
+
for (let f = 0; f < k; f++) {
|
|
121
|
+
if (done.includes(f)) continue;
|
|
122
|
+
best[f] = bestLevel(f, best, done, (ties) => ties[0])[0];
|
|
123
|
+
done.push(f);
|
|
124
|
+
}
|
|
125
|
+
}
|
|
126
|
+
for (const [c, combo] of combos.entries()) {
|
|
127
|
+
const at = indexOf(combo, best);
|
|
128
|
+
if (open[c][at] === 1) {
|
|
129
|
+
open[c][at] = 0;
|
|
130
|
+
left--;
|
|
131
|
+
for (const d of combo) openBy[d][best[d]]--;
|
|
132
|
+
}
|
|
133
|
+
}
|
|
134
|
+
rows.push(best);
|
|
135
|
+
}
|
|
136
|
+
return rows;
|
|
137
|
+
}
|
|
138
|
+
/**
|
|
139
|
+
* This function gives a covering array over named dimensions: each row has one value of each dimension. The values of a
|
|
140
|
+
* dimension are its levels, in their order. The options and the draws are those of `coveringArray`. The value of each name
|
|
141
|
+
* in a row has the type of the levels of its dimension. Thus dimensions of different types can be in one call.
|
|
142
|
+
*/
|
|
143
|
+
function coveringRows(dimensions, r, options = {}) {
|
|
144
|
+
const names = Object.keys(dimensions);
|
|
145
|
+
const levels = dimensions;
|
|
146
|
+
return coveringArray(names.map((name) => levels[name].length), r, options).map((row) => Object.fromEntries(names.map((name, i) => [name, levels[name][row[i]]])));
|
|
147
|
+
}
|
|
148
|
+
/**
|
|
149
|
+
* This function gives the coverage of some rows over named dimensions, with the strength `t` (the default is 2). A row holds a
|
|
150
|
+
* combination when it has each of its values. The function compares the values as text with `String`, and it ignores the
|
|
151
|
+
* fields of a row that are not dimensions. With fewer dimensions than `t`, the combinations are those of all the dimensions.
|
|
152
|
+
* Thus no dimensions give one empty combination, with the key `""`.
|
|
153
|
+
*/
|
|
154
|
+
function tupleCoverage(rows, dimensions, strength = 2) {
|
|
155
|
+
const names = Object.keys(dimensions);
|
|
156
|
+
const t = strengthOf(names.length, { strength });
|
|
157
|
+
const combos = combinations(names.length, t);
|
|
158
|
+
const keyOf = (combo, values) => combo.map((d, i) => `${names[d]}=${String(values[i])}`).join("&");
|
|
159
|
+
let tuples = 0;
|
|
160
|
+
for (const combo of combos) tuples += combo.reduce((product, d) => product * dimensions[names[d]].length, 1);
|
|
161
|
+
if (tuples > 1e7) throw new RangeError(`tupleCoverage: ${tuples} combinations of values, more than ${COVERING_LIMIT}.`);
|
|
162
|
+
const seen = /* @__PURE__ */ new Set();
|
|
163
|
+
for (const row of rows) for (const combo of combos) seen.add(keyOf(combo, combo.map((d) => row[names[d]])));
|
|
164
|
+
const missing = [];
|
|
165
|
+
for (const combo of combos) {
|
|
166
|
+
const values = combo.map((d) => dimensions[names[d]]);
|
|
167
|
+
const walk = (i, chosen) => {
|
|
168
|
+
if (i === combo.length) {
|
|
169
|
+
const key = keyOf(combo, chosen);
|
|
170
|
+
if (!seen.has(key)) missing.push(key);
|
|
171
|
+
return;
|
|
172
|
+
}
|
|
173
|
+
for (const value of values[i]) walk(i + 1, [...chosen, value]);
|
|
174
|
+
};
|
|
175
|
+
walk(0, []);
|
|
176
|
+
}
|
|
177
|
+
const covered = tuples - missing.length;
|
|
178
|
+
return {
|
|
179
|
+
tuples,
|
|
180
|
+
covered,
|
|
181
|
+
share: tuples === 0 ? 1 : covered / tuples,
|
|
182
|
+
missing
|
|
183
|
+
};
|
|
184
|
+
}
|
|
185
|
+
export { COVERING_CANDIDATES, COVERING_LIMIT, coveringArray, coveringRows, tupleCoverage };
|
|
186
|
+
|
|
187
|
+
//# sourceMappingURL=covering.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"covering.js","names":[],"sources":["../src/covering.ts"],"sourcesContent":["/**\n * Covering arrays: few rows that still hold each combination of `t` values of `t` different dimensions.\n * With the strength 2, each pair of values of 2 dimensions is in one row or more (a pairwise array).\n */\nimport type { Random } from \"./random.ts\";\n\n/** The default count of candidate rows for each row that `coveringArray` keeps. */\nexport const COVERING_CANDIDATES = 50;\n\n/** The largest count of combinations of values that one array covers. A larger array is an error, not a long run. */\nexport const COVERING_LIMIT = 10_000_000;\n\n/** The options of `coveringArray` and `coveringRows`. */\nexport interface CoveringOptions {\n /** The strength `t`: each `t` values of `t` different dimensions are in one row or more. The default is 2. */\n readonly strength?: number;\n /** The count of candidate rows for each row that the array keeps. The default is `COVERING_CANDIDATES`. */\n readonly candidates?: number;\n}\n\n/** The coverage of a set of rows over some dimensions. */\nexport interface Coverage {\n /** The count of the combinations of `t` values of `t` different dimensions. */\n readonly tuples: number;\n /** The count of the combinations that one row or more holds. */\n readonly covered: number;\n /** `covered` divided by `tuples`. Dimensions with no combination give 1. */\n readonly share: number;\n /** The combinations that no row holds, as `<dimension>=<value>&<dimension>=<value>`, in the order of the dimensions. */\n readonly missing: readonly string[];\n}\n\nconst isWhole = (value: unknown, least: number): value is number => typeof value === \"number\" && Number.isSafeInteger(value) && value >= least;\n\n/** This function gives each set of `t` indices from 0 to `k - 1`, each set in increasing order, the sets in lexical order. */\nfunction combinations(k: number, t: number): number[][] {\n const out: number[][] = [];\n const pick: number[] = [];\n const walk = (from: number): void => {\n if (pick.length === t) {\n out.push([...pick]);\n return;\n }\n for (let i = from; i <= k - (t - pick.length); i++) {\n pick.push(i);\n walk(i + 1);\n pick.pop();\n }\n };\n walk(0);\n return out;\n}\n\n/** This function checks the options and gives the strength for `k` dimensions: the given strength, or `k` when there are fewer dimensions. */\nfunction strengthOf(k: number, options: CoveringOptions): number {\n const strength = options.strength ?? 2;\n if (!isWhole(strength, 1)) throw new RangeError(`covering: the strength is a whole number of 1 or more, not ${String(strength)}.`);\n return Math.min(strength, k);\n}\n\n/**\n * This function gives a covering array of strength `t` over dimensions with `levels[i]` levels each. Each row has the index\n * of one level of each dimension. With fewer dimensions than `t`, the array covers each combination of all the dimensions.\n * Thus no dimensions give one empty row, as the product of no sets has one item.\n *\n * The algorithm is a greedy AETG. Each row starts at a level with the most open combinations. The array makes `candidates`\n * rows, and it keeps the row that covers the most new combinations. Each candidate takes the dimensions in a random order.\n * Each dimension takes the level that covers the most new combinations with the dimensions before it.\n * The random draws come from `r`, thus the same levels, options and seed give the same rows.\n *\n * This function throws a `RangeError` for a dimension with no level, for bad options, and for more than `COVERING_LIMIT` combinations.\n */\nexport function coveringArray(levels: readonly number[], r: Random, options: CoveringOptions = {}): number[][] {\n for (const [i, size] of levels.entries()) {\n if (!isWhole(size, 1)) throw new RangeError(`coveringArray: dimension ${i} has ${String(size)} levels, not a whole number of 1 or more.`);\n }\n const t = strengthOf(levels.length, options);\n const candidates = options.candidates ?? COVERING_CANDIDATES;\n if (!isWhole(candidates, 1)) throw new RangeError(`coveringArray: candidates is a whole number of 1 or more, not ${String(candidates)}.`);\n const k = levels.length;\n if (k === 0) return [[]];\n\n const combos = combinations(k, t);\n const comboOf = new Map(combos.map((combo, index) => [combo.join(\",\"), index]));\n const sizes = combos.map((combo) => combo.reduce((product, d) => product * levels[d]!, 1));\n const total = sizes.reduce((sum, size) => sum + size, 0);\n if (total > COVERING_LIMIT) throw new RangeError(`coveringArray: ${total} combinations of values, more than ${COVERING_LIMIT}.`);\n // open[c][index] is 1 while the combination `index` of the values of the dimensions `combos[c]` has no row.\n const open = sizes.map((size) => new Uint8Array(size).fill(1));\n // openBy[d][v] is the count of the open combinations that hold level `v` of dimension `d`.\n const openBy = levels.map((size, d) => new Array<number>(size).fill(combos.reduce((sum, combo, c) => sum + (combo.includes(d) ? sizes[c]! / levels[d]! : 0), 0)));\n let left = total;\n const indexOf = (combo: readonly number[], row: readonly number[]): number => combo.reduce((index, d) => index * levels[d]! + row[d]!, 0);\n // The level of dimension `f` that closes the most open combinations with the levels of the row on the dimensions `done`.\n // The gain of a level counts each set of `t - 1` dimensions of `done` with `f`. The function draws among the ties with `choose`.\n const bestLevel = (f: number, row: number[], done: readonly number[], choose: (ties: number[]) => number): [level: number, gain: number] => {\n const sets = combinations(done.length, t - 1).map((rest) => {\n const combo = [...rest.map((i) => done[i]!), f].sort((a, b) => a - b);\n return { flags: open[comboOf.get(combo.join(\",\"))!]!, combo };\n });\n let top = -1;\n let tops: number[] = [];\n for (let v = 0; v < levels[f]!; v++) {\n row[f] = v;\n let n = 0;\n for (const { flags, combo } of sets) n += flags[indexOf(combo, row)]!;\n if (n > top) {\n top = n;\n tops = [];\n }\n if (n === top) tops.push(v);\n }\n return [choose(tops), top];\n };\n\n const rows: number[][] = [];\n while (left > 0) {\n let most = -1;\n let starts: [number, number][] = [];\n for (let d = 0; d < k; d++) {\n for (let v = 0; v < levels[d]!; v++) {\n if (openBy[d]![v]! > most) {\n most = openBy[d]![v]!;\n starts = [];\n }\n if (openBy[d]![v] === most) starts.push([d, v]);\n }\n }\n let best: number[] = [];\n let bestGain = -1;\n for (let c = 0; c < candidates; c++) {\n const [first, level] = r.pick(starts);\n const row = new Array<number>(k).fill(-1);\n row[first] = level;\n const done = [first];\n let gain = t === 1 ? open[comboOf.get(String(first))!]![level]! : 0;\n for (const f of r.shuffle([...Array(k).keys()].filter((d) => d !== first))) {\n const [chosen, top] = bestLevel(f, row, done, (ties) => r.pick(ties));\n row[f] = chosen;\n gain += top;\n done.push(f);\n }\n if (gain > bestGain) {\n best = row;\n bestGain = gain;\n }\n }\n if (bestGain === 0) {\n // With a strength of 3 or more, the greedy rows can miss each open combination. The row then starts from the first open\n // combination, and each other dimension takes its lowest level with the most gain. This row closes one combination or more.\n const c = open.findIndex((flags) => flags.includes(1));\n let index = open[c]!.indexOf(1);\n best = new Array<number>(k).fill(-1);\n for (const d of [...combos[c]!].reverse()) {\n best[d] = index % levels[d]!;\n index = Math.floor(index / levels[d]!);\n }\n const done = [...combos[c]!];\n for (let f = 0; f < k; f++) {\n if (done.includes(f)) continue;\n best[f] = bestLevel(f, best, done, (ties) => ties[0]!)[0];\n done.push(f);\n }\n }\n for (const [c, combo] of combos.entries()) {\n const at = indexOf(combo, best);\n if (open[c]![at] === 1) {\n open[c]![at] = 0;\n left--;\n for (const d of combo) openBy[d]![best[d]!]!--;\n }\n }\n rows.push(best);\n }\n return rows;\n}\n\n/**\n * This function gives a covering array over named dimensions: each row has one value of each dimension. The values of a\n * dimension are its levels, in their order. The options and the draws are those of `coveringArray`. The value of each name\n * in a row has the type of the levels of its dimension. Thus dimensions of different types can be in one call.\n */\nexport function coveringRows<D extends Readonly<Record<string, readonly unknown[]>>>(dimensions: D, r: Random, options: CoveringOptions = {}): { [K in keyof D]: D[K][number] }[] {\n const names = Object.keys(dimensions);\n const levels: Readonly<Record<string, readonly unknown[]>> = dimensions;\n return coveringArray(\n names.map((name) => levels[name]!.length),\n r,\n options,\n ).map((row) => Object.fromEntries(names.map((name, i) => [name, levels[name]![row[i]!]])) as { [K in keyof D]: D[K][number] });\n}\n\n/**\n * This function gives the coverage of some rows over named dimensions, with the strength `t` (the default is 2). A row holds a\n * combination when it has each of its values. The function compares the values as text with `String`, and it ignores the\n * fields of a row that are not dimensions. With fewer dimensions than `t`, the combinations are those of all the dimensions.\n * Thus no dimensions give one empty combination, with the key `\"\"`.\n */\nexport function tupleCoverage(rows: readonly Readonly<Record<string, unknown>>[], dimensions: Readonly<Record<string, readonly unknown[]>>, strength = 2): Coverage {\n const names = Object.keys(dimensions);\n const t = strengthOf(names.length, { strength });\n const combos = combinations(names.length, t);\n const keyOf = (combo: readonly number[], values: readonly unknown[]): string => combo.map((d, i) => `${names[d]}=${String(values[i])}`).join(\"&\");\n let tuples = 0;\n for (const combo of combos) tuples += combo.reduce((product, d) => product * dimensions[names[d]!]!.length, 1);\n if (tuples > COVERING_LIMIT) throw new RangeError(`tupleCoverage: ${tuples} combinations of values, more than ${COVERING_LIMIT}.`);\n const seen = new Set<string>();\n for (const row of rows) {\n for (const combo of combos) seen.add(keyOf(combo, combo.map((d) => row[names[d]!])));\n }\n const missing: string[] = [];\n for (const combo of combos) {\n const values = combo.map((d) => dimensions[names[d]!]!);\n const walk = (i: number, chosen: unknown[]): void => {\n if (i === combo.length) {\n const key = keyOf(combo, chosen);\n if (!seen.has(key)) missing.push(key);\n return;\n }\n for (const value of values[i]!) walk(i + 1, [...chosen, value]);\n };\n walk(0, []);\n }\n const covered = tuples - missing.length;\n return { tuples, covered, share: tuples === 0 ? 1 : covered / tuples, missing };\n}\n"],"mappings":";;AAOA,MAAa,sBAAsB;;AAGnC,MAAa,iBAAiB;AAsB9B,MAAM,WAAW,OAAgB,UAAmC,OAAO,UAAU,YAAY,OAAO,cAAc,KAAK,KAAK,SAAS;;AAGzI,SAAS,aAAa,GAAW,GAAuB;CACtD,MAAM,MAAkB,CAAC;CACzB,MAAM,OAAiB,CAAC;CACxB,MAAM,QAAQ,SAAuB;EACnC,IAAI,KAAK,WAAW,GAAG;GACrB,IAAI,KAAK,CAAC,GAAG,IAAI,CAAC;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W,MAAM,GAAI,CAAE,QAAQ,CAAC;CAC7G,IAAI,SAAA,KAAyB,MAAM,IAAI,WAAW,kBAAkB,OAAO,qCAAqC,eAAe,EAAE;CACjI,MAAM,uBAAO,IAAI,IAAY;CAC7B,KAAK,MAAM,OAAO,MAChB,KAAK,MAAM,SAAS,QAAQ,KAAK,IAAI,MAAM,OAAO,MAAM,KAAK,MAAM,IAAI,MAAM,GAAI,CAAC,CAAC;CAErF,MAAM,UAAoB,CAAC;CAC3B,KAAK,MAAM,SAAS,QAAQ;EAC1B,MAAM,SAAS,MAAM,KAAK,MAAM,WAAW,MAAM,GAAK;EACtD,MAAM,QAAQ,GAAW,WAA4B;GACnD,IAAI,MAAM,MAAM,QAAQ;IACtB,MAAM,MAAM,MAAM,OAAO,MAAM;IAC/B,IAAI,CAAC,KAAK,IAAI,GAAG,GAAG,QAAQ,KAAK,GAAG;IACpC;GACF;GACA,KAAK,MAAM,SAAS,OAAO,IAAK,KAAK,IAAI,GAAG,CAAC,GAAG,QAAQ,KAAK,CAAC;EAChE;EACA,KAAK,GAAG,CAAC,CAAC;CACZ;CACA,MAAM,UAAU,SAAS,QAAQ;CACjC,OAAO;EAAE;EAAQ;EAAS,OAAO,WAAW,IAAI,IAAI,UAAU;EAAQ;CAAQ;AAChF"}
|
package/build/designs.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"designs.d.ts","names":[],"sources":["../src/designs.ts"],"mappings":";;;iBAOiB;;WAEN;;WAEA;;WAEA;;WAEA,eAAe;;WAEf;;WAEA;;;iBAIM;WACN;WACA,qBAAqB;;;YAIpB,QAAQ,SAAS;;iBAGZ;WACN;WACA;;WAEA;;;;;;;
|
|
1
|
+
{"version":3,"file":"designs.d.ts","names":[],"sources":["../src/designs.ts"],"mappings":";;;iBAOiB;;WAEN;;WAEA;;WAEA;;WAEA,eAAe;;WAEf;;WAEA;;;iBAIM;WACN;WACA,qBAAqB;;;YAIpB,QAAQ,SAAS;;iBAGZ;WACN;WACA;;WAEA;;;;;;;wBA0FK,UAAU,QAAQ,aAAa,GAAG,UAAU,4BAA4B;;wBAgBxE,aAAa,QAAQ,aAAa,sCAAsC,GAAG,SAAS;;wBAMpF,aAAa,WAAW,WAAW,GAAG;;;;;wBAUtC,eAAe,WAAW,WAAW,GAAG;;;;;wBAgBxC,iBAAiB,gBAAgB,WAAW,GAAG,QAAQ;;;;;;wBAoBvD,eAAe,WAAW,WAAW,GAAG,QAAQ,4BAAsC"}
|
package/build/designs.js
CHANGED
|
@@ -20,17 +20,26 @@ function belowOne(x) {
|
|
|
20
20
|
function count(fn, name, value) {
|
|
21
21
|
if (!Number.isSafeInteger(value) || value < 1) throw new RangeError(`${fn}: ${name} is ${value}, and it must be an integer from 1.`);
|
|
22
22
|
}
|
|
23
|
-
/**
|
|
24
|
-
function
|
|
23
|
+
/**
|
|
24
|
+
* This function examines a dimension of a family. A range that is not finite, an integer dimension without integer ends and
|
|
25
|
+
* a bad scale are each a `RangeError`.
|
|
26
|
+
*/
|
|
27
|
+
function checkDimension(family, dim) {
|
|
25
28
|
const where = `${family}.${dim.name}`;
|
|
26
29
|
if (!Number.isFinite(dim.min) || !Number.isFinite(dim.max) || dim.min > dim.max) throw new RangeError(`${where}: the range ${dim.min} to ${dim.max} is not a finite range.`);
|
|
27
30
|
if (dim.integer === true && (!Number.isSafeInteger(dim.min) || !Number.isSafeInteger(dim.max))) throw new RangeError(`${where}: an integer dimension needs integer ends, not ${dim.min} and ${dim.max}.`);
|
|
31
|
+
if (dim.distribution !== void 0 && dim.scale !== void 0) throw new RangeError(`${where}: a dimension with a distribution has no scale.`);
|
|
32
|
+
if (dim.scale === "log" && !(dim.min > 0)) throw new RangeError(`${where}: a log scale needs a minimum above 0, not ${dim.min}.`);
|
|
33
|
+
}
|
|
34
|
+
/** This function examines a dimension and gives the map from a uniform number in [0, 1) to a value of the dimension. */
|
|
35
|
+
function dimensionMap(family, dim, r) {
|
|
36
|
+
const where = `${family}.${dim.name}`;
|
|
37
|
+
checkDimension(family, dim);
|
|
28
38
|
const end = dim.integer === true ? dim.max + 1 : dim.max;
|
|
29
39
|
const top = dim.integer === true ? nextDown(end) : end;
|
|
30
40
|
const whole = (x) => dim.integer === true ? Math.min(dim.max, Math.floor(x)) : x;
|
|
31
41
|
const clamp = (x) => Math.min(top, Math.max(dim.min, x));
|
|
32
42
|
if (dim.distribution !== void 0) {
|
|
33
|
-
if (dim.scale !== void 0) throw new RangeError(`${where}: a dimension with a distribution has no scale.`);
|
|
34
43
|
const d = distributionOf(dim.distribution, r);
|
|
35
44
|
const low = d.cdf(nextDown(dim.min));
|
|
36
45
|
const high = d.cdf(top);
|
|
@@ -42,22 +51,29 @@ function dimensionMap(family, dim, r) {
|
|
|
42
51
|
};
|
|
43
52
|
}
|
|
44
53
|
if (dim.scale === "log") {
|
|
45
|
-
if (!(dim.min > 0)) throw new RangeError(`${where}: a log scale needs a minimum above 0, not ${dim.min}.`);
|
|
46
54
|
const span = Math.log(end / dim.min);
|
|
47
55
|
return (u) => whole(clamp(dim.min * Math.exp(u * span)));
|
|
48
56
|
}
|
|
49
57
|
return (u) => whole(clamp(dim.min + u * (end - dim.min)));
|
|
50
58
|
}
|
|
51
59
|
/**
|
|
52
|
-
* This function gives the
|
|
53
|
-
*
|
|
54
|
-
* same seed gives the same map, and a new dimension does not change the others.
|
|
60
|
+
* This function gives the names of the dimensions of a family. A family with no dimension is a `RangeError`. A name that
|
|
61
|
+
* is empty or not unique is also a `RangeError`.
|
|
55
62
|
*/
|
|
56
|
-
function
|
|
63
|
+
function familyNames(family) {
|
|
57
64
|
if (family.dimensions.length === 0) throw new RangeError(`${family.name}: a family needs one dimension or more.`);
|
|
58
65
|
const names = family.dimensions.map((d) => d.name);
|
|
59
66
|
const twice = names.find((n, i) => n === "" || names.indexOf(n) !== i);
|
|
60
67
|
if (twice !== void 0) throw new RangeError(`${family.name}: the dimension name "${twice}" is empty or not unique.`);
|
|
68
|
+
return names;
|
|
69
|
+
}
|
|
70
|
+
/**
|
|
71
|
+
* This function gives the map from a point of the unit cube to a point of the family. Coordinate `i` gives the value of
|
|
72
|
+
* dimension `i`. The parameters of each distribution come from `r.fork("dimension:" + name)` one time. Thus the
|
|
73
|
+
* same seed gives the same map, and a new dimension does not change the others.
|
|
74
|
+
*/
|
|
75
|
+
function familyMap(family, r) {
|
|
76
|
+
const names = familyNames(family);
|
|
61
77
|
const maps = family.dimensions.map((d) => dimensionMap(family.name, d, r.fork(`dimension:${d.name}`)));
|
|
62
78
|
return (unit) => {
|
|
63
79
|
if (unit.length !== maps.length) throw new RangeError(`${family.name}: a point needs ${maps.length} coordinates, not ${unit.length}.`);
|
|
@@ -129,6 +145,6 @@ function saltelliDesign(n, d, r, base = "random") {
|
|
|
129
145
|
ab: Array.from({ length: d }, (_, i) => a.map((row, k) => row.map((x, j) => j === i ? b[k][j] : x)))
|
|
130
146
|
};
|
|
131
147
|
}
|
|
132
|
-
export { familyMap, familyPoints, latinHypercube, randomDesign, saltelliDesign, stratifiedDesign };
|
|
148
|
+
export { checkDimension, familyMap, familyNames, familyPoints, latinHypercube, randomDesign, saltelliDesign, stratifiedDesign };
|
|
133
149
|
|
|
134
150
|
//# sourceMappingURL=designs.js.map
|
package/build/designs.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"designs.js","names":[],"sources":["../src/designs.ts"],"sourcesContent":["// Input families and the designs that draw their points (R5). A design gives points of the unit cube. `familyMap`\n// takes each point to a point of the family: a value from the range of each dimension.\nimport type { DistributionSpec } from \"./distributions.ts\";\nimport { distributionOf } from \"./quantiles.ts\";\nimport type { Random } from \"./random.ts\";\n\n/** One dimension of an input family. */\nexport interface Dimension {\n /** The name of the dimension. It is a key of each point. */\n readonly name: string;\n /** The smallest value. */\n readonly min: number;\n /** The largest value. A uniform or log dimension that is not `integer` gets values below `max`. */\n readonly max: number;\n /** The distribution of the values, cut to the range. Without it, the values are uniform in the range. */\n readonly distribution?: DistributionSpec;\n /** With `log`, the logarithm of the value is uniform. `min` must be above 0. A dimension with a distribution has no scale. */\n readonly scale?: \"linear\" | \"log\";\n /** With `true`, each value is an integer. `min` and `max` must be integers. */\n readonly integer?: boolean;\n}\n\n/** An input family: its name and its dimensions. */\nexport interface InputFamily {\n readonly name: string;\n readonly dimensions: readonly Dimension[];\n}\n\n/** One point of a family: one value for each dimension, by name. */\nexport type Point = Readonly<Record<string, number>>;\n\n/** The Saltelli design: the matrices `a` and `b`, and for each dimension `i` the matrix `ab[i]`. */\nexport interface SaltelliDesign {\n readonly a: number[][];\n readonly b: number[][];\n /** `ab[i]` is `a` with the column `i` of `b`. */\n readonly ab: number[][][];\n}\n\nconst BELOW_ONE = 1 - Number.EPSILON / 2;\n\n/** This function gives the next double toward minus infinity. */\nfunction nextDown(x: number): number {\n if (x === 0) return -Number.MIN_VALUE;\n const f = new Float64Array([x]);\n const bits = new BigInt64Array(f.buffer);\n bits[0] = x > 0 ? bits[0]! - 1n : bits[0]! + 1n;\n return f[0]!;\n}\n\n/** This function gives the next double toward plus infinity. */\nfunction nextUp(x: number): number {\n return -nextDown(-x);\n}\n\n/** This function keeps a value below 1. A sum of a stratum and a draw can round up to 1. */\nfunction belowOne(x: number): number {\n return x < 1 ? x : BELOW_ONE;\n}\n\nfunction count(fn: string, name: string, value: number): void {\n if (!Number.isSafeInteger(value) || value < 1) throw new RangeError(`${fn}: ${name} is ${value}, and it must be an integer from 1.`);\n}\n\n/** This function examines a dimension and gives the map from a uniform number in [0, 1) to a value of the dimension. */\nfunction dimensionMap(family: string, dim: Dimension, r: Random): (u: number) => number {\n const where = `${family}.${dim.name}`;\n if (!Number.isFinite(dim.min) || !Number.isFinite(dim.max) || dim.min > dim.max) {\n throw new RangeError(`${where}: the range ${dim.min} to ${dim.max} is not a finite range.`);\n }\n if (dim.integer === true && (!Number.isSafeInteger(dim.min) || !Number.isSafeInteger(dim.max))) {\n throw new RangeError(`${where}: an integer dimension needs integer ends, not ${dim.min} and ${dim.max}.`);\n }\n // An integer dimension takes the floor of a value from [min, max + 1).\n const end = dim.integer === true ? dim.max + 1 : dim.max;\n const top = dim.integer === true ? nextDown(end) : end;\n const whole = (x: number): number => (dim.integer === true ? Math.min(dim.max, Math.floor(x)) : x);\n const clamp = (x: number): number => Math.min(top, Math.max(dim.min, x));\n if (dim.distribution !== undefined) {\n if (dim.scale !== undefined) throw new RangeError(`${where}: a dimension with a distribution has no scale.`);\n const d = distributionOf(dim.distribution, r);\n const low = d.cdf(nextDown(dim.min));\n const high = d.cdf(top);\n if (!(high > low)) throw new RangeError(`${where}: the distribution has no probability from ${dim.min} to ${dim.max}.`);\n // A discrete quantile at `low` can be a value below `min`. The smallest value above `low` is then the first value in the range.\n const first = d.quantile(nextUp(low));\n return (u) => {\n const x = d.quantile(low + u * (high - low));\n return whole(clamp(x < dim.min ? first : x));\n };\n }\n if (dim.scale === \"log\") {\n if (!(dim.min > 0)) throw new RangeError(`${where}: a log scale needs a minimum above 0, not ${dim.min}.`);\n // The form `min * exp(u * span)` gives `min` exactly at 0.\n const span = Math.log(end / dim.min);\n return (u) => whole(clamp(dim.min * Math.exp(u * span)));\n }\n return (u) => whole(clamp(dim.min + u * (end - dim.min)));\n}\n\n/**\n * This function gives the map from a point of the unit cube to a point of the family. Coordinate `i` gives the value of\n * dimension `i`. The parameters of each distribution come from `r.fork(\"dimension:\" + name)` one time. Thus the\n * same seed gives the same map, and a new dimension does not change the others.\n */\nexport function familyMap(family: InputFamily, r: Random): (unit: readonly number[]) => Point {\n if (family.dimensions.length === 0) throw new RangeError(`${family.name}: a family needs one dimension or more.`);\n const names = family.dimensions.map((d) => d.name);\n const twice = names.find((n, i) => n === \"\" || names.indexOf(n) !== i);\n if (twice !== undefined) throw new RangeError(`${family.name}: the dimension name \"${twice}\" is empty or not unique.`);\n const maps = family.dimensions.map((d) => dimensionMap(family.name, d, r.fork(`dimension:${d.name}`)));\n return (unit) => {\n if (unit.length !== maps.length) throw new RangeError(`${family.name}: a point needs ${maps.length} coordinates, not ${unit.length}.`);\n const point: Record<string, number> = {};\n maps.forEach((map, i) => {\n const u = unit[i]!;\n if (!(u >= 0 && u < 1)) throw new RangeError(`${family.name}: coordinate ${i} is ${u}, and it must be from 0 to below 1.`);\n point[names[i]!] = map(u);\n });\n return point;\n };\n}\n\n/** This function gives the points of the family at the points of a unit design. */\nexport function familyPoints(family: InputFamily, unit: readonly (readonly number[])[], r: Random): Point[] {\n const map = familyMap(family, r);\n return unit.map(map);\n}\n\n/** This function gives `n` independent uniform points of the unit cube in `d` dimensions. The draws go row by row. */\nexport function randomDesign(n: number, d: number, r: Random): number[][] {\n count(\"randomDesign\", \"n\", n);\n count(\"randomDesign\", \"d\", d);\n return Array.from({ length: n }, () => Array.from({ length: d }, () => r.next()));\n}\n\n/**\n * This function gives a Latin hypercube of `n` points in `d` dimensions. Each column has exactly one point in each of\n * the `n` strata `[k/n, (k+1)/n)`. For each column, the draws are one shuffle of the strata, then one draw in each point.\n */\nexport function latinHypercube(n: number, d: number, r: Random): number[][] {\n count(\"latinHypercube\", \"n\", n);\n count(\"latinHypercube\", \"d\", d);\n const rows = Array.from({ length: n }, () => new Array<number>(d));\n const strata = Array.from({ length: n }, (_, k) => k);\n for (let j = 0; j < d; j++) {\n const order = r.shuffle(strata);\n for (let i = 0; i < n; i++) rows[i]![j] = belowOne((order[i]! + r.next()) / n);\n }\n return rows;\n}\n\n/**\n * This function gives a stratified grid: `strata` strata on each axis, so `strata^d` cells, and one uniform point in\n * each cell. The cells go in the order of their index in base `strata`, with the first dimension as the last digit.\n */\nexport function stratifiedDesign(strata: number, d: number, r: Random, limit = 1_000_000): number[][] {\n count(\"stratifiedDesign\", \"strata\", strata);\n count(\"stratifiedDesign\", \"d\", d);\n const n = strata ** d;\n if (n > limit) throw new RangeError(`stratifiedDesign: ${strata}^${d} = ${n} cells is above the limit ${limit}.`);\n return Array.from({ length: n }, (_, cell) => {\n let rest = cell;\n return Array.from({ length: d }, () => {\n const k = rest % strata;\n rest = Math.floor(rest / strata);\n return belowOne((k + r.next()) / strata);\n });\n });\n}\n\n/**\n * This function gives the Saltelli design for the Sobol indices of a model with `d` inputs: `a`, `b` and the `d`\n * matrices `ab`. The design has `n * (d + 2)` points for the model. `a` comes from `r.fork(\"A\")`, and `b` comes\n * from `r.fork(\"B\")`. With `base` `\"latin\"`, each is a Latin hypercube.\n */\nexport function saltelliDesign(n: number, d: number, r: Random, base: \"random\" | \"latin\" = \"random\"): SaltelliDesign {\n const make = base === \"latin\" ? latinHypercube : randomDesign;\n const a = make(n, d, r.fork(\"A\"));\n const b = make(n, d, r.fork(\"B\"));\n const ab = Array.from({ length: d }, (_, i) => a.map((row, k) => row.map((x, j) => (j === i ? b[k]![j]! : x))));\n return { a, b, ab };\n}\n"],"mappings":";;AAuCA,MAAM,YAAY,IAAI,OAAO,UAAU;;AAGvC,SAAS,SAAS,GAAmB;CACnC,IAAI,MAAM,GAAG,OAAO,CAAC,OAAO;CAC5B,MAAM,IAAI,IAAI,aAAa,CAAC,CAAC,CAAC;CAC9B,MAAM,OAAO,IAAI,cAAc,EAAE,MAAM;CACvC,KAAK,KAAK,IAAI,IAAI,KAAK,KAAM,KAAK,KAAK,KAAM;CAC7C,OAAO,EAAE;AACX;;AAGA,SAAS,OAAO,GAAmB;CACjC,OAAO,CAAC,SAAS,CAAC,CAAC;AACrB;;AAGA,SAAS,SAAS,GAAmB;CACnC,OAAO,IAAI,IAAI,IAAI;AACrB;AAEA,SAAS,MAAM,IAAY,MAAc,OAAqB;CAC5D,IAAI,CAAC,OAAO,cAAc,KAAK,KAAK,QAAQ,GAAG,MAAM,IAAI,WAAW,GAAG,GAAG,IAAI,KAAK,MAAM,MAAM,oCAAoC;AACrI;;AAGA,SAAS,aAAa,QAAgB,KAAgB,GAAkC;CACtF,MAAM,QAAQ,GAAG,OAAO,GAAG,IAAI;CAC/B,IAAI,CAAC,OAAO,SAAS,IAAI,GAAG,KAAK,CAAC,OAAO,SAAS,IAAI,GAAG,KAAK,IAAI,M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GAAW,OAA2B,UAA0B;CACnH,MAAM,OAAO,SAAS,UAAU,iBAAiB;CACjD,MAAM,IAAI,KAAK,GAAG,GAAG,EAAE,KAAK,GAAG,CAAC;CAChC,MAAM,IAAI,KAAK,GAAG,GAAG,EAAE,KAAK,GAAG,CAAC;CAEhC,OAAO;EAAE;EAAG;EAAG,IADJ,MAAM,KAAK,EAAE,QAAQ,EAAE,IAAI,GAAG,MAAM,EAAE,KAAK,KAAK,MAAM,IAAI,KAAK,GAAG,MAAO,MAAM,IAAI,EAAE,EAAE,CAAE,KAAM,CAAE,CAAC,CAC7F;CAAE;AACpB"}
|
|
1
|
+
{"version":3,"file":"designs.js","names":[],"sources":["../src/designs.ts"],"sourcesContent":["// Input families and the designs that draw their points (R5). A design gives points of the unit cube. `familyMap`\n// takes each point to a point of the family: a value from the range of each dimension.\nimport type { DistributionSpec } from \"./distributions.ts\";\nimport { distributionOf } from \"./quantiles.ts\";\nimport type { Random } from \"./random.ts\";\n\n/** One dimension of an input family. */\nexport interface Dimension {\n /** The name of the dimension. It is a key of each point. */\n readonly name: string;\n /** The smallest value. */\n readonly min: number;\n /** The largest value. A uniform or log dimension that is not `integer` gets values below `max`. */\n readonly max: number;\n /** The distribution of the values, cut to the range. Without it, the values are uniform in the range. */\n readonly distribution?: DistributionSpec;\n /** With `log`, the logarithm of the value is uniform. `min` must be above 0. A dimension with a distribution has no scale. */\n readonly scale?: \"linear\" | \"log\";\n /** With `true`, each value is an integer. `min` and `max` must be integers. */\n readonly integer?: boolean;\n}\n\n/** An input family: its name and its dimensions. */\nexport interface InputFamily {\n readonly name: string;\n readonly dimensions: readonly Dimension[];\n}\n\n/** One point of a family: one value for each dimension, by name. */\nexport type Point = Readonly<Record<string, number>>;\n\n/** The Saltelli design: the matrices `a` and `b`, and for each dimension `i` the matrix `ab[i]`. */\nexport interface SaltelliDesign {\n readonly a: number[][];\n readonly b: number[][];\n /** `ab[i]` is `a` with the column `i` of `b`. */\n readonly ab: number[][][];\n}\n\nconst BELOW_ONE = 1 - Number.EPSILON / 2;\n\n/** This function gives the next double toward minus infinity. */\nfunction nextDown(x: number): number {\n if (x === 0) return -Number.MIN_VALUE;\n const f = new Float64Array([x]);\n const bits = new BigInt64Array(f.buffer);\n bits[0] = x > 0 ? bits[0]! - 1n : bits[0]! + 1n;\n return f[0]!;\n}\n\n/** This function gives the next double toward plus infinity. */\nfunction nextUp(x: number): number {\n return -nextDown(-x);\n}\n\n/** This function keeps a value below 1. A sum of a stratum and a draw can round up to 1. */\nfunction belowOne(x: number): number {\n return x < 1 ? x : BELOW_ONE;\n}\n\nfunction count(fn: string, name: string, value: number): void {\n if (!Number.isSafeInteger(value) || value < 1) throw new RangeError(`${fn}: ${name} is ${value}, and it must be an integer from 1.`);\n}\n\n/**\n * This function examines a dimension of a family. A range that is not finite, an integer dimension without integer ends and\n * a bad scale are each a `RangeError`.\n */\nexport function checkDimension(family: string, dim: Dimension): void {\n const where = `${family}.${dim.name}`;\n if (!Number.isFinite(dim.min) || !Number.isFinite(dim.max) || dim.min > dim.max) {\n throw new RangeError(`${where}: the range ${dim.min} to ${dim.max} is not a finite range.`);\n }\n if (dim.integer === true && (!Number.isSafeInteger(dim.min) || !Number.isSafeInteger(dim.max))) {\n throw new RangeError(`${where}: an integer dimension needs integer ends, not ${dim.min} and ${dim.max}.`);\n }\n if (dim.distribution !== undefined && dim.scale !== undefined) throw new RangeError(`${where}: a dimension with a distribution has no scale.`);\n if (dim.scale === \"log\" && !(dim.min > 0)) throw new RangeError(`${where}: a log scale needs a minimum above 0, not ${dim.min}.`);\n}\n\n/** This function examines a dimension and gives the map from a uniform number in [0, 1) to a value of the dimension. */\nfunction dimensionMap(family: string, dim: Dimension, r: Random): (u: number) => number {\n const where = `${family}.${dim.name}`;\n checkDimension(family, dim);\n // An integer dimension takes the floor of a value from [min, max + 1).\n const end = dim.integer === true ? dim.max + 1 : dim.max;\n const top = dim.integer === true ? nextDown(end) : end;\n const whole = (x: number): number => (dim.integer === true ? Math.min(dim.max, Math.floor(x)) : x);\n const clamp = (x: number): number => Math.min(top, Math.max(dim.min, x));\n if (dim.distribution !== undefined) {\n const d = distributionOf(dim.distribution, r);\n const low = d.cdf(nextDown(dim.min));\n const high = d.cdf(top);\n if (!(high > low)) throw new RangeError(`${where}: the distribution has no probability from ${dim.min} to ${dim.max}.`);\n // A discrete quantile at `low` can be a value below `min`. The smallest value above `low` is then the first value in the range.\n const first = d.quantile(nextUp(low));\n return (u) => {\n const x = d.quantile(low + u * (high - low));\n return whole(clamp(x < dim.min ? first : x));\n };\n }\n if (dim.scale === \"log\") {\n // The form `min * exp(u * span)` gives `min` exactly at 0.\n const span = Math.log(end / dim.min);\n return (u) => whole(clamp(dim.min * Math.exp(u * span)));\n }\n return (u) => whole(clamp(dim.min + u * (end - dim.min)));\n}\n\n/**\n * This function gives the names of the dimensions of a family. A family with no dimension is a `RangeError`. A name that\n * is empty or not unique is also a `RangeError`.\n */\nexport function familyNames(family: InputFamily): string[] {\n if (family.dimensions.length === 0) throw new RangeError(`${family.name}: a family needs one dimension or more.`);\n const names = family.dimensions.map((d) => d.name);\n const twice = names.find((n, i) => n === \"\" || names.indexOf(n) !== i);\n if (twice !== undefined) throw new RangeError(`${family.name}: the dimension name \"${twice}\" is empty or not unique.`);\n return names;\n}\n\n/**\n * This function gives the map from a point of the unit cube to a point of the family. Coordinate `i` gives the value of\n * dimension `i`. The parameters of each distribution come from `r.fork(\"dimension:\" + name)` one time. Thus the\n * same seed gives the same map, and a new dimension does not change the others.\n */\nexport function familyMap(family: InputFamily, r: Random): (unit: readonly number[]) => Point {\n const names = familyNames(family);\n const maps = family.dimensions.map((d) => dimensionMap(family.name, d, r.fork(`dimension:${d.name}`)));\n return (unit) => {\n if (unit.length !== maps.length) throw new RangeError(`${family.name}: a point needs ${maps.length} coordinates, not ${unit.length}.`);\n const point: Record<string, number> = {};\n maps.forEach((map, i) => {\n const u = unit[i]!;\n if (!(u >= 0 && u < 1)) throw new RangeError(`${family.name}: coordinate ${i} is ${u}, and it must be from 0 to below 1.`);\n point[names[i]!] = map(u);\n });\n return point;\n };\n}\n\n/** This function gives the points of the family at the points of a unit design. */\nexport function familyPoints(family: InputFamily, unit: readonly (readonly number[])[], r: Random): Point[] {\n const map = familyMap(family, r);\n return unit.map(map);\n}\n\n/** This function gives `n` independent uniform points of the unit cube in `d` dimensions. The draws go row by row. */\nexport function randomDesign(n: number, d: number, r: Random): number[][] {\n count(\"randomDesign\", \"n\", n);\n count(\"randomDesign\", \"d\", d);\n return Array.from({ length: n }, () => Array.from({ length: d }, () => r.next()));\n}\n\n/**\n * This function gives a Latin hypercube of `n` points in `d` dimensions. Each column has exactly one point in each of\n * the `n` strata `[k/n, (k+1)/n)`. For each column, the draws are one shuffle of the strata, then one draw in each point.\n */\nexport function latinHypercube(n: number, d: number, r: Random): number[][] {\n count(\"latinHypercube\", \"n\", n);\n count(\"latinHypercube\", \"d\", d);\n const rows = Array.from({ length: n }, () => new Array<number>(d));\n const strata = Array.from({ length: n }, (_, k) => k);\n for (let j = 0; j < d; j++) {\n const order = r.shuffle(strata);\n for (let i = 0; i < n; i++) rows[i]![j] = belowOne((order[i]! + r.next()) / n);\n }\n return rows;\n}\n\n/**\n * This function gives a stratified grid: `strata` strata on each axis, so `strata^d` cells, and one uniform point in\n * each cell. The cells go in the order of their index in base `strata`, with the first dimension as the last digit.\n */\nexport function stratifiedDesign(strata: number, d: number, r: Random, limit = 1_000_000): number[][] {\n count(\"stratifiedDesign\", \"strata\", strata);\n count(\"stratifiedDesign\", \"d\", d);\n const n = strata ** d;\n if (n > limit) throw new RangeError(`stratifiedDesign: ${strata}^${d} = ${n} cells is above the limit ${limit}.`);\n return Array.from({ length: n }, (_, cell) => {\n let rest = cell;\n return Array.from({ length: d }, () => {\n const k = rest % strata;\n rest = Math.floor(rest / strata);\n return belowOne((k + r.next()) / strata);\n });\n });\n}\n\n/**\n * This function gives the Saltelli design for the Sobol indices of a model with `d` inputs: `a`, `b` and the `d`\n * matrices `ab`. The design has `n * (d + 2)` points for the model. `a` comes from `r.fork(\"A\")`, and `b` comes\n * from `r.fork(\"B\")`. With `base` `\"latin\"`, each is a Latin hypercube.\n */\nexport function saltelliDesign(n: number, d: number, r: Random, base: \"random\" | \"latin\" = \"random\"): SaltelliDesign {\n const make = base === \"latin\" ? latinHypercube : randomDesign;\n const a = make(n, d, r.fork(\"A\"));\n const b = make(n, d, r.fork(\"B\"));\n const ab = Array.from({ length: d }, (_, i) => a.map((row, k) => row.map((x, j) => (j === i ? b[k]![j]! : x))));\n return { a, b, ab };\n}\n"],"mappings":";;AAuCA,MAAM,YAAY,IAAI,OAAO,UAAU;;AAGvC,SAAS,SAAS,GAAmB;CACnC,IAAI,MAAM,GAAG,OAAO,CAAC,OAAO;CAC5B,MAAM,IAAI,IAAI,aAAa,CAAC,CAAC,CAAC;CAC9B,MAAM,OAAO,IAAI,cAAc,EAAE,MAAM;CACvC,KAAK,KAAK,IAAI,IAAI,KAAK,KAAM,KAAK,KAAK,KAAM;CAC7C,OAAO,EAAE;AACX;;AAGA,SAAS,OAAO,GAAmB;CACjC,OAAO,CAAC,SAAS,CAAC,CAAC;AACrB;;AAGA,SAAS,SAAS,GAAmB;CACnC,OAAO,IAAI,IAAI,IAAI;AACrB;AAEA,SAAS,MAAM,IAAY,MAAc,OAAqB;CAC5D,IAAI,CAAC,OAAO,cAAc,KAAK,KAAK,QAAQ,GAAG,MAAM,IAAI,WAAW,GAAG,GAAG,IAAI,KAAK,MAAM,MAAM,oCAAoC;AACrI;;;;;AAMA,SAAgB,eAAe,QAAgB,KAAsB;CACnE,MAAM,QAAQ,GAAG,OAAO,GAAG,IAAI;CAC/B,IAAI,CAAC,OAAO,SAAS,IAAI,GAAG,KAAK,CAAC,OAAO,SAAS,IAAI,GAAG,KAAK,IAAI,MAAM,IAAI,KAC1E,MAAM,IAAI,WAAW,GAAG,MAAM,cAAc,IAAI,IAAI,MAAM,IAAI,IAAI,wBAAwB;CAE5F,IAAI,IAAI,YAAY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AAO,MAAM;GAC/B,OAAO,UAAU,IAAI,EAAE,KAAK,KAAK,MAAM;EACzC,CAAC;CACH,CAAC;AACH;;;;;;AAOA,SAAgB,eAAe,GAAW,GAAW,GAAW,OAA2B,UAA0B;CACnH,MAAM,OAAO,SAAS,UAAU,iBAAiB;CACjD,MAAM,IAAI,KAAK,GAAG,GAAG,EAAE,KAAK,GAAG,CAAC;CAChC,MAAM,IAAI,KAAK,GAAG,GAAG,EAAE,KAAK,GAAG,CAAC;CAEhC,OAAO;EAAE;EAAG;EAAG,IADJ,MAAM,KAAK,EAAE,QAAQ,EAAE,IAAI,GAAG,MAAM,EAAE,KAAK,KAAK,MAAM,IAAI,KAAK,GAAG,MAAO,MAAM,IAAI,EAAE,EAAE,CAAE,KAAM,CAAE,CAAC,CAC7F;CAAE;AACpB"}
|
package/build/index.d.ts
CHANGED
|
@@ -1,8 +1,10 @@
|
|
|
1
|
+
import { COVERING_CANDIDATES, COVERING_LIMIT, Coverage, CoveringOptions, coveringArray, coveringRows, tupleCoverage } from "./covering.js";
|
|
1
2
|
import { DistributionSpec, Param, dependsOnLibm, sampler } from "./distributions.js";
|
|
2
3
|
import { normalCdf, normalQuantile } from "./normal.js";
|
|
3
4
|
import { Distribution, betaCdf, distributionOf } from "./quantiles.js";
|
|
4
5
|
import { Dimension, InputFamily, Point, SaltelliDesign, familyMap, familyPoints, latinHypercube, randomDesign, saltelliDesign, stratifiedDesign } from "./designs.js";
|
|
5
6
|
import { CanonicalOptions, Sha256Options, canonicalHash, canonicalJson, sha256Hex } from "./hash.js";
|
|
7
|
+
import { SHRINK_CHECKS, SHRINK_TOLERANCE, ShrinkOptions, ShrinkStep, Shrunk, shrinkPoint, shrinkPointAsync, shrinkTarget } from "./shrink.js";
|
|
6
8
|
import { DIAGRAM_BOX_AREA, GIT_BLOB_BYTES, RECORDED_TABLES, RecordedTable, recordedSpec } from "./recorded.js";
|
|
7
9
|
import { Random, Source, deriveSeed, fnv1a32, mulberry32, plackettLuceOrder, random, randomOf, seedOf, seedsFrom, stablePick } from "./random.js";
|
|
8
|
-
export { type CanonicalOptions, DIAGRAM_BOX_AREA, type Dimension, type Distribution, type DistributionSpec, GIT_BLOB_BYTES, type InputFamily, type Param, type Point, RECORDED_TABLES, type Random, type RecordedTable, type SaltelliDesign, type Sha256Options, type Source, betaCdf, canonicalHash, canonicalJson, dependsOnLibm, deriveSeed, distributionOf, familyMap, familyPoints, fnv1a32, latinHypercube, mulberry32, normalCdf, normalQuantile, plackettLuceOrder, random, randomDesign, randomOf, recordedSpec, saltelliDesign, sampler, seedOf, seedsFrom, sha256Hex, stablePick, stratifiedDesign };
|
|
10
|
+
export { COVERING_CANDIDATES, COVERING_LIMIT, type CanonicalOptions, type Coverage, type CoveringOptions, DIAGRAM_BOX_AREA, type Dimension, type Distribution, type DistributionSpec, GIT_BLOB_BYTES, type InputFamily, type Param, type Point, RECORDED_TABLES, type Random, type RecordedTable, SHRINK_CHECKS, SHRINK_TOLERANCE, type SaltelliDesign, type Sha256Options, type ShrinkOptions, type ShrinkStep, type Shrunk, type Source, betaCdf, canonicalHash, canonicalJson, coveringArray, coveringRows, dependsOnLibm, deriveSeed, distributionOf, familyMap, familyPoints, fnv1a32, latinHypercube, mulberry32, normalCdf, normalQuantile, plackettLuceOrder, random, randomDesign, randomOf, recordedSpec, saltelliDesign, sampler, seedOf, seedsFrom, sha256Hex, shrinkPoint, shrinkPointAsync, shrinkTarget, stablePick, stratifiedDesign, tupleCoverage };
|
package/build/index.js
CHANGED
|
@@ -1,8 +1,10 @@
|
|
|
1
|
+
import { COVERING_CANDIDATES, COVERING_LIMIT, coveringArray, coveringRows, tupleCoverage } from "./covering.js";
|
|
1
2
|
import { dependsOnLibm, sampler } from "./distributions.js";
|
|
2
3
|
import { normalCdf, normalQuantile } from "./normal.js";
|
|
3
4
|
import { betaCdf, distributionOf } from "./quantiles.js";
|
|
4
5
|
import { familyMap, familyPoints, latinHypercube, randomDesign, saltelliDesign, stratifiedDesign } from "./designs.js";
|
|
5
6
|
import { canonicalHash, canonicalJson, sha256Hex } from "./hash.js";
|
|
7
|
+
import { SHRINK_CHECKS, SHRINK_TOLERANCE, shrinkPoint, shrinkPointAsync, shrinkTarget } from "./shrink.js";
|
|
6
8
|
import { DIAGRAM_BOX_AREA, GIT_BLOB_BYTES, RECORDED_TABLES, recordedSpec } from "./recorded.js";
|
|
7
9
|
import { deriveSeed, fnv1a32, mulberry32, plackettLuceOrder, random, randomOf, seedOf, seedsFrom, stablePick } from "./random.js";
|
|
8
|
-
export { DIAGRAM_BOX_AREA, GIT_BLOB_BYTES, RECORDED_TABLES, betaCdf, canonicalHash, canonicalJson, dependsOnLibm, deriveSeed, distributionOf, familyMap, familyPoints, fnv1a32, latinHypercube, mulberry32, normalCdf, normalQuantile, plackettLuceOrder, random, randomDesign, randomOf, recordedSpec, saltelliDesign, sampler, seedOf, seedsFrom, sha256Hex, stablePick, stratifiedDesign };
|
|
10
|
+
export { COVERING_CANDIDATES, COVERING_LIMIT, DIAGRAM_BOX_AREA, GIT_BLOB_BYTES, RECORDED_TABLES, SHRINK_CHECKS, SHRINK_TOLERANCE, betaCdf, canonicalHash, canonicalJson, coveringArray, coveringRows, dependsOnLibm, deriveSeed, distributionOf, familyMap, familyPoints, fnv1a32, latinHypercube, mulberry32, normalCdf, normalQuantile, plackettLuceOrder, random, randomDesign, randomOf, recordedSpec, saltelliDesign, sampler, seedOf, seedsFrom, sha256Hex, shrinkPoint, shrinkPointAsync, shrinkTarget, stablePick, stratifiedDesign, tupleCoverage };
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
import { Dimension, InputFamily, Point } from "./designs.js";
|
|
2
|
+
/** The default count of the most checks of one shrink, with the check of the first point. */
|
|
3
|
+
export declare const SHRINK_CHECKS = 1e3;
|
|
4
|
+
/** The default width of the last interval of a bisection, as a share of the range of a dimension that is not an integer. */
|
|
5
|
+
export declare const SHRINK_TOLERANCE = 1e-6;
|
|
6
|
+
/** The options of a shrink. */
|
|
7
|
+
export interface ShrinkOptions {
|
|
8
|
+
/** The most checks of points, with the check of the first point. The default is `SHRINK_CHECKS`. */
|
|
9
|
+
readonly maxChecks?: number;
|
|
10
|
+
/**
|
|
11
|
+
* The width of the last interval of a bisection on a dimension that is not an integer, as a share of its range. A log
|
|
12
|
+
* dimension uses the range of the logarithm. The default is `SHRINK_TOLERANCE`.
|
|
13
|
+
*/
|
|
14
|
+
readonly tolerance?: number;
|
|
15
|
+
}
|
|
16
|
+
/** One move of a shrink: the dimension, its value before the move and its value after the move. */
|
|
17
|
+
export interface ShrinkStep {
|
|
18
|
+
readonly dimension: string;
|
|
19
|
+
readonly from: number;
|
|
20
|
+
readonly to: number;
|
|
21
|
+
}
|
|
22
|
+
/** The result of a shrink. */
|
|
23
|
+
export interface Shrunk {
|
|
24
|
+
/** The last point that failed. Each key of the first point stays. */
|
|
25
|
+
readonly point: Point;
|
|
26
|
+
/** The moves, in their order. */
|
|
27
|
+
readonly steps: readonly ShrinkStep[];
|
|
28
|
+
/** The count of checks, with the check of the first point. */
|
|
29
|
+
readonly checks: number;
|
|
30
|
+
/** The value `true` tells that the budget of checks ended before a round with no move. */
|
|
31
|
+
readonly exhausted: boolean;
|
|
32
|
+
}
|
|
33
|
+
/** This function gives the target of a dimension: the value of its range nearest to 0. */
|
|
34
|
+
export declare function shrinkTarget(dimension: Dimension): number;
|
|
35
|
+
/**
|
|
36
|
+
* This function shrinks a point of a family that fails. Each dimension moves toward `shrinkTarget`, while the point still fails.
|
|
37
|
+
* - In each round, each dimension first tries its target. Then a bisection on the scale of the dimension finds the edge of the failure.
|
|
38
|
+
* - The rounds continue until a round has no move, or until the budget of checks ends.
|
|
39
|
+
* - The function `fails` gives `true` for a point that fails. A first point that does not fail is a `RangeError`.
|
|
40
|
+
* - The shrink has no random draws. Thus the same point and the same function give the same result.
|
|
41
|
+
*/
|
|
42
|
+
export declare function shrinkPoint(family: InputFamily, point: Point, fails: (point: Point) => boolean, options?: ShrinkOptions): Shrunk;
|
|
43
|
+
/** This function is `shrinkPoint` for a function `fails` that gives a promise, for example a check in a child process. */
|
|
44
|
+
export declare function shrinkPointAsync(family: InputFamily, point: Point, fails: (point: Point) => boolean | Promise<boolean>, options?: ShrinkOptions): Promise<Shrunk>;
|
|
45
|
+
//# sourceMappingURL=shrink.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"shrink.d.ts","names":[],"sources":["../src/shrink.ts"],"mappings":";;qBAMa;;qBAGA;;iBAGI;;WAEN;;;;;WAKA;;;iBAIM;WACN;WACA;WACA;;;iBAIM;;WAEN,OAAO;;WAEP,gBAAgB;;WAEhB;;WAEA;;;wBAIK,aAAa,WAAW;;;;;;;;wBAiGxB,YAAY,QAAQ,aAAa,OAAO,OAAO,QAAQ,OAAO,mBAAmB,UAAS,gBAAqB;;wBAQzG,iBAAiB,QAAQ,aAAa,OAAO,OAAO,QAAQ,OAAO,oBAAoB,kBAAkB,UAAS,gBAAqB,QAAQ"}
|
package/build/shrink.js
ADDED
|
@@ -0,0 +1,130 @@
|
|
|
1
|
+
import { checkDimension, familyNames } from "./designs.js";
|
|
2
|
+
// src/shrink.ts
|
|
3
|
+
/** The default count of the most checks of one shrink, with the check of the first point. */
|
|
4
|
+
const SHRINK_CHECKS = 1e3;
|
|
5
|
+
/** The default width of the last interval of a bisection, as a share of the range of a dimension that is not an integer. */
|
|
6
|
+
const SHRINK_TOLERANCE = 1e-6;
|
|
7
|
+
/** This function gives the target of a dimension: the value of its range nearest to 0. */
|
|
8
|
+
function shrinkTarget(dimension) {
|
|
9
|
+
if (dimension.min > 0) return dimension.min;
|
|
10
|
+
if (dimension.max < 0) return dimension.max;
|
|
11
|
+
return 0;
|
|
12
|
+
}
|
|
13
|
+
/** This function examines a dimension and the value of the first point in it. A bad value is a `RangeError`. */
|
|
14
|
+
function checkValue(family, dim, value) {
|
|
15
|
+
checkDimension(family, dim);
|
|
16
|
+
const where = `shrinkPoint: ${family}.${dim.name}`;
|
|
17
|
+
if (typeof value !== "number" || !(value >= dim.min && value <= dim.max)) throw new RangeError(`${where}: the value ${value} is not in the range ${dim.min} to ${dim.max}.`);
|
|
18
|
+
if (dim.integer === true && !Number.isSafeInteger(value)) throw new RangeError(`${where}: the value ${value} is not an integer.`);
|
|
19
|
+
}
|
|
20
|
+
/** This function tells if a bisection on a dimension can stop: the values `good` and `bad` are near enough. */
|
|
21
|
+
function near(dim, good, bad, tolerance) {
|
|
22
|
+
if (dim.integer === true) return Math.abs(good - bad) <= 1;
|
|
23
|
+
if (dim.scale === "log") return Math.abs(Math.log(good / bad)) <= tolerance * Math.log(dim.max / dim.min);
|
|
24
|
+
return Math.abs(good - bad) <= tolerance * (dim.max - dim.min);
|
|
25
|
+
}
|
|
26
|
+
/** This function gives the value between `bad` and `good` for the next check: the middle on the scale of the dimension. */
|
|
27
|
+
function middle(dim, good, bad) {
|
|
28
|
+
if (dim.scale === "log") {
|
|
29
|
+
const mid = Math.sqrt(good * bad);
|
|
30
|
+
return dim.integer === true ? Math.round(mid) : mid;
|
|
31
|
+
}
|
|
32
|
+
return dim.integer === true ? bad + Math.trunc((good - bad) / 2) : bad + (good - bad) / 2;
|
|
33
|
+
}
|
|
34
|
+
/**
|
|
35
|
+
* This generator is the core of a shrink. It gives each point to check, and it takes `true` back for a point that fails.
|
|
36
|
+
* Its return value is the result.
|
|
37
|
+
*/
|
|
38
|
+
function* shrinkCore(family, first, options) {
|
|
39
|
+
const maxChecks = options.maxChecks ?? 1e3;
|
|
40
|
+
const tolerance = options.tolerance ?? 1e-6;
|
|
41
|
+
if (!Number.isSafeInteger(maxChecks) || maxChecks < 1) throw new RangeError(`shrinkPoint: maxChecks is a whole number of 1 or more, not ${maxChecks}.`);
|
|
42
|
+
if (!(tolerance > 0 && tolerance < 1)) throw new RangeError(`shrinkPoint: the tolerance is above 0 and below 1, not ${tolerance}.`);
|
|
43
|
+
familyNames(family);
|
|
44
|
+
for (const dim of family.dimensions) checkValue(family.name, dim, first[dim.name]);
|
|
45
|
+
let point = { ...first };
|
|
46
|
+
const steps = [];
|
|
47
|
+
let checks = 1;
|
|
48
|
+
if (!(yield point)) throw new RangeError(`shrinkPoint: the first point of ${family.name} does not fail.`);
|
|
49
|
+
const result = (exhausted) => ({
|
|
50
|
+
point,
|
|
51
|
+
steps,
|
|
52
|
+
checks,
|
|
53
|
+
exhausted
|
|
54
|
+
});
|
|
55
|
+
const move = (dim, from, to) => {
|
|
56
|
+
point = {
|
|
57
|
+
...point,
|
|
58
|
+
[dim.name]: to
|
|
59
|
+
};
|
|
60
|
+
steps.push({
|
|
61
|
+
dimension: dim.name,
|
|
62
|
+
from,
|
|
63
|
+
to
|
|
64
|
+
});
|
|
65
|
+
};
|
|
66
|
+
for (let moved = true; moved;) {
|
|
67
|
+
moved = false;
|
|
68
|
+
for (const dim of family.dimensions) {
|
|
69
|
+
const from = point[dim.name];
|
|
70
|
+
const target = shrinkTarget(dim);
|
|
71
|
+
if (from === target) continue;
|
|
72
|
+
if (checks >= maxChecks) return result(true);
|
|
73
|
+
checks++;
|
|
74
|
+
if (yield {
|
|
75
|
+
...point,
|
|
76
|
+
[dim.name]: target
|
|
77
|
+
}) {
|
|
78
|
+
move(dim, from, target);
|
|
79
|
+
moved = true;
|
|
80
|
+
continue;
|
|
81
|
+
}
|
|
82
|
+
let good = from;
|
|
83
|
+
let bad = target;
|
|
84
|
+
let ended = false;
|
|
85
|
+
while (!near(dim, good, bad, tolerance)) {
|
|
86
|
+
const mid = middle(dim, good, bad);
|
|
87
|
+
if (mid === good || mid === bad) break;
|
|
88
|
+
if (checks >= maxChecks) {
|
|
89
|
+
ended = true;
|
|
90
|
+
break;
|
|
91
|
+
}
|
|
92
|
+
checks++;
|
|
93
|
+
if (yield {
|
|
94
|
+
...point,
|
|
95
|
+
[dim.name]: mid
|
|
96
|
+
}) good = mid;
|
|
97
|
+
else bad = mid;
|
|
98
|
+
}
|
|
99
|
+
if (good !== from) {
|
|
100
|
+
move(dim, from, good);
|
|
101
|
+
if (dim.integer === true || !near(dim, good, from, tolerance)) moved = true;
|
|
102
|
+
}
|
|
103
|
+
if (ended) return result(true);
|
|
104
|
+
}
|
|
105
|
+
}
|
|
106
|
+
return result(false);
|
|
107
|
+
}
|
|
108
|
+
/**
|
|
109
|
+
* This function shrinks a point of a family that fails. Each dimension moves toward `shrinkTarget`, while the point still fails.
|
|
110
|
+
* - In each round, each dimension first tries its target. Then a bisection on the scale of the dimension finds the edge of the failure.
|
|
111
|
+
* - The rounds continue until a round has no move, or until the budget of checks ends.
|
|
112
|
+
* - The function `fails` gives `true` for a point that fails. A first point that does not fail is a `RangeError`.
|
|
113
|
+
* - The shrink has no random draws. Thus the same point and the same function give the same result.
|
|
114
|
+
*/
|
|
115
|
+
function shrinkPoint(family, point, fails, options = {}) {
|
|
116
|
+
const core = shrinkCore(family, point, options);
|
|
117
|
+
let next = core.next();
|
|
118
|
+
while (next.done !== true) next = core.next(fails(next.value) === true);
|
|
119
|
+
return next.value;
|
|
120
|
+
}
|
|
121
|
+
/** This function is `shrinkPoint` for a function `fails` that gives a promise, for example a check in a child process. */
|
|
122
|
+
async function shrinkPointAsync(family, point, fails, options = {}) {
|
|
123
|
+
const core = shrinkCore(family, point, options);
|
|
124
|
+
let next = core.next();
|
|
125
|
+
while (next.done !== true) next = core.next(await fails(next.value) === true);
|
|
126
|
+
return next.value;
|
|
127
|
+
}
|
|
128
|
+
export { SHRINK_CHECKS, SHRINK_TOLERANCE, shrinkPoint, shrinkPointAsync, shrinkTarget };
|
|
129
|
+
|
|
130
|
+
//# sourceMappingURL=shrink.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"shrink.js","names":[],"sources":["../src/shrink.ts"],"sourcesContent":["// The shrinking of a failed point of an input family (R9). Each dimension moves toward its target while the point still\n// fails. The core is a generator: it gives each point to check, and the caller gives back `true` for a point that fails.\n// Thus one core serves a check in this process and a check that waits, for example a child process.\nimport { type Dimension, type InputFamily, type Point, checkDimension, familyNames } from \"./designs.ts\";\n\n/** The default count of the most checks of one shrink, with the check of the first point. */\nexport const SHRINK_CHECKS = 1000;\n\n/** The default width of the last interval of a bisection, as a share of the range of a dimension that is not an integer. */\nexport const SHRINK_TOLERANCE = 1e-6;\n\n/** The options of a shrink. */\nexport interface ShrinkOptions {\n /** The most checks of points, with the check of the first point. The default is `SHRINK_CHECKS`. */\n readonly maxChecks?: number;\n /**\n * The width of the last interval of a bisection on a dimension that is not an integer, as a share of its range. A log\n * dimension uses the range of the logarithm. The default is `SHRINK_TOLERANCE`.\n */\n readonly tolerance?: number;\n}\n\n/** One move of a shrink: the dimension, its value before the move and its value after the move. */\nexport interface ShrinkStep {\n readonly dimension: string;\n readonly from: number;\n readonly to: number;\n}\n\n/** The result of a shrink. */\nexport interface Shrunk {\n /** The last point that failed. Each key of the first point stays. */\n readonly point: Point;\n /** The moves, in their order. */\n readonly steps: readonly ShrinkStep[];\n /** The count of checks, with the check of the first point. */\n readonly checks: number;\n /** The value `true` tells that the budget of checks ended before a round with no move. */\n readonly exhausted: boolean;\n}\n\n/** This function gives the target of a dimension: the value of its range nearest to 0. */\nexport function shrinkTarget(dimension: Dimension): number {\n if (dimension.min > 0) return dimension.min;\n if (dimension.max < 0) return dimension.max;\n return 0;\n}\n\n/** This function examines a dimension and the value of the first point in it. A bad value is a `RangeError`. */\nfunction checkValue(family: string, dim: Dimension, value: number | undefined): void {\n checkDimension(family, dim);\n const where = `shrinkPoint: ${family}.${dim.name}`;\n if (typeof value !== \"number\" || !(value >= dim.min && value <= dim.max)) throw new RangeError(`${where}: the value ${value} is not in the range ${dim.min} to ${dim.max}.`);\n if (dim.integer === true && !Number.isSafeInteger(value)) throw new RangeError(`${where}: the value ${value} is not an integer.`);\n}\n\n/** This function tells if a bisection on a dimension can stop: the values `good` and `bad` are near enough. */\nfunction near(dim: Dimension, good: number, bad: number, tolerance: number): boolean {\n if (dim.integer === true) return Math.abs(good - bad) <= 1;\n if (dim.scale === \"log\") return Math.abs(Math.log(good / bad)) <= tolerance * Math.log(dim.max / dim.min);\n return Math.abs(good - bad) <= tolerance * (dim.max - dim.min);\n}\n\n/** This function gives the value between `bad` and `good` for the next check: the middle on the scale of the dimension. */\nfunction middle(dim: Dimension, good: number, bad: number): number {\n if (dim.scale === \"log\") {\n const mid = Math.sqrt(good * bad);\n return dim.integer === true ? Math.round(mid) : mid;\n }\n return dim.integer === true ? bad + Math.trunc((good - bad) / 2) : bad + (good - bad) / 2;\n}\n\n/**\n * This generator is the core of a shrink. It gives each point to check, and it takes `true` back for a point that fails.\n * Its return value is the result.\n */\nfunction* shrinkCore(family: InputFamily, first: Point, options: ShrinkOptions): Generator<Point, Shrunk, boolean> {\n const maxChecks = options.maxChecks ?? SHRINK_CHECKS;\n const tolerance = options.tolerance ?? SHRINK_TOLERANCE;\n if (!Number.isSafeInteger(maxChecks) || maxChecks < 1) throw new RangeError(`shrinkPoint: maxChecks is a whole number of 1 or more, not ${maxChecks}.`);\n if (!(tolerance > 0 && tolerance < 1)) throw new RangeError(`shrinkPoint: the tolerance is above 0 and below 1, not ${tolerance}.`);\n familyNames(family);\n for (const dim of family.dimensions) checkValue(family.name, dim, first[dim.name]);\n let point: Point = { ...first };\n const steps: ShrinkStep[] = [];\n let checks = 1;\n if (!(yield point)) throw new RangeError(`shrinkPoint: the first point of ${family.name} does not fail.`);\n const result = (exhausted: boolean): Shrunk => ({ point, steps, checks, exhausted });\n // The function `move` keeps a value that failed, and records the step.\n const move = (dim: Dimension, from: number, to: number): void => {\n point = { ...point, [dim.name]: to };\n steps.push({ dimension: dim.name, from, to });\n };\n for (let moved = true; moved; ) {\n moved = false;\n for (const dim of family.dimensions) {\n const from = point[dim.name]!;\n const target = shrinkTarget(dim);\n if (from === target) continue;\n if (checks >= maxChecks) return result(true);\n checks++;\n if (yield { ...point, [dim.name]: target }) {\n move(dim, from, target);\n moved = true;\n continue;\n }\n // The value `good` fails, and the value `bad` does not fail. The bisection keeps the two near the edge of the failure.\n let good = from;\n let bad = target;\n let ended = false;\n while (!near(dim, good, bad, tolerance)) {\n const mid = middle(dim, good, bad);\n if (mid === good || mid === bad) break;\n if (checks >= maxChecks) {\n ended = true;\n break;\n }\n checks++;\n if (yield { ...point, [dim.name]: mid }) good = mid;\n else bad = mid;\n }\n if (good !== from) {\n move(dim, from, good);\n // A move of a double within the tolerance starts no new round. Else each round can move it a little, until the budget ends.\n if (dim.integer === true || !near(dim, good, from, tolerance)) moved = true;\n }\n if (ended) return result(true);\n }\n }\n return result(false);\n}\n\n/**\n * This function shrinks a point of a family that fails. Each dimension moves toward `shrinkTarget`, while the point still fails.\n * - In each round, each dimension first tries its target. Then a bisection on the scale of the dimension finds the edge of the failure.\n * - The rounds continue until a round has no move, or until the budget of checks ends.\n * - The function `fails` gives `true` for a point that fails. A first point that does not fail is a `RangeError`.\n * - The shrink has no random draws. Thus the same point and the same function give the same result.\n */\nexport function shrinkPoint(family: InputFamily, point: Point, fails: (point: Point) => boolean, options: ShrinkOptions = {}): Shrunk {\n const core = shrinkCore(family, point, options);\n let next = core.next();\n while (next.done !== true) next = core.next(fails(next.value) === true);\n return next.value;\n}\n\n/** This function is `shrinkPoint` for a function `fails` that gives a promise, for example a check in a child process. */\nexport async function shrinkPointAsync(family: InputFamily, point: Point, fails: (point: Point) => boolean | Promise<boolean>, options: ShrinkOptions = {}): Promise<Shrunk> {\n const core = shrinkCore(family, point, options);\n let next = core.next();\n while (next.done !== true) next = core.next((await fails(next.value)) === true);\n return next.value;\n}\n"],"mappings":";;;AAMA,MAAa,gBAAgB;;AAG7B,MAAa,mBAAmB;;AAiChC,SAAgB,aAAa,WAA8B;CACzD,IAAI,UAAU,MAAM,GAAG,OAAO,UAAU;CACxC,IAAI,UAAU,MAAM,GAAG,OAAO,UAAU;CACxC,OAAO;AACT;;AAGA,SAAS,WAAW,QAAgB,KAAgB,OAAiC;CACnF,eAAe,QAAQ,GAAG;CAC1B,MAAM,QAAQ,gBAAgB,OAAO,GAAG,IAAI;CAC5C,IAAI,OAAO,UA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rB;;;;;;;;AASA,SAAgB,YAAY,QAAqB,OAAc,OAAkC,UAAyB,CAAC,GAAW;CACpI,MAAM,OAAO,WAAW,QAAQ,OAAO,OAAO;CAC9C,IAAI,OAAO,KAAK,KAAK;CACrB,OAAO,KAAK,SAAS,MAAM,OAAO,KAAK,KAAK,MAAM,KAAK,KAAK,MAAM,IAAI;CACtE,OAAO,KAAK;AACd;;AAGA,eAAsB,iBAAiB,QAAqB,OAAc,OAAqD,UAAyB,CAAC,GAAoB;CAC3K,MAAM,OAAO,WAAW,QAAQ,OAAO,OAAO;CAC9C,IAAI,OAAO,KAAK,KAAK;CACrB,OAAO,KAAK,SAAS,MAAM,OAAO,KAAK,KAAM,MAAM,MAAM,KAAK,KAAK,MAAO,IAAI;CAC9E,OAAO,KAAK;AACd"}
|
package/package.json
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
{
|
|
2
2
|
"$schema": "https://json.schemastore.org/package",
|
|
3
3
|
"name": "@mark1russell7/rigor-generators",
|
|
4
|
-
"version": "0.1.
|
|
5
|
-
"description": "A seeded random number generator (mulberry32) with the draws that tests and benchmarks make: integers, picks, weights, shuffles, samples, normal values and named streams. It also gives a content hash: SHA-256 and canonical JSON (RFC 8785).",
|
|
4
|
+
"version": "0.1.18",
|
|
5
|
+
"description": "A seeded random number generator (mulberry32) with the draws that tests and benchmarks make: integers, picks, weights, shuffles, samples, normal values and named streams. It also gives covering arrays (pairwise and of strength t), and a content hash: SHA-256 and canonical JSON (RFC 8785).",
|
|
6
6
|
"keywords": [
|
|
7
7
|
"random",
|
|
8
8
|
"seed",
|
|
@@ -16,7 +16,10 @@
|
|
|
16
16
|
"deterministic",
|
|
17
17
|
"testing",
|
|
18
18
|
"benchmark",
|
|
19
|
-
"fixtures"
|
|
19
|
+
"fixtures",
|
|
20
|
+
"pairwise",
|
|
21
|
+
"covering-array",
|
|
22
|
+
"combinatorial-testing"
|
|
20
23
|
],
|
|
21
24
|
"homepage": "https://github.com/mark1russell7/rigor/tree/main/packages/generators#readme",
|
|
22
25
|
"bugs": {
|
|
@@ -43,6 +46,7 @@
|
|
|
43
46
|
},
|
|
44
47
|
"devDependencies": {
|
|
45
48
|
"@mark1russell7/cue": "^2.0.0",
|
|
49
|
+
"@mark1russell7/rigor-testkit": "^0.1.11",
|
|
46
50
|
"@types/node": "^26.6.5",
|
|
47
51
|
"esbuild": "^0.28.2",
|
|
48
52
|
"fast-check": "^4.10.2",
|