# Constraint optimization without gradient

**URL:** <https://discourse.julialang.org/t/constraint-optimization-without-gradient/11040>\
**Category:** Optimization (Mathematical)\
**Created:** [May 21, 2018, 12:06pm UTC](https://discourse.julialang.org/t/constraint-optimization-without-gradient/11040 "2018-05-21T12:06:45Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![sarnatas](https://avatars.discourse-cdn.com/v4/letter/s/e5b9ba/32.png) [@sarnatas](https://discourse.julialang.org/u/sarnatas)\
**Post date:** [May 21, 2018, 12:06pm UTC](https://discourse.julialang.org/t/constraint-optimization-without-gradient/11040/1 "2018-05-21T12:06:45Z")

</div>

Hello,  
I am very new in Julia, so sorry in advance for my questions.  
I have some issues about the optimize function from Optim.jl package.  
First of all, I was not able to find a complete list with description of every optimization algorithm that I can use. I know that Nelder Mead is the default one gradient-free, and that LBFGS is the default one gradient-prone, but I would like to study every available algorithm to decide which one I could use, without finding a list in the documentation.

An othe issue, is that I would like to apply a simple constraint without using gradient and/or hessian. Actually, to be more precise, I just need a solution for the optimization which gives me all positive values.

This is the function I would like to optimize, to find the parameters x:

function A(x)  
T = 0.0  
partial\_sum1 = 0.0  
partial\_sum2 = 0.0  
regularisation\_factor = x[end]  
regularisation = norm(x[1:end-1])  
for i = 1:44  
numerator = 0.0  
denominator = 0.0  
for j = 1:44  
numerator += Q[i,j]x[j]  
denominator += (Q[i,j]+M[i,j])x[j]  
end  
partial\_sum1 = numerator/denominator  
partial\_sum2 = smooth\_intronic\_average[i]/(2smooth\_intronic\_average[i]+smooth\_exonic\_average[i])  
T += (partial\_sum1 - partial\_sum2)^2  
end  
T +=regularisation\_factorregularisation^2  
return T  
end

where smooth\_intronic\_average and smooth\_exonic\_average are two arrays of length 44, and Q and M are two matrices (44 x 50).  
That’s what I have done so far:

optimization = optimize(A, initial\_guess)

with different initial\_guess. In any case, I had negative values in any case, more or less, that are not good for the scientific purpose I am using this function (the x values should be transcription rates of a gene expression, that cannot be negative).

Thank you to everyone for your help.

S.

---

<div class="post-metadata">

**Author:** ![kristoffer.carlsson](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/kristoffer.carlsson/32/22_2.png) [@kristoffer.carlsson](https://discourse.julialang.org/u/kristoffer.carlsson)\
**Post date:** [May 21, 2018, 12:16pm UTC](https://discourse.julialang.org/t/constraint-optimization-without-gradient/11040/2 "2018-05-21T12:16:39Z")

</div>

Please read [PSA: how to quote code with backticks](https://discourse.julialang.org/t/psa-how-to-quote-code-with-backticks/7530) to see how you can quote your code to make it more readable.

---

<div class="post-metadata">

**Author:** ![tfk17lstm](https://avatars.discourse-cdn.com/v4/letter/t/f0a364/32.png) [@tfk17lstm](https://discourse.julialang.org/u/tfk17lstm)\
**Post date:** [May 21, 2018, 12:19pm UTC](https://discourse.julialang.org/t/constraint-optimization-without-gradient/11040/3 "2018-05-21T12:19:14Z")

</div>

Have you tried with: [https://github.com/JuliaOpt/NLopt.jl/blob/master/README.md](https://github.com/JuliaOpt/NLopt.jl/blob/master/README.md)?

I have used in R for free derivative optimization an it works amazingly great.

---

<div class="post-metadata">

**Author:** ![ChrisRackauckas](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/chrisrackauckas/32/77_2.png) [@ChrisRackauckas](https://discourse.julialang.org/u/ChrisRackauckas)\
**Post date:** [May 21, 2018, 12:23pm UTC](https://discourse.julialang.org/t/constraint-optimization-without-gradient/11040/4 "2018-05-21T12:23:23Z")

</div>

If you really want to do nonlinear constrained optimization without gradients, I would recommend BlackBoxOptim.jl (box constraints only) or NLopt.jl. Optim.jl doesn’t do constrained (right now) and most of its methods use gradients.
