R equivalent of MATLAB's fmincon for constrained optimization? - r

Is there an equivalent to the MATLAB function fmincon() which finds the minimum of a constrained non-linear function (with linear equality AND inequality constraints) in R?
I can rule out constrOptim (doesn't support equality constraints) and quadprog (only quadratic functions) which are listed on the R Optimization task page.

The package nloptr is an R interface to NLopt, a library for nonlinear optimization with algorithms for unconstrained optimization, bound-constrained optimization, and general nonlinear inequality/equality constraints.

There is also a package called pracma which includes fmincon() function similar to Matlab version.

Related

What are the equivalent functions of fmincon with 'trust-region-reflective' algorithm and fminsearchbnd in R?

I am trying to reproduce the following matlab functions in R. I need to find the closest approximations of fmincon and fminsearchbnd in R.
if license('test','optimization_toolbox')
% IF OPTIMIZATION TOOLBOX IS PRESENT, AN ANALYTICAL GRADIENT BASED
% MINIMIZATION APPROACH IS USED (trust-region-reflective)
if(exist('optimoptions', 'file'))
options = optimoptions('fmincon','Algorithm','trust-region-reflective','Display','off','GradObj','on','MaxIter',2000,...
'MaxFunEvals',10000,'TolFun',1e-8,'TolX',1e-8);
else
options = optimset('Algorithm','trust-region-reflective','Display','off','GradObj','on','MaxIter',2000,...
'MaxFunEvals',10000,'TolFun',1e-8,'TolX',1e-8);
end
[xfit1,fval1] = fmincon(FUN_MIN_GRAD_PARAMETRIZED,x0,[],[],[],[],LB,UB,[],options);
end
% WE also USE A CONSTRAINED VERSION OF FREELY AVAILABLE fminsearch
% (THIS USES DERIFVATIVE FREE SIMPLEX ALGORITHM)
[xfit2,fval2] = fminsearchbnd(FUN_MIN_GRAD_PARAMETRIZED,x0,LB,UB,optimset(...
'MaxIter',2000,'MaxFunEvals',10000,'TolFun',1e-8,'TolX',1e-8));
The pracma package provides fmincon equivalence but with the Squential
Quadratic Programming (SQP) approach.
Are there any equivalent functions of fmincon with trust-region-reflective algorithm and fminsearchbnd in R?

What is the best package/algorithm to solve a large optimization problem in R?

The problem has an exponential objective and exponential equality constraint function.Both my objective and constraint function are differentiable.
I would want to solve it using lagrange method and also want the function to output lagrange multiplier. I am currently exploring aug_lag in nloptr and solnp in rsolnp.
First question:
Would you suggest these packages or i should explore any other package?
Second question:
I know that rsolnp and nloptr performs local optimisation majorly but if i want to do global optimisation on a similar problem, can you suggest any package / algorithm?

Optimization in R with arbitrary constraints

I have done it in Excel but need to run a proper simulation in R.
I need to minimize function F(x) (x is a vector) while having constraints that sum(x)=1, all values in x are [0,1] and another function G(x) > G_0.
I have tried it with optim and constrOptim. None of them give you this option.
The problem you are referring to is (presumably) a non-linear optimization with non-linear constraints. This is one of the most general optimization problems.
The package I have used for these purposes is called nloptr: see here. From my experience, it is both versatile and fast. You can specify both equality and inequality constaints by setting eval_g_eq and eval_g_ineq, correspondingly. If the jacobians are known explicitly (can be derived analytically), specify them for faster convergence; otherwise, a numerical approximation is used.
Use this list as a general reference to optimization problems.
Write the set of equations using the Lagrange multiplier, then solve using the R command nlm.
You can do this in the OpenMx Package (currently host at the site listed below. Aiming for 2.0 relase on cran this year)
It is a general purpose package mostly used for Structural Equation Modelling, but handling nonlinear constraints.
FOr your case, make an mxModel() with your algebras expressed in mxAlgebras() and the constraints in mxConstraints()
When you mxRun() the model, the algebras will be solved within the constraints, if possible.
http://openmx.psyc.virginia.edu/

linear program solver with box/bound constraints?

Is there a linear program optimizer in R that supports upper and lower bound constraints?
The libraries limSolve and lpSolve do not support bound constraints.
It is not at all clear from the R Cran Optimization Task View page which LP optimizers support bound constraints.
Please note that all linear programming solvers assume their variables are positive. If you need different lower bounds, the easiest thing is to perform a linear transformation on the variables, apply lpSolve (or Rglpk), and retransform the variables. This has been explained in a posting to R-help some time ago -- which I am not able to find at the moment.
By the way, Rglpk has a parameter 'bounds' that allows to define upper and lower bounds through vectors, not matrices. That may attenuate your concern about matrices growing too fast.
Commands in the Rglpk package do constraints.
Or consider the General Purpose Continuous Solvers;
Package stats offers several general purpose optimization routines. First, function optim() provides an implementation of the Broyden-Fletcher-Goldfarb-Shanno (BFGS) method, bounded BFGS, conjugate gradient, Nelder-Mead, and simulated annealing (SANN) optimization methods. It utilizes gradients, if provided, for faster convergence. Typically it is used for unconstrained optimization but includes an option for box-constrained optimization.
Additionally, for minimizing a function subject to linear inequality constraints stats contains the routine constrOptim().
nlminb() offers unconstrained and constrained optimization using PORT routines.

MATLAB's quadprog equivalent in R?

What is the equivalent of MATLAB's quadprog function in R in terms of function specification?
Note that it is not the R package quadprog (although the optimization procedure is the identical).
The R library quadprog uses the 'meq' argument to distinguish between equality and inequality constraints whereas MATLAB has separate arguments for these two. The MATLAB approach is far more convenient for my purposes.
It's not a big deal to transform my arguments to fit but it would be a nice convenience if there is an implementation in R that matches the specification in MATLAB.
Note:
MATLAB quadprog documentation
R quadprog documentation
If you can make the translation and you just want a more convenient function you'll have to make your own wrapper. There is no more similar solution in a package. Someone on here might do it for you but it sounds like you can do it yourself.

Resources