@thi.ng/lowdisc 0.3.42 → 0.3.44

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/CHANGELOG.md CHANGED
@@ -1,6 +1,6 @@
1
1
  # Change Log
2
2
 
3
- - **Last updated**: 2023-12-03T12:13:31Z
3
+ - **Last updated**: 2023-12-11T10:07:09Z
4
4
  - **Generator**: [thi.ng/monopub](https://thi.ng/monopub)
5
5
 
6
6
  All notable changes to this project will be documented in this file.
package/README.md CHANGED
@@ -89,7 +89,7 @@ For Node.js REPL:
89
89
  const lowdisc = await import("@thi.ng/lowdisc");
90
90
  ```
91
91
 
92
- Package sizes (brotli'd, pre-treeshake): ESM: 449 bytes
92
+ Package sizes (brotli'd, pre-treeshake): ESM: 450 bytes
93
93
 
94
94
  ## Dependencies
95
95
 
package/halton.js CHANGED
@@ -1,38 +1,25 @@
1
1
  import { lowDiscrepancy } from "./lowdisc.js";
2
- /**
3
- * Iterator yielding 1D Halton sequence for given `base` (preferably a prime).
4
- *
5
- * @remarks
6
- * Ported from Python version at: https://en.wikipedia.org/wiki/Halton_sequence
7
- *
8
- * @param base -
9
- */
10
- export function* halton(base) {
11
- let n = 0;
12
- let d = 1;
13
- let invB = 1 / base;
14
- while (true) {
15
- let x = d - n;
16
- if (x === 1) {
17
- n = 1;
18
- d *= base;
19
- }
20
- else {
21
- let y = (d * invB) | 0;
22
- while (x <= y) {
23
- y = (y * invB) | 0;
24
- }
25
- n = (base + 1) * y - x;
26
- }
27
- yield n / d;
2
+ function* halton(base) {
3
+ let n = 0;
4
+ let d = 1;
5
+ let invB = 1 / base;
6
+ while (true) {
7
+ let x = d - n;
8
+ if (x === 1) {
9
+ n = 1;
10
+ d *= base;
11
+ } else {
12
+ let y = d * invB | 0;
13
+ while (x <= y) {
14
+ y = y * invB | 0;
15
+ }
16
+ n = (base + 1) * y - x;
28
17
  }
18
+ yield n / d;
19
+ }
29
20
  }
30
- /**
31
- * n-dimensional version of {@link halton}. Takes a vector of `bases` (one per
32
- * dimension) and yields iterator of nD points. If `offset` > 0, the stated
33
- * number of initial iterations will be skipped.
34
- *
35
- * @param bases -
36
- * @param offset -
37
- */
38
- export const haltonND = (bases, offset = 0) => lowDiscrepancy(bases.map(halton), offset);
21
+ const haltonND = (bases, offset = 0) => lowDiscrepancy(bases.map(halton), offset);
22
+ export {
23
+ halton,
24
+ haltonND
25
+ };
package/kronecker.js CHANGED
@@ -1,30 +1,11 @@
1
1
  import { lowDiscrepancy } from "./lowdisc.js";
2
- /** @internal */
3
2
  const fract = (x) => x - Math.floor(x);
4
- /**
5
- * Iterator yielding 1D Kronecker Recurrence sequence for given `alpha` and
6
- * `start` values, where `y(i) = fract(start + i * alpha)` and `i` is the
7
- * iteration counter. The `alpha` param should be an irrational number in the
8
- * `(0..1)` interval.
9
- *
10
- * @remarks
11
- * Reference:
12
- * - https://math.stackexchange.com/a/2848339
13
- * - http://extremelearning.com.au/unreasonable-effectiveness-of-quasirandom-sequences/
14
- *
15
- * @param alpha -
16
- * @param start -
17
- */
18
- export function* kronecker(alpha, start = 0) {
19
- while (true)
20
- yield (start = fract(start + alpha));
3
+ function* kronecker(alpha, start = 0) {
4
+ while (true)
5
+ yield start = fract(start + alpha);
21
6
  }
22
- /**
23
- * n-dimensional version of {@link kronecker}. Takes a vector of `alphas` (one
24
- * per dimension) and yields iterator of nD points. If `offset` > 0, the stated
25
- * number of initial iterations will be skipped.
26
- *
27
- * @param bases -
28
- * @param offset -
29
- */
30
- export const kroneckerND = (alphas, offset = 0) => lowDiscrepancy(alphas.map(kronecker), offset);
7
+ const kroneckerND = (alphas, offset = 0) => lowDiscrepancy(alphas.map(kronecker), offset);
8
+ export {
9
+ kronecker,
10
+ kroneckerND
11
+ };
package/lowdisc.js CHANGED
@@ -1,44 +1,29 @@
1
1
  import { assert } from "@thi.ng/errors/assert";
2
- /**
3
- * General purpose iterator yielding n-dimensional sequence values obtained from
4
- * given per-dimension sequence generators. Omits `offset` (default: 0) initial
5
- * values.
6
- *
7
- * @remarks
8
- * This function acts as shared impl for all other sequence generators in this
9
- * package.
10
- *
11
- * @param dims -
12
- * @param offset -
13
- */
14
- export const lowDiscrepancy = (dims, offset = 0) => {
15
- const num = dims.length;
16
- assert(num > 0, `invalid dimensions`);
17
- const [x, y, z] = dims;
18
- const iter = num === 1
19
- ? (function* () {
20
- while (true)
21
- yield [x.next().value];
22
- })()
23
- : num === 2
24
- ? (function* () {
25
- while (true)
26
- yield [x.next().value, y.next().value];
27
- })()
28
- : num === 3
29
- ? (function* () {
30
- while (true)
31
- yield [
32
- x.next().value,
33
- y.next().value,
34
- z.next().value,
35
- ];
36
- })()
37
- : (function* () {
38
- while (true)
39
- yield dims.map((d) => d.next().value);
40
- })();
41
- for (; offset-- > 0;)
42
- iter.next();
43
- return iter;
2
+ const lowDiscrepancy = (dims, offset = 0) => {
3
+ const num = dims.length;
4
+ assert(num > 0, `invalid dimensions`);
5
+ const [x, y, z] = dims;
6
+ const iter = num === 1 ? function* () {
7
+ while (true)
8
+ yield [x.next().value];
9
+ }() : num === 2 ? function* () {
10
+ while (true)
11
+ yield [x.next().value, y.next().value];
12
+ }() : num === 3 ? function* () {
13
+ while (true)
14
+ yield [
15
+ x.next().value,
16
+ y.next().value,
17
+ z.next().value
18
+ ];
19
+ }() : function* () {
20
+ while (true)
21
+ yield dims.map((d) => d.next().value);
22
+ }();
23
+ for (; offset-- > 0; )
24
+ iter.next();
25
+ return iter;
26
+ };
27
+ export {
28
+ lowDiscrepancy
44
29
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@thi.ng/lowdisc",
3
- "version": "0.3.42",
3
+ "version": "0.3.44",
4
4
  "description": "n-dimensional low-discrepancy sequence generators/iterators",
5
5
  "type": "module",
6
6
  "module": "./index.js",
@@ -24,7 +24,9 @@
24
24
  "author": "Karsten Schmidt (https://thi.ng)",
25
25
  "license": "Apache-2.0",
26
26
  "scripts": {
27
- "build": "yarn clean && tsc --declaration",
27
+ "build": "yarn build:esbuild && yarn build:decl",
28
+ "build:decl": "tsc --declaration --emitDeclarationOnly",
29
+ "build:esbuild": "esbuild --format=esm --platform=neutral --target=es2022 --tsconfig=tsconfig.json --outdir=. src/**/*.ts",
28
30
  "clean": "rimraf --glob '*.js' '*.d.ts' '*.map' doc",
29
31
  "doc": "typedoc --excludePrivate --excludeInternal --out doc src/index.ts",
30
32
  "doc:ae": "mkdir -p .ae/doc .ae/temp && api-extractor run --local --verbose",
@@ -33,11 +35,11 @@
33
35
  "test": "bun test"
34
36
  },
35
37
  "dependencies": {
36
- "@thi.ng/errors": "^2.4.4"
38
+ "@thi.ng/errors": "^2.4.6"
37
39
  },
38
40
  "devDependencies": {
39
41
  "@microsoft/api-extractor": "^7.38.3",
40
- "@thi.ng/testament": "^0.4.3",
42
+ "esbuild": "^0.19.8",
41
43
  "rimraf": "^5.0.5",
42
44
  "tools": "^0.0.1",
43
45
  "typedoc": "^0.25.4",
@@ -92,5 +94,5 @@
92
94
  "status": "beta",
93
95
  "year": 2020
94
96
  },
95
- "gitHead": "04d1de79f256d7a53c6b5fd157b37f49bc88e11d\n"
97
+ "gitHead": "5e7bafedfc3d53bc131469a28de31dd8e5b4a3ff\n"
96
98
  }
package/plastic.js CHANGED
@@ -1,42 +1,22 @@
1
1
  import { assert } from "@thi.ng/errors/assert";
2
2
  import { kronecker } from "./kronecker.js";
3
3
  import { lowDiscrepancy } from "./lowdisc.js";
4
- /**
5
- * Computes the `d`-th Harmonious number, with:
6
- *
7
- * - d=1 : PHI (Golden ratio)
8
- * - d=2 : PLASTIC (Plastic number)
9
- *
10
- * @remarks
11
- * See {@link plasticND} for references.
12
- *
13
- * @param d -
14
- * @param i -
15
- */
16
- export const phi = (d, i = 18) => {
17
- assert(d > 0, `d must be > 0`);
18
- d = 1 / (d + 1);
19
- let x = 2;
20
- while (i-- > 0)
21
- x = (1 + x) ** d;
22
- return x;
4
+ const phi = (d, i = 18) => {
5
+ assert(d > 0, `d must be > 0`);
6
+ d = 1 / (d + 1);
7
+ let x = 2;
8
+ while (i-- > 0)
9
+ x = (1 + x) ** d;
10
+ return x;
23
11
  };
24
- /**
25
- * Additive Recurrence R2 sequence using n-dimensional {@link kronecker}
26
- * configured with Harmonious Numbers (based on Plastic number).
27
- *
28
- * @remarks
29
- * References:
30
- *
31
- * - http://extremelearning.com.au/unreasonable-effectiveness-of-quasirandom-sequences/
32
- * - https://en.wikipedia.org/wiki/Plastic_number
33
- * - https://bib.irb.hr/datoteka/628836.Plastic_Number_-_Construct.pdf
34
- *
35
- * @param dim -
36
- */
37
- export const plasticND = (dim, offset = 0) => {
38
- const g = phi(dim);
39
- return lowDiscrepancy(new Array(dim)
40
- .fill(0)
41
- .map((_, i) => kronecker(1 / Math.pow(g, i + 1), 0.5)), offset);
12
+ const plasticND = (dim, offset = 0) => {
13
+ const g = phi(dim);
14
+ return lowDiscrepancy(
15
+ new Array(dim).fill(0).map((_, i) => kronecker(1 / Math.pow(g, i + 1), 0.5)),
16
+ offset
17
+ );
18
+ };
19
+ export {
20
+ phi,
21
+ plasticND
42
22
  };