askill
optimization

optimizationSafety 90Repository

Generate a native numerical optimization library — Nelder-Mead, BFGS, L-BFGS, CG, Newton, Newton Trust Region, More-Thuente, Fminbox, Simulated Annealing, Krylov Trust Region, IPNewton — from a verified TypeScript reference

1 stars
1.2k downloads
Updated 2/5/2026

Package Files

Loading files...
SKILL.md

Optimization Skill

A modular numerical optimization library. Minimizes scalar functions of one or more variables using derivative-free (Nelder-Mead, Brent 1D, Simulated Annealing), first-order (gradient descent, BFGS, L-BFGS, conjugate gradient), second-order (Newton, Newton Trust Region, Krylov Trust Region), and constrained (Fminbox, IPNewton) methods.

When to use this skill

When you need to minimize a function without adding an optimization library dependency. Covers the core algorithms that scipy.optimize.minimize and Optim.jl provide, implemented from scratch with clear provenance.

Arguments

$ARGUMENTS has the format: <nodes> [--lang <language>]

  • nodes: Space-separated list of node names to translate, or all for every node. Nodes must be provided in dependency order (see the node graph below).
  • --lang: Target language (e.g. python, rust, go, typescript). Defaults to typescript if omitted.

Examples:

  • nelder-mead --lang python — translate just the Nelder-Mead subset to Python
  • all --lang rust — translate the full library to Rust
  • bfgs l-bfgs minimize --lang go — translate selected nodes to Go

Node Graph

vec-ops ─────────────────────────┬──→ line-search ──────┬──→ hager-zhang ──────┐
                                 │                      │                      │
                                 ├──→ more-thuente      │                      │
                                 │                      │                      │
result-types ──────┬─────────────┤                      │                      │
                   │             │                      │                      │
test-functions     │   finite-diff ─────────────────────┤                      │
                   │             │                      │                      │
                   │     finite-hessian ←───────────────┤                      │
                   │             │                      │                      │
                   ├──→ nelder-mead                     │                      │
                   │                                    │                      │
                   ├──→ brent-1d (standalone)            │                      │
                   │                                    │                      │
                   ├──→ gradient-descent ←──────────────┤                      │
                   │                                    │                      │
                   ├──→ bfgs ←─────────────────────────┤                      │
                   │                                    │                      │
                   ├──→ l-bfgs ←───────────────────────┤                      │
                   │                                    │                      │
                   ├──→ conjugate-gradient ←────────────┴──────────────────────┘
                   │                                    │
                   ├──→ newton ←───────────────────────┤←── finite-hessian
                   │                                    │
                   ├──→ newton-trust-region ←───────────┤←── finite-hessian
                   │                                    │
                   ├──→ fminbox ←──────────────────────┤
                   │                                    │
                   ├──→ simulated-annealing               │
                   │                                    │
                   ├──→ krylov-trust-region ←──────────┤←── finite-hessian
                   │                                    │
                   ├──→ ip-newton ←───────────────────┤←── finite-hessian
                   │                                    │
                   └──→ minimize (root: public API) ←──┘

Nodes

NodeTypeDepends OnDescription
vec-opsleafPure vector arithmetic: dot, norm, add, sub, scale, etc.
result-typesleafOptimizeResult, OptimizeOptions, convergence checking
test-functionsleafStandard test functions (Sphere, Rosenbrock, etc.) with analytic gradients
finite-diffinternalvec-opsNumerical gradient via forward/central differences
finite-hessianinternalFull Hessian via central differences + Hessian-vector product
line-searchinternalvec-opsBacktracking (Armijo) and Strong Wolfe line search
hager-zhanginternalvec-ops, line-searchHager-Zhang line search with approximate Wolfe conditions
more-thuenteinternalvec-ops, line-searchMore-Thuente line search with cubic interpolation and strong Wolfe conditions
brent-1dleafBrent's method for 1D minimization on a bounded interval
nelder-meadinternalvec-ops, result-typesDerivative-free simplex optimizer
gradient-descentinternalvec-ops, result-types, line-search, finite-diffSteepest descent with backtracking
bfgsinternalvec-ops, result-types, line-search, finite-diffFull-memory quasi-Newton with Wolfe line search
l-bfgsinternalvec-ops, result-types, line-search, finite-diffLimited-memory BFGS with two-loop recursion
conjugate-gradientinternalvec-ops, result-types, hager-zhang, finite-diffNonlinear CG with Hager-Zhang beta and line search
newtoninternalvec-ops, result-types, line-search, finite-diff, finite-hessianNewton's method with Cholesky solve and modified Newton regularization
newton-trust-regioninternalvec-ops, result-types, finite-diff, finite-hessianNewton with dogleg trust region subproblem
fminboxinternalvec-ops, result-types, any-of(bfgs, l-bfgs, conjugate-gradient, gradient-descent)Box-constrained optimization via log-barrier method
simulated-annealinginternalresult-typesDerivative-free stochastic global optimizer with Metropolis criterion
krylov-trust-regioninternalvec-ops, result-types, finite-diff, finite-hessianNewton-type optimizer using Steihaug-Toint truncated CG (Hessian-vector products only)
ip-newtoninternalvec-ops, result-types, finite-diff, finite-hessianPrimal-dual interior-point Newton for general nonlinear constraints
minimizerootresult-types, any-of(nelder-mead, gradient-descent, bfgs, l-bfgs, conjugate-gradient, newton, newton-trust-region)Dispatcher: selects algorithm from method + gradient availability

Subset Extraction

  • Just Nelder-Mead (derivative-free): vec-ops + result-types + nelder-mead
  • Just BFGS: vec-ops + result-types + line-search + finite-diff + bfgs
  • Just CG: vec-ops + result-types + line-search + hager-zhang + finite-diff + conjugate-gradient
  • Just Newton: vec-ops + result-types + line-search + finite-diff + finite-hessian + newton
  • Just Newton TR: vec-ops + result-types + finite-diff + finite-hessian + newton-trust-region
  • Just Brent 1D: brent-1d (standalone, no dependencies)
  • Just Fminbox (BFGS): vec-ops + result-types + line-search + finite-diff + bfgs + fminbox
  • Just Simulated Annealing: result-types + simulated-annealing
  • Just Krylov TR: vec-ops + result-types + finite-diff + finite-hessian + krylov-trust-region
  • Just IPNewton: vec-ops + result-types + finite-diff + finite-hessian + ip-newton
  • Full library: all 21 nodes
  • Test functions are optional — only needed for validation

Handling help

When $ARGUMENTS is help, read HELP.md and use it to guide the user through node and language selection. The help guide contains a decision tree covering derivative availability, constraint types, problem scale, and language idioms. Walk through it interactively, asking the user about their requirements, then recommend specific nodes and a target language.

Translation Workflow

For each node in dependency order:

  1. If $ARGUMENTS is help, read HELP.md and guide the user interactively
  2. Read the node spec at nodes/<name>/spec.md for behavior, API, and test vectors
  3. Read language-specific hints at nodes/<name>/to-<lang>.md if available
  4. Generate the implementation and tests in the target language
  5. If the spec is ambiguous, consult the TypeScript reference at reference/src/<name>.ts

Generated Code Documentation

Every public function, class, type, and interface in generated code must have idiomatic doc comments in the target language's standard format:

LanguageFormat
TypeScriptJSDoc (/** */) with @param, @returns
PythonGoogle-style docstrings with Args, Returns, Raises
Kotlin/JavaKDoc/JavaDoc (/** */) with @param, @return, @throws
C#XML doc comments (///) with <summary>, <param>, <returns>
GoGoDoc comments (starting with the function/type name)
Rust/// doc comments with # Arguments, # Returns, # Errors
C++Doxygen (/** or ///) with @brief, @param, @return
SwiftDocC (///) with - Parameters:, - Returns:, - Throws:

Doc comments should describe what the function does, its parameters, return value, and error conditions. Derive content from the node spec — do not invent behavior not in the spec.

Each generated file must include a provenance header as the first comment, in the file's idiomatic comment style:

Generated by {agent} using {model}
From special:optimization (https://github.com/caryden/special)
Node: {node-name}

Replace {agent}, {model}, and {node-name} with actual values. The provenance trace makes generated code traceable back to the skill and model that produced it.

The reference code is TypeScript with 100% line and function coverage. Every node has a corresponding test file at reference/src/<name>.test.ts that serves as the behavioral contract. Cross-validation against scipy v1.17.0 and Optim.jl v2.0.0 is documented in reference/CROSS-VALIDATION.md.

Key Design Decisions (Off-Policy)

These defaults differ across libraries. Our choices are documented with provenance:

ParameterOur ValuescipyOptim.jlMATLAB
Gradient tolerance1e-81e-51e-81e-6
Step tolerance1e-8disabled1e-8
Function tolerance1e-121e-1201e-6
Max iterations1000varies1000400
Wolfe c11e-41e-41e-41e-4
Wolfe c20.90.90.90.9
Default method (no grad)nelder-meadBFGS+FDNelderMeadfminsearch
Default method (with grad)bfgsBFGSLBFGSfminunc

Error Handling

  • Line search failure: return result with converged=false and a descriptive message
  • Max iterations exceeded: return result with converged=false
  • Division by zero in finite differences: not guarded (caller's responsibility)
  • No exceptions thrown by optimizers — all results are returned via OptimizeResult
  • Invalid method name in minimize: throw an error before optimization begins
  • Empty or zero-length input vectors: behavior is undefined (caller must validate)

Install

Download ZIP
Requires askill CLI v1.0+

AI Quality Score

93/100Analyzed 2/18/2026

Highly comprehensive and well-structured skill for generating numerical optimization libraries. Excellent coverage with clear sections including when-to-use guidance, detailed node graph, translation workflow, documentation requirements, and design decisions. Actionable with step-by-step instructions and clear examples. Highly reusable due to multi-language support and modular node design. Well-organized with tables, diagrams, and clear formatting.

90
95
95
95
90

Metadata

Licenseunknown
Version-
Updated2/5/2026
Publishercaryden

Tags

apigithubgithub-actionstesting