Can anyone help me for knowing the options of genetic algorithm?

回答 (2 件)

Star Strider
Star Strider 2024 年 8 月 20 日
To list them all —
opts = optimoptions(@ga)
opts =
ga options: Set properties: No options set. Default properties: ConstraintTolerance: 1.0000e-03 CreationFcn: [] CrossoverFcn: [] CrossoverFraction: 0.8000 Display: 'final' EliteCount: '0.05*PopulationSize' FitnessLimit: -Inf FitnessScalingFcn: @fitscalingrank FunctionTolerance: 1.0000e-06 HybridFcn: [] InitialPopulationMatrix: [] InitialPopulationRange: [] InitialScoresMatrix: [] MaxGenerations: '100*numberOfVariables' MaxStallGenerations: 50 MaxStallTime: Inf MaxTime: Inf MutationFcn: [] NonlinearConstraintAlgorithm: 'auglag' OutputFcn: [] PlotFcn: [] PopulationSize: '50 when numberOfVariables <= 5, else 200' PopulationType: 'doubleVector' SelectionFcn: [] UseParallel: 0 UseVectorized: 0
Change the ones you need to change. This is a structure, so to display 'FunctionTolerance' refer to it as —
FcnTol = opts.FunctionTolerance
FcnTol = 1.0000e-06
To change it, use a similar approach —
opts.FunctionTolerance = 1E-5
opts =
ga options: Set properties: FunctionTolerance: 1.0000e-05 Default properties: ConstraintTolerance: 1.0000e-03 CreationFcn: [] CrossoverFcn: [] CrossoverFraction: 0.8000 Display: 'final' EliteCount: '0.05*PopulationSize' FitnessLimit: -Inf FitnessScalingFcn: @fitscalingrank HybridFcn: [] InitialPopulationMatrix: [] InitialPopulationRange: [] InitialScoresMatrix: [] MaxGenerations: '100*numberOfVariables' MaxStallGenerations: 50 MaxStallTime: Inf MaxTime: Inf MutationFcn: [] NonlinearConstraintAlgorithm: 'auglag' OutputFcn: [] PlotFcn: [] PopulationSize: '50 when numberOfVariables <= 5, else 200' PopulationType: 'doubleVector' SelectionFcn: [] UseParallel: 0 UseVectorized: 0
.

7 件のコメント

noura
noura 2024 年 8 月 20 日
What are they determined based on and how do I know if I need to change them or not?
Star Strider
Star Strider 2024 年 8 月 20 日
I would leave them as their set default values initially. Only change them if that would improve the results of your optimisation.
noura
noura 2024 年 8 月 20 日
Sorry for asking again but i'm beginner in matlab How can i test the optimization results?
Star Strider
Star Strider 2024 年 8 月 20 日
No wories!
Run your ga code and see if the resulkts are essentially what you expect. If they are not, first check your fitness function (or your objective function, depending no how your fitness function is constructed) to be certain it is doing the correct calculations. (One way to do that would be to give it a set of appropriate parameters and then run it to see what it produces. It does not have to be exact — that is the purpose of running the optimisation — however it has to make sense and produce a reasonable result.) After that, run the ga optimisation a few times to see what it cones up with. If some of the results are acceptable although imprecise, set the appropriate options to decrease the tolerances or increase the number of generations and see if you can improve the result. (I have sets of options that I use for specific problems, so when you find a set that works, save it somewhere to use with similar problems.)
Note: to list all of the options,
orderfields(struct(optimoptions(@ga)))
Warning: Calling STRUCT on an object prevents the object from hiding its implementation details and should thus be avoided. Use DISP or DISPLAY to see the visible public details of an object. See 'help struct' for more information.
ans = struct with fields:
ConstraintTolerance: 1.0000e-03 CreationFcn: [] CrossoverFcn: [] CrossoverFraction: 0.8000 Display: 'final' EliteCount: '0.05*PopulationSize' FitnessLimit: -Inf FitnessScalingFcn: @fitscalingrank FromOptimProblem: 0 FunctionTolerance: 1.0000e-06 GaVersion: 2 GacommonVersion: 2 Generations: '100*numberOfVariables' HybridFcn: [] InitialPenalty: 10 InitialPopulation: [] InitialPopulationMatrix: [] InitialPopulationRange: [] InitialScores: [] InitialScoresMatrix: [] IntegerTolerance: 1.0000e-05 MaxGenerations: '100*numberOfVariables' MaxStallGenerations: 50 MaxStallTime: Inf MaxTime: Inf MigrationDirection: 'forward' MigrationFraction: 0.2000 MigrationInterval: 20 MutationFcn: [] NonlinConAlgorithm: 'auglag' NonlinearConstraintAlgorithm: 'auglag' OptionsStore: [1x1 struct] OutputFcn: [] OutputFcns: [] PenaltyFactor: 100 PlotFcn: [] PlotFcns: [] PlotInterval: 1 PopInitRange: [] PopulationSize: '50 when numberOfVariables <= 5, else 200' PopulationType: 'doubleVector' ProblemdefOptions: [1x1 struct] PropertyMetaInfo: [1x1 struct] SelectionFcn: [] SolverName: 'ga' StallGenLimit: 50 StallTest: 'averageChange' StallTimeLimit: Inf TimeLimit: Inf TolCon: 1.0000e-03 TolFun: 1.0000e-06 UseParallel: 0 UseVectorized: 0 Vectorized: 'off' Version: []
noura
noura 2024 年 8 月 21 日
What about the time it took more than 8 hours and doesn't complete?
Star Strider
Star Strider 2024 年 8 月 21 日
@noura — That depends on what the problem is, how many parameters are in the model, and the nature of the fitness function itself.
In my optimoptions structure, I include:
'PlotFcn',@gaplotbestf, 'PlotInterval',1
This tells me how the fitness is progressing.
I would have to see (and understand) your fitness function in order to provide anything further.

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

Steven Lord
Steven Lord 2024 年 8 月 20 日

0 投票

Since you've said you're a beginner with MATLAB (and presumably Global Optimization Toolbox), I recommend starting off with the tutorials for how to get started with Global Optimization Toolbox on this documentation page. There are also three examples linked from that page (click the Examples link just below the blue Help Center bar running across the screen, direct link is here.) The examples don't go into the various options available to the various solvers in that much depth, as they're intended to help you get started and at least at first you may not need to change those options.
There are a few examples in the Genetic Algorithm category that go into a little more depth about those options. I'm looking specifically at "Effects of Genetic Algorithm Options". To get to that category, click on "Genetic Algorithm" on the "Get Started" Examples page (the second link above, direct link to those examples here.)
Finally, looking at the list of Self-Paced Online Courses (the "Training Courses" link from the Help Center, direct link here) I'm not 100% sure if the Optimization Onramp covers Global Optimization Toolbox as well or if it focuses mainly or solely on Optimization Toolbox. But it may be of interest and/or use to you.

カテゴリ

質問済み:

2024 年 8 月 20 日

コメント済み:

2024 年 8 月 21 日

Community Treasure Hunt

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

Start Hunting!

Translated by