Search All of the Math Forum:

Views expressed in these public forums are not endorsed by NCTM or The Math Forum.

Notice: We are no longer accepting new posts, but the forums will continue to be readable.

Topic: plot genetic algorithm output
Replies: 2   Last Post: Jun 7, 2013 5:34 PM

 Messages: [ Previous | Next ]
 Alan Weiss Posts: 1,430 Registered: 11/27/08
Re: plot genetic algorithm output
Posted: Jun 7, 2013 3:24 PM

On 6/7/2013 2:31 PM, mado wrote:
> how to plot X or Kp against the number of generations on y axis ?
>
> clc
> clear
> %initialize genetic
> %___________________________________
> nvar=2;
> FitnessFcn = @PID_objfun_ITAE
> LB=[4 2 ];UB=[50 80 ];
> options = gaoptimset;
> options=gaoptimset(options,'populationsize',30,'Generations',6,'SelectionFcn',
> @selectionroulette) %options = gaoptimset(options,'InitialPop',
> final_pop); % to improve search
> options = gaoptimset(options,'MutationFcn' ,{ @mutationuniform 0.001 });
> options = gaoptimset(options,'CrossoverFcn',@crossoverarithmetic);
> options = gaoptimset(options,'PopInitRange' ,[4 2 ;50 80 ]);% bounds
> for ITAE
> %options = gaoptimset(options,'PopInitRange' ,[3 2 0;12 15
> 5]);%bounds for MSE
> options = gaoptimset(options,'PlotFcns', { @gaplotbestf
> @gaplotbestindiv });
>
> %start algorithm
> %______________________________________
> [x,fval,exitflag,output,final_pop]=ga(FitnessFcn,nvar,[],[],[],[],LB,UB,[],options)
>
> fprintf('Genetic Algorithm values :KP = %7.5f;KI = %7.4f ',x(1),x(2) )

You can write a custom plot function to plot whatever you like:

Here is an example: