Main Content

이 번역 페이지는 최신 내용을 담고 있지 않습니다. 최신 내용을 영문으로 보려면 여기를 클릭하십시오.

최대 세대 수와 정체 세대 수 설정

MaxGenerations 옵션은 유전 알고리즘에서 사용하는 최대 세대 수를 결정합니다. Stopping Conditions for the Algorithm 항목을 참조하십시오. MaxGenerations를 늘리면 최종 결과를 개선할 수 있습니다. 관련 옵션인 MaxStallGenerationsga가 몇 스텝에 걸쳐 진척 상황을 검토할지 제어합니다. MaxStallGenerations를 늘리면 알고리즘이 함수 실행을 더 많이 수행하여 더 나은 해를 구해야 할 때 ga가 이를 계속 진행하도록 할 수 있습니다.

예를 들어, 10개 변수와 디폴트 파라미터를 사용하여 rastriginsfcn을 최적화해 보겠습니다. 솔버가 최솟값 0으로 가까워지는 과정을 관찰하기 위해 함수의 로그를 최적화합니다.

rng default % For reproducibility
fun = @(x)log(rastriginsfcn(x));
nvar = 10;
options = optimoptions('ga','PlotFcn',"gaplotbestf");
[x,fval] = ga(fun,nvar,[],[],[],[],[],[],[],options)
ga stopped because the average change in the fitness value is less than options.FunctionTolerance.

Figure Genetic Algorithm contains an axes object. The axes object with title Best: 1.45396 Mean: 4.52748, xlabel Generation, ylabel Fitness value contains 2 objects of type scatter. These objects represent Best fitness, Mean fitness.

x = 1×10

   -0.0495   -0.0670   -0.0485    0.0174   -0.0087    0.0275   -0.0383    0.0620   -1.0047   -0.0298

fval = 1.4540

ga가 원점의 최적점에 근접하면 멈춥니다. 더 나은 해를 얻기 위해 정체 세대 제한을 500으로, 세대 제한을 1,000으로 설정합니다.

options = optimoptions(options,'MaxStallGenerations',500,'MaxGenerations',1000);
rng default % For reproducibility
[x,fval] = ga(fun,nvar,[],[],[],[],[],[],[],options)
ga stopped because it exceeded options.MaxGenerations.

Figure Genetic Algorithm contains an axes object. The axes object with title Best: -3.14667 Mean: -1.31642, xlabel Generation, ylabel Fitness value contains 2 objects of type scatter. These objects represent Best fitness, Mean fitness.

x = 1×10

    0.0025   -0.0039    0.0021   -0.0030   -0.0053    0.0033    0.0080    0.0012    0.0006    0.0088

fval = -3.1467

이번에는 솔버가 실제 최솟값에 훨씬 더 가깝게 근접합니다.

관련 항목