@mark1russell7/rigor-generators 0.1.4 → 0.1.5

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.
@@ -0,0 +1,41 @@
1
+ import { Random } from "./random.js";
2
+ /** A parameter of a family: one value, or a range from `min` to `max` that `sampler` draws from once. */
3
+ export type Param = number | readonly [min: number, max: number];
4
+ /** A family of distributions and its parameters. */
5
+ export type DistributionSpec = {
6
+ readonly family: "lognormal";
7
+ readonly mu: Param;
8
+ readonly sigma: Param;
9
+ } | {
10
+ readonly family: "pareto";
11
+ readonly scale: Param;
12
+ readonly shape: Param;
13
+ } | {
14
+ readonly family: "zipf";
15
+ readonly n: number;
16
+ readonly exponent: Param;
17
+ } | {
18
+ readonly family: "beta";
19
+ readonly a: Param;
20
+ readonly b: Param;
21
+ } | {
22
+ readonly family: "mixture";
23
+ readonly parts: readonly {
24
+ readonly weight: number;
25
+ readonly part: DistributionSpec;
26
+ }[];
27
+ } | {
28
+ readonly family: "recorded";
29
+ readonly values: readonly number[];
30
+ };
31
+ /**
32
+ * This function gives a sampler of a family. It fixes each parameter once, so a range gives one point of the family.
33
+ * Each call of the sampler gives one number. The same seed and the same spec give the same numbers on one platform.
34
+ */
35
+ export declare function sampler(spec: DistributionSpec, r: Random): () => number;
36
+ /**
37
+ * This function tells if the numbers of a family use `Math.exp`, `Math.log` or `Math.pow`.
38
+ * The result of those functions can change between JavaScript engines. Thus such a family has the same numbers only on one platform.
39
+ */
40
+ export declare function dependsOnLibm(spec: DistributionSpec): boolean;
41
+ //# sourceMappingURL=distributions.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"distributions.d.ts","names":[],"sources":["../src/distributions.ts"],"mappings":";;YAKY,2BAA2B,aAAa;;YAGxC;WACG;WAA8B,IAAI;WAAgB,OAAO;;WACzD;WAA2B,OAAO;WAAgB,OAAO;;WACzD;WAAyB;WAAoB,UAAU;;WACvD;WAAyB,GAAG;WAAgB,GAAG;;WAC/C;WAA4B;aAA2B;aAAyB,MAAM;;;WACtF;WAA6B;;;;;;wBAsD5B,QAAQ,MAAM,kBAAkB,GAAG;;;;;wBAkDnC,cAAc,MAAM"}
@@ -0,0 +1,102 @@
1
+ // src/distributions.ts
2
+ /** This function examines a parameter. Both ends of a range must pass `valid`. */
3
+ function checked(family, name, param, valid, rule) {
4
+ const ends = typeof param === "number" ? [param] : param;
5
+ for (const value of ends) if (!Number.isFinite(value) || !valid(value)) throw new RangeError(`${family}: ${name} is ${value}, and it must be ${rule}.`);
6
+ if (typeof param !== "number" && param[0] > param[1]) throw new RangeError(`${family}: the range of ${name} starts above its end.`);
7
+ }
8
+ /** This function gives the value of a parameter: the number, or one draw from the range. */
9
+ function valueOf(param, r) {
10
+ return typeof param === "number" ? param : r.range(param[0], param[1]);
11
+ }
12
+ /** This function gives a gamma sample with the scale 1 (Marsaglia and Tsang, 2000). A shape below 1 uses the boost `U^(1/shape)`. */
13
+ function gamma(r, shape) {
14
+ if (shape < 1) return gamma(r, shape + 1) * Math.pow(1 - r.next(), 1 / shape);
15
+ const d = shape - 1 / 3;
16
+ const c = 1 / Math.sqrt(9 * d);
17
+ for (;;) {
18
+ const x = r.normal();
19
+ const v = (1 + c * x) ** 3;
20
+ if (v <= 0) continue;
21
+ if (Math.log(1 - r.next()) < .5 * x * x + d - d * v + d * Math.log(v)) return d * v;
22
+ }
23
+ }
24
+ /** This function gives the sampler of the ranks from 1 to `n`, with a probability in proportion to `rank^-exponent`. */
25
+ function zipfSampler(n, exponent, r) {
26
+ const totals = [];
27
+ let total = 0;
28
+ for (let rank = 1; rank <= n; rank++) {
29
+ total += Math.pow(rank, -exponent);
30
+ totals.push(total);
31
+ }
32
+ return () => {
33
+ const at = r.next() * total;
34
+ let lo = 0;
35
+ let hi = n - 1;
36
+ while (lo < hi) {
37
+ const mid = lo + hi >>> 1;
38
+ if (totals[mid] > at) hi = mid;
39
+ else lo = mid + 1;
40
+ }
41
+ return lo + 1;
42
+ };
43
+ }
44
+ /**
45
+ * This function gives a sampler of a family. It fixes each parameter once, so a range gives one point of the family.
46
+ * Each call of the sampler gives one number. The same seed and the same spec give the same numbers on one platform.
47
+ */
48
+ function sampler(spec, r) {
49
+ switch (spec.family) {
50
+ case "lognormal": {
51
+ checked("lognormal", "sigma", spec.sigma, (v) => v >= 0, "0 or more");
52
+ checked("lognormal", "mu", spec.mu, () => true, "finite");
53
+ const mu = valueOf(spec.mu, r);
54
+ const sigma = valueOf(spec.sigma, r);
55
+ return () => Math.exp(r.normal(mu, sigma));
56
+ }
57
+ case "pareto": {
58
+ checked("pareto", "scale", spec.scale, (v) => v > 0, "above 0");
59
+ checked("pareto", "shape", spec.shape, (v) => v > 0, "above 0");
60
+ const scale = valueOf(spec.scale, r);
61
+ const shape = valueOf(spec.shape, r);
62
+ return () => scale / Math.pow(1 - r.next(), 1 / shape);
63
+ }
64
+ case "zipf":
65
+ if (!Number.isSafeInteger(spec.n) || spec.n < 1) throw new RangeError(`zipf: n is ${spec.n}, and it must be a whole number of 1 or more.`);
66
+ checked("zipf", "exponent", spec.exponent, (v) => v >= 0, "0 or more");
67
+ return zipfSampler(spec.n, valueOf(spec.exponent, r), r);
68
+ case "beta": {
69
+ checked("beta", "a", spec.a, (v) => v > 0, "above 0");
70
+ checked("beta", "b", spec.b, (v) => v > 0, "above 0");
71
+ const a = valueOf(spec.a, r);
72
+ const b = valueOf(spec.b, r);
73
+ return () => {
74
+ const x = gamma(r, a);
75
+ return x / (x + gamma(r, b));
76
+ };
77
+ }
78
+ case "mixture": {
79
+ if (spec.parts.length === 0) throw new RangeError("mixture: the list of the parts is empty.");
80
+ for (const { weight } of spec.parts) checked("mixture", "weight", weight, (v) => v > 0, "above 0");
81
+ const parts = spec.parts.map(({ part }) => sampler(part, r));
82
+ const weights = spec.parts.map(({ weight }) => weight);
83
+ return () => parts[r.weighted(weights)]();
84
+ }
85
+ case "recorded":
86
+ if (spec.values.length === 0) throw new RangeError("recorded: the list of the values is empty.");
87
+ for (const value of spec.values) checked("recorded", "value", value, () => true, "finite");
88
+ return () => r.pick(spec.values);
89
+ }
90
+ }
91
+ /**
92
+ * This function tells if the numbers of a family use `Math.exp`, `Math.log` or `Math.pow`.
93
+ * The result of those functions can change between JavaScript engines. Thus such a family has the same numbers only on one platform.
94
+ */
95
+ function dependsOnLibm(spec) {
96
+ if (spec.family === "recorded") return false;
97
+ if (spec.family === "mixture") return spec.parts.some(({ part }) => dependsOnLibm(part));
98
+ return true;
99
+ }
100
+ export { dependsOnLibm, sampler };
101
+
102
+ //# sourceMappingURL=distributions.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"distributions.js","names":[],"sources":["../src/distributions.ts"],"sourcesContent":["// Open families of distributions for generated inputs. A family has parameters, and a parameter can be a range.\n// A corpus names a point of a family, so a new size distribution does not need a new closed value.\nimport type { Random } from \"./random.ts\";\n\n/** A parameter of a family: one value, or a range from `min` to `max` that `sampler` draws from once. */\nexport type Param = number | readonly [min: number, max: number];\n\n/** A family of distributions and its parameters. */\nexport type DistributionSpec =\n | { readonly family: \"lognormal\"; readonly mu: Param; readonly sigma: Param }\n | { readonly family: \"pareto\"; readonly scale: Param; readonly shape: Param }\n | { readonly family: \"zipf\"; readonly n: number; readonly exponent: Param }\n | { readonly family: \"beta\"; readonly a: Param; readonly b: Param }\n | { readonly family: \"mixture\"; readonly parts: readonly { readonly weight: number; readonly part: DistributionSpec }[] }\n | { readonly family: \"recorded\"; readonly values: readonly number[] };\n\n/** This function examines a parameter. Both ends of a range must pass `valid`. */\nfunction checked(family: string, name: string, param: Param, valid: (value: number) => boolean, rule: string): void {\n const ends = typeof param === \"number\" ? [param] : param;\n for (const value of ends) {\n if (!Number.isFinite(value) || !valid(value)) throw new RangeError(`${family}: ${name} is ${value}, and it must be ${rule}.`);\n }\n if (typeof param !== \"number\" && param[0] > param[1]) throw new RangeError(`${family}: the range of ${name} starts above its end.`);\n}\n\n/** This function gives the value of a parameter: the number, or one draw from the range. */\nfunction valueOf(param: Param, r: Random): number {\n return typeof param === \"number\" ? param : r.range(param[0], param[1]);\n}\n\n/** This function gives a gamma sample with the scale 1 (Marsaglia and Tsang, 2000). A shape below 1 uses the boost `U^(1/shape)`. */\nfunction gamma(r: Random, shape: number): number {\n if (shape < 1) return gamma(r, shape + 1) * Math.pow(1 - r.next(), 1 / shape);\n const d = shape - 1 / 3;\n const c = 1 / Math.sqrt(9 * d);\n for (;;) {\n const x = r.normal();\n const v = (1 + c * x) ** 3;\n if (v <= 0) continue;\n if (Math.log(1 - r.next()) < 0.5 * x * x + d - d * v + d * Math.log(v)) return d * v;\n }\n}\n\n/** This function gives the sampler of the ranks from 1 to `n`, with a probability in proportion to `rank^-exponent`. */\nfunction zipfSampler(n: number, exponent: number, r: Random): () => number {\n const totals: number[] = [];\n let total = 0;\n for (let rank = 1; rank <= n; rank++) {\n total += Math.pow(rank, -exponent);\n totals.push(total);\n }\n return () => {\n const at = r.next() * total;\n let lo = 0;\n let hi = n - 1;\n while (lo < hi) {\n const mid = (lo + hi) >>> 1;\n if (totals[mid]! > at) hi = mid;\n else lo = mid + 1;\n }\n return lo + 1;\n };\n}\n\n/**\n * This function gives a sampler of a family. It fixes each parameter once, so a range gives one point of the family.\n * Each call of the sampler gives one number. The same seed and the same spec give the same numbers on one platform.\n */\nexport function sampler(spec: DistributionSpec, r: Random): () => number {\n switch (spec.family) {\n case \"lognormal\": {\n checked(\"lognormal\", \"sigma\", spec.sigma, (v) => v >= 0, \"0 or more\");\n checked(\"lognormal\", \"mu\", spec.mu, () => true, \"finite\");\n const mu = valueOf(spec.mu, r);\n const sigma = valueOf(spec.sigma, r);\n return () => Math.exp(r.normal(mu, sigma));\n }\n case \"pareto\": {\n checked(\"pareto\", \"scale\", spec.scale, (v) => v > 0, \"above 0\");\n checked(\"pareto\", \"shape\", spec.shape, (v) => v > 0, \"above 0\");\n const scale = valueOf(spec.scale, r);\n const shape = valueOf(spec.shape, r);\n return () => scale / Math.pow(1 - r.next(), 1 / shape);\n }\n case \"zipf\": {\n if (!Number.isSafeInteger(spec.n) || spec.n < 1) throw new RangeError(`zipf: n is ${spec.n}, and it must be a whole number of 1 or more.`);\n checked(\"zipf\", \"exponent\", spec.exponent, (v) => v >= 0, \"0 or more\");\n return zipfSampler(spec.n, valueOf(spec.exponent, r), r);\n }\n case \"beta\": {\n checked(\"beta\", \"a\", spec.a, (v) => v > 0, \"above 0\");\n checked(\"beta\", \"b\", spec.b, (v) => v > 0, \"above 0\");\n const a = valueOf(spec.a, r);\n const b = valueOf(spec.b, r);\n return () => {\n const x = gamma(r, a);\n return x / (x + gamma(r, b));\n };\n }\n case \"mixture\": {\n if (spec.parts.length === 0) throw new RangeError(\"mixture: the list of the parts is empty.\");\n for (const { weight } of spec.parts) checked(\"mixture\", \"weight\", weight, (v) => v > 0, \"above 0\");\n const parts = spec.parts.map(({ part }) => sampler(part, r));\n const weights = spec.parts.map(({ weight }) => weight);\n return () => parts[r.weighted(weights)]!();\n }\n case \"recorded\": {\n if (spec.values.length === 0) throw new RangeError(\"recorded: the list of the values is empty.\");\n for (const value of spec.values) checked(\"recorded\", \"value\", value, () => true, \"finite\");\n return () => r.pick(spec.values);\n }\n }\n}\n\n/**\n * This function tells if the numbers of a family use `Math.exp`, `Math.log` or `Math.pow`.\n * The result of those functions can change between JavaScript engines. Thus such a family has the same numbers only on one platform.\n */\nexport function dependsOnLibm(spec: DistributionSpec): boolean {\n if (spec.family === \"recorded\") return false;\n if (spec.family === \"mixture\") return spec.parts.some(({ part }) => dependsOnLibm(part));\n return true;\n}\n"],"mappings":";;AAiBA,SAAS,QAAQ,QAAgB,MAAc,OAAc,OAAmC,MAAoB;CAClH,MAAM,OAAO,OAAO,UAAU,WAAW,CAAC,KAAK,IAAI;CACnD,KAAK,MAAM,SAAS,MAClB,IAAI,CAAC,OAAO,SAAS,KAAK,KAAK,CAAC,MAAM,KAAK,GAAG,MAAM,IAAI,WAAW,GAAG,OAAO,IAAI,KAAK,MAAM,MAAM,mBAAmB,KAAK,EA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K,MAAM,EAAE,YAAY,KAAK,OAAO,QAAQ,WAAW,UAAU,SAAS,MAAM,IAAI,GAAG,SAAS;GACjG,MAAM,QAAQ,KAAK,MAAM,KAAK,EAAE,WAAW,QAAQ,MAAM,CAAC,CAAC;GAC3D,MAAM,UAAU,KAAK,MAAM,KAAK,EAAE,aAAa,MAAM;GACrD,aAAa,MAAM,EAAE,SAAS,OAAO,EAAE,CAAE;EAC3C;EACA,KAAK;GACH,IAAI,KAAK,OAAO,WAAW,GAAG,MAAM,IAAI,WAAW,4CAA4C;GAC/F,KAAK,MAAM,SAAS,KAAK,QAAQ,QAAQ,YAAY,SAAS,aAAa,MAAM,QAAQ;GACzF,aAAa,EAAE,KAAK,KAAK,MAAM;CAEnC;AACF;;;;;AAMA,SAAgB,cAAc,MAAiC;CAC7D,IAAI,KAAK,WAAW,YAAY,OAAO;CACvC,IAAI,KAAK,WAAW,WAAW,OAAO,KAAK,MAAM,MAAM,EAAE,WAAW,cAAc,IAAI,CAAC;CACvF,OAAO;AACT"}
package/build/index.d.ts CHANGED
@@ -1,135 +1,4 @@
1
- /**
2
- * A pseudo-random number generator with a seed, and the draws that tests and benchmarks make from it.
3
- *
4
- * The generator is mulberry32. It is fast, it has 32 bits of state and it gives the same sequence for
5
- * the same seed on each platform. It is not for cryptography. Each repository that copied mulberry32
6
- * gets the same numbers from `random(seed).next`, so a move to this package keeps the records equal.
7
- */
8
- /** A source of uniform numbers from 0 (included) to 1 (not included). */
9
- type Source = () => number;
10
- /** The generator mulberry32. The seed is read as a 32-bit unsigned integer. */
11
- export declare function mulberry32(seed: number): Source;
12
- /**
13
- * The FNV-1a hash of 32 bits of a string. The option `input` selects the units that the hash reads:
14
- *
15
- * - `"utf8"` (the default): the UTF-8 bytes from `TextEncoder`. A lone surrogate becomes the bytes of U+FFFD.
16
- * - `"utf16"`: the UTF-16 code units of the string, one unit for each step, from `charCodeAt`.
17
- * - `"wtf8"`: the UTF-8 bytes of each code point. A lone surrogate becomes its own 3 bytes (WTF-8).
18
- *
19
- * For a string without a lone surrogate, `"utf8"` and `"wtf8"` give the same hash.
20
- */
21
- export declare function fnv1a32(text: string, options?: {
22
- readonly input?: "utf8" | "utf16" | "wtf8";
23
- }): number;
24
- /** The 32-bit seed of a number (its low 32 bits, unsigned) or of a string (its FNV-1a hash). */
25
- export declare function seedOf(seed: number | string): number;
26
- /** The seed of the stream with the name `label` under `seed`: the hash of `"<seed>:<label>"`. */
27
- export declare function deriveSeed(seed: number, label: string): number;
28
- interface Random {
29
- /** The 32-bit seed that the generator started with. Write it in each failure message, so a run can replay. */
30
- readonly seed: number;
31
- /** A uniform number from 0 (included) to 1 (not included). */
32
- next(): number;
33
- /** A uniform integer from `min` to `max`, both included. */
34
- int(min: number, max: number): number;
35
- /** A uniform integer from 0 (included) to `n` (not included). */
36
- below(n: number): number;
37
- /** A uniform number from `min` (included) to `max` (not included). */
38
- range(min: number, max: number): number;
39
- /** `true` with the probability `p`. */
40
- chance(p: number): boolean;
41
- /** One item of a list that is not empty, each with the same probability. */
42
- pick<T>(items: readonly T[]): T;
43
- /** The index of a weight, with a probability in proportion to the weight. One draw. */
44
- weighted(weights: readonly number[]): number;
45
- /** A new list with the items in a uniform random order (Fisher–Yates, from the end). */
46
- shuffle<T>(items: readonly T[]): T[];
47
- /** `k` different items of a list, in the order of the draw (a partial Fisher–Yates). */
48
- sample<T>(items: readonly T[], k: number): T[];
49
- /** A normal sample (Box–Muller, two draws). */
50
- normal(mean?: number, sd?: number): number;
51
- /** An independent generator for the part of the work with the name `label`. The same labels give the same streams. */
52
- fork(label: string): Random;
53
- }
54
- /** A generator with draws, from a seed. The default source is mulberry32. */
55
- export declare function random(seed: number | string, source?: (seed: number) => Source): Random;
56
- /** A generator with draws, from a source that you give. `fork` uses `source` for the new streams. */
57
- export declare function randomOf(next: Source, seed: number, source?: (seed: number) => Source): Random;
58
- /**
59
- * The seeds of a run: the seed in `given` (the text of an environment variable, for example
60
- * `process.env.SEED`), else the default seeds. An empty text gives the defaults.
61
- */
62
- export declare function seedsFrom(given: string | undefined, defaults: readonly number[]): number[];
63
- /** A parameter of a family: one value, or a range from `min` to `max` that `sampler` draws from once. */
64
- type Param = number | readonly [min: number, max: number];
65
- /** A family of distributions and its parameters. */
66
- type DistributionSpec = {
67
- readonly family: "lognormal";
68
- readonly mu: Param;
69
- readonly sigma: Param;
70
- } | {
71
- readonly family: "pareto";
72
- readonly scale: Param;
73
- readonly shape: Param;
74
- } | {
75
- readonly family: "zipf";
76
- readonly n: number;
77
- readonly exponent: Param;
78
- } | {
79
- readonly family: "beta";
80
- readonly a: Param;
81
- readonly b: Param;
82
- } | {
83
- readonly family: "mixture";
84
- readonly parts: readonly {
85
- readonly weight: number;
86
- readonly part: DistributionSpec;
87
- }[];
88
- } | {
89
- readonly family: "recorded";
90
- readonly values: readonly number[];
91
- };
92
- /**
93
- * This function gives a sampler of a family. It fixes each parameter once, so a range gives one point of the family.
94
- * Each call of the sampler gives one number. The same seed and the same spec give the same numbers on one platform.
95
- */
96
- export declare function sampler(spec: DistributionSpec, r: Random): () => number;
97
- /**
98
- * This function tells if the numbers of a family use `Math.exp`, `Math.log` or `Math.pow`.
99
- * The result of those functions can change between JavaScript engines. Thus such a family has the same numbers only on one platform.
100
- */
101
- export declare function dependsOnLibm(spec: DistributionSpec): boolean;
102
- /** A table of recorded values and the facts of its source. */
103
- interface RecordedTable {
104
- /** The name of the table. */
105
- readonly name: string;
106
- /** What one value measures. */
107
- readonly measure: string;
108
- /** The link to the source, with the commit of the read. */
109
- readonly source: string;
110
- /** The license of the source. */
111
- readonly license: string;
112
- /** The notice of the license of the source, or an empty string when it has no notice. */
113
- readonly notice: string;
114
- /** The date of the read. */
115
- readonly date: string;
116
- /** The count of the recorded values. */
117
- readonly count: number;
118
- /** The median of the recorded values. */
119
- readonly median: number;
120
- /**
121
- * The 100 midpoint quantiles, from the lowest to the highest.
122
- * The value at index `i` has the rank `floor(count * (i + 0.5) / 100)` of the sorted values. Each value thus stands for 1 percent of the recorded values.
123
- */
124
- readonly quantiles: readonly number[];
125
- }
126
- /** The areas of the boxes of 293 real diagrams: the actors of the Ptolemy II models, in the flattened form of the ELK model set. */
127
- export declare const DIAGRAM_BOX_AREA: RecordedTable;
128
- /** The sizes of the files of one large public git tree. A treemap of a repository has weights of this kind. */
129
- export declare const GIT_BLOB_BYTES: RecordedTable;
130
- /** The recorded tables, by name. */
131
- export declare const RECORDED_TABLES: Readonly<Record<string, RecordedTable>>;
132
- /** This function gives the spec of the family `recorded` that draws from a table. */
133
- export declare function recordedSpec(table: RecordedTable): DistributionSpec;
134
- export type { DistributionSpec, Param, Random, RecordedTable, Source };
135
- //# sourceMappingURL=index.d.ts.map
1
+ import { Random, Source, deriveSeed, fnv1a32, mulberry32, random, randomOf, seedOf, seedsFrom } from "./random.js";
2
+ import { DistributionSpec, Param, dependsOnLibm, sampler } from "./distributions.js";
3
+ import { DIAGRAM_BOX_AREA, GIT_BLOB_BYTES, RECORDED_TABLES, RecordedTable, recordedSpec } from "./recorded.js";
4
+ export { DIAGRAM_BOX_AREA, type DistributionSpec, GIT_BLOB_BYTES, type Param, RECORDED_TABLES, type Random, type RecordedTable, type Source, dependsOnLibm, deriveSeed, fnv1a32, mulberry32, random, randomOf, recordedSpec, sampler, seedOf, seedsFrom };