optimization-test-functions 1.0.0 → 1.0.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/LICENSE +21 -21
- package/README.md +41 -9
- package/package.json +28 -28
- package/src/index.d.ts +88 -81
- package/src/index.js +73 -21
package/LICENSE
CHANGED
|
@@ -1,21 +1,21 @@
|
|
|
1
|
-
MIT License
|
|
2
|
-
|
|
3
|
-
Copyright (c) 2026 Mark Colley
|
|
4
|
-
|
|
5
|
-
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
-
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
-
in the Software without restriction, including without limitation the rights
|
|
8
|
-
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
-
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
-
furnished to do so, subject to the following conditions:
|
|
11
|
-
|
|
12
|
-
The above copyright notice and this permission notice shall be included in all
|
|
13
|
-
copies or substantial portions of the Software.
|
|
14
|
-
|
|
15
|
-
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
-
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
-
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
-
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
-
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
-
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
-
SOFTWARE.
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Mark Colley
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
CHANGED
|
@@ -1,8 +1,14 @@
|
|
|
1
1
|
# optimization-test-functions
|
|
2
2
|
|
|
3
|
+
[](https://www.npmjs.com/package/optimization-test-functions)
|
|
4
|
+
[](https://github.com/M-Colley/optimization-test-functions/actions/workflows/ci.yml)
|
|
5
|
+
[](./LICENSE)
|
|
6
|
+
|
|
3
7
|
Standard global-optimization benchmarks and classical psychophysical laws, in
|
|
4
8
|
JavaScript. No dependencies, no build step, ESM.
|
|
5
9
|
|
|
10
|
+
**On npm:** <https://www.npmjs.com/package/optimization-test-functions>
|
|
11
|
+
|
|
6
12
|
Every function ships with the metadata you need to use it correctly: the domain
|
|
7
13
|
it is actually defined on, its known optimum, and which direction is the
|
|
8
14
|
interesting one.
|
|
@@ -58,7 +64,7 @@ law states — Hick–Hyman returns a reaction time, so lower is better, and
|
|
|
58
64
|
| `branin` | 2 | `[-5, 10] × [0, 15]` | `0.397887`, three times |
|
|
59
65
|
| `rosenbrock` | ≥ 2 | `[-5, 10]ᵈ` | `0` at all-ones |
|
|
60
66
|
| `rastrigin` | any | `[-5.12, 5.12]ᵈ` | `0` at the origin |
|
|
61
|
-
| `michalewicz` | any | `[0, π]ᵈ` | d-dependent |
|
|
67
|
+
| `michalewicz` | any | `[0, π]ᵈ` | d-dependent; exact for d ≤ 10 |
|
|
62
68
|
|
|
63
69
|
### Classical psychophysical laws
|
|
64
70
|
|
|
@@ -84,8 +90,8 @@ shekel.meta;
|
|
|
84
90
|
// name: 'Shekel', dims: 4, sense: 'min',
|
|
85
91
|
// domain: d => [[0, 10], [0, 10], [0, 10], [0, 10]],
|
|
86
92
|
// optimum: {
|
|
87
|
-
// value: -10.
|
|
88
|
-
// at: () => [4.
|
|
93
|
+
// value: -10.536443153483528,
|
|
94
|
+
// at: () => [4.000746868270634, 3.9995094800857736, 4.000746868270634, 3.9995094800857736],
|
|
89
95
|
// approx: [4, 4, 4, 4],
|
|
90
96
|
// note: 'for m = 10',
|
|
91
97
|
// },
|
|
@@ -95,9 +101,27 @@ shekel.meta;
|
|
|
95
101
|
|
|
96
102
|
Shekel is a good example of why the metadata is worth having. Its minimum is
|
|
97
103
|
almost always quoted at `(4, 4, 4, 4)`, but that is only approximate — the
|
|
98
|
-
neighbouring wells pull it slightly off, and `f(4,4,4,4) = -10.
|
|
104
|
+
neighbouring wells pull it slightly off, and `f(4,4,4,4) = -10.536284`, not
|
|
99
105
|
`-10.536443`. Both the quoted and the refined location are recorded.
|
|
100
106
|
|
|
107
|
+
Every stated optimum is re-derived at 50 significant digits rather than copied,
|
|
108
|
+
which matters more than it sounds. Some widely circulated values are wrong:
|
|
109
|
+
|
|
110
|
+
| function | commonly quoted | true minimum, these constants |
|
|
111
|
+
|---|---|---|
|
|
112
|
+
| `hartmann3` | `-3.86278214782076` at `(0.114614, 0.555649, 0.852547)` | `-3.8627797873326624` at `(0.1145889, 0.5556489, 0.8525470)` |
|
|
113
|
+
| `hartmann6` | `-3.322368011391339` | `-3.3223680114155147` |
|
|
114
|
+
|
|
115
|
+
The quoted Hartmann-3 value is 2.4e-6 *below* the true minimum, so no point
|
|
116
|
+
attains it, and simple regret measured against it can never reach zero. The
|
|
117
|
+
quoted Hartmann-6 value is the function at the rounded six-digit location, not
|
|
118
|
+
the minimum. Where a commonly quoted location differs from the true one, it is
|
|
119
|
+
kept as `optimum.approx`.
|
|
120
|
+
|
|
121
|
+
Michalewicz is separable, so its d-dimensional minimum is exactly the sum of
|
|
122
|
+
one-dimensional minima. `michalewicz.meta.optimum.known` gives it for every
|
|
123
|
+
`d` from 1 to 10, not only the usual three.
|
|
124
|
+
|
|
101
125
|
## Optional parameters
|
|
102
126
|
|
|
103
127
|
```js
|
|
@@ -127,12 +151,19 @@ evaluated on the wrong box.
|
|
|
127
151
|
|
|
128
152
|
## Correctness
|
|
129
153
|
|
|
130
|
-
|
|
154
|
+
Three independent checks, all run in CI:
|
|
131
155
|
|
|
132
|
-
- `npm test` —
|
|
133
|
-
|
|
134
|
-
|
|
156
|
+
- `npm test` — 13 tests. Verifies that every stated optimum is attained at its
|
|
157
|
+
stated location to within a few ulps, that compass search started there
|
|
158
|
+
finds nothing better, and that 200 000 random points inside each domain fail
|
|
159
|
+
to beat it. Checks every tabulated Michalewicz optimum by solving the
|
|
160
|
+
separable problem directly. Also covers dimension validation, `negate`
|
|
161
|
+
(which flips the optimum and monotonicity along with the sense), and the
|
|
135
162
|
per-axis domain mapping.
|
|
163
|
+
- `python test/crosscheck_optima.py` — re-derives every stated optimum and its
|
|
164
|
+
location at 50 significant digits with [mpmath](https://mpmath.org), from the
|
|
165
|
+
exact decimal constants, and fails if the library disagrees by more than a
|
|
166
|
+
few ulps in value or 1e-9 in location.
|
|
136
167
|
- `python test/crosscheck_botorch.py` — compares **308 values across 11
|
|
137
168
|
functions** against [BoTorch](https://botorch.org)'s `test_functions.synthetic`,
|
|
138
169
|
the reference implementation most of the Bayesian-optimization field uses.
|
|
@@ -154,7 +185,8 @@ Two independent checks, both run in CI:
|
|
|
154
185
|
fails on BoTorch's precision, not on ours.
|
|
155
186
|
|
|
156
187
|
Schwefel is not in BoTorch, and the psychophysical laws are not optimization
|
|
157
|
-
benchmarks, so those five are
|
|
188
|
+
benchmarks, so those five are not in the BoTorch comparison. Schwefel's optimum
|
|
189
|
+
is in the mpmath check; the psychophysical laws are checked by the JS suite.
|
|
158
190
|
|
|
159
191
|
## Notes
|
|
160
192
|
|
package/package.json
CHANGED
|
@@ -1,28 +1,28 @@
|
|
|
1
|
-
{
|
|
2
|
-
"name": "optimization-test-functions",
|
|
3
|
-
"version": "1.0.
|
|
4
|
-
"description": "Canonical global-optimization benchmarks and classical psychophysical laws, with per-axis domains and known optima. Zero dependencies.",
|
|
5
|
-
"keywords": [
|
|
6
|
-
"optimization", "benchmark", "test-functions", "global-optimization",
|
|
7
|
-
"ackley", "rastrigin", "rosenbrock", "griewank", "hartmann", "branin",
|
|
8
|
-
"schwefel", "shekel", "michalewicz", "eggholder", "powell",
|
|
9
|
-
"bayesian-optimization", "psychophysics", "hci", "fitts", "hick", "stevens"
|
|
10
|
-
],
|
|
11
|
-
"type": "module",
|
|
12
|
-
"main": "./src/index.js",
|
|
13
|
-
"exports": {
|
|
14
|
-
".": { "types": "./src/index.d.ts", "default": "./src/index.js" }
|
|
15
|
-
},
|
|
16
|
-
"types": "./src/index.d.ts",
|
|
17
|
-
"files": ["src/"],
|
|
18
|
-
"sideEffects": false,
|
|
19
|
-
"engines": { "node": ">=18" },
|
|
20
|
-
"scripts": {
|
|
21
|
-
"test": "node --test"
|
|
22
|
-
},
|
|
23
|
-
"license": "MIT",
|
|
24
|
-
"author": "Mark Colley",
|
|
25
|
-
"repository": { "type": "git", "url": "git+https://github.com/M-Colley/optimization-test-functions.git" },
|
|
26
|
-
"bugs": { "url": "https://github.com/M-Colley/optimization-test-functions/issues" },
|
|
27
|
-
"homepage": "https://github.com/M-Colley/optimization-test-functions#readme"
|
|
28
|
-
}
|
|
1
|
+
{
|
|
2
|
+
"name": "optimization-test-functions",
|
|
3
|
+
"version": "1.0.1",
|
|
4
|
+
"description": "Canonical global-optimization benchmarks and classical psychophysical laws, with per-axis domains and known optima. Zero dependencies.",
|
|
5
|
+
"keywords": [
|
|
6
|
+
"optimization", "benchmark", "test-functions", "global-optimization",
|
|
7
|
+
"ackley", "rastrigin", "rosenbrock", "griewank", "hartmann", "branin",
|
|
8
|
+
"schwefel", "shekel", "michalewicz", "eggholder", "powell",
|
|
9
|
+
"bayesian-optimization", "psychophysics", "hci", "fitts", "hick", "stevens"
|
|
10
|
+
],
|
|
11
|
+
"type": "module",
|
|
12
|
+
"main": "./src/index.js",
|
|
13
|
+
"exports": {
|
|
14
|
+
".": { "types": "./src/index.d.ts", "default": "./src/index.js" }
|
|
15
|
+
},
|
|
16
|
+
"types": "./src/index.d.ts",
|
|
17
|
+
"files": ["src/"],
|
|
18
|
+
"sideEffects": false,
|
|
19
|
+
"engines": { "node": ">=18" },
|
|
20
|
+
"scripts": {
|
|
21
|
+
"test": "node --test"
|
|
22
|
+
},
|
|
23
|
+
"license": "MIT",
|
|
24
|
+
"author": "Mark Colley",
|
|
25
|
+
"repository": { "type": "git", "url": "git+https://github.com/M-Colley/optimization-test-functions.git" },
|
|
26
|
+
"bugs": { "url": "https://github.com/M-Colley/optimization-test-functions/issues" },
|
|
27
|
+
"homepage": "https://github.com/M-Colley/optimization-test-functions#readme"
|
|
28
|
+
}
|
package/src/index.d.ts
CHANGED
|
@@ -1,81 +1,88 @@
|
|
|
1
|
-
export type Vec = readonly number[] | Float64Array | Float32Array;
|
|
2
|
-
|
|
3
|
-
/** One [lo, hi] pair per axis. */
|
|
4
|
-
export type Box = [number, number][];
|
|
5
|
-
|
|
6
|
-
export interface Optimum {
|
|
7
|
-
/** The optimal value, or null when it depends on the dimension. */
|
|
8
|
-
value: number | null;
|
|
9
|
-
/** The location, given the dimension. Absent when `value` is null. */
|
|
10
|
-
at?: (d: number) => number[];
|
|
11
|
-
/** A commonly quoted but only approximate location, where one exists. */
|
|
12
|
-
approx?: number[];
|
|
13
|
-
/** Every global optimum, for functions that have more than one. */
|
|
14
|
-
all?: number[][];
|
|
15
|
-
/**
|
|
16
|
-
known?: Record<number, number>;
|
|
17
|
-
note?: string;
|
|
18
|
-
}
|
|
19
|
-
|
|
20
|
-
export interface Meta {
|
|
21
|
-
name: string;
|
|
22
|
-
/** 'any', a fixed number, or a description such as 'multiple of 4'. */
|
|
23
|
-
dims: number | string;
|
|
24
|
-
/** Which direction is interesting. Nothing here is silently negated. */
|
|
25
|
-
sense: 'min' | 'max';
|
|
26
|
-
/** The function's own domain, per axis, at dimension d. */
|
|
27
|
-
domain: (d: number) => Box;
|
|
28
|
-
optimum: Optimum;
|
|
29
|
-
/** Present on the psychophysical laws; false or a direction. */
|
|
30
|
-
monotone?: false | 'increasing' | 'decreasing';
|
|
31
|
-
note?: string;
|
|
32
|
-
reference: string;
|
|
33
|
-
}
|
|
34
|
-
|
|
35
|
-
export interface TestFunction<O = Record<string, never>> {
|
|
36
|
-
(x: Vec, options?: O): number;
|
|
37
|
-
meta: Meta;
|
|
38
|
-
}
|
|
39
|
-
|
|
40
|
-
/* classical optimization benchmarks -- minimized */
|
|
41
|
-
export const ackley: TestFunction<{ a?: number; b?: number; c?: number }>;
|
|
42
|
-
export const griewank: TestFunction;
|
|
43
|
-
export const schwefel: TestFunction;
|
|
44
|
-
export const eggholder: TestFunction;
|
|
45
|
-
export const powell: TestFunction;
|
|
46
|
-
export const shekel: TestFunction<{ m?: number }>;
|
|
47
|
-
export const hartmann3: TestFunction;
|
|
48
|
-
export const hartmann6: TestFunction;
|
|
49
|
-
export const branin: TestFunction<{
|
|
50
|
-
a?: number; b?: number; c?: number; r?: number; s?: number; t?: number;
|
|
51
|
-
}>;
|
|
52
|
-
export const rosenbrock: TestFunction;
|
|
53
|
-
export const rastrigin: TestFunction;
|
|
54
|
-
export const michalewicz: TestFunction<{ m?: number }>;
|
|
55
|
-
|
|
56
|
-
/* classical psychophysical laws */
|
|
57
|
-
export const yerkesDodson: TestFunction<{ peak?: number; width?: number }>;
|
|
58
|
-
export const stevens: TestFunction<{ a?: number }>;
|
|
59
|
-
export const hickHyman: TestFunction<{ a?: number; b?: number }>;
|
|
60
|
-
export const weberFechner: TestFunction<{ i0?: number }>;
|
|
61
|
-
|
|
62
|
-
export type FunctionName =
|
|
63
|
-
| 'ackley' | 'griewank' | 'schwefel' | 'eggholder' | 'powell' | 'shekel'
|
|
64
|
-
| 'hartmann3' | 'hartmann6' | 'branin' | 'rosenbrock' | 'rastrigin'
|
|
65
|
-
| 'michalewicz' | 'yerkesDodson' | 'stevens' | 'hickHyman' | 'weberFechner';
|
|
66
|
-
|
|
67
|
-
export const functions: Record<FunctionName, TestFunction<any>>;
|
|
68
|
-
export const optimizationBenchmarks: FunctionName[];
|
|
69
|
-
export const psychophysicalLaws: FunctionName[];
|
|
70
|
-
|
|
71
|
-
/**
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
1
|
+
export type Vec = readonly number[] | Float64Array | Float32Array;
|
|
2
|
+
|
|
3
|
+
/** One [lo, hi] pair per axis. */
|
|
4
|
+
export type Box = [number, number][];
|
|
5
|
+
|
|
6
|
+
export interface Optimum {
|
|
7
|
+
/** The optimal value, or null when it depends on the dimension. */
|
|
8
|
+
value: number | null;
|
|
9
|
+
/** The location, given the dimension. Absent when `value` is null. */
|
|
10
|
+
at?: (d: number) => number[];
|
|
11
|
+
/** A commonly quoted but only approximate location, where one exists. */
|
|
12
|
+
approx?: number[];
|
|
13
|
+
/** Every global optimum, for functions that have more than one. */
|
|
14
|
+
all?: number[][];
|
|
15
|
+
/** Optimal values keyed by dimension, when the optimum is d-dependent. */
|
|
16
|
+
known?: Record<number, number>;
|
|
17
|
+
note?: string;
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
export interface Meta {
|
|
21
|
+
name: string;
|
|
22
|
+
/** 'any', a fixed number, or a description such as 'multiple of 4'. */
|
|
23
|
+
dims: number | string;
|
|
24
|
+
/** Which direction is interesting. Nothing here is silently negated. */
|
|
25
|
+
sense: 'min' | 'max';
|
|
26
|
+
/** The function's own domain, per axis, at dimension d. */
|
|
27
|
+
domain: (d: number) => Box;
|
|
28
|
+
optimum: Optimum;
|
|
29
|
+
/** Present on the psychophysical laws; false or a direction. */
|
|
30
|
+
monotone?: false | 'increasing' | 'decreasing';
|
|
31
|
+
note?: string;
|
|
32
|
+
reference: string;
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
export interface TestFunction<O = Record<string, never>> {
|
|
36
|
+
(x: Vec, options?: O): number;
|
|
37
|
+
meta: Meta;
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
/* classical optimization benchmarks -- minimized */
|
|
41
|
+
export const ackley: TestFunction<{ a?: number; b?: number; c?: number }>;
|
|
42
|
+
export const griewank: TestFunction;
|
|
43
|
+
export const schwefel: TestFunction;
|
|
44
|
+
export const eggholder: TestFunction;
|
|
45
|
+
export const powell: TestFunction;
|
|
46
|
+
export const shekel: TestFunction<{ m?: number }>;
|
|
47
|
+
export const hartmann3: TestFunction;
|
|
48
|
+
export const hartmann6: TestFunction;
|
|
49
|
+
export const branin: TestFunction<{
|
|
50
|
+
a?: number; b?: number; c?: number; r?: number; s?: number; t?: number;
|
|
51
|
+
}>;
|
|
52
|
+
export const rosenbrock: TestFunction;
|
|
53
|
+
export const rastrigin: TestFunction;
|
|
54
|
+
export const michalewicz: TestFunction<{ m?: number }>;
|
|
55
|
+
|
|
56
|
+
/* classical psychophysical laws */
|
|
57
|
+
export const yerkesDodson: TestFunction<{ peak?: number; width?: number }>;
|
|
58
|
+
export const stevens: TestFunction<{ a?: number }>;
|
|
59
|
+
export const hickHyman: TestFunction<{ a?: number; b?: number }>;
|
|
60
|
+
export const weberFechner: TestFunction<{ i0?: number }>;
|
|
61
|
+
|
|
62
|
+
export type FunctionName =
|
|
63
|
+
| 'ackley' | 'griewank' | 'schwefel' | 'eggholder' | 'powell' | 'shekel'
|
|
64
|
+
| 'hartmann3' | 'hartmann6' | 'branin' | 'rosenbrock' | 'rastrigin'
|
|
65
|
+
| 'michalewicz' | 'yerkesDodson' | 'stevens' | 'hickHyman' | 'weberFechner';
|
|
66
|
+
|
|
67
|
+
export const functions: Record<FunctionName, TestFunction<any>>;
|
|
68
|
+
export const optimizationBenchmarks: FunctionName[];
|
|
69
|
+
export const psychophysicalLaws: FunctionName[];
|
|
70
|
+
|
|
71
|
+
/**
|
|
72
|
+
* Wrap a function so a minimizer can be used as a maximizer, or vice versa.
|
|
73
|
+
* `meta.sense`, `meta.optimum.value`, `meta.optimum.known` and
|
|
74
|
+
* `meta.monotone` all flip with the sign.
|
|
75
|
+
*/
|
|
76
|
+
export function negate<O>(f: TestFunction<O>): TestFunction<O>;
|
|
77
|
+
|
|
78
|
+
/**
|
|
79
|
+
* The per-axis domain of `name` at dimension `d`. `d` is optional for
|
|
80
|
+
* fixed-dimension functions and must match their dimension if given.
|
|
81
|
+
*/
|
|
82
|
+
export function domain(name: FunctionName, d?: number): Box;
|
|
83
|
+
|
|
84
|
+
/** Map a point from the unit cube onto `name`'s own domain. */
|
|
85
|
+
export function fromUnitCube(name: FunctionName, u: Vec): number[];
|
|
86
|
+
|
|
87
|
+
declare const _default: Record<FunctionName, TestFunction<any>>;
|
|
88
|
+
export default _default;
|
package/src/index.js
CHANGED
|
@@ -36,10 +36,26 @@ const mean = (x) => {
|
|
|
36
36
|
return s / x.length;
|
|
37
37
|
};
|
|
38
38
|
|
|
39
|
-
/**
|
|
39
|
+
/**
|
|
40
|
+
* Wrap a function so a minimizer can be used as a maximizer, or vice versa.
|
|
41
|
+
* The metadata follows: the sense, the optimum value (and any per-dimension
|
|
42
|
+
* table of them) and the direction of monotonicity all flip with the sign.
|
|
43
|
+
*/
|
|
40
44
|
export function negate(f) {
|
|
41
45
|
const g = (...args) => -f(...args);
|
|
42
|
-
if (f.meta)
|
|
46
|
+
if (f.meta) {
|
|
47
|
+
const { sense, monotone, optimum } = f.meta;
|
|
48
|
+
g.meta = {
|
|
49
|
+
...f.meta,
|
|
50
|
+
sense: sense === 'min' ? 'max' : 'min',
|
|
51
|
+
optimum: { ...optimum, value: optimum.value === null ? null : -optimum.value },
|
|
52
|
+
};
|
|
53
|
+
if (optimum.known) {
|
|
54
|
+
g.meta.optimum.known = Object.fromEntries(
|
|
55
|
+
Object.entries(optimum.known).map(([d, v]) => [d, -v]));
|
|
56
|
+
}
|
|
57
|
+
if (monotone) g.meta.monotone = monotone === 'increasing' ? 'decreasing' : 'increasing';
|
|
58
|
+
}
|
|
43
59
|
return g;
|
|
44
60
|
}
|
|
45
61
|
|
|
@@ -87,11 +103,12 @@ export function schwefel(x) {
|
|
|
87
103
|
assertLength(x, 'schwefel', (n) => n >= 1);
|
|
88
104
|
let s = 0;
|
|
89
105
|
for (let i = 0; i < x.length; i++) s += x[i] * Math.sin(Math.sqrt(Math.abs(x[i])));
|
|
90
|
-
|
|
106
|
+
// max of t sin(sqrt t): t = u^2 where tan(u) = -u/2, solved at 50 digits
|
|
107
|
+
return 418.9828872724337 * x.length - s;
|
|
91
108
|
}
|
|
92
109
|
schwefel.meta = {
|
|
93
110
|
name: 'Schwefel', dims: 'any', sense: 'min', domain: cube(-500, 500),
|
|
94
|
-
optimum: { value: 0, at: (d) => new Array(d).fill(420.
|
|
111
|
+
optimum: { value: 0, at: (d) => new Array(d).fill(420.96874635998205) },
|
|
95
112
|
reference: 'Schwefel, H.-P. (1981). Numerical Optimization of Computer Models.',
|
|
96
113
|
};
|
|
97
114
|
|
|
@@ -104,7 +121,7 @@ export function eggholder(x) {
|
|
|
104
121
|
}
|
|
105
122
|
eggholder.meta = {
|
|
106
123
|
name: 'Eggholder', dims: 2, sense: 'min', domain: () => [[-512, 512], [-512, 512]],
|
|
107
|
-
optimum: { value: -959.
|
|
124
|
+
optimum: { value: -959.6406627208509, at: () => [512, 404.2318051137578] },
|
|
108
125
|
reference: 'Vanaret et al. (2014); after Whitley et al. (1996).',
|
|
109
126
|
};
|
|
110
127
|
|
|
@@ -135,7 +152,9 @@ const SHEKEL_C = [0.1, 0.2, 0.2, 0.4, 0.4, 0.6, 0.3, 0.7, 0.5, 0.5];
|
|
|
135
152
|
/** Shekel. Four dimensions, `m` narrow wells on a flat plain. */
|
|
136
153
|
export function shekel(x, { m = 10 } = {}) {
|
|
137
154
|
assertLength(x, 'shekel', (n) => n === 4);
|
|
138
|
-
if (!(m >= 1 && m <= 10))
|
|
155
|
+
if (!(Number.isInteger(m) && m >= 1 && m <= 10)) {
|
|
156
|
+
throw new RangeError('shekel: m must be an integer in 1..10');
|
|
157
|
+
}
|
|
139
158
|
let s = 0;
|
|
140
159
|
for (let i = 0; i < m; i++) {
|
|
141
160
|
let q = 0;
|
|
@@ -147,21 +166,25 @@ export function shekel(x, { m = 10 } = {}) {
|
|
|
147
166
|
shekel.meta = {
|
|
148
167
|
name: 'Shekel', dims: 4, sense: 'min', domain: cube(0, 10),
|
|
149
168
|
optimum: {
|
|
150
|
-
value: -10.
|
|
169
|
+
value: -10.536443153483528,
|
|
151
170
|
// Almost always quoted as (4, 4, 4, 4), which is only approximate: the
|
|
152
171
|
// neighbouring wells pull the minimum slightly off that corner, and
|
|
153
|
-
// f(4,4,4,4) = -10.
|
|
154
|
-
|
|
172
|
+
// f(4,4,4,4) = -10.536284, not -10.536443. Refined location below; it
|
|
173
|
+
// has x1 = x3 and x2 = x4, as the symmetry of the wells requires.
|
|
174
|
+
at: () => [4.000746868270634, 3.9995094800857736, 4.000746868270634, 3.9995094800857736],
|
|
155
175
|
approx: [4, 4, 4, 4],
|
|
156
176
|
note: 'for m = 10',
|
|
157
177
|
},
|
|
158
|
-
reference: 'Shekel, J. (1971).
|
|
178
|
+
reference: 'Shekel, J. (1971). Test functions for multimodal search techniques. '
|
|
179
|
+
+ 'Fifth Annual Princeton Conf. on Information Science and Systems.',
|
|
159
180
|
};
|
|
160
181
|
|
|
161
182
|
const H_ALPHA = [1.0, 1.2, 3.0, 3.2];
|
|
162
183
|
const H3_A = [[3.0, 10, 30], [0.1, 10, 35], [3.0, 10, 30], [0.1, 10, 35]];
|
|
184
|
+
// v / 1e4 rather than v * 1e-4: 1e-4 is inexact, and the product is 1 ulp off
|
|
185
|
+
// the decimal constant for a third of the entries; the quotient never is.
|
|
163
186
|
const H3_P = [[3689, 1170, 2673], [4699, 4387, 7470],
|
|
164
|
-
[1091, 8732, 5547], [381, 5743, 8828]].map((r) => r.map((v) => v
|
|
187
|
+
[1091, 8732, 5547], [381, 5743, 8828]].map((r) => r.map((v) => v / 1e4));
|
|
165
188
|
|
|
166
189
|
/** Hartmann 3-D. Four Gaussian basins of unequal depth. */
|
|
167
190
|
export function hartmann3(x) {
|
|
@@ -176,7 +199,14 @@ export function hartmann3(x) {
|
|
|
176
199
|
}
|
|
177
200
|
hartmann3.meta = {
|
|
178
201
|
name: 'Hartmann-3', dims: 3, sense: 'min', domain: cube(0, 1),
|
|
179
|
-
optimum: {
|
|
202
|
+
optimum: {
|
|
203
|
+
value: -3.8627797873326624,
|
|
204
|
+
// The widely copied -3.86278214782076 is 2.4e-6 BELOW the true minimum,
|
|
205
|
+
// so no point attains it, and the usual location (kept as `approx`) is
|
|
206
|
+
// 2.5e-5 off in x1. Both re-derived at 50 digits.
|
|
207
|
+
at: () => [0.11458887665506896, 0.55564889461693, 0.8525469846866774],
|
|
208
|
+
approx: [0.114614, 0.555649, 0.852547],
|
|
209
|
+
},
|
|
180
210
|
reference: 'Hartman, J. K. (1973). Naval Research Logistics Quarterly 20(3).',
|
|
181
211
|
};
|
|
182
212
|
|
|
@@ -184,7 +214,7 @@ const H6_A = [[10, 3, 17, 3.5, 1.7, 8], [0.05, 10, 17, 0.1, 8, 14],
|
|
|
184
214
|
[3, 3.5, 1.7, 10, 17, 8], [17, 8, 0.05, 10, 0.1, 14]];
|
|
185
215
|
const H6_P = [[1312, 1696, 5569, 124, 8283, 5886], [2329, 4135, 8307, 3736, 1004, 9991],
|
|
186
216
|
[2348, 1451, 3522, 2883, 3047, 6650], [4047, 8828, 8732, 5743, 1091, 381]]
|
|
187
|
-
.map((r) => r.map((v) => v
|
|
217
|
+
.map((r) => r.map((v) => v / 1e4));
|
|
188
218
|
|
|
189
219
|
/** Hartmann 6-D. The usual stress test for a GP with one lengthscale per axis. */
|
|
190
220
|
export function hartmann6(x) {
|
|
@@ -200,8 +230,12 @@ export function hartmann6(x) {
|
|
|
200
230
|
hartmann6.meta = {
|
|
201
231
|
name: 'Hartmann-6', dims: 6, sense: 'min', domain: cube(0, 1),
|
|
202
232
|
optimum: {
|
|
203
|
-
value
|
|
204
|
-
|
|
233
|
+
// The usual value -3.322368011391339 is f at the usual six-digit
|
|
234
|
+
// location (kept as `approx`), not the minimum, which is 2.4e-11 lower.
|
|
235
|
+
value: -3.3223680114155147,
|
|
236
|
+
at: () => [0.20168951100670543, 0.15001069182345797, 0.476873974221897,
|
|
237
|
+
0.2753324304940561, 0.31165161660011326, 0.6573005340656203],
|
|
238
|
+
approx: [0.20169, 0.150011, 0.476874, 0.275332, 0.311652, 0.6573],
|
|
205
239
|
},
|
|
206
240
|
reference: 'Hartman, J. K. (1973). Naval Research Logistics Quarterly 20(3).',
|
|
207
241
|
};
|
|
@@ -220,9 +254,9 @@ export function branin(x, { a = 1, b = 5.1 / (4 * Math.PI ** 2), c = 5 / Math.PI
|
|
|
220
254
|
branin.meta = {
|
|
221
255
|
name: 'Branin', dims: 2, sense: 'min', domain: () => [[-5, 10], [0, 15]],
|
|
222
256
|
optimum: {
|
|
223
|
-
value:
|
|
257
|
+
value: 5 / (4 * Math.PI),
|
|
224
258
|
at: () => [-Math.PI, 12.275],
|
|
225
|
-
all: [[-Math.PI, 12.275], [Math.PI, 2.275], [
|
|
259
|
+
all: [[-Math.PI, 12.275], [Math.PI, 2.275], [3 * Math.PI, 2.475]],
|
|
226
260
|
},
|
|
227
261
|
reference: 'Branin, F. H. (1972). IBM Journal of Research and Development 16(5).',
|
|
228
262
|
};
|
|
@@ -268,8 +302,17 @@ michalewicz.meta = {
|
|
|
268
302
|
name: 'Michalewicz', dims: 'any', sense: 'min', domain: cube(0, Math.PI),
|
|
269
303
|
optimum: {
|
|
270
304
|
value: null,
|
|
271
|
-
|
|
272
|
-
|
|
305
|
+
// f is a sum of one-dimensional terms, so its d-D minimum is exactly the
|
|
306
|
+
// sum of the 1-D minima. Each was solved at 50 digits; see
|
|
307
|
+
// test/crosscheck_optima.py.
|
|
308
|
+
note: 'depends on d; exact for d = 1..10 at m = 10. Agrees with the published '
|
|
309
|
+
+ '-1.8013 (d=2), -4.687658 (d=5) and -9.66015 (d=10).',
|
|
310
|
+
known: {
|
|
311
|
+
1: -0.8013034100985525, 2: -1.8013034100985525, 3: -2.7603946799945587,
|
|
312
|
+
4: -3.698857098466642, 5: -4.687658179088146, 6: -5.687658179088146,
|
|
313
|
+
7: -6.680885314444028, 8: -7.663757350716239, 9: -8.66015171564134,
|
|
314
|
+
10: -9.66015171564134,
|
|
315
|
+
},
|
|
273
316
|
},
|
|
274
317
|
reference: 'Michalewicz, Z. (1996). Genetic Algorithms + Data Structures = Evolution Programs.',
|
|
275
318
|
};
|
|
@@ -296,6 +339,7 @@ export function yerkesDodson(x, { peak = 0.5, width = 0.15 } = {}) {
|
|
|
296
339
|
yerkesDodson.meta = {
|
|
297
340
|
name: 'Yerkes-Dodson', dims: 'any', sense: 'max', domain: cube(0, 1), monotone: false,
|
|
298
341
|
optimum: { value: 1, at: (d) => new Array(d).fill(0.5) },
|
|
342
|
+
note: 'The 1908 paper reports the effect, not a formula; the Gaussian inverted-U is a stylisation.',
|
|
299
343
|
reference: 'Yerkes, R. M., & Dodson, J. D. (1908). J. Comparative Neurology and Psychology 18.',
|
|
300
344
|
};
|
|
301
345
|
|
|
@@ -372,15 +416,23 @@ export function domain(name, d) {
|
|
|
372
416
|
const f = functions[name];
|
|
373
417
|
if (!f) throw new RangeError(`unknown function: ${name}`);
|
|
374
418
|
const dims = f.meta.dims;
|
|
375
|
-
if (typeof dims === 'number')
|
|
419
|
+
if (typeof dims === 'number') {
|
|
420
|
+
if (d !== undefined && d !== dims) throw new RangeError(`${name} is ${dims}-D, not ${d}-D`);
|
|
421
|
+
d = dims;
|
|
422
|
+
}
|
|
376
423
|
if (d === undefined) throw new RangeError(`${name}: dimension is required`);
|
|
424
|
+
if (!(Number.isInteger(d) && d >= 1)) {
|
|
425
|
+
throw new RangeError(`${name}: dimension must be a positive integer, got ${d}`);
|
|
426
|
+
}
|
|
377
427
|
return f.meta.domain(d);
|
|
378
428
|
}
|
|
379
429
|
|
|
380
430
|
/** Uniformly map a point from the unit cube onto `name`'s own domain. */
|
|
381
431
|
export function fromUnitCube(name, u) {
|
|
382
432
|
const box = domain(name, u.length);
|
|
383
|
-
|
|
433
|
+
// Array.from, not u.map: a Float32Array input would otherwise come back as
|
|
434
|
+
// a Float32Array and round the mapped point to single precision.
|
|
435
|
+
return Array.from(u, (v, i) => box[i][0] + v * (box[i][1] - box[i][0]));
|
|
384
436
|
}
|
|
385
437
|
|
|
386
438
|
export default functions;
|