Prev: Matlab and FTDI VCP drivers
Next: function handles
From: Marco on 21 Mar 2010 17:31 Hi, I got a problem with the definition of the Hessian used by the FMINCON function. I'm using the interior-point algorithm to solve a constrained nonlinear problem. I calculated the analytic expression of both gradient and Hessian, and I'm passing both to FMINCON using the options ('GradObj','on') and ('Hessian','user-supplied'). The Hessian function is a separate defined function named @hessmgrp. It works, but I have a programming problem. My Hessian is a function of two vectors: the target vector and another vector. The input arguments of the Hessian function are only two, the target vector and the Lagrange multipliers, that is function h = hessmgrp(y,lambda) Then, I have to pass the extra parameter to this function. I read the optim toolbox manual and found different solutions. Eventually, the only way I found is to define global variables and use them locally. It is not the best solution, as remarked in the manual. Does anybody of you know how to pass extra parameters to the Hessian function in a more appropriate way? Thanks in advance Marco
From: Steven Lord on 21 Mar 2010 18:21 "Marco " <marinimar(a)gmail.com> wrote in message news:ho636m$g99$1(a)fred.mathworks.com... > Hi, > I got a problem with the definition of the Hessian used by the FMINCON > function. > I'm using the interior-point algorithm to solve a constrained nonlinear > problem. > I calculated the analytic expression of both gradient and Hessian, and > I'm passing both to FMINCON using the options ('GradObj','on') and > ('Hessian','user-supplied'). The Hessian function is a separate defined > function named @hessmgrp. It works, but I have a programming problem. > > My Hessian is a function of two vectors: the target vector and another > vector. The input arguments of the Hessian function are only two, the > target vector > and the Lagrange multipliers, that is > > function h = hessmgrp(y,lambda) > > Then, I have to pass the extra parameter to this function. I read the > optim toolbox manual and found different solutions. Eventually, the only > way I found is to define global variables and use them locally. It is not > the best solution, as remarked in the manual. > > Does anybody of you know how to pass extra parameters to > the Hessian function in a more appropriate way? Anonymous function. Specify your Hessian function as @(y, lambda) hessmgrp(y, lambda, whateverOtherParametersYouWant) [as long as whateverOtherParametersYouWant are defined before you create this anonymous function handle.] -- Steve Lord slord(a)mathworks.com comp.soft-sys.matlab (CSSM) FAQ: http://matlabwiki.mathworks.com/MATLAB_FAQ
From: Marco on 22 Mar 2010 12:35 Thanks, it works now! Marco "Steven Lord" <slord(a)mathworks.com> wrote in message <ho664c$rjl$1(a)fred.mathworks.com>... > > "Marco " <marinimar(a)gmail.com> wrote in message > news:ho636m$g99$1(a)fred.mathworks.com... > > Hi, > > I got a problem with the definition of the Hessian used by the FMINCON > > function. > > I'm using the interior-point algorithm to solve a constrained nonlinear > > problem. > > I calculated the analytic expression of both gradient and Hessian, and > > I'm passing both to FMINCON using the options ('GradObj','on') and > > ('Hessian','user-supplied'). The Hessian function is a separate defined > > function named @hessmgrp. It works, but I have a programming problem. > > > > My Hessian is a function of two vectors: the target vector and another > > vector. The input arguments of the Hessian function are only two, the > > target vector > > and the Lagrange multipliers, that is > > > > function h = hessmgrp(y,lambda) > > > > Then, I have to pass the extra parameter to this function. I read the > > optim toolbox manual and found different solutions. Eventually, the only > > way I found is to define global variables and use them locally. It is not > > the best solution, as remarked in the manual. > > > > Does anybody of you know how to pass extra parameters to > > the Hessian function in a more appropriate way? > > Anonymous function. Specify your Hessian function as @(y, lambda) > hessmgrp(y, lambda, whateverOtherParametersYouWant) [as long as > whateverOtherParametersYouWant are defined before you create this anonymous > function handle.] > > -- > Steve Lord > slord(a)mathworks.com > comp.soft-sys.matlab (CSSM) FAQ: http://matlabwiki.mathworks.com/MATLAB_FAQ >
From: Manthos Vogiatzoglou on 22 Mar 2010 18:21 Steven thank you for the very helpfull comment. I have exactly the same problem as Marco, however my constraints are linear therefore in my case the hessian of the objective is the same as the hessian of the Lagrangian. Does this change anything? In my case how should I pass the hessian function to optimset? @(y)HessianFcn(y,[],myextraparameters) or @(y,lambda)HessianFcn(y,lambda,myextraparameters) or in another way? Thanks again!!!
|
Pages: 1 Prev: Matlab and FTDI VCP drivers Next: function handles |