@mark1russell7/rigor-generators 0.2.0 → 0.2.1
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 +2 -0
- package/build/designs.d.ts +9 -0
- package/build/designs.d.ts.map +1 -1
- package/build/designs.js +26 -1
- package/build/designs.js.map +1 -1
- package/build/index.d.ts +2 -2
- package/build/index.js +2 -2
- package/package.json +2 -2
package/README.md
CHANGED
|
@@ -139,6 +139,8 @@ const points = familyPoints(family, latinHypercube(200, 3, random("design")), ra
|
|
|
139
139
|
|
|
140
140
|
A distribution of a dimension uses its `cdf` and its `quantile`, from `distributionOf`. The value of a coordinate `u` is the quantile of `u` in the probability of the range. Thus a Latin hypercube also gives one value in each stratum of the probability.
|
|
141
141
|
|
|
142
|
+
`oneAtATimePoints(family, n, base, r)` gives points of the family, not of the unit cube. It gives one block of `n` points for each dimension. In a block, one dimension takes one value in each of `n` strata, and each other dimension keeps its value in `base`. A base value can be out of the range, for example 0 for a log dimension. Thus each block gives the law of one dimension, with the others held. The column of a dimension comes from `r.fork("column:" + name)`, thus a new dimension does not change the blocks of the others.
|
|
143
|
+
|
|
142
144
|
The parameters of a dimension come from `r.fork("dimension:" + name)`. The same seed gives the same points, and a new dimension does not change the values of the others.
|
|
143
145
|
|
|
144
146
|
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.
|
package/build/designs.d.ts
CHANGED
|
@@ -55,4 +55,13 @@ export declare function stratifiedDesign(strata: number, d: number, r: Random, l
|
|
|
55
55
|
* from `r.fork("B")`. With `base` `"latin"`, each is a Latin hypercube.
|
|
56
56
|
*/
|
|
57
57
|
export declare function saltelliDesign(n: number, d: number, r: Random, base?: "random" | "latin"): SaltelliDesign;
|
|
58
|
+
/**
|
|
59
|
+
* This function gives a design of one dimension at a time: one block of `n` points for each dimension, in the order of the
|
|
60
|
+
* dimensions. In the block of a dimension, the dimension takes the values of a Latin column of `n` strata. Each other
|
|
61
|
+
* dimension keeps its value in `base`. The column of a dimension comes from `r.fork("column:" + name)`, and the map comes
|
|
62
|
+
* from `familyMap(family, r)`. Thus a new dimension does not change the blocks of the others. A base value can be out of
|
|
63
|
+
* the range of its dimension, for example 0 for a log dimension. A base with no finite value for a dimension is a `RangeError`.
|
|
64
|
+
* A fraction for an integer dimension and a base value with no dimension are also a `RangeError`.
|
|
65
|
+
*/
|
|
66
|
+
export declare function oneAtATimePoints(family: InputFamily, n: number, base: Point, r: Random): Point[];
|
|
58
67
|
//# sourceMappingURL=designs.d.ts.map
|
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;;;;;;;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"}
|
|
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;;;;;;;;;wBAgBtF,iBAAiB,QAAQ,aAAa,WAAW,MAAM,OAAO,GAAG,SAAS"}
|
package/build/designs.js
CHANGED
|
@@ -145,6 +145,31 @@ function saltelliDesign(n, d, r, base = "random") {
|
|
|
145
145
|
ab: Array.from({ length: d }, (_, i) => a.map((row, k) => row.map((x, j) => j === i ? b[k][j] : x)))
|
|
146
146
|
};
|
|
147
147
|
}
|
|
148
|
-
|
|
148
|
+
/**
|
|
149
|
+
* This function gives a design of one dimension at a time: one block of `n` points for each dimension, in the order of the
|
|
150
|
+
* dimensions. In the block of a dimension, the dimension takes the values of a Latin column of `n` strata. Each other
|
|
151
|
+
* dimension keeps its value in `base`. The column of a dimension comes from `r.fork("column:" + name)`, and the map comes
|
|
152
|
+
* from `familyMap(family, r)`. Thus a new dimension does not change the blocks of the others. A base value can be out of
|
|
153
|
+
* the range of its dimension, for example 0 for a log dimension. A base with no finite value for a dimension is a `RangeError`.
|
|
154
|
+
* A fraction for an integer dimension and a base value with no dimension are also a `RangeError`.
|
|
155
|
+
*/
|
|
156
|
+
function oneAtATimePoints(family, n, base, r) {
|
|
157
|
+
count("oneAtATimePoints", "n", n);
|
|
158
|
+
const map = familyMap(family, r);
|
|
159
|
+
const names = familyNames(family);
|
|
160
|
+
const extra = Object.keys(base).find((name) => !names.includes(name));
|
|
161
|
+
if (extra !== void 0) throw new RangeError(`${family.name}: the base gives "${extra}", and the family has no dimension with this name.`);
|
|
162
|
+
for (const dim of family.dimensions) {
|
|
163
|
+
const value = base[dim.name];
|
|
164
|
+
if (value === void 0 || !Number.isFinite(value) || dim.integer === true && !Number.isInteger(value)) throw new RangeError(`${family.name}.${dim.name}: the base value ${value} is not a value of the dimension.`);
|
|
165
|
+
}
|
|
166
|
+
return names.flatMap((name, i) => latinHypercube(n, 1, r.fork(`column:${name}`)).map(([u]) => {
|
|
167
|
+
const unit = names.map(() => 0);
|
|
168
|
+
unit[i] = u;
|
|
169
|
+
const moved = map(unit)[name];
|
|
170
|
+
return Object.fromEntries(names.map((each) => [each, each === name ? moved : base[each]]));
|
|
171
|
+
}));
|
|
172
|
+
}
|
|
173
|
+
export { checkDimension, familyMap, familyNames, familyPoints, latinHypercube, oneAtATimePoints, randomDesign, saltelliDesign, stratifiedDesign };
|
|
149
174
|
|
|
150
175
|
//# 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/**\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,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AO,KAAK,MAAM,OAAO,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"}
|
|
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\n/**\n * This function gives a design of one dimension at a time: one block of `n` points for each dimension, in the order of the\n * dimensions. In the block of a dimension, the dimension takes the values of a Latin column of `n` strata. Each other\n * dimension keeps its value in `base`. The column of a dimension comes from `r.fork(\"column:\" + name)`, and the map comes\n * from `familyMap(family, r)`. Thus a new dimension does not change the blocks of the others. A base value can be out of\n * the range of its dimension, for example 0 for a log dimension. A base with no finite value for a dimension is a `RangeError`.\n * A fraction for an integer dimension and a base value with no dimension are also a `RangeError`.\n */\nexport function oneAtATimePoints(family: InputFamily, n: number, base: Point, r: Random): Point[] {\n count(\"oneAtATimePoints\", \"n\", n);\n const map = familyMap(family, r);\n const names = familyNames(family);\n const extra = Object.keys(base).find((name) => !names.includes(name));\n if (extra !== undefined) throw new RangeError(`${family.name}: the base gives \"${extra}\", and the family has no dimension with this name.`);\n for (const dim of family.dimensions) {\n const value = base[dim.name];\n if (value === undefined || !Number.isFinite(value) || (dim.integer === true && !Number.isInteger(value))) {\n throw new RangeError(`${family.name}.${dim.name}: the base value ${value} is not a value of the dimension.`);\n }\n }\n return names.flatMap((name, i) =>\n latinHypercube(n, 1, r.fork(`column:${name}`)).map(([u]) => {\n const unit = names.map(() => 0);\n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ING_CANDIDATES, COVERING_LIMIT, Coverage, CoveringOptions, coverin
|
|
|
2
2
|
import { DistributionSpec, Param, dependsOnLibm, sampler } from "./distributions.js";
|
|
3
3
|
import { normalCdf, normalQuantile } from "./normal.js";
|
|
4
4
|
import { Distribution, betaCdf, distributionOf } from "./quantiles.js";
|
|
5
|
-
import { Dimension, InputFamily, Point, SaltelliDesign, familyMap, familyPoints, latinHypercube, randomDesign, saltelliDesign, stratifiedDesign } from "./designs.js";
|
|
5
|
+
import { Dimension, InputFamily, Point, SaltelliDesign, familyMap, familyPoints, latinHypercube, oneAtATimePoints, randomDesign, saltelliDesign, stratifiedDesign } from "./designs.js";
|
|
6
6
|
import { CanonicalOptions, Sha256Options, canonicalHash, canonicalJson, sha256Hex } from "./hash.js";
|
|
7
7
|
import { SHRINK_CHECKS, SHRINK_TOLERANCE, ShrinkOptions, ShrinkStep, Shrunk, shrinkPoint, shrinkPointAsync, shrinkTarget } from "./shrink.js";
|
|
8
8
|
import { DIAGRAM_BOX_AREA, GIT_BLOB_BYTES, RECORDED_TABLES, RecordedTable, recordedSpec } from "./recorded.js";
|
|
9
9
|
import { Random, Source, deriveSeed, fnv1a32, mulberry32, plackettLuceOrder, random, randomOf, seedOf, seedsFrom, stablePick } from "./random.js";
|
|
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 };
|
|
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, oneAtATimePoints, plackettLuceOrder, random, randomDesign, randomOf, recordedSpec, saltelliDesign, sampler, seedOf, seedsFrom, sha256Hex, shrinkPoint, shrinkPointAsync, shrinkTarget, stablePick, stratifiedDesign, tupleCoverage };
|
package/build/index.js
CHANGED
|
@@ -2,9 +2,9 @@ import { COVERING_CANDIDATES, COVERING_LIMIT, coveringArray, coveringRows, tuple
|
|
|
2
2
|
import { dependsOnLibm, sampler } from "./distributions.js";
|
|
3
3
|
import { normalCdf, normalQuantile } from "./normal.js";
|
|
4
4
|
import { betaCdf, distributionOf } from "./quantiles.js";
|
|
5
|
-
import { familyMap, familyPoints, latinHypercube, randomDesign, saltelliDesign, stratifiedDesign } from "./designs.js";
|
|
5
|
+
import { familyMap, familyPoints, latinHypercube, oneAtATimePoints, randomDesign, saltelliDesign, stratifiedDesign } from "./designs.js";
|
|
6
6
|
import { canonicalHash, canonicalJson, sha256Hex } from "./hash.js";
|
|
7
7
|
import { SHRINK_CHECKS, SHRINK_TOLERANCE, shrinkPoint, shrinkPointAsync, shrinkTarget } from "./shrink.js";
|
|
8
8
|
import { DIAGRAM_BOX_AREA, GIT_BLOB_BYTES, RECORDED_TABLES, recordedSpec } from "./recorded.js";
|
|
9
9
|
import { deriveSeed, fnv1a32, mulberry32, plackettLuceOrder, random, randomOf, seedOf, seedsFrom, stablePick } from "./random.js";
|
|
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 };
|
|
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, oneAtATimePoints, plackettLuceOrder, random, randomDesign, randomOf, recordedSpec, saltelliDesign, sampler, seedOf, seedsFrom, sha256Hex, shrinkPoint, shrinkPointAsync, shrinkTarget, stablePick, stratifiedDesign, tupleCoverage };
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"$schema": "https://json.schemastore.org/package",
|
|
3
3
|
"name": "@mark1russell7/rigor-generators",
|
|
4
|
-
"version": "0.2.
|
|
4
|
+
"version": "0.2.1",
|
|
5
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",
|
|
@@ -46,7 +46,7 @@
|
|
|
46
46
|
},
|
|
47
47
|
"devDependencies": {
|
|
48
48
|
"@mark1russell7/cue": "^2.0.0",
|
|
49
|
-
"@mark1russell7/rigor-testkit": "^0.
|
|
49
|
+
"@mark1russell7/rigor-testkit": "^0.2.0",
|
|
50
50
|
"@types/node": "^26.6.5",
|
|
51
51
|
"esbuild": "^0.28.2",
|
|
52
52
|
"fast-check": "^4.10.2",
|