0

Does Matlab have an equivalent to nlminb in R?

I realize that lsqcurvefit is available in Matlab, but I specifically want a function that uses a derivative-based method, ideally exactly the same one as nlminb uses.

nlminb is described in this Stats.StackExhange.com answer.

I do not want to use the 'trust-region-refelective' method emplyed by lsqcurvefit for constrained problems.

Community
  • 1
  • 1
Bazman
  • 2,058
  • 9
  • 45
  • 65
  • Are you actually performing maximum likelihood estimation as in the linked Stats.StackExhange.com question/answer? – horchler Nov 21 '13 at 19:45
  • No I'm performing a least squares fit but I want to test a new optimizer against a derivative based one. – Bazman Nov 21 '13 at 20:01

1 Answers1

1

Matlab's fmincon uses Quasi-Newton methods with constraints if the appropriate 'Algorithm' option is specified. Apparently R's nlminb is based on the L-BFGS-B code. Using the 'interior-point' algorithm this method of approximating the Hessian can be specified:

options = optimoptions('fmincon','Algorithm','interior-point','Hessian','lbfgs');

Unless you're running out of memory, the value of using 'lbfgs' over the default 'bfgs' is questionable. Try them all.

horchler
  • 18,384
  • 4
  • 37
  • 73
  • Would using lsqcurvefit with the levenberg-marquardt algorithm (i.e. I drop the constraints but make sure the initial guesses are well within the desired boundries) also approximate nlminb well? Or is fmincon closer? – Bazman Nov 21 '13 at 20:50
  • 1
    No idea. Levenberg-Marquardt is not a quasi-Newton method. It's a combination of [Gauss-Newton](http://en.wikipedia.org/wiki/Gauss–Newton_algorithm) and gradient descent. It is very robust. `lsqcurvefit` is designed for fitting data, so if that's your application try it. I don't see why you could use the default `'trust-region-reflective'` either, unless one of the [required conditions to use it is not met](http://www.mathworks.com/help/optim/ug/lsqcurvefit.html#f192109), which the function will warn you about. – horchler Nov 21 '13 at 22:26
  • Hey there when I try running this with fminunc I get: ??? Error using ==> optimset at 223 Invalid value for OPTIONS parameter Algorithm: must be 'active-set', 'trust-region-reflective', 'interior-point', 'interior-point-convex', 'levenberg-marquardt', 'trust-region-dogleg', 'lm-line-search', or 'sqp'. Error in ==> Optimal_Lambda_fmin at 64 options=optimset('Algorithm','quasi-newton','HessUpdate','bfgs','MaxFunEvals',10000,'TolFun',1e-16,'MaxIter',10000); Although 'quasi-newton' is shown as an available algo for the 2013b edition I am using 2011a!! – Bazman Nov 25 '13 at 13:17
  • Do you know which if any of the above algorithms is the same as nlminb? – Bazman Nov 25 '13 at 13:17
  • I can get it to run with: options=optimset('Algorithm','interior-point','Hessian','lbfgs','MaxFunEvals',10000,'TolFun',1e-16,'MaxIter',10000); [cn(:,ii,jj),residual(:,ii,jj),exitflag(:,ii,jj),output(:,ii,jj)]=fmincon(@(l)NSS_fmin(l,mats,mats2,y2,yc_m),L0,[],[],[],[],lbn,ubn,[],options); but would prefer to run it with the same algo as in nlminb but without any restrictions – Bazman Nov 25 '13 at 13:21
  • If you're using an older version of Matlab, you should always read the documentation for *your version* (`doc fminunc` in this case) not the one online unless you know they're the same. You can find [archived documentation for older versions here](http://www.mathworks.com/help/doc-archives.html). – horchler Nov 25 '13 at 19:04
  • 1
    In R2011a with `fminunc`, [here are the actual choices for algorithm](http://www.mathworks.com/help/releases/R2011a/toolbox/optim/ug/brhkghv-18.html#bsbwxz1). Despite what the error says, you can't actually set an `'Algorthm'` property for this solver, only if the the problem is large or medium scale, which will change things. The large scale method requires you to specify a gradient. If you use the medium scale method, the you can specify `'bfgs'` for the `'HessUpdate'` property, which may be closest to `nlminb`. – horchler Nov 25 '13 at 19:13