I am trying to find the values of 19 free variables from my data, using the psw optimization algorithm. I got interest in seeing the evolution of the 19 variables together with the minimization of the objective function, over the iterations. I then want to compare this againnst the genetic algorithm.
with the genetic algorithm I am able to to so, and get information (see code below), but with the psw I am no cabable of doing it. With the ga, I call this function from gaoptimset('PlotFcns',{@gaplotbestf, @gapop_func},...
Can you help me with this? Thank you a lot
function [state,options,optchanged] = gapop_func(options,state,flag)
persistent best r history_min history_max %h1
optchanged = false;
switch flag
case 'init'
best = state.Population;
assignin('base','gapopbestx',best);
case 'iter'
ibest = state.Best(end);
ibest = find(state.Score == ibest,1,'last');
bestx = state.Population(ibest,:);
best = [best; bestx];
assignin('base','gapop_max_best',history_max);
case 'done'
assignin('base','gapopbestx',best);
end

 채택된 답변

Alan Weiss
Alan Weiss 2018년 12월 28일

1 개 추천

The syntaxes for output functions differ between ga and particleswarm. For an example of a particleswarm output function, see this example. For the correct way to set options for particleswarm, see the same example (you must use optimoptions to set options).
Alan Weiss
MATLAB mathematical toolbox documentation

댓글 수: 5

Marco Marchese
Marco Marchese 2018년 12월 29일
Thank you very much. this was very useful!
My doubt is now, what if I wanted to extract the value of each dimension (a.k.a. each nvars) that I am looking at each iteration and see how that converges?
Marco
Alan Weiss
Alan Weiss 2019년 1월 3일
The optimValues.bestx field contains the current best point at each iteration. This is a 19-element vector for the problem you described.
Alan Weiss
MATLAB mathematical toolbox documentation
Alan Weiss
Alan Weiss 2019년 1월 3일
Allow me to make one further observation. Generally, patternsearch is the most reliable and fastest-converging solver for nonsmooth problems. Please be sure to compare with it. And, if your problem is smooth, you should use fmincon instead. To search for a global solution using fmincon, try MultiStart. To search for a global solution using patternsearch, try uniformly distributed initial points:
x0 = lb + rand(size(lb)).*(ub - lb);
Good luck,
Alan Weiss
MATLAB mathematical toolbox documentation
Marco Marchese
Marco Marchese 2019년 1월 7일
Thank you for the suggestion. The issue is that my function is quite complex and the computational time is very extended, thus I do not see much difference between G.A., PSO, Patternsearch. I have a non-smooth, non-linear function with a set of unknown values that i need to fit from experimental data.
Marco Marchese
Marco Marchese 2019년 1월 28일
Apparently both patternsearch and PSO work out fine.
Is there a way I can extract confidence intervals from here? I would want to avoid to pass through nlingit,lsqcurvefit or lsqnonlin.

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

질문:

2018년 12월 27일

댓글:

2019년 1월 28일

Community Treasure Hunt

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

Start Hunting!

Translated by