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.
Files changed (80) hide show
  1. package/CODING_RULES.md +161 -0
  2. package/LICENSE +22 -0
  3. package/README.md +807 -0
  4. package/dist/core/adjointGradientDescent.d.ts +61 -0
  5. package/dist/core/adjointGradientDescent.d.ts.map +1 -0
  6. package/dist/core/adjointGradientDescent.js +764 -0
  7. package/dist/core/adjointGradientDescent.js.map +1 -0
  8. package/dist/core/constrainedGaussNewton.d.ts +44 -0
  9. package/dist/core/constrainedGaussNewton.d.ts.map +1 -0
  10. package/dist/core/constrainedGaussNewton.js +314 -0
  11. package/dist/core/constrainedGaussNewton.js.map +1 -0
  12. package/dist/core/constrainedLevenbergMarquardt.d.ts +46 -0
  13. package/dist/core/constrainedLevenbergMarquardt.d.ts.map +1 -0
  14. package/dist/core/constrainedLevenbergMarquardt.js +469 -0
  15. package/dist/core/constrainedLevenbergMarquardt.js.map +1 -0
  16. package/dist/core/constrainedUtils.d.ts +92 -0
  17. package/dist/core/constrainedUtils.d.ts.map +1 -0
  18. package/dist/core/constrainedUtils.js +364 -0
  19. package/dist/core/constrainedUtils.js.map +1 -0
  20. package/dist/core/convergence.d.ts +35 -0
  21. package/dist/core/convergence.d.ts.map +1 -0
  22. package/dist/core/convergence.js +51 -0
  23. package/dist/core/convergence.js.map +1 -0
  24. package/dist/core/createGradientFunction.d.ts +85 -0
  25. package/dist/core/createGradientFunction.d.ts.map +1 -0
  26. package/dist/core/createGradientFunction.js +93 -0
  27. package/dist/core/createGradientFunction.js.map +1 -0
  28. package/dist/core/effectiveJacobian.d.ts +90 -0
  29. package/dist/core/effectiveJacobian.d.ts.map +1 -0
  30. package/dist/core/effectiveJacobian.js +128 -0
  31. package/dist/core/effectiveJacobian.js.map +1 -0
  32. package/dist/core/finiteDiff.d.ts +171 -0
  33. package/dist/core/finiteDiff.d.ts.map +1 -0
  34. package/dist/core/finiteDiff.js +363 -0
  35. package/dist/core/finiteDiff.js.map +1 -0
  36. package/dist/core/gaussNewton.d.ts +29 -0
  37. package/dist/core/gaussNewton.d.ts.map +1 -0
  38. package/dist/core/gaussNewton.js +151 -0
  39. package/dist/core/gaussNewton.js.map +1 -0
  40. package/dist/core/gradientDescent.d.ts +35 -0
  41. package/dist/core/gradientDescent.d.ts.map +1 -0
  42. package/dist/core/gradientDescent.js +204 -0
  43. package/dist/core/gradientDescent.js.map +1 -0
  44. package/dist/core/jacobianComputation.d.ts +24 -0
  45. package/dist/core/jacobianComputation.d.ts.map +1 -0
  46. package/dist/core/jacobianComputation.js +38 -0
  47. package/dist/core/jacobianComputation.js.map +1 -0
  48. package/dist/core/levenbergMarquardt.d.ts +36 -0
  49. package/dist/core/levenbergMarquardt.d.ts.map +1 -0
  50. package/dist/core/levenbergMarquardt.js +286 -0
  51. package/dist/core/levenbergMarquardt.js.map +1 -0
  52. package/dist/core/lineSearch.d.ts +42 -0
  53. package/dist/core/lineSearch.d.ts.map +1 -0
  54. package/dist/core/lineSearch.js +106 -0
  55. package/dist/core/lineSearch.js.map +1 -0
  56. package/dist/core/logger.d.ts +77 -0
  57. package/dist/core/logger.d.ts.map +1 -0
  58. package/dist/core/logger.js +162 -0
  59. package/dist/core/logger.js.map +1 -0
  60. package/dist/core/types.d.ts +427 -0
  61. package/dist/core/types.d.ts.map +1 -0
  62. package/dist/core/types.js +15 -0
  63. package/dist/core/types.js.map +1 -0
  64. package/dist/index.d.ts +26 -0
  65. package/dist/index.d.ts.map +1 -0
  66. package/dist/index.js +29 -0
  67. package/dist/index.js.map +1 -0
  68. package/dist/utils/formatting.d.ts +27 -0
  69. package/dist/utils/formatting.d.ts.map +1 -0
  70. package/dist/utils/formatting.js +54 -0
  71. package/dist/utils/formatting.js.map +1 -0
  72. package/dist/utils/matrix.d.ts +63 -0
  73. package/dist/utils/matrix.d.ts.map +1 -0
  74. package/dist/utils/matrix.js +129 -0
  75. package/dist/utils/matrix.js.map +1 -0
  76. package/dist/utils/resultFormatter.d.ts +122 -0
  77. package/dist/utils/resultFormatter.d.ts.map +1 -0
  78. package/dist/utils/resultFormatter.js +342 -0
  79. package/dist/utils/resultFormatter.js.map +1 -0
  80. 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"}