Does Octave have a ScaleProblem equivalent for fmincon? - matlab

I'm in the process of porting a large set of MATLAB scripts to Octave. Some of the scripts use the MATLAB Optimization toolbox, specifically the fmincon function. In the optim package in Octave, the fmincon function exists but has different parameters. Is there a way to replicate the ScaleProblem parameter in Octave's fmincon?
In my Octave script, I use optimset:
options = optimset('fmincon','Algorithm','sqp','ScaleProblem','obj-and-constr', ...);
Which causes the following warning:
warning: optimset: unrecognized option: ScaleProblem
Is there a workaround for this?

Apart from the trivial advise to write a wrapper that looks for this parameter-value pair, scales the matrices & calls fmincon without the ScaleProblem option, I can only emphasize to use the NLopt-toolbox from the MIT: https://nlopt.readthedocs.io/en/latest/ it got far more optimization algorithms with a neat matlab/octave interface, all open-source, and -- to my experience -- often more accurate and faster indeed =)

Related

Why does fmincon yield different solutions

I am very new to MatLab. Thus I am sorry if this is very basic.
I use a function called fmincon to do find a solution for minimizing a function. Why do I get different solutions for running fmincon?
I would like to know a satisfying or convincing mathematical or programming explanation for having different solutions using fmincon.
Check these limitations in the MATLAB documentation.
fmincon is a gradient-based method that is designed to work on problems where the objective and constraint functions are both continuous and have continuous first derivatives.
The function is very delicate and it is best if you can avoid it. It only works neatly on problems that are neatly defined to begin with. Any deviation can lead to local instead of global minima, and these can depend (among other things) on your initial solution estimate or starting point.
As fmincon is sensitive to initial point, If you set different start point for the fmincon, you might get a different solution in each apply. You can find one of the algorithms of fmincon here.

Multi-variable Fitness Function error using Optimization Tool

I have the following fitness function:
function f = objfun(x,t)
f = x.*(t-x);
end
When i try to use this code as a fitness function using MATLAB's Optimization Tool and the Genetic Algorithm (ga) solver, i get the following error:
Error running optimization. Not enough input arguments.
I know the function has only 2 variables and I'm passing it those few variables so I have no idea why I am getting this error.
Can someone please help me fix this?
I never worked in Matlab because I heard that is slow (see for instance this thread: Performance Tradeoff - When is MATLAB better/slower than C/C++).
for genetic algorithms you need the highest speed possible because for complex problems you need very large populations...
I suggest to use C/C++. Here is a very light C implementation of a Genetic Algorithm that I've made for solving the function optimization problem: http://create-technology.blogspot.ro/2015/03/a-genetic-algorithm-for-solving.html

Optimization of multivariable function In Matlab

I have a function fun(x,y,z), such that say, x=1:10, y=50:60, z=100:105. Which optimization method (and how) I can use to get the minimum of this function, for example, where (x,y,z)=(3,52,101). I am working in Matlab.
Thank you for any help
Algorithms
There are many many algorithms out there that you can use for direct search optimization such as Nelder-Mead, Particle Swarm, Genetic Algorithm, etc.
I believe Nelder-Mead is a simplex optimization method which is used by fminsearch function in MATLAB.
Also, there is Genetic Algorithm which comes with MATLAB Global Optimization toolbox. You may want to give that a try as well.
Particle Swarm Optimization (PSO) is another direct search method that you can use. However, there is no official toolbox for Particle Swarm method built by Mathworks. The good news is there is quite a few PSO toolbox developed by other people. I personally have used this one and am quite happy with the performance. Its syntax is similar to Genetic Algorithm functions that come with Global Optimization Toolbox.
Discrete Optimization
Regarding your question that you are looking for a set of integer values namely x,y, and z corresponding to the minimum objective function value, I would add a part at the beginning of the objective function that rounds the variables to the closest integers and then feeds them to your main function fun(x,y,z). This way you would discretize your function space.
I hope my answer helps.

How to use integer and binary variables with matlab GA toolbox?

I used matlab GA toolbox to solve an integer programming problem. The problem has some binary variables.
I used nonlinear constraints such as x*(1-x) = 0 for binary variables, but matlab outputs real values for these variables.
One another problem is that final solution is not feasible! I used this line of code:
options = gaoptimset(options,'CreationFcn', #gacreationlinearfeasible);
But matlab still generating no feasible solutions.
A friend suggested using inequality constraints instead of equality ones, but that failed.
Then there is two problems. 1) say matlab about binary variables, 2) generating feasible solutions.
How can I use matlab GA for my problem?
I'm not sure it is best solution, but I solved my problem by substitute constraints for penalty coefficients in fitness function.
After all, as a suggestion, anyone who has same problem can try GAlib (C++ genetic library) instead of matlab.

is there a faster version of fminbnd in matlab?

I am now using fminbnd in Matlab, and I find it relatively slow (I am using it inside a nested loop). The function itself, its interface and the values it returns are great, but when looking into the .m file I see it is not optimized. As a matter of fact, I was hoping for something like that to be written as a mex.
Anyone knows of an alternative to fminbnd that works much faster and does not have as much overhead?
It's written like that because it has to evaluate (feval) your user-defined function(s) on every iteration. Matlab's ODE solvers work in the same way. In current Matlab it's costly for a C/C++ code to call a user-defined Matlab function and read in its return values iteratively.
Make sure you're using the options correctly, that fminbnd is the correct tool (maybe a simpler scheme would be better or, since this in a loop, maybe a multi-dimensional method like fminsearch would be more appropriate), and have optimized your objective function. The next easiest thing would be to try compiling your Matlab code to C or C++ (see codgen). You'll likely need to compile in your objective function, and all of the options, as well in order to avoid the slowdown issues mentioned above. I've not tried this for fminbnd, but I did see mention of it working online. If your objective function itself is complicated, you could try just converting it to a mex function.
fminbnd is based on Brent's method. You can find C, C++, and FORTRAN code for that here. The GSL also has a version: gsl_min_fminimizer_brent.