Global search and Handle function specification

The original code was using "fmincon" to minimize the function MSM_likelihood below:
[parameters,LL,exitflag,output]=fmincon('MSM_likelihood',startingvals,[],[],[],[],LB,UB, [],options,kbar,data,A_template);
HOWEVER, I am trying to run the optimization by using Global Search instead and that requires a function handle, which I believe I used sixmin for that. My code is below:
sixmin = @(input,kbar,data,A_template,estim_flag)MSM_likelihood;
opts = optimoptions(@fmincon,'Algorithm','interior-point');
problem = createOptimProblem('fmincon','x0',startingvals,...
'objective',sixmin(input,kbar,data,A_template,estim_flag),'lb',LB,'ub',UB,...
'options',opts);
gs = GlobalSearch;
[x,f] = run(gs,problem)
Somehow, the code doesn't run as expected. Please help! I really appreciate it!

Antworten (2)

Walter Roberson
Walter Roberson am 26 Feb. 2016

0 Stimmen

'objective' needs to be followed by a function handle, but instead you are following it by the result of calling sixmin on particular parameters. You should probably just have sixmin (no parameters following) at that point.

4 Kommentare

Tien Nguyen
Tien Nguyen am 26 Feb. 2016
Hello Walter,
Thank you for a quick reply. Seems like the code ran a little bit but I ran into another problem.
Matlab shows error with these codes: sixmin = @(input,kbar,data,A_template,estim_flag)MSM_likelihood;
input = [estim_flag(1);input;estim_flag(2);estim_flag(3)];
Could you please let me know if the syntax is correct for the two listed? Thank you.
When that function handle is invoked with five input arguments, it will call MSM_likelihood with ZERO input arguments. I'm guessing that's not what you want. If you want to pass all five inputs into MSM_likelihood:
sixmin = @(input,kbar,data,A_template,estim_flag) ...
MSM_likelihood(input,kbar,data,A_template,estim_flag);
I broke this definition across two lines using ... for ease of display in Answers, but you could put it all on one line if you want.
Tien Nguyen
Tien Nguyen am 2 Mär. 2016
Hello Steven,
For some strange reason, Matlab shows:
Not enough input arguments.
Error in MSM_modified>@(input,kbar,data,A_template,estim_flag)MSM_likelihood(input,kbar,data,A_template,estim_flag) (line 72) MSM_likelihood(input,kbar,data,A_template,estim_flag);
Which is weird cause I put in 5 inputs? Do you have any idea? Thank you so much!
sixmin = @(input) MSM_likelihood(input,kbar,data,A_template,estim_flag);

Melden Sie sich an, um zu kommentieren.

Alan Weiss
Alan Weiss am 29 Feb. 2016

0 Stimmen

You might want to try the following line of code instead:
sixmin = @MSM_likelihood;
The function handle for fmincon must contain exactly one argument. See Passing Extra Parameters for more information.
Alan Weiss
MATLAB mathematical toolbox documentation

Gefragt:

am 26 Feb. 2016

Kommentiert:

am 2 Mär. 2016

Community Treasure Hunt

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

Start Hunting!

Translated by