Matlab Coder and fminsearch: what implementation strategy?

3 ビュー (過去 30 日間)
Nicolas
Nicolas 2014 年 11 月 8 日
コメント済み: Ryan Livingston 2014 年 11 月 10 日
Hi all,
I'd like to use Matlab Coder to speed up optimization when the 'fminsearch' function is used. This function seems supported by Matlab R2014b (<http://www.mathworks.fr/help/coder/ug/functions-supported-for-code-generation--alphabetical-list.html)>.
Here is my problem. I do not know
  1. how to apply Matlab Coder in my case since anonymous and nested functions are not supported
  2. which is the best implementation strategy for the following kind of problem where I need to pass parameters and data for the optimization process
Here is the function
function [x,fval,exitflag,output] = myfun1(parameters, data_1, data_2, data_n)
options = optimset('FunValCheck','on','MaxFunEvals',5000,'MaxIter',5000);
objfun = @(parameters)myfun2(parameters, data_1, data_2, data_n);
[x,fval,exitflag,output] = fminsearch(objfun,parameters,options);
end
Thanks.

採用された回答

Ryan Livingston
Ryan Livingston 2014 年 11 月 9 日
編集済み: Ryan Livingston 2014 年 11 月 9 日
One workaround is to model the anonymous function's parameters using a sub-function and persistent variables. The idea is to make objfun a sub-function and data_1,data_2,data_n be persistent variables in objfun. Then you use nargin of objfun to update the parameters' values when called with more than one argument.
You can see an implementation of such a function at:
that describes a similar workaround for MATLAB Coder and QUADGK.
  2 件のコメント
Nicolas
Nicolas 2014 年 11 月 10 日
Dear Ryan,
thank you for your prompt reply.
Your solution works and I obtain a speed improvement close to 6 for my first tries. Matlab Coder is a great tool.
Thanks again for your help,
Nicolas
Ryan Livingston
Ryan Livingston 2014 年 11 月 10 日
That's great to hear Nicolas, thanks.
You're quite welcome.

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeMATLAB Coder についてさらに検索

製品

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by