Code covered by the BSD License  

Highlights from
optimize

4.88889

4.9 | 9 ratings Rate this file 43 Downloads (last 30 days) File Size: 112.18 KB File ID: #24298
image thumbnail

optimize

by Rody Oldenhuis

 

29 May 2009 (Updated 05 Aug 2009)

optimize (non)linear (in)equality constrained functions with FMINSEARCH

| Watch this File

File Information
Description

OPTIMIZE is an improvement upon the functions FMINSEARCHBND and FMINSEARCHCON written by John d'Errico (also available on the file exchange). It solves the optimization problem

min f(x)

s.t.

lb <= x <= ub
A * x < b
Aeq * x = beq
c(x) <= 0
ceq(x) = 0

using a coordinate transformation for the bound constraints, and penalty functions for the other constraints. The penalty functions used are pseudo-adaptive: normally, an exponential penalty is used. However, if the amount of constraint violation is severe, this could lead to numerical overflow. To prevent this, the penalty function is converted to a linear function in case it is too large for the exponential constraint.

The main differences between OPTIMIZE and FMINSEARCHCON are

 - (non)linear equality constraints can now be used
 - strictness is more controllable

While FMINSEARCHCON does not permit ANY function evaluation outside the feasible domain, OPTIMIZE can be either allowed (default) or disallowed ('strict' or 'superstrict' options) to do so.

Its behavior is similar to that of FMINCON (except for the really fancy stuff), which makes it useful for those who do not have the optimization toolbox. Also, it is particularly useful in case your function is hard or impossible to differentiate. In such cases, FMINCON is forced to compute the derivatives numerically, which usually takes > 60% of the computation time if you have a sizeable problem. Since FMINSEARCH is the engine for OPTIMIZE, no derivatives are required, which might make it more efficient than using FMINCON.

Some basic examples are included in a published M-file. I recycled most of the examples (and help text) from FMINSEARCHCON -- see its documentation for more underlying theory.

UPDATES:
--------------------------
    You may now also omit the argument [x0], which (when [lb] and [ub] are given) will try to optimize the problem *globally*; simply a few randomly generated starting points inside [lb,ub] will be used to optimize the problem, so that the minimum returned is more likely to be the global minimum. Note however that the number of required function evaluations is considerable. This method should only be used for "cheap" objective functions. See my other release (GODLIKE) for a more robust way to optimize problems globally.

    Also, an additional argument [algorithm] may be provided. When you set it to 'NelderMead', an internal version of the Nelder-Mead simplex method will be used, in stead of the one implemented in FMINSEARCH. The internal one is usually less accurate, but slightly more robust and internally more efficient. This is the recommended method for problems of larger dimensionality.

Usage:
--------------------------
sol = OPTIMIZE(func, x0)
sol = OPTIMIZE(func, x0, lb, ub)
sol = OPTIMIZE(func, x0, lb, ub, A, b)
sol = OPTIMIZE(func, x0, lb, ub, A, b, Aeq, beq)
sol = OPTIMIZE(func, x0, lb, ub, A, b, Aeq, beq, nonlcon)
sol = OPTIMIZE(func, x0, lb, ub, A, b, Aeq, beq, nonlcon, strictness)
 sol = OPTIMIZE(func, x0, lb, ub, A, b, Aeq, beq, nonlcon, strictness, options)
 sol = OPTIMIZE(func, x0, lb, ub, A, b, Aeq, beq, nonlcon, strictness, options, algorithm)

[sol, fval] = OPTIMIZE(func, ...)
[sol, fval, exitflag] = OPTIMIZE(func, ...)
[sol, fval, exitflag, output] = OPTIMIZE(func, ...)

Acknowledgements

The author wishes to acknowledge the following in the creation of this submission:
fminsearchbnd, fminsearchcon

MATLAB release MATLAB 7.7 (R2008b)
Tags for This File  
Everyone's Tags
Tags I've Applied
Add New Tags Please login to tag files.
Comments and Ratings (11)
29 May 2009 John D'Errico

Well done.

02 Jun 2009 Thierry Dalon

Hi!
looks GREAT!
could you add to the package the source for the testoptimize.m, please ?
 maybe add it as well as a demo alike TMW optimdemos.

02 Jun 2009 Rody Oldenhuis

Thierry: it's basically already included (the included HTML is a published M-file, so all commands can basically be copy-pasted). But once I get home tonight, I'll included it nonetheless for completeness. As for the demo, that would indeed be great! I'll see to it. Thanks for the suggestion!

As for the dependencies: To my knowledge, FMINSEARCH is indeed included in MATLAB's standard library (in my version it's located in R2008b\toolbox\matlab\funfun\fminsearch.m), but of course FMINCON is only included in the optimization toolbox (located in R2008b\toolbox\shared\optimlib\fmincon.m), so OPTIMIZE is for everyone in need of a "basic" FMINCON ^_^

14 Oct 2009 Ben

Code seems to work great. Thanks.
Is there any way to set the increment size for the x0 range? Allow me to clarify: lets say a have a lower bound of -2 and an upper bound of 2. I want the guesses to increment by 0.1. So effectively, I want to check the values [-2:0.1:2]. Where in your code can I set the 0.1 increment? Also, can that increment be different for each variable in x0?

09 Feb 2010 Nagendra

please specify the algorithm journal paper which is used to write this algorithm

15 Feb 2010 Andre Guy Tranquille  
07 Jul 2010 Sky Sartorius  
31 Aug 2010 Ryan Webb

I use optimize for many problems, however I have found a bug when optimize is used with the distributed computing toolbox. When it is being run on a worker, it gives an "Undefined Function Handle" error.

Unfortuntely I am unable to trace exactly what line this error comes from, but I can say that it is after line 398. The likely culprit is when optimize calls fminsearch and funfncP is out of scope somehow...

13 Feb 2011 Alexei  
29 Jul 2011 Marco G

Very Good it does work!! I was using the routine to solve a constrained problem (my constraints are basically non negativity of the x´s and that they sum up to one: Sum_i x_i =1) with some additional parameters in the objective function. I noticed that the contraint of the sum is not perfectly matched (i.e sum is 0.9 or so) even though I used ´strict´ option. Is there a way to force the constraint to be respected and maybe lose something somewhere else( e.g. less optimal minimization)? thx for help

11 Dec 2011 Shmuel

nice, but change line 12 in the testoptimize
to :
clc, rosen = @(x) (1-x(1))^2 + 105*(x(2)-x(1)^2)^2 -6000*sinc(x(2)^2+x(1)^2); % adding local minima.
and you get a local minimume solver as fminsearch is.

Please login to add a comment or rating.
Updates
30 Jul 2009

Two bugs fixed:

1) [x0] can now be a matrix, just as in FMINSEARCH.
2) Fixed a minor issue with the strictness setting

Also, I cleaned up the code somewhat, and expanded error handling a bit.

04 Aug 2009

Corrected problem with 1D-functions, and included more robust version of the NM-algorithm (see changelog)

05 Aug 2009

Removed dependency on the optimization toolbox (TolCon). Added global routine, and an associated exitflag (-3).

Tag Activity for this File
Tag Applied By Date/Time
optimization Rody Oldenhuis 29 May 2009 09:37:23
constrained optimization Rody Oldenhuis 29 May 2009 09:37:23
derivativefree optimization Rody Oldenhuis 29 May 2009 09:37:23
constrained neldermead algorithm Rody Oldenhuis 29 May 2009 09:37:23
directsearch Rody Oldenhuis 29 May 2009 09:37:23
optimization Nagendra 09 Feb 2010 07:45:31

Contact us at files@mathworks.com