numra-autodiff
Automatic differentiation for the Numra workspace — forward-mode dual numbers and reverse-mode tape, with a bridge module that plugs AD-derived gradients and Jacobians into numra-optim and numra-fit.
Forward-mode uses Dual<S> numbers and costs O(n) passes for n inputs (best when outputs ≫ inputs — Jacobians of small systems, ODE sensitivity). Reverse-mode uses a tape and costs O(m) passes for m outputs (best when inputs ≫ outputs — gradients of scalar objectives, the standard optimization case).
Example
use ;
// f(x, y) = x² + y², gradient at (3, 4) should be (6, 8)
let grad = gradient;
assert!;
assert!;
For reverse-mode:
use grad;
let g = grad;
assert!;
assert!;
What's in this crate
Dual<S>— forward-mode dual numbersgradient,jacobian— forward-mode gradient and Jacobian of closuresreverse::Var,reverse::grad— reverse-mode tape-based variables and gradienttape— low-level tape for custom reverse-mode pipelinesbridge::gradient_closure,bridge::model_jacobian_closure— adapters that expose AD-derived gradients / Jacobians in the calling-convention used bynumra-optim'sOptimProblem::gradientandnumra-fit'scurve_fit_with_jacobian
Composes with
numra-optim— supplies gradients for BFGS, L-BFGS, Levenberg-Marquardt, SQP viabridge::gradient_closurenumra-fit— analytical Jacobians for nonlinear least-squares residuals viabridge::model_jacobian_closurenumra-ocp— gradients for parameter-estimation and optimal-control objectives
See interop workflows for the verified autodiff → optimization → curve-fitting workflow.
Install
[]
= "0.1"
Or via the umbrella crate:
[]
= "0.1"
Documentation
- API: https://docs.rs/numra-autodiff
- Book: Automatic differentiation
- Source: https://github.com/moussaoutlook/numra-rs/tree/main/numra-autodiff
License
Numra Academic & Research License (Non-Commercial). Academic and research use is free; commercial use requires a separate license — contact contact@spectralautomata.com. See LICENSE.