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.
Related
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?
I found the package mtsdi and the corresponding function mnimput:
R Documentation
This function gives very good results for my data sets. However, I would like to understand the mathematical background of the function. I am familiar with the EM algorithm but how exactly does the function work? How are splines used here and is there a connection with the algorithm derived by Schafer?
I'm porting some matlab code that uses rcond() to test for singularity, as also recommended here (for matlab singularity testing).
I see that there is a cond() function in Julia (as also in Matlab), but rcond() doesn't appear to be available by default:
ERROR: rcond not defined
I'd assume that rcond(), like the Matlab version is more efficient than 1/cond(). Is there such a function in Julia, perhaps using an add-on module?
Julia calculates the condition number using the ratio of maximum to the minimum of the eigenvalues (got to love open source, no more MATLAB black boxs!)
Julia doesn't have a rcond function in Base, and I'm unaware of one in any package. If it did, it'd just be the ratio of the maximum to the minimum instead. I'm not sure why its efficient in MATLAB, but its quite possible that whatever the reason is it doesn't carry though to Julia.
Matlab's rcond is an optimization based upon the fact that its an estimate of the condition number for square matrices. In my testing and given that its help mentions LAPACK's 1-norm estimator, it appears as though it uses LAPACK's dgecon.f. In fact, this is exactly what Julia does when you ask for the condition number of a square matrix with the 1- or Inf-norm.
So you can simply define
rcond(A::StridedMatrix) = 1/cond(A,1)
You can save Julia from twice-inverting LAPACK's results by manually combining cond(::StridedMatrix) and cond(::LU), but the savings here will almost certainly be immeasurable. Where there is a measurable savings, however, is that you can directly take the norm(A) instead of reconstructing a matrix similar to A through its LU factorization.
rcond(A::StridedMatrix) = LAPACK.gecon!('1', lufact(A).factors, norm(A, 1))
In my tests, this behaves identically to Matlab's rcond (2014b), and provides a decent speedup.
I am working on clustering of variables in matlab. Two functions come in ClustOfVar package in R, called hcluster() and cutreevar().
I am good in Matlab and would like to use alternatives of hcluster() and cutreevar() in it.
Does Matlab has any inbuilt function which computes exactly same as hcluster() and cutreevar() does in R?
Need help.
Thanks
for heirarchical clustering you'll probably want to look at clusterdata. Note that you'll need the statistical toolbox for this function.
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.