@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 +1 -1
- package/README.md +1 -1
- package/halton.js +22 -35
- package/kronecker.js +8 -27
- package/lowdisc.js +27 -42
- package/package.json +7 -5
- package/plastic.js +17 -37
package/CHANGELOG.md
CHANGED
package/README.md
CHANGED
package/halton.js
CHANGED
|
@@ -1,38 +1,25 @@
|
|
|
1
1
|
import { lowDiscrepancy } from "./lowdisc.js";
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
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
|
-
|
|
32
|
-
|
|
33
|
-
|
|
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
|
-
|
|
6
|
-
|
|
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
|
-
|
|
24
|
-
|
|
25
|
-
|
|
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
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
*
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
*
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
*
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
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.
|
|
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
|
|
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.
|
|
38
|
+
"@thi.ng/errors": "^2.4.6"
|
|
37
39
|
},
|
|
38
40
|
"devDependencies": {
|
|
39
41
|
"@microsoft/api-extractor": "^7.38.3",
|
|
40
|
-
"
|
|
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": "
|
|
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
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
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
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
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
|
};
|