### Install LeastSquaresOptim.jl Package Source: https://github.com/matthieugomez/leastsquaresoptim.jl/blob/main/README.md Use this command to add the LeastSquaresOptim package to your Julia environment. Ensure you are in the Pkg REPL mode by pressing ']' in the Julia REPL. ```julia using Pkg Pkg.add("LeastSquaresOptim") ``` -------------------------------- ### `optimize` — Simple (Optim-style) interface Source: https://context7.com/matthieugomez/leastsquaresoptim.jl/llms.txt Minimizes `sum(f(x).^2)` starting from `x` using a copying, non-mutating call. The function `f` maps a parameter vector to a residual vector. The optimizer is specified as the third argument. ```APIDOC ## `optimize` — Simple (Optim-style) interface Minimizes `sum(f(x).^2)` starting from `x` using a copying, non-mutating call. The function `f` maps a parameter vector to a residual vector. The optimizer is specified as the third argument. ### Method Signature ```julia optimize(f, x0, optimizer) optimize(f, x0, optimizer; autodiff = :central) ``` ### Parameters - **f** - The objective function mapping a parameter vector to a residual vector. - **x0** - The initial guess for the parameters. - **optimizer** - The optimization algorithm to use (e.g., `Dogleg()`, `LevenbergMarquardt()`). - **autodiff** - (Optional) Method for automatic differentiation. Defaults to `:central`. Can be `:forward`. ### Request Example ```julia using LeastSquaresOptim function rosenbrock(x) [1 - x[1], 100 * (x[2] - x[1]^2)] end x0 = zeros(2) r1 = optimize(rosenbrock, x0, Dogleg()) println(r1) r2 = optimize(rosenbrock, x0, LevenbergMarquardt(); autodiff = :forward) println(r2.converged) println(r2.minimizer) println(r2.ssr) ``` ### Response Returns a `LeastSquaresResult` object containing the optimization results. ``` -------------------------------- ### LeastSquaresProblem Definition Source: https://context7.com/matthieugomez/leastsquaresoptim.jl/llms.txt Define a non-linear least squares problem using `LeastSquaresProblem`. This constructor is flexible, allowing for minimal setup with only `x`, `f!`, and `output_length`, or more advanced configurations including pre-allocated sparse Jacobians and custom Jacobian functions `g!`. Automatic differentiation can be specified. ```julia using LeastSquaresOptim # Minimal construction: only x, f!, and output_length required nls_auto = LeastSquaresProblem( x = [500.0, 0.0001], f! = (out, x) -> begin data_y = [10.07, 14.73, 17.94, 23.93] data_t = [77.6, 114.9, 141.1, 190.8] for i in eachindex(data_y) out[i] = data_y[i] - x[1] * (1 - exp(-x[2] * data_t[i])) end end, output_length = 4, autodiff = :central # default; use :forward for ForwardDiff ) r = optimize!(nls_auto, Dogleg()) println(r.minimizer) # ≈ [238.94, 0.000550] # Construction with a pre-allocated sparse Jacobian using SparseArrays J_sparse = sparse(zeros(9, 6)) # pre-build sparsity structure nls_sparse = LeastSquaresProblem( x = ones(6), y = ones(9), f! = (fvec, x) -> begin fvec[1] = 3.0 - x[1]*x[4]; fvec[2] = 2.0 - x[1]*x[5]; fvec[3] = 5.0 - x[1]*x[6] fvec[4] = 4.5 - x[2]*x[4]; fvec[5] = 3.2 - x[2]*x[5]; fvec[6] = 2.0 - x[2]*x[6] fvec[7] = 5.0 - x[3]*x[4]; fvec[8] = 1.3 - x[3]*x[5]; fvec[9] = 1.5 - x[3]*x[6] end, J = J_sparse, g! = (J, x) -> begin # fill J in-place (sparse or dense) fill!(nonzeros(J), 0.0) # ... (fill entries) end ) r = optimize!(nls_sparse, LevenbergMarquardt(LeastSquaresOptim.LSMR())) println(r.converged) # true ``` -------------------------------- ### Dogleg Optimizer with Default QR Solver Source: https://context7.com/matthieugomez/leastsquaresoptim.jl/llms.txt Demonstrates the default behavior of the Dogleg optimizer using the QR solver for dense Jacobians. Shows how to configure custom convergence tolerances and enable trace storage. ```julia using LeastSquaresOptim function rosenbrock(x) [1 - x[1], 100 * (x[2] - x[1]^2)] end # Default solver (QR) chosen automatically for dense Jacobian r = optimize(rosenbrock, zeros(2), Dogleg()) println(r.optimizer) # "Dogleg" println(r.converged) # true # Explicitly specify Cholesky solver r_chol = optimize(rosenbrock, zeros(2), Dogleg(LeastSquaresOptim.Cholesky())) println(r_chol.converged) # true # Explicitly specify iterative LSMR solver r_lsmr = optimize(rosenbrock, zeros(2), Dogleg(LeastSquaresOptim.LSMR())) println(r_lsmr.converged) # true # Custom convergence tolerances and trace r_trace = optimize(rosenbrock, zeros(2), Dogleg(); x_tol = 1e-12, f_tol = 1e-12, g_tol = 1e-12, iterations = 500, store_trace = true, show_trace = false ) println(r_trace.tr[1]) # OptimizationState at iteration 0 ``` -------------------------------- ### In-place Optimization with Objective and Jacobian Functions Source: https://github.com/matthieugomez/leastsquaresoptim.jl/blob/main/README.md This in-place syntax is useful when you can provide both the objective function (`f!`) and its Jacobian (`g!`). This can lead to significant performance improvements by avoiding automatic differentiation. ```julia function rosenbrock_g!(J, x) J[1, 1] = -1 J[1, 2] = 0 J[2, 1] = -200 * x[1] J[2, 2] = 100 end optimize!(LeastSquaresProblem(x = zeros(2), f! = rosenbrock_f!, g! = rosenbrock_g!, output_length = 2), Dogleg()) ``` -------------------------------- ### QR Solver for Dense Jacobians Source: https://context7.com/matthieugomez/leastsquaresoptim.jl/llms.txt Demonstrates using the QR decomposition solver with both Dogleg and LevenbergMarquardt optimizers. This solver is suitable for dense Jacobians and requires strided matrix types. ```julia using LeastSquaresOptim function rosenbrock(x) [1 - x[1], 100 * (x[2] - x[1]^2)] end # Dogleg + QR (default for dense problems) r = optimize(rosenbrock, zeros(2), Dogleg(LeastSquaresOptim.QR())) println(r.converged) # true # LevenbergMarquardt + QR r2 = optimize(rosenbrock, zeros(2), LevenbergMarquardt(LeastSquaresOptim.QR())) println(r2.converged) # true ``` -------------------------------- ### LevenbergMarquardt Optimizer for Dense and Sparse Problems Source: https://context7.com/matthieugomez/leastsquaresoptim.jl/llms.txt Illustrates the LevenbergMarquardt optimizer for both dense and sparse Jacobian scenarios. For dense problems, QR is shown, while for sparse problems, the default LSMR solver is used. ```julia using LeastSquaresOptim, SparseArrays # Dense use case — explicit QR solver function rosenbrock(x) [1 - x[1], 100 * (x[2] - x[1]^2)] end r = optimize(rosenbrock, zeros(2), LevenbergMarquardt(LeastSquaresOptim.QR())) println(r.converged) # true println(r.minimizer) # [1.0, 1.0] # Sparse use case — LSMR solver (default for sparse J) function f_sparse!(fvec, x) fvec[1] = 3.0 - x[1]*x[4]; fvec[2] = 2.0 - x[1]*x[5]; fvec[3] = 5.0 - x[1]*x[6] fvec[4] = 4.5 - x[2]*x[4]; fvec[5] = 3.2 - x[2]*x[5]; fvec[6] = 2.0 - x[2]*x[6] fvec[7] = 5.0 - x[3]*x[4]; fvec[8] = 1.3 - x[3]*x[5]; fvec[9] = 1.5 - x[3]*x[6] end J = sparse(ones(9, 6)) nls = LeastSquaresProblem(x = ones(6), y = ones(9), f! = f_sparse!, J = J, g! = (J, x) -> nothing) # provide real g! in practice r = optimize!(nls, LevenbergMarquardt(LeastSquaresOptim.LSMR())) println(r.optimizer) # "LevenbergMarquardt" ``` -------------------------------- ### Box Constraints with Dogleg and Levenberg-Marquardt Source: https://context7.com/matthieugomez/leastsquaresoptim.jl/llms.txt Applies box constraints (lower and upper bounds) to optimization parameters using `lower` and `upper` keyword arguments. Demonstrates constraining to non-negative values and to a box excluding the global minimum. ```julia using LeastSquaresOptim function rosenbrock(x) [1 - x[1], 100 * (x[2] - x[1]^2)] end x0 = zeros(2) # Constrain all parameters to be non-negative r = optimize(rosenbrock, x0, Dogleg(); lower = fill(0.0, 2), upper = fill(Inf, 2) ) println(r.converged) # true println(r.minimizer) # [1.0, 1.0] (unconstrained optimum is within bounds) # Constrain to a box that excludes the global minimum r2 = optimize(rosenbrock, x0, LevenbergMarquardt(); lower = fill(-2.0, 2), upper = fill(0.5, 2) # x[1] ≤ 0.5, so [1,1] is infeasible ) println(r2.minimizer) # solution projected to boundary ``` -------------------------------- ### In-place optimize! Interface with LeastSquaresProblem Source: https://context7.com/matthieugomez/leastsquaresoptim.jl/llms.txt Use the `optimize!` function for in-place optimization, mutating the `x` field of a `LeastSquaresProblem`. This is suitable for performance-critical applications and allows pre-allocation of residual and Jacobian arrays, as well as providing an analytic Jacobian function `g!`. ```julia using LeastSquaresOptim function rosenbrock_f!(out, x) out[1] = 1 - x[1] out[2] = 100 * (x[2] - x[1]^2) end function rosenbrock_g!(J, x) J[1, 1] = -1 J[1, 2] = 0 J[2, 1] = -200 * x[1] J[2, 2] = 100 end # Build problem with analytic Jacobian nls = LeastSquaresProblem( x = zeros(2), f! = rosenbrock_f!, g! = rosenbrock_g!, output_length = 2 ) r = optimize!(nls, Dogleg()) println(r.converged) # true println(r.minimizer) # [1.0, 1.0] println(r.ssr) # ≈ 0.0 println(r.iterations) # small number, e.g. 2 # Reuse the same nls object (x is already at the solution; reset x first for a new run) nls.x .= zeros(2) r2 = optimize!(nls, LevenbergMarquardt()) println(r2.converged) # true ``` -------------------------------- ### Cholesky Solver for Dense Jacobians Source: https://context7.com/matthieugomez/leastsquaresoptim.jl/llms.txt Shows the Cholesky factorization solver for dense Jacobians, applicable to both Dogleg and LevenbergMarquardt optimizers. It's generally faster than QR for well-conditioned problems but less robust. ```julia using LeastSquaresOptim function rosenbrock(x) [1 - x[1], 100 * (x[2] - x[1]^2)] end r = optimize(rosenbrock, zeros(2), Dogleg(LeastSquaresOptim.Cholesky())) println(r.converged) # true println(r.minimizer) # [1.0, 1.0] r2 = optimize(rosenbrock, zeros(2), LevenbergMarquardt(LeastSquaresOptim.Cholesky())) println(r2.converged) # true ``` -------------------------------- ### Specify Least Squares Solvers for Optimizers Source: https://github.com/matthieugomez/leastsquaresoptim.jl/blob/main/README.md Customize the underlying solver used by the optimizers for dense or sparse Jacobians. QR() or Cholesky() are for dense Jacobians, while LSMR() is for sparse Jacobians. Defaults are Dogleg(QR()) for dense and LevenbergMarquardt(LSMR()) for sparse. ```julia optimize(rosenbrock, x0, Dogleg(LeastSquaresOptim.QR())) optimize(rosenbrock, x0, LevenbergMarquardt(LeastSquaresOptim.LSMR())) ``` -------------------------------- ### `optimize!` — In-place interface with `LeastSquaresProblem` Source: https://context7.com/matthieugomez/leastsquaresoptim.jl/llms.txt Solves the problem in-place, mutating `nls.x` to the solution. Accepts pre-allocated residual `y` and Jacobian `J` arrays, and an optional analytic Jacobian function `g!`. Returns a `LeastSquaresResult`. ```APIDOC ## `optimize!` — In-place interface with `LeastSquaresProblem` Solves the problem in-place, mutating `nls.x` to the solution. Accepts pre-allocated residual `y` and Jacobian `J` arrays, and an optional analytic Jacobian function `g!`. Returns a `LeastSquaresResult`. ### Method Signature ```julia optimize!(nls_problem, optimizer) ``` ### Parameters - **nls_problem** - A `LeastSquaresProblem` object defining the optimization problem. - **optimizer** - The optimization algorithm to use (e.g., `Dogleg()`, `LevenbergMarquardt()`). Can also specify a linear algebra solver, e.g., `LevenbergMarquardt(LeastSquaresOptim.LSMR())`. ### Request Example ```julia using LeastSquaresOptim function rosenbrock_f!(out, x) out[1] = 1 - x[1] out[2] = 100 * (x[2] - x[1]^2) end function rosenbrock_g!(J, x) J[1, 1] = -1 J[1, 2] = 0 J[2, 1] = -200 * x[1] J[2, 2] = 100 end nls = LeastSquaresProblem( x = zeros(2), f! = rosenbrock_f!, g! = rosenbrock_g!, output_length = 2 ) r = optimize!(nls, Dogleg()) println(r.converged) println(r.minimizer) println(r.ssr) println(r.iterations) nls.x .= zeros(2) r2 = optimize!(nls, LevenbergMarquardt()) println(r2.converged) ``` ### Response Returns a `LeastSquaresResult` object containing the optimization results. ``` -------------------------------- ### Simple optimize Interface Source: https://context7.com/matthieugomez/leastsquaresoptim.jl/llms.txt Use the `optimize` function for a straightforward, non-mutating approach to minimize `sum(f(x).^2)`. It accepts a function `f` mapping parameters to residuals, an initial guess `x0`, and an optimizer. Supports various optimizers and automatic differentiation. ```julia using LeastSquaresOptim # Rosenbrock as a least-squares problem: f(x) = [1 - x[1], 100*(x[2] - x[1]^2)] function rosenbrock(x) [1 - x[1], 100 * (x[2] - x[1]^2)] end x0 = zeros(2) # Dogleg optimizer with default QR solver and central finite differences r1 = optimize(rosenbrock, x0, Dogleg()) println(r1) # Results of Optimization Algorithm # * Status: success # * Candidate solution # Final objective value: 0.000000e+00 # * Found with # Algorithm: Dogleg # * Convergence measures # |x - x'| ≤ 1.0e-08 # * Work counters # Iterations: 16 # f(x) calls: 17 # J(x) calls: 16 # mul! calls: 16 # Levenberg-Marquardt optimizer with ForwardDiff automatic differentiation r2 = optimize(rosenbrock, x0, LevenbergMarquardt(); autodiff = :forward) println(r2.converged) # true println(r2.minimizer) # [1.0, 1.0] println(r2.ssr) # ≈ 0.0 ``` -------------------------------- ### Inspecting LeastSquaresResult Source: https://context7.com/matthieugomez/leastsquaresoptim.jl/llms.txt Demonstrates how to access and interpret the fields of a `LeastSquaresResult` object, including convergence status, minimizer, sum of squared residuals, iteration counts, and per-iteration trace. ```julia using LeastSquaresOptim function rosenbrock(x) [1 - x[1], 100 * (x[2] - x[1]^2)] end r = optimize(rosenbrock, zeros(2), Dogleg(); store_trace = true) # Core result fields println(r.converged) # true (any of x/f/g convergence) println(r.x_converged) # parameter change convergence println(r.f_converged) # objective change convergence println(r.g_converged) # gradient norm convergence println(r.minimizer) # [1.0, 1.0] println(r.ssr) # ≈ 0.0 (sum of squared residuals) println(r.iterations) # e.g. 16 println(r.f_calls) # number of f evaluations println(r.g_calls) # number of Jacobian evaluations println(r.mul_calls) # number of matrix-vector products (relevant for LSMR) println(r.optimizer) # "Dogleg" # Access per-iteration trace for state in r.tr.states println("iter=$(state.iteration) ssr=$(state.value) |g|=$(state.g_norm)") end # Pretty-print full summary show(r) ``` -------------------------------- ### Optimize Non-linear Least Squares with Dogleg or Levenberg-Marquardt Source: https://github.com/matthieugomez/leastsquaresoptim.jl/blob/main/README.md Use this for a straightforward approach to solving non-linear least squares problems. It requires defining the objective function and an initial guess. Supports different optimization algorithms like Dogleg and Levenberg-Marquardt. ```julia using LeastSquaresOptim function rosenbrock(x) [1 - x[1], 100 * (x[2]-x[1]^2)] end x0 = zeros(2) optimize(rosenbrock, x0, Dogleg()) optimize(rosenbrock, x0, LevenbergMarquardt()) ``` -------------------------------- ### In-place Optimization with Objective Function Source: https://github.com/matthieugomez/leastsquaresoptim.jl/blob/main/README.md Utilize this in-place syntax for performance when defining objective functions. The `f!` function modifies the output vector directly. Ensure `output_length` is correctly specified. ```julia using LeastSquaresOptim function rosenbrock_f!(out, x) out[1] = 1 - x[1] out[2] = 100 * (x[2]-x[1]^2) end optimize!(LeastSquaresProblem(x = zeros(2), f! = rosenbrock_f!, output_length = 2, autodiff = :central), Dogleg()) ``` -------------------------------- ### LSMR Solver for Iterative Subproblem Solving Source: https://context7.com/matthieugomez/leastsquaresoptim.jl/llms.txt Illustrates the LSMR iterative solver, which works with various matrix types including sparse matrices and custom operators. It uses a diagonal preconditioner and can accept a custom one. ```julia using LeastSquaresOptim, SparseArrays # ---- Dense use ---- function rosenbrock(x) [1 - x[1], 100 * (x[2] - x[1]^2)] end r = optimize(rosenbrock, zeros(2), LevenbergMarquardt(LeastSquaresOptim.LSMR())) println(r.converged) # true ``` -------------------------------- ### Custom Preconditioner for LSMR Source: https://context7.com/matthieugomez/leastsquaresoptim.jl/llms.txt Implements a custom preconditioner for the LSMR solver. The preconditioner is updated in each iteration based on the Jacobian and regularization parameter. ```julia struct MyPreconditioner diag::Vector{Float64} end function LinearAlgebra.ldiv!(y, P::MyPreconditioner, x) y .= x ./ P.diag end P = MyPreconditioner(ones(2)) preconditioner! = (P, x, J, λ) -> (P.diag .= sum(abs2, J, dims=1)[:] .+ λ; P) r_custom = optimize(rosenbrock, zeros(2), LevenbergMarquardt(LeastSquaresOptim.LSMR(preconditioner!, P))) println(r_custom.converged) # true ``` -------------------------------- ### Curve Fitting with LeastSquaresProblem Source: https://context7.com/matthieugomez/leastsquaresoptim.jl/llms.txt Fits a parametric model (Misra1a) to data by defining residuals as `observed - predicted`. Uses `LeastSquaresProblem` with automatic differentiation for optimization. ```julia using LeastSquaresOptim, Statistics, Test # Misra1a model: y = β₁(1 - exp(-β₂·t)) data_t = [77.6, 114.9, 141.1, 190.8, 239.9, 289.0, 332.8, 378.4, 434.8, 477.3, 536.8, 593.1, 689.1, 760.0] data_y = [10.07, 14.73, 17.94, 23.93, 29.61, 35.18, 40.02, 44.82, 50.76, 55.05, 61.01, 66.40, 75.47, 81.78] function misra_f!(out, beta) for i in eachindex(data_y) out[i] = data_y[i] - beta[1] * (1 - exp(-beta[2] * data_t[i])) end end nls = LeastSquaresProblem( x = [500.0, 0.0001], f! = misra_f!, output_length = length(data_y), autodiff = :central ) r = optimize!(nls, Dogleg(LeastSquaresOptim.QR()); x_tol = 1e-12, f_tol = 1e-12) println(r.converged) # true println(r.minimizer) # ≈ [238.94, 0.000550] (NIST certified values) solution = [2.3894212918E+02, 5.5015643181E-04] @test norm(r.minimizer - solution) < 1e-3 ``` -------------------------------- ### Sparse Jacobian with LSMR Source: https://context7.com/matthieugomez/leastsquaresoptim.jl/llms.txt Defines a sparse Jacobian and uses it with the LSMR solver for optimization. This is efficient for large, sparse problems. ```julia function f!(fvec, x) fvec[1] = 3.0 - x[1]*x[4]; fvec[2] = 2.0 - x[1]*x[5]; fvec[3] = 5.0 - x[1]*x[6] fvec[4] = 4.5 - x[2]*x[4]; fvec[5] = 3.2 - x[2]*x[5]; fvec[6] = 2.0 - x[2]*x[6] fvec[7] = 5.0 - x[3]*x[4]; fvec[8] = 1.3 - x[3]*x[5]; fvec[9] = 1.5 - x[3]*x[6] end function g!(J::SparseMatrixCSC, x) vals = nonzeros(J) vals[1]=-x[4]; vals[2]=-x[1]; vals[3]=-x[5]; vals[4]=-x[1] vals[5]=-x[6]; vals[6]=-x[1]; vals[7]=-x[4]; vals[8]=-x[2] vals[9]=-x[5]; vals[10]=-x[2]; vals[11]=-x[6]; vals[12]=-x[2] vals[13]=-x[4]; vals[14]=-x[3]; vals[15]=-x[5]; vals[16]=-x[3] vals[17]=-x[6]; vals[18]=-x[3] end J_sp = sparse(ones(9, 6)) nls = LeastSquaresProblem(x = ones(6), y = ones(9), f! = f!, J = J_sp, g! = g!) r = optimize!(nls, LevenbergMarquardt(LeastSquaresOptim.LSMR())) println(r.converged) # true println(r.mul_calls) # number of matrix-vector products used ``` -------------------------------- ### `LeastSquaresProblem` — Problem definition Source: https://context7.com/matthieugomez/leastsquaresoptim.jl/llms.txt Constructs a non-linear least squares problem. Can be used with or without a pre-allocated Jacobian; when neither `g!` nor a custom `J` is provided, the Jacobian is computed via automatic differentiation. ```APIDOC ## `LeastSquaresProblem` — Problem definition Constructs a non-linear least squares problem. Can be used with or without a pre-allocated Jacobian; when neither `g!` nor a custom `J` is provided, the Jacobian is computed via automatic differentiation. ### Constructor Signature ```julia LeastSquaresProblem(; x, f!, output_length, autodiff = :central, y = nothing, J = nothing, g! = nothing) ``` ### Parameters - **x** - Initial parameter vector. - **f!** - Function that computes the residual vector `out` given the parameter vector `x`. - **output_length** - The length of the residual vector (number of equations). - **autodiff** - (Optional) Method for automatic differentiation. Defaults to `:central`. Can be `:forward`. - **y** - (Optional) Pre-allocated vector for residuals. If not provided, it will be allocated internally. - **J** - (Optional) Pre-allocated matrix for the Jacobian. If not provided, the Jacobian will be computed via `g!` or automatic differentiation. - **g!** - (Optional) Function that computes the Jacobian matrix `J` given the parameter vector `x`. ### Request Example ```julia using LeastSquaresOptim # Minimal construction with automatic differentiation nls_auto = LeastSquaresProblem( x = [500.0, 0.0001], f! = (out, x) -> begin data_y = [10.07, 14.73, 17.94, 23.93] data_t = [77.6, 114.9, 141.1, 190.8] for i in eachindex(data_y) out[i] = data_y[i] - x[1] * (1 - exp(-x[2] * data_t[i])) end end, output_length = 4, autodiff = :central ) r = optimize!(nls_auto, Dogleg()) println(r.minimizer) # Construction with a pre-allocated sparse Jacobian using SparseArrays J_sparse = sparse(zeros(9, 6)) nls_sparse = LeastSquaresProblem( x = ones(6), y = ones(9), f! = (fvec, x) -> begin fvec[1] = 3.0 - x[1]*x[4]; fvec[2] = 2.0 - x[1]*x[5]; fvec[3] = 5.0 - x[1]*x[6] fvec[4] = 4.5 - x[2]*x[4]; fvec[5] = 3.2 - x[2]*x[5]; fvec[6] = 2.0 - x[2]*x[6] fvec[7] = 5.0 - x[3]*x[4]; fvec[8] = 1.3 - x[3]*x[5]; fvec[9] = 1.5 - x[3]*x[6] end, J = J_sparse, g! = (J, x) -> begin # fill J in-place (sparse or dense) fill!(nonzeros(J), 0.0) # ... (fill entries) end ) r = optimize!(nls_sparse, LevenbergMarquardt(LeastSquaresOptim.LSMR())) println(r.converged) ``` ### Response Returns a `LeastSquaresProblem` object that can be used with the `optimize!` function. ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.