numopt-js 0.1.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.
- package/CODING_RULES.md +161 -0
- package/LICENSE +22 -0
- package/README.md +807 -0
- package/dist/core/adjointGradientDescent.d.ts +61 -0
- package/dist/core/adjointGradientDescent.d.ts.map +1 -0
- package/dist/core/adjointGradientDescent.js +764 -0
- package/dist/core/adjointGradientDescent.js.map +1 -0
- package/dist/core/constrainedGaussNewton.d.ts +44 -0
- package/dist/core/constrainedGaussNewton.d.ts.map +1 -0
- package/dist/core/constrainedGaussNewton.js +314 -0
- package/dist/core/constrainedGaussNewton.js.map +1 -0
- package/dist/core/constrainedLevenbergMarquardt.d.ts +46 -0
- package/dist/core/constrainedLevenbergMarquardt.d.ts.map +1 -0
- package/dist/core/constrainedLevenbergMarquardt.js +469 -0
- package/dist/core/constrainedLevenbergMarquardt.js.map +1 -0
- package/dist/core/constrainedUtils.d.ts +92 -0
- package/dist/core/constrainedUtils.d.ts.map +1 -0
- package/dist/core/constrainedUtils.js +364 -0
- package/dist/core/constrainedUtils.js.map +1 -0
- package/dist/core/convergence.d.ts +35 -0
- package/dist/core/convergence.d.ts.map +1 -0
- package/dist/core/convergence.js +51 -0
- package/dist/core/convergence.js.map +1 -0
- package/dist/core/createGradientFunction.d.ts +85 -0
- package/dist/core/createGradientFunction.d.ts.map +1 -0
- package/dist/core/createGradientFunction.js +93 -0
- package/dist/core/createGradientFunction.js.map +1 -0
- package/dist/core/effectiveJacobian.d.ts +90 -0
- package/dist/core/effectiveJacobian.d.ts.map +1 -0
- package/dist/core/effectiveJacobian.js +128 -0
- package/dist/core/effectiveJacobian.js.map +1 -0
- package/dist/core/finiteDiff.d.ts +171 -0
- package/dist/core/finiteDiff.d.ts.map +1 -0
- package/dist/core/finiteDiff.js +363 -0
- package/dist/core/finiteDiff.js.map +1 -0
- package/dist/core/gaussNewton.d.ts +29 -0
- package/dist/core/gaussNewton.d.ts.map +1 -0
- package/dist/core/gaussNewton.js +151 -0
- package/dist/core/gaussNewton.js.map +1 -0
- package/dist/core/gradientDescent.d.ts +35 -0
- package/dist/core/gradientDescent.d.ts.map +1 -0
- package/dist/core/gradientDescent.js +204 -0
- package/dist/core/gradientDescent.js.map +1 -0
- package/dist/core/jacobianComputation.d.ts +24 -0
- package/dist/core/jacobianComputation.d.ts.map +1 -0
- package/dist/core/jacobianComputation.js +38 -0
- package/dist/core/jacobianComputation.js.map +1 -0
- package/dist/core/levenbergMarquardt.d.ts +36 -0
- package/dist/core/levenbergMarquardt.d.ts.map +1 -0
- package/dist/core/levenbergMarquardt.js +286 -0
- package/dist/core/levenbergMarquardt.js.map +1 -0
- package/dist/core/lineSearch.d.ts +42 -0
- package/dist/core/lineSearch.d.ts.map +1 -0
- package/dist/core/lineSearch.js +106 -0
- package/dist/core/lineSearch.js.map +1 -0
- package/dist/core/logger.d.ts +77 -0
- package/dist/core/logger.d.ts.map +1 -0
- package/dist/core/logger.js +162 -0
- package/dist/core/logger.js.map +1 -0
- package/dist/core/types.d.ts +427 -0
- package/dist/core/types.d.ts.map +1 -0
- package/dist/core/types.js +15 -0
- package/dist/core/types.js.map +1 -0
- package/dist/index.d.ts +26 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +29 -0
- package/dist/index.js.map +1 -0
- package/dist/utils/formatting.d.ts +27 -0
- package/dist/utils/formatting.d.ts.map +1 -0
- package/dist/utils/formatting.js +54 -0
- package/dist/utils/formatting.js.map +1 -0
- package/dist/utils/matrix.d.ts +63 -0
- package/dist/utils/matrix.d.ts.map +1 -0
- package/dist/utils/matrix.js +129 -0
- package/dist/utils/matrix.js.map +1 -0
- package/dist/utils/resultFormatter.d.ts +122 -0
- package/dist/utils/resultFormatter.d.ts.map +1 -0
- package/dist/utils/resultFormatter.js +342 -0
- package/dist/utils/resultFormatter.js.map +1 -0
- package/package.json +74 -0
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* This file implements the adjoint method for constrained optimization problems.
|
|
3
|
+
*
|
|
4
|
+
* The adjoint method efficiently computes gradients for constrained optimization
|
|
5
|
+
* by solving for an adjoint variable λ instead of explicitly inverting matrices.
|
|
6
|
+
*
|
|
7
|
+
* Mathematical background:
|
|
8
|
+
* - For constraint c(p, x) = 0, the implicit function theorem gives:
|
|
9
|
+
* df/dp = ∂f/∂p - ∂f/∂x (∂c/∂x)^-1 ∂c/∂p
|
|
10
|
+
* - Instead of computing (∂c/∂x)^-1 ∂c/∂p explicitly, we solve:
|
|
11
|
+
* (∂c/∂x)^T λ = (∂f/∂x)^T
|
|
12
|
+
* Then: df/dp = ∂f/∂p - λ^T ∂c/∂p
|
|
13
|
+
* - This requires solving only one linear system per iteration instead of
|
|
14
|
+
* paramCount systems, making it much more efficient.
|
|
15
|
+
*
|
|
16
|
+
* For residual functions r(p, x) where f = 1/2 r^T r:
|
|
17
|
+
* - Solve: (∂c/∂x)^T λ = r^T ∂r/∂x
|
|
18
|
+
* - Then: df/dp = r^T ∂r/∂p - λ^T ∂c/∂p
|
|
19
|
+
*
|
|
20
|
+
* References:
|
|
21
|
+
* - Nocedal & Wright, "Numerical Optimization" (2nd ed.), Chapter 12 (constrained optimization)
|
|
22
|
+
* - Adjoint method is widely used in optimal control and shape optimization
|
|
23
|
+
*
|
|
24
|
+
* Role in system:
|
|
25
|
+
* - Provides efficient constrained optimization using adjoint method
|
|
26
|
+
* - Supports both cost functions and residual functions
|
|
27
|
+
* - Uses finite differences or analytical derivatives
|
|
28
|
+
* - For residual functions r(p, x), can compute dr/dp (Jacobian matrix) efficiently
|
|
29
|
+
* by reusing ∂c/∂x decomposition for all residual components. This is more efficient
|
|
30
|
+
* than BFGS or Lagrange multiplier methods. The Jacobian enables Gauss-Newton or
|
|
31
|
+
* Levenberg-Marquardt methods for quadratic convergence in constrained optimization
|
|
32
|
+
*
|
|
33
|
+
* For first-time readers:
|
|
34
|
+
* - Start with adjointGradientDescent function
|
|
35
|
+
* - Understand how adjoint variable λ is computed
|
|
36
|
+
* - Check how states x are updated using linear approximation
|
|
37
|
+
*/
|
|
38
|
+
import type { ConstrainedCostFn, ConstrainedResidualFn, ConstraintFn, AdjointGradientDescentOptions, AdjointGradientDescentResult } from './types.js';
|
|
39
|
+
/**
|
|
40
|
+
* Performs adjoint gradient descent optimization to minimize a constrained cost function.
|
|
41
|
+
*
|
|
42
|
+
* Algorithm:
|
|
43
|
+
* 1. Start with initial parameters p0 and states x0 (satisfying c(p0, x0) = 0)
|
|
44
|
+
* 2. Compute partial derivatives ∂f/∂p, ∂f/∂x, ∂c/∂p, ∂c/∂x
|
|
45
|
+
* 3. Solve adjoint equation: (∂c/∂x)^T λ = (∂f/∂x)^T
|
|
46
|
+
* 4. Compute gradient: df/dp = ∂f/∂p - λ^T ∂c/∂p
|
|
47
|
+
* 5. Update parameters: p_new = p_old - stepSize * df/dp
|
|
48
|
+
* 6. Update states: x_new = x_old - (∂c/∂x)^-1 ∂c/∂p · Δp (linear approximation)
|
|
49
|
+
* 7. Repeat until convergence or max iterations
|
|
50
|
+
*
|
|
51
|
+
* Supports both cost functions f(p,x) and residual functions r(p,x) where f = 1/2 r^T r.
|
|
52
|
+
*
|
|
53
|
+
* @param initialParameters - Initial parameter vector p0
|
|
54
|
+
* @param initialStates - Initial state vector x0 (should satisfy c(p0, x0) = 0)
|
|
55
|
+
* @param costFunction - Cost function f(p, x) or residual function r(p, x)
|
|
56
|
+
* @param constraintFunction - Constraint function c(p, x) = 0
|
|
57
|
+
* @param options - Optimization options
|
|
58
|
+
* @returns Optimization result with final parameters, states, and constraint norm
|
|
59
|
+
*/
|
|
60
|
+
export declare function adjointGradientDescent(initialParameters: Float64Array, initialStates: Float64Array, costFunction: ConstrainedCostFn | ConstrainedResidualFn, constraintFunction: ConstraintFn, options?: AdjointGradientDescentOptions): AdjointGradientDescentResult;
|
|
61
|
+
//# sourceMappingURL=adjointGradientDescent.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"adjointGradientDescent.d.ts","sourceRoot":"","sources":["../../src/core/adjointGradientDescent.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAoCG;AAKH,OAAO,KAAK,EACV,iBAAiB,EACjB,qBAAqB,EACrB,YAAY,EACZ,6BAA6B,EAC7B,4BAA4B,EAC7B,MAAM,YAAY,CAAC;AAssCpB;;;;;;;;;;;;;;;;;;;;GAoBG;AACH,wBAAgB,sBAAsB,CACpC,iBAAiB,EAAE,YAAY,EAC/B,aAAa,EAAE,YAAY,EAC3B,YAAY,EAAE,iBAAiB,GAAG,qBAAqB,EACvD,kBAAkB,EAAE,YAAY,EAChC,OAAO,GAAE,6BAAkC,GAC1C,4BAA4B,CA6D9B"}
|