JuliaNLSolvers/LsqFit.jl

Simple curve fitting in Julia

What it solves

LsqFit.jl solves the problem of fitting a mathematical model with unknown parameters to observed data, especially when the model is nonlinear in the parameters. It finds the parameter values that minimize the sum of squared differences between the model's predictions and the data.

How it works

You define a model function that takes independent variables and parameters, then pass it to curve_fit along with data and initial parameter guesses. The library iteratively adjusts the parameters using the Levenberg-Marquardt algorithm until the residuals are minimized. You can optionally supply a Jacobian function, use automatic differentiation, impose bounds on parameters, add weights to data points, or use in-place functions to speed up computation. After fitting, you can get standard errors, confidence intervals, and covariance matrices for the parameters.

Who it's for

This is for Julia users who need to fit nonlinear models to data. It's suitable for scientists, engineers, and data analysts who want a lightweight, flexible fitting tool without leaving the Julia ecosystem.

Highlights

  • Pure Julia implementation with an MIT license.
  • Uses the robust Levenberg-Marquardt algorithm.
  • Supports multivariate regression and multiple independent variables.
  • Allows parameter bounds and mixed bounded/unbounded variables.
  • Optional weights for data points (including precision weights, analytic weights, frequency weights).
  • Can accept analytical Jacobians or use finite differences or forward-mode automatic differentiation (ForwardDiff.jl).
  • Supports in-place model and Jacobian functions to reduce memory and time.
  • Includes geodesic acceleration to improve convergence.
  • Provides statistical outputs: standard errors, margin of error, confidence intervals, and covariance matrix.

Related

  • Project
  • Project
  • Project
  • Project