How does the ga in matlab give exitflag 1 before reaching the stall generation limit ?

4 views (last 30 days)
How does the ga in matlab throw an exitflag 1 before reaching the stall generation limit of 50 ? It throws exitflag 1 even if I set total generations less than 50.
I would sincerely appreciate your response this question.
Thanks,
  7 Comments
Mandar
Mandar on 28 Sep 2014
I am using MATLAB R2012a.
I do not have any non-linear constraints in my problem. So, it should not be using the constraint tolerance (TolCon) for convergence or for exiting the algorithm.
Geoff Hayes
Geoff Hayes on 28 Sep 2014
Do you have the documentation for 2012a with respect to the exit flag of the ga function? Perhaps it has changed in the newer releases…
For example, at Global Optimization Toolbox Release Notes, the Genetic Algorithm changes for R2014a includes the comment
ga now stops when the average relative change in best fitness value over StallGenLimit generations is less than the TolFun tolerance. Previously, the stopping criterion was a weighted average relative change, where the weighting factor was (1/2)n for the nth prior iteration. This change usually causes ga to take more iterations. The new StallTest option, with default value 'totalChange', controls the stopping criterion. Set StallTest to 'geometricWeighted' to recover the previous behavior.
Though when I look at the ga exitflag documentation for R2012a Global Optimization Toolbox and the equivalent for 2014a, the descriptions are the same.
You may want to contact The MathWorks support concerning this question.

Sign in to comment.

Answers (2)

Alan Weiss
Alan Weiss on 29 Sep 2014
I don't understand how you are seeing what you report. My reading of the GA code shows that it should give an exit flag of 0 when it hits a generation limit that is smaller than the stall generation limit.
Perhaps you can post your exact options call, your exact call to GA, and the exact exit message.
Alan Weiss
MATLAB mathematical toolbox documentation
  3 Comments
Alan Weiss
Alan Weiss on 30 Sep 2014
If you want help, please post your exact options call, your exact call to GA, and the exact exit message. And then ask a question about the exact output that you find confusing.
Alan Weiss
MATLAB mathematical toolbox documentation
Mandar
Mandar on 30 Sep 2014
Below is my exact code,
options = gaoptimset('PlotFcns',{@gaplotbestf,@gaplotmaxconstr},'Display','iter','Generations', 5,'StallGenLimit',[],'TolFun',1e-3);
ObjectiveFunction = @simple_fitness;
nvars = 2; % Number of variables LB = [0 0]; % Lower bound UB = [1 13]; % Upper bound
ConstraintFunction = @sim_const;
[x,fval, exitflag,output] = ga(ObjectiveFunction,nvars,[],[],[],[],LB,UB,ConstraintFunction,options)
%% Constraint Function
function [c, ceq] = sim_const(x) c = []; ceq = [];
%% Fitness Function
function y = simple_fitness(x)
y = 100 * (x(1)^2 - x(2)) ^2 + (1 - x(1))^2;
%% Results
Best max Stall
Generation f-count f(x) constraint Generations
1 140 0.635724 0 0
2 260 0.635724 0 1
Optimization terminated: average change in the fitness value less than options.TolFun and constraint violation is less than options.TolCon.
exitflag =
1
output =
problemtype: 'nonlinearconstr'
rngstate: [1x1 struct]
generations: 2
funccount: 260
message: [1x140 char]
maxconstraint: 0
%%
My question here is about interpreting exitflag 1 for ga problem type 'nonlinearconstr' when the constraint function is an empty set.
When I read the documentation for exitflag 1 for 'nonlinearconstr' problems, it says,
With nonlinear constraints — Magnitude of the complementarity measure (see Definitions) is less than sqrt(TolCon), the subproblem is solved using a tolerance less than TolFun, and the constraint violation is less than TolCon.
Since my constraint function is an empty set (options.TolCon = []), which criteria is the solver using to stop the optimization process ?
If the solver is using "average change in the fitness value less than options.TolFun" as the stopping criterion,
how is the "average change" calculated (and over how many generations) ?

Sign in to comment.


Alan Weiss
Alan Weiss on 30 Sep 2014
Thank you for posting the options, GA call, and returned info.
As you realize, having a nonlinear constraint function, even one that returns all empty, changes the GA algorithm and exit conditions. And having an all-empty return for the nonlinear constraint makes it behave in hard-to-understand ways. For example, when GA internally compares the magnitude of the constraint function, it is comparing [] to some value such as TolCon. What is the result of that comparison? Say you try
3 <= 5
ans =
1
[] <= 5
ans =
[]
So, in the end, I have to say that it is not clear to me what happens internally when GA makes these comparisons.
It seems to me that the question you are asking is "What happens if I give GA an unexpected function?" And my answer is "I guess it does unexpected things."
Sorry, I really don't know any more than that. Sorry for the long answer to a short question.
Alan Weiss
MATLAB mathematical toolbox documentation
  2 Comments
Mandar
Mandar on 30 Sep 2014
Hi Alan, Thanks for your response.
Do you know what the documentation means by:
"the subproblem is solved using a tolerance less than TolFun".
This is from the explanation of exitflag 1 for 'nonlinearconstr' problems.
"With nonlinear constraints — Magnitude of the complementarity measure (see Definitions) is less than sqrt(TolCon), the subproblem is solved using a tolerance less than TolFun , and the constraint violation is less than TolCon."
Alan Weiss
Alan Weiss on 1 Oct 2014
The subproblem is described here. In addition to the formulas, the relevant portion of the documentation is:
The genetic algorithm minimizes a sequence of subproblems, each of which is an approximation of the original problem. Each subproblem has a fixed value of λ, s, and ρ. When the subproblem is minimized to a required accuracy and satisfies feasibility conditions, the Lagrangian estimates are updated. Otherwise, the penalty parameter is increased by a penalty factor (PenaltyFactor). This results in a new subproblem formulation and minimization problem. These steps are repeated until the stopping criteria are met.
I hope that this is clear. Remember, TolFun operates as a stopping criterion for GA as follows:
Function tolerance (TolFun) — The algorithm stops if the average relative change in the best fitness function value over Stall generations is less than or equal to Function tolerance.
Alan Weiss
MATLAB mathematical toolbox documentation

Sign in to comment.

Tags

Community Treasure Hunt

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

Start Hunting!