# \#optim

**URL:** https://discourse.julialang.org/tag/optim/112.md

[Latest](https://discourse.julialang.org/latest.md) · [Categories](https://discourse.julialang.org/categories.md) · [Tags](https://discourse.julialang.org/tags.md)

---

## [Optimization convergence requirements](https://discourse.julialang.org/t/optimization-convergence-requirements/139122)

<div class="topic-metadata">

**Author:** [@dgagnon](https://discourse.julialang.org/u/dgagnon)\
**Replies:** 5\
**Last updated:** [September 1, 2026, 10:23am UTC](https://discourse.julialang.org/t/optimization-convergence-requirements/139122 "2026-09-01T10:23:47Z")

</div>

Hello I have a function from \[0,1\] to \[0,1\], which I can shown to always have a unique maximum. I have been using Optim.jl with the default Brent’s method to compute it. I am a statistician, not a specialist on numeric…

---

## [Problem with Optim.optimize](https://discourse.julialang.org/t/problem-with-optim-optimize/135368)

<div class="topic-metadata">

**Author:** [@dnldlg](https://discourse.julialang.org/u/dnldlg)\
**Replies:** 2\
**Last updated:** [January 31, 2026, 1:45pm UTC](https://discourse.julialang.org/t/problem-with-optim-optimize/135368 "2026-01-31T13:45:23Z")

</div>

Consider the minimal example using Optim f(x) = (x\[1\]-2)^2 + (x\[2\]-3)^2 + sin(3\*x\[1\] + 1) + cos(5\*x\[2\]) optimize(f, \[1., 1.\], BFGS()) For reasons that I don’t comprehend, I get the following error: ERROR: BoundsErro…

---

## [Combining \`Optim\` and \`FieldVector\` from \`StaticArrays\`](https://discourse.julialang.org/t/combining-optim-and-fieldvector-from-staticarrays/131472)

<div class="topic-metadata">

**Author:** [@NoFishLikeIan](https://discourse.julialang.org/u/NoFishLikeIan)\
**Replies:** 3\
**Last updated:** [August 9, 2025, 10:15am UTC](https://discourse.julialang.org/t/combining-optim-and-fieldvector-from-staticarrays/131472 "2025-08-09T10:15:56Z")

</div>

I’m getting a MethodError in LBFGS when trying to use a custom mutable struct that inherits from FieldVector for an optimization problem. using StaticArrays using Optimization, OptimizationOptimJL mutable struct Point{…

---

## [Optimizing an objective function which contains auto-diifferentiation](https://discourse.julialang.org/t/optimizing-an-objective-function-which-contains-auto-diifferentiation/130395)

<div class="topic-metadata">

**Author:** [@sn248](https://discourse.julialang.org/u/sn248)\
**Replies:** 3\
**Last updated:** [July 2, 2025, 12:22pm UTC](https://discourse.julialang.org/t/optimizing-an-objective-function-which-contains-auto-diifferentiation/130395 "2025-07-02T12:22:33Z")

</div>

Hi I am trying to optimize an objective function which itself contains auto-differentiation, but the optimization fails, so I tried with a trivial example and it still fails. If anyone can suggest any approaches, that w…

---

## [Covariance Optimization for Joint estimation using UKF](https://discourse.julialang.org/t/covariance-optimization-for-joint-estimation-using-ukf/129677)

<div class="topic-metadata">

**Author:** [@vh94](https://discourse.julialang.org/u/vh94)\
**Replies:** 5\
**Last updated:** [June 16, 2025, 9:08am UTC](https://discourse.julialang.org/t/covariance-optimization-for-joint-estimation-using-ukf/129677 "2025-06-16T09:08:14Z")

</div>

Hello, I am using an Unscented Kalman Filter to perform a joint state and parameter estimation. I am trying to improve the accuracy of the parameters estimation foremost ( fit to the measured data is less important) . F…

---

## [Matrix inverse as objective](https://discourse.julialang.org/t/matrix-inverse-as-objective/129162)

<div class="topic-metadata">

**Author:** [@Rick](https://discourse.julialang.org/u/Rick)\
**Replies:** 2\
**Last updated:** [May 20, 2025, 5:51am UTC](https://discourse.julialang.org/t/matrix-inverse-as-objective/129162 "2025-05-20T05:51:58Z")

</div>

Hi everyone, I am trying to solve a semi-definite program with an objective that contains a matrix inverse. More precisely, let a \\geq 0, and A be a positive definite matrix of size d \\times d. \\mathbf{1} below is a ve…

---

## [Change loss function depending on the iteration count within Optim.jl](https://discourse.julialang.org/t/change-loss-function-depending-on-the-iteration-count-within-optim-jl/128362)

<div class="topic-metadata">

**Author:** [@roflmaostc](https://discourse.julialang.org/u/roflmaostc)\
**Replies:** 4\
**Last updated:** [April 25, 2025, 10:24pm UTC](https://discourse.julialang.org/t/change-loss-function-depending-on-the-iteration-count-within-optim-jl/128362 "2025-04-25T22:24:50Z")

</div>

Hi, let’s say I have a loss function which I want to change depending on the iteration count. For example: function l(x, target) target\_warp = f\_warp(target, iteration\_count) sum(abs2, x .- target\_warp) end I…

---

## [\`Optimization.LBFGS\` fails to converge while \`Optim.NelderMead()\` works](https://discourse.julialang.org/t/optimization-lbfgs-fails-to-converge-while-optim-neldermead-works/121016)

<div class="topic-metadata">

**Author:** [@jling](https://discourse.julialang.org/u/jling)\
**Replies:** 11\
**Last updated:** [March 29, 2025, 2:42am UTC](https://discourse.julialang.org/t/optimization-lbfgs-fails-to-converge-while-optim-neldermead-works/121016 "2025-03-29T02:42:36Z")

</div>

Reproducer: MWE.converge.jl · GitHub

---

## [Interior-Point Newton tries points outside of the constraint set](https://discourse.julialang.org/t/interior-point-newton-tries-points-outside-of-the-constraint-set/127215)

<div class="topic-metadata">

**Author:** [@JADekker](https://discourse.julialang.org/u/JADekker)\
**Replies:** 5\
**Last updated:** [March 21, 2025, 2:12pm UTC](https://discourse.julialang.org/t/interior-point-newton-tries-points-outside-of-the-constraint-set/127215 "2025-03-21T14:12:59Z")

</div>

Hi, I’m using Interior-Point Newton to solve a constrained optimization problem where my objective function is not (always) defined outside the constraint set. I found that Interior-Point Newton sometimes tries points ou…

---

## [Parameters Optimization with Optim](https://discourse.julialang.org/t/parameters-optimization-with-optim/125760)

<div class="topic-metadata">

**Author:** [@luke98](https://discourse.julialang.org/u/luke98)\
**Replies:** 4\
**Last updated:** [February 12, 2025, 6:57am UTC](https://discourse.julialang.org/t/parameters-optimization-with-optim/125760 "2025-02-12T06:57:45Z")

</div>

Hi Everyone, I have a model that is regulated by a set of parameters. I am trying to choose the parameters so that the model matches some moments that I get from the data. This is my code: lower\_bounds = \[0.0, 1e-2, …

---

## [Choosing a package for univariate (convex) optimization in Julia](https://discourse.julialang.org/t/choosing-a-package-for-univariate-convex-optimization-in-julia/109089)

<div class="topic-metadata">

**Author:** [@gdalle](https://discourse.julialang.org/u/gdalle)\
**Replies:** 8\
**Last updated:** [November 28, 2024, 4:34pm UTC](https://discourse.julialang.org/t/choosing-a-package-for-univariate-convex-optimization-in-julia/109089 "2024-11-28T16:34:55Z")

</div>

I need to solve 1d convex optimization programs, where I have access to all derivatives. Ideally I’d use Optim.jl but the interface only supports vectors. The backend NLSolvers.jl works but the documentation is not as de…

---

## [Autodifferentiation of model with fixed and mutable parameters](https://discourse.julialang.org/t/autodifferentiation-of-model-with-fixed-and-mutable-parameters/123208)

<div class="topic-metadata">

**Author:** [@EminentCoder](https://discourse.julialang.org/u/EminentCoder)\
**Replies:** 3\
**Last updated:** [November 28, 2024, 1:06pm UTC](https://discourse.julialang.org/t/autodifferentiation-of-model-with-fixed-and-mutable-parameters/123208 "2024-11-28T13:06:00Z")

</div>

Hello all, I am currently trying to build a model where some of the model-parameters need to be optimized while others have to remain fixed. The current approach works rather well, but I have some trouble with auto-diff…

---

## [Multivariable optimization of matrices with "no method matching zero(::Type{Matrix{Float64}})"](https://discourse.julialang.org/t/multivariable-optimization-of-matrices-with-no-method-matching-zero-type-matrix-float64/122207)

<div class="topic-metadata">

**Author:** [@ctucker](https://discourse.julialang.org/u/ctucker)\
**Replies:** 4\
**Last updated:** [November 4, 2024, 4:02am UTC](https://discourse.julialang.org/t/multivariable-optimization-of-matrices-with-no-method-matching-zero-type-matrix-float64/122207 "2024-11-04T04:02:38Z")

</div>

Hello, I am trying to maximize a message-passing Conditional Random Field using Optim.jl, and since I am optimizing for matrices I have to supply the gradient functions myself. Each of the individual functions work when…

---

## [Parallelized calls to Optim.optimize use the same number of threads as a single threaded call](https://discourse.julialang.org/t/parallelized-calls-to-optim-optimize-use-the-same-number-of-threads-as-a-single-threaded-call/121388)

<div class="topic-metadata">

**Author:** [@adannenberg](https://discourse.julialang.org/u/adannenberg)\
**Replies:** 4\
**Last updated:** [October 16, 2024, 4:56pm UTC](https://discourse.julialang.org/t/parallelized-calls-to-optim-optimize-use-the-same-number-of-threads-as-a-single-threaded-call/121388 "2024-10-16T16:56:18Z")

</div>

To investigate how sample size affects uncertainty in parameter inference, I do something like: Θ\_example = something #Θ is a vector of the parameters I'm trying to infer Θvec = zeros(numSamples, size(Θ\_example)) for …

---

## [Save the optimization results while the optimization is running (Optim.jl)](https://discourse.julialang.org/t/save-the-optimization-results-while-the-optimization-is-running-optim-jl/119116)

<div class="topic-metadata">

**Author:** [@mesonepigreco](https://discourse.julialang.org/u/mesonepigreco)\
**Replies:** 7\
**Last updated:** [September 11, 2024, 4:25pm UTC](https://discourse.julialang.org/t/save-the-optimization-results-while-the-optimization-is-running-optim-jl/119116 "2024-09-11T16:25:51Z")

</div>

Hi, I am running a minimization using Optim. Since it is very slow, I would like to save the results while running so that if I need to switch off the computer and brutally interrupt the minimization, I still have someth…

---

## [Hacking LineSearches.jl to parallelize step estimation](https://discourse.julialang.org/t/hacking-linesearches-jl-to-parallelize-step-estimation/116787)

<div class="topic-metadata">

**Author:** [@tom-plaa](https://discourse.julialang.org/u/tom-plaa)\
**Replies:** 10\
**Last updated:** [July 9, 2024, 9:38am UTC](https://discourse.julialang.org/t/hacking-linesearches-jl-to-parallelize-step-estimation/116787 "2024-07-09T09:38:35Z")

</div>

I want to hack Linesearches.jl to be able to stick a @threads macro on the linesearch part. I have an objective function for an optimization problem which has many parameters and is also very expensive to compute. This …

---

## [Chi2 (chisq) fit non-convergence using Optimization.jl](https://discourse.julialang.org/t/chi2-chisq-fit-non-convergence-using-optimization-jl/116313)

<div class="topic-metadata">

**Author:** [@jling](https://discourse.julialang.org/u/jling)\
**Replies:** 1\
**Last updated:** [June 27, 2024, 5:16pm UTC](https://discourse.julialang.org/t/chi2-chisq-fit-non-convergence-using-optimization-jl/116313 "2024-06-27T17:16:26Z")

</div>

using CairoMakie, FHist using Optimization, OptimizationOptimJL, OptimizationMultistartOptimization hist\_mjj12\_rosa = Hist1D(; binedges=0:2:1000, bincounts=\[0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0…

---

## [What is the best way to modify existing or add new optimizer in Optim?](https://discourse.julialang.org/t/what-is-the-best-way-to-modify-existing-or-add-new-optimizer-in-optim/114553)

<div class="topic-metadata">

**Author:** [@PetrosStefanou](https://discourse.julialang.org/u/PetrosStefanou)\
**Replies:** 4\
**Last updated:** [May 24, 2024, 7:59am UTC](https://discourse.julialang.org/t/what-is-the-best-way-to-modify-existing-or-add-new-optimizer-in-optim/114553 "2024-05-24T07:59:24Z")

</div>

Hi everyone, I am wondering what would be the best way to modify an existing optimizer or add a totally new on in Optim. My interest is modify the update formula of the inverse Hessian approximation in BFGS algorithm. …

---

## [Gradient-based optimization when gradient is only a function of y = f(x)](https://discourse.julialang.org/t/gradient-based-optimization-when-gradient-is-only-a-function-of-y-f-x/113674)

<div class="topic-metadata">

**Author:** [@dieg0](https://discourse.julialang.org/u/dieg0)\
**Replies:** 3\
**Last updated:** [May 1, 2024, 8:47pm UTC](https://discourse.julialang.org/t/gradient-based-optimization-when-gradient-is-only-a-function-of-y-f-x/113674 "2024-05-01T20:47:01Z")

</div>

Hi all, I am new to Julia, coming from MATLAB. I am writing some optimization code that tries to find parameters by minimizing the difference between some already computed probabilities (s) and model estimated probabilit…

---

## [How to print solver status and reason for termination for NLopt and Optimization.jl](https://discourse.julialang.org/t/how-to-print-solver-status-and-reason-for-termination-for-nlopt-and-optimization-jl/111308)

<div class="topic-metadata">

**Author:** [@structural](https://discourse.julialang.org/u/structural)\
**Replies:** 1\
**Last updated:** [March 7, 2024, 7:48pm UTC](https://discourse.julialang.org/t/how-to-print-solver-status-and-reason-for-termination-for-nlopt-and-optimization-jl/111308 "2024-03-07T19:48:18Z")

</div>

I am searching for a minimum using NLopt.LN\_SBPLX. The optimizer stops prematurely after ~100 iterations without throwing any errors or printing any messages. display(sol) simply returns the last parameter vector that wa…

---

## [Forward differentiation and differential equations](https://discourse.julialang.org/t/forward-differentiation-and-differential-equations/21002)

<div class="topic-metadata">

**Author:** [@moesphere](https://discourse.julialang.org/u/moesphere)\
**Replies:** 13\
**Last updated:** [November 7, 2023, 9:01am UTC](https://discourse.julialang.org/t/forward-differentiation-and-differential-equations/21002 "2023-11-07T09:01:46Z")

</div>

I am trying to use forward AD in combination with solving an ODE using DifferentialEquations.jl. I want to use an own loss function. However, with the is-in-place version there is a type assertion error. I have come up w…

---

## [How to access values of JuMP variables during optimization](https://discourse.julialang.org/t/how-to-access-values-of-jump-variables-during-optimization/110914)

<div class="topic-metadata">

**Author:** [@structural](https://discourse.julialang.org/u/structural)\
**Replies:** 7\
**Last updated:** [February 28, 2024, 8:39pm UTC](https://discourse.julialang.org/t/how-to-access-values-of-jump-variables-during-optimization/110914 "2024-02-28T20:39:49Z")

</div>

Is there a way to access values of JuMP variables during the optimization? I need to use JuMP for a constrained optimization. At each iteration of the optimization, I need to access the values of the parameters (i.e., v…

---

## [Choice variable doesn't optimize the objective function](https://discourse.julialang.org/t/choice-variable-doesnt-optimize-the-objective-function/110633)

<div class="topic-metadata">

**Author:** [@Ayesha](https://discourse.julialang.org/u/Ayesha)\
**Replies:** 3\
**Last updated:** [February 25, 2024, 12:34am UTC](https://discourse.julialang.org/t/choice-variable-doesnt-optimize-the-objective-function/110633 "2024-02-25T00:34:31Z")

</div>

begin # set parameters b = 100.0 r = 0.2 α = 0.85 θ = 2.5 β = 0.9 A = 1.0 s = 1.0 end begin f(b) = b^α Y₂(b,θ) = θ\*f(b) C₂(R₂,b,θ) = Y₂(b,θ) - R₂ R̄(b,r) = (1+r)\*b U₂(R₂, θ, b, α) = A\*log(max(θ \* f(b) - …

---

## [Passing struct as argument to optimizer](https://discourse.julialang.org/t/passing-struct-as-argument-to-optimizer/109209)

<div class="topic-metadata">

**Author:** [@structural](https://discourse.julialang.org/u/structural)\
**Replies:** 2\
**Last updated:** [January 24, 2024, 9:38pm UTC](https://discourse.julialang.org/t/passing-struct-as-argument-to-optimizer/109209 "2024-01-24T21:38:51Z")

</div>

Is it possible to pass a struct of parameters as an argument to an optimizer? The example below estimates an OLS model in which the intercept and slope are passed a vector p. function ssr(y,x,p) return sum((y .- (p\[…

---

## [Getting ForwardDiff.Dual to propagate through function](https://discourse.julialang.org/t/getting-forwarddiff-dual-to-propagate-through-function/107506)

<div class="topic-metadata">

**Author:** [@keynescoefen](https://discourse.julialang.org/u/keynescoefen)\
**Replies:** 5\
**Last updated:** [December 13, 2023, 8:01am UTC](https://discourse.julialang.org/t/getting-forwarddiff-dual-to-propagate-through-function/107506 "2023-12-13T08:01:43Z")

</div>

Hello! I would like to automatically differentiate a log-likelihood to obtain gradients and Hessians but have trouble propagating ForwardDiff.Dual types through my function. I have the same questions as here and tried t…

---

## [PRIMA: a package for solving general nonlinear optimization problems without using derivatives](https://discourse.julialang.org/t/prima-a-package-for-solving-general-nonlinear-optimization-problems-without-using-derivatives/105134)

<div class="topic-metadata">

**Author:** [@Zaikun](https://discourse.julialang.org/u/Zaikun)\
**Replies:** 4\
**Last updated:** [October 19, 2023, 2:05am UTC](https://discourse.julialang.org/t/prima-a-package-for-solving-general-nonlinear-optimization-problems-without-using-derivatives/105134 "2023-10-19T02:05:19Z")

</div>

Hi everyone, I am very glad to announce PRIMA, a package for solving general nonlinear optimization problems without using derivatives. PRIMA provides the reference implementation for M.J.D. Powell’s renowned derivativ…

---

## [Optim does not optimize in several minutes and it takes 10 seconds for scipy](https://discourse.julialang.org/t/optim-does-not-optimize-in-several-minutes-and-it-takes-10-seconds-for-scipy/101756)

<div class="topic-metadata">

**Author:** [@kunzaatko](https://discourse.julialang.org/u/kunzaatko)\
**Replies:** 1\
**Last updated:** [July 31, 2023, 4:46pm UTC](https://discourse.julialang.org/t/optim-does-not-optimize-in-several-minutes-and-it-takes-10-seconds-for-scipy/101756 "2023-07-31T16:46:35Z")

</div>

I am optimizing cross correlation of two arrays taken over there transfer function intersection. My function looks like this: otf\_lr\_1 = otf(tf, fft\_lr\_1, Δxy) # does not change with Δϕ fxs = fftfreq(size(fft\_lr\_2, 1), …

---

## [Get MLE parameters (e.g., p-value, confidence intervals...) from a Turing model using Optim.jl](https://discourse.julialang.org/t/get-mle-parameters-e-g-p-value-confidence-intervals-from-a-turing-model-using-optim-jl/101433)

<div class="topic-metadata">

**Author:** [@DominiqueMakowski](https://discourse.julialang.org/u/DominiqueMakowski)\
**Replies:** 3\
**Last updated:** [July 12, 2023, 9:11pm UTC](https://discourse.julialang.org/t/get-mle-parameters-e-g-p-value-confidence-intervals-from-a-turing-model-using-optim-jl/101433 "2023-07-12T21:11:03Z")

</div>

EDIT: There is now PR to add this feature to Turing This might be a very silly question… but assuming the following simple linear model: using Turing using DataFrames using LinearAlgebra x = \[0, 1, 2, 3, 4, 5, 6, 7,…

---

## [Can't fit dose response curve, could you tell me Why and How](https://discourse.julialang.org/t/cant-fit-dose-response-curve-could-you-tell-me-why-and-how/79996)

<div class="topic-metadata">

**Author:** [@MEEMO](https://discourse.julialang.org/u/MEEMO)\
**Replies:** 2\
**Last updated:** [June 23, 2023, 8:43am UTC](https://discourse.julialang.org/t/cant-fit-dose-response-curve-could-you-tell-me-why-and-how/79996 "2023-06-23T08:43:04Z")

</div>

Hello there ! I just have started programming and Julia these days, and I am trying fitting curve (dose response) by Optim.jl But I can’t obtain better parameters and predictions (the all predictions have same value ev…

---

## [How to use \`precondprep\` with \`Optim.jl\`?](https://discourse.julialang.org/t/how-to-use-precondprep-with-optim-jl/100288)

<div class="topic-metadata">

**Author:** [@fph](https://discourse.julialang.org/u/fph)\
**Replies:** 0\
**Last updated:** [June 13, 2023, 3:57pm UTC](https://discourse.julialang.org/t/how-to-use-precondprep-with-optim-jl/100288 "2023-06-13T15:57:13Z")

</div>

How do I use precondprep within Optim.jl to use a preconditioner that changes at each step? The results of the function seem to be ignored in my attempts. Example: using Optim res = optimize(x-\>(x\[1\]-1)^4 + x\[2\]^2, \[2.;…

[Next page](https://discourse.julialang.org/tag/optim/112.md?match_all_tags=true&page=1&tags%5B%5D=optim)
