4.96429

5.0 | 28 ratings Rate this file 220 downloads (last 30 days) File Size: 12.8 KB File ID: #8277

fminsearchbnd

by John D'Errico

 

11 Aug 2005 (Updated 28 Sep 2006)

Code covered by BSD License  

Bound constrained optimization using fminsearch.

Editor's Notes:


This is a File Exchange Select file.



Select files are submissions that have been peer-reviewed and approved as meeting a high standard of utility and quality.

Download Now | Watch this File

File Information
Description

Fminsearch does not admit bound constraints.
However simple transformation methods exist to
convert a bound constrained problem into an
unconstrained problem.

Fminsearchbnd is used exactly like fminsearch,
except that bounds are applied to the variables.
The bounds are applied internally, using a
transformation of the variables. (Quadratic for
single bounds, sin(x) for dual bounds.)

The bounds are inclusive inequalities, which admit
the boundary values themselves, but will not permit
ANY function evaluations outside the bounds.

Note that fminsearchbnd allows the user to exactly fix a variable at some given value, by setting both bounds to the exact same value.

Example usage:
rosen = @(x) (1-x(1)).^2 + 105*(x(2)-x(1).^2).^2;

% unconstrained fminsearch solution
fminsearch(rosen,[3 3])
ans =
    1.0000 1.0000

% Lower bounds, no upper bounds
fminsearchbnd(rosen,[2.5 2.5],[2 2],[])
ans =
    2.0000 4.0000

Lower bounds on both vars, upper bound on x(2)
fminsearchbnd(rosen,[2.5 2.5],[2 2],[inf 3])
ans =
    2.0000 3.0000

Acknowledgements
This submission has inspired the following:
Fminspleas, Zfit, fminsearchbnd new, Fminsearchcon, optimize
MATLAB release MATLAB 7.0.1 (R14SP1)
Other requirements This code should work on any release of matlab which allows the use of sub-functions.
Zip File Content  
Published M Files fminsearchbnd_demo
Other Files fminsearchbnd/.DS_Store,
fminsearchbnd/demo/.DS_Store,
fminsearchbnd/demo/fminsearchbnd_demo.m,
fminsearchbnd/doc/.DS_Store,
fminsearchbnd/doc/Understanding_fminsearchbnd.rtf,
fminsearchbnd/fminsearchbnd.m,
fminsearchbnd/test/.DS_Store,
fminsearchbnd/test/test_main.m,
license.txt
Tags for This File  
Everyone's Tags
Tags I've Applied
Add New Tags Please login to tag files.
Comments and Ratings (31)
12 Aug 2005 Ken Campbell

Nice trick solving a common problem

23 Aug 2005 Vijit Nair

This is a great funcn. Thanks John.

23 Sep 2005 Evan Palmer

Works really well and is very handy! Nice job!

07 Oct 2005 Kaushik b

Thanks a lot. It really useful and works beautifully.

20 Dec 2005 Rui Miguel

I was really needing it! thanks a lot.
Has worked flawlessly for me.

18 Jan 2006 cedric penard

Works very well, exellent ! Thanks.

07 Apr 2006 G.H. Rao

excellent program. on these lines I applied bounds successfully to the genetic algorithm program 'ga' of Matlab release 14

14 Jun 2006 CC Gomez

Nicely written.

11 Jul 2006 Yes its Good

works very well!

11 Aug 2006 Umberto .  
28 Nov 2006 Dmitrey Kroshko

I connected John D'Errico file to the OpenOpt project
http://www.mathworks.com/matlabcentral/fileexchange/loadFile.do?objectId=13115&objectType=file
& informed him (I hope my letter passed antispam filter OK)
if any pretensions will be received, I promise to exclude the one
btw now default inner solver is Shor ralg with AST, which is better than current implementation of fminsearch, at least, for those task I tried with. Also, it can handle (sub)gradient info provided by user, and corresponding changes in John code were made.

13 Feb 2007 Natis Angarita  
15 Mar 2007 jimmy tsai

It's great. I couldn't solve my problem with fmincon but did it with this file. I really appreciate it.

20 Mar 2007 Eli Tom

Nice indeed.

05 May 2007 Lauren Cooney

thank you for this great program! it saved me a lot of time and frustration!

31 May 2007 Yang Zhang

I like this program and do you think it is possible to expand it to deal with linear constraints?

31 May 2007 John D'Errico

See fminsearchcon for linear and nonlinear inequality constraints. Equality constraints are more difficult to implement when coupled with bound constraints as implemented using transformations - John.

05 Jun 2007 Alex Chirokov

I really like this code: it is very well written and useful.

11 Jun 2007 Yossef Ehrlichman

It's really working. Helped alot! Matlab should incoprate it into its libraries.

15 Nov 2007 Mert Sabuncu

excellent code - gets the job done!

29 Nov 2007 Ken Purchase

Notice: I have submitted a slightly modified version that includes output and plot functions as well as slightly improved handling of varargin. Search for fminsearch.

The original is excellent and very useful- I hope the changes didn't break anything.

25 Apr 2008 M. P.

Worked beautifully for my own optimization problem. Thanks John.

25 Apr 2008 M. P.  
10 Sep 2008 Chirackel Yoonus

Very useful

08 Nov 2008 leo nidas

Thanks John!

19 Nov 2008 Umesh Rudrapatna

Thanks a lot! Helped me a lot.

21 May 2009 Chris Men

the beauty is yours.

23 Jul 2009 Srinivasa Chemudupati

Cannot Thank you enough John!!

07 Sep 2009 Will

Excellent modification to create a very useful algorithm. Thanks!

16 Sep 2009 Ryan Webb

 Great Function. Used it mane times.

However, now I have a trickier problem where one of the boundaries is a function of one of the variables. Making UB a function of xtrans is possible, but how would fminsearchbnd determine this intent given that the cases for transformation (k) are determined solely by the initial numerical values of the constraints? Thoughts?

16 Sep 2009 John D'Errico

Ryan,

This is really not a bound constrained problem. Your constraint is a general one, either a linear or a nonlinear inequality constraint.

The simple solution is to use a code that allows explicit linear or nonlinear constraints. There are a few on the FEX. In fact my fminsearchcon on the FEX does that, by applying a penalty to the problem when a constraint is violated. You might also look at optimize, by Rody Oldenhuis. This code allows explicit constraints of all forms.

However, there is a simple way to solve this class of problem with fminsearchbnd. Use another class of transformation. For example, suppose one wishes to minimize the function f(x,y), subject to the "bound" constraint that x <= erf(y).

Transform your problem such that

u = x + erf(y)
v = x - erf(y)

Clearly, v must be bounded above by 0. So use fminsearchbnd to optimize over the two dimensional domain (u,v). Inside your objective function, for any value of (u,v) you will compute the parameters (x,y) as

x = (u + v)/2;
y = erfinv(u - x);

Now you can finish evaluating the function f(x,y).

The only problem here happens if you also had other fixed bounds on x and y. But many other transformations would also have worked. For example, this transformation:

u = x
v = x - erf(y)

will still allow simple bound constraints on the parameter x, as well as allowing the nonlinear constraint x <= erf(y) as a bound constraint.

John

Please login to add a comment or rating.
Updates
11 Oct 2005

Fixed a problem when a variable with dual bounds
is started at exactly the mid-point of the bounds.

09 Nov 2005

Allow the user to fix a variable by setting the lower
and upper bounds equal.

09 Nov 2005

Version 3: also solves unbounded problems.

12 Jun 2006

Release 2.1: Fixed a bug when some variables are fixed and other variables are bounded from both above and below.

24 Jul 2006

Update for FX Select nomination structure - added demo, test and doc files

28 Sep 2006

Bug fix - allow an OutputFcn to operate properly, providing the parameter values in the correct domain.

Tag Activity for this File
Tag Applied By Date/Time
optimization John D'Errico 22 Oct 2008 07:55:49
bound constraints John D'Errico 22 Oct 2008 07:55:49
fminsearch John D'Errico 22 Oct 2008 07:55:49
transformation John D'Errico 22 Oct 2008 07:55:49
problem John D'Errico 22 Oct 2008 07:55:49
unconstrained John D'Errico 22 Oct 2008 07:55:49
 

MATLAB Central Terms of Use

NOTICE: Any content you submit to MATLAB Central, including personal information, is not subject to the protections which may be afforded information collected under other sections of The MathWorks, Inc. Web site. You are entirely responsible for all content that you upload, post, e-mail, transmit or otherwise make available via MATLAB Central. The MathWorks does not control the content posted by visitors to MATLAB Central and, does not guarantee the accuracy, integrity, or quality of such content. Under no circumstances will The MathWorks be liable in any way for any content not authored by The MathWorks, or any loss or damage of any kind incurred as a result of the use of any content posted, e-mailed, transmitted or otherwise made available via MATLAB Central. Read the complete Terms prior to use.

Contact us at files@mathworks.com