numopt-js 0.2.0 → 0.3.0

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.
Files changed (34) hide show
  1. package/CODING_RULES.md +161 -161
  2. package/LICENSE +22 -22
  3. package/README.md +905 -877
  4. package/dist/core/adjointGradientDescent.d.ts.map +1 -1
  5. package/dist/core/adjointGradientDescent.js +2 -0
  6. package/dist/core/adjointGradientDescent.js.map +1 -1
  7. package/dist/core/constrainedGaussNewton.d.ts.map +1 -1
  8. package/dist/core/constrainedGaussNewton.js +1 -0
  9. package/dist/core/constrainedGaussNewton.js.map +1 -1
  10. package/dist/core/constrainedLevenbergMarquardt.d.ts.map +1 -1
  11. package/dist/core/constrainedLevenbergMarquardt.js +3 -2
  12. package/dist/core/constrainedLevenbergMarquardt.js.map +1 -1
  13. package/dist/core/convergence.d.ts +1 -1
  14. package/dist/core/convergence.d.ts.map +1 -1
  15. package/dist/core/convergence.js +3 -2
  16. package/dist/core/convergence.js.map +1 -1
  17. package/dist/core/gaussNewton.d.ts.map +1 -1
  18. package/dist/core/gaussNewton.js +1 -0
  19. package/dist/core/gaussNewton.js.map +1 -1
  20. package/dist/core/gradientDescent.d.ts.map +1 -1
  21. package/dist/core/gradientDescent.js +2 -0
  22. package/dist/core/gradientDescent.js.map +1 -1
  23. package/dist/core/levenbergMarquardt.d.ts.map +1 -1
  24. package/dist/core/levenbergMarquardt.js +4 -2
  25. package/dist/core/levenbergMarquardt.js.map +1 -1
  26. package/dist/core/types.d.ts +7 -1
  27. package/dist/core/types.d.ts.map +1 -1
  28. package/dist/index.browser.js +20 -10
  29. package/dist/index.browser.js.map +1 -1
  30. package/dist/index.cjs +4021 -0
  31. package/dist/index.cjs.map +1 -0
  32. package/dist/utils/resultFormatter.js +4 -4
  33. package/dist/utils/resultFormatter.js.map +1 -1
  34. package/package.json +90 -87
package/CODING_RULES.md CHANGED
@@ -1,161 +1,161 @@
1
- # Coding Rules
2
-
3
- This document defines the coding standards for numopt-js.
4
-
5
- ## 1. No Magic Numbers
6
-
7
- All numeric constants must be named constants with clear meaning.
8
-
9
- **Bad:**
10
- ```typescript
11
- if (lambda > 1e-6) {
12
- // ...
13
- }
14
- ```
15
-
16
- **Good:**
17
- ```typescript
18
- const MINIMUM_LAMBDA_THRESHOLD = 1e-6;
19
- if (lambda > MINIMUM_LAMBDA_THRESHOLD) {
20
- // ...
21
- }
22
- ```
23
-
24
- ## 2. File Header Comments
25
-
26
- Every file must start with a comment explaining:
27
- - What the file does
28
- - Its role in the overall system
29
- - Guidance for first-time readers
30
-
31
- **Example:**
32
- ```typescript
33
- /**
34
- * This file implements the Levenberg-Marquardt algorithm for solving
35
- * nonlinear least squares problems.
36
- *
37
- * Role in system:
38
- * - Core optimization algorithm (Phase 3)
39
- * - Builds upon Gauss-Newton method (Phase 2)
40
- * - Uses numerical differentiation utilities
41
- *
42
- * For first-time readers:
43
- * - Start with the main function `levenbergMarquardt`
44
- * - Understand the lambda update strategy
45
- * - Check convergence criteria implementation
46
- */
47
- ```
48
-
49
- ## 3. No Abbreviations
50
-
51
- Function and variable names must be self-documenting. Obvious conventions like `i` for loop counters are acceptable.
52
-
53
- **Bad:**
54
- ```typescript
55
- function calcJ(p: Float64Array): Matrix {
56
- // ...
57
- }
58
- ```
59
-
60
- **Good:**
61
- ```typescript
62
- function computeJacobianMatrix(parameters: Float64Array): Matrix {
63
- // ...
64
- }
65
- ```
66
-
67
- ## 4. Comment Philosophy: WHY, not WHAT
68
-
69
- Comments should explain **WHY**, not **WHAT**. Code should be self-explanatory.
70
-
71
- **Bad:**
72
- ```typescript
73
- // Calculate the gradient
74
- const gradient = computeGradient(parameters);
75
- ```
76
-
77
- **Good:**
78
- ```typescript
79
- // Using central difference instead of forward difference for better accuracy
80
- // at the cost of one additional function evaluation per parameter
81
- const gradient = computeGradient(parameters);
82
- ```
83
-
84
- ## 5. Variable Naming Awareness
85
-
86
- Distinguish between:
87
- - **Constants** (never change): `UPPER_SNAKE_CASE`
88
- - **Configurable values** (may change): `camelCase` with clear names
89
- - **User-provided values** (user can change): `camelCase` with descriptive names
90
-
91
- **Example:**
92
- ```typescript
93
- const MAXIMUM_ITERATIONS = 1000; // Constant
94
- const stepSize = options.stepSize ?? DEFAULT_STEP_SIZE; // Configurable
95
- const userProvidedParameters = initialParams; // User-provided
96
- ```
97
-
98
- ## 6. Function Length Limit
99
-
100
- Functions must not exceed 50 lines. Break down complex functions into smaller, focused functions.
101
-
102
- ## 7. No Deep Nesting
103
-
104
- Use early returns and guard clauses to reduce nesting depth.
105
-
106
- **Bad:**
107
- ```typescript
108
- function processData(data: Data) {
109
- if (data !== null) {
110
- if (data.isValid) {
111
- if (data.values.length > 0) {
112
- // process...
113
- }
114
- }
115
- }
116
- }
117
- ```
118
-
119
- **Good:**
120
- ```typescript
121
- function processData(data: Data) {
122
- if (data === null) return;
123
- if (!data.isValid) return;
124
- if (data.values.length === 0) return;
125
-
126
- // process...
127
- }
128
- ```
129
-
130
- ## 8. DRY Principle
131
-
132
- Strictly avoid code duplication. Extract common logic into reusable functions.
133
-
134
- **Bad:**
135
- ```typescript
136
- function computeA() {
137
- const result = expensiveComputation();
138
- return result * 2;
139
- }
140
-
141
- function computeB() {
142
- const result = expensiveComputation();
143
- return result * 3;
144
- }
145
- ```
146
-
147
- **Good:**
148
- ```typescript
149
- function expensiveComputation(): number {
150
- // ...
151
- }
152
-
153
- function computeA(): number {
154
- return expensiveComputation() * 2;
155
- }
156
-
157
- function computeB(): number {
158
- return expensiveComputation() * 3;
159
- }
160
- ```
161
-
1
+ # Coding Rules
2
+
3
+ This document defines the coding standards for numopt-js.
4
+
5
+ ## 1. No Magic Numbers
6
+
7
+ All numeric constants must be named constants with clear meaning.
8
+
9
+ **Bad:**
10
+ ```typescript
11
+ if (lambda > 1e-6) {
12
+ // ...
13
+ }
14
+ ```
15
+
16
+ **Good:**
17
+ ```typescript
18
+ const MINIMUM_LAMBDA_THRESHOLD = 1e-6;
19
+ if (lambda > MINIMUM_LAMBDA_THRESHOLD) {
20
+ // ...
21
+ }
22
+ ```
23
+
24
+ ## 2. File Header Comments
25
+
26
+ Every file must start with a comment explaining:
27
+ - What the file does
28
+ - Its role in the overall system
29
+ - Guidance for first-time readers
30
+
31
+ **Example:**
32
+ ```typescript
33
+ /**
34
+ * This file implements the Levenberg-Marquardt algorithm for solving
35
+ * nonlinear least squares problems.
36
+ *
37
+ * Role in system:
38
+ * - Core optimization algorithm (Phase 3)
39
+ * - Builds upon Gauss-Newton method (Phase 2)
40
+ * - Uses numerical differentiation utilities
41
+ *
42
+ * For first-time readers:
43
+ * - Start with the main function `levenbergMarquardt`
44
+ * - Understand the lambda update strategy
45
+ * - Check convergence criteria implementation
46
+ */
47
+ ```
48
+
49
+ ## 3. No Abbreviations
50
+
51
+ Function and variable names must be self-documenting. Obvious conventions like `i` for loop counters are acceptable.
52
+
53
+ **Bad:**
54
+ ```typescript
55
+ function calcJ(p: Float64Array): Matrix {
56
+ // ...
57
+ }
58
+ ```
59
+
60
+ **Good:**
61
+ ```typescript
62
+ function computeJacobianMatrix(parameters: Float64Array): Matrix {
63
+ // ...
64
+ }
65
+ ```
66
+
67
+ ## 4. Comment Philosophy: WHY, not WHAT
68
+
69
+ Comments should explain **WHY**, not **WHAT**. Code should be self-explanatory.
70
+
71
+ **Bad:**
72
+ ```typescript
73
+ // Calculate the gradient
74
+ const gradient = computeGradient(parameters);
75
+ ```
76
+
77
+ **Good:**
78
+ ```typescript
79
+ // Using central difference instead of forward difference for better accuracy
80
+ // at the cost of one additional function evaluation per parameter
81
+ const gradient = computeGradient(parameters);
82
+ ```
83
+
84
+ ## 5. Variable Naming Awareness
85
+
86
+ Distinguish between:
87
+ - **Constants** (never change): `UPPER_SNAKE_CASE`
88
+ - **Configurable values** (may change): `camelCase` with clear names
89
+ - **User-provided values** (user can change): `camelCase` with descriptive names
90
+
91
+ **Example:**
92
+ ```typescript
93
+ const MAXIMUM_ITERATIONS = 1000; // Constant
94
+ const stepSize = options.stepSize ?? DEFAULT_STEP_SIZE; // Configurable
95
+ const userProvidedParameters = initialParams; // User-provided
96
+ ```
97
+
98
+ ## 6. Function Length Limit
99
+
100
+ Functions must not exceed 50 lines. Break down complex functions into smaller, focused functions.
101
+
102
+ ## 7. No Deep Nesting
103
+
104
+ Use early returns and guard clauses to reduce nesting depth.
105
+
106
+ **Bad:**
107
+ ```typescript
108
+ function processData(data: Data) {
109
+ if (data !== null) {
110
+ if (data.isValid) {
111
+ if (data.values.length > 0) {
112
+ // process...
113
+ }
114
+ }
115
+ }
116
+ }
117
+ ```
118
+
119
+ **Good:**
120
+ ```typescript
121
+ function processData(data: Data) {
122
+ if (data === null) return;
123
+ if (!data.isValid) return;
124
+ if (data.values.length === 0) return;
125
+
126
+ // process...
127
+ }
128
+ ```
129
+
130
+ ## 8. DRY Principle
131
+
132
+ Strictly avoid code duplication. Extract common logic into reusable functions.
133
+
134
+ **Bad:**
135
+ ```typescript
136
+ function computeA() {
137
+ const result = expensiveComputation();
138
+ return result * 2;
139
+ }
140
+
141
+ function computeB() {
142
+ const result = expensiveComputation();
143
+ return result * 3;
144
+ }
145
+ ```
146
+
147
+ **Good:**
148
+ ```typescript
149
+ function expensiveComputation(): number {
150
+ // ...
151
+ }
152
+
153
+ function computeA(): number {
154
+ return expensiveComputation() * 2;
155
+ }
156
+
157
+ function computeB(): number {
158
+ return expensiveComputation() * 3;
159
+ }
160
+ ```
161
+
package/LICENSE CHANGED
@@ -1,22 +1,22 @@
1
- MIT License
2
-
3
- Copyright (c) 2024 numopt-js contributors
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.
22
-
1
+ MIT License
2
+
3
+ Copyright (c) 2024 numopt-js contributors
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.
22
+