0% found this document useful (0 votes)
28 views6 pages

Ga For Op Tim Ization Using Mat Lab

Uploaded by

Miau25
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
28 views6 pages

Ga For Op Tim Ization Using Mat Lab

Uploaded by

Miau25
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 6

See discussions, stats, and author profiles for this publication at: https://www.researchgate.

net/publication/258789666

Optimization of Function by using a New MATLAB based Genetic Algorithm


Procedure

Article in International Journal of Computer Applications · January 2013


DOI: 10.5120/10001-4212

CITATIONS READS
24 8,490

3 authors:

Gn Purohit Arun Sherry


Banasthali University HCL TalentCare
89 PUBLICATIONS 480 CITATIONS 11 PUBLICATIONS 109 CITATIONS

SEE PROFILE SEE PROFILE

Manish Saraswat
Geetanjali Institute of Technical Studies
4 PUBLICATIONS 25 CITATIONS

SEE PROFILE

All content following this page was uploaded by Manish Saraswat on 23 July 2019.

The user has requested enhancement of the downloaded file.


Volume 4, No. 3, March 2013 (Special Issue)
International Journal of Advanced Research in Computer Science
RESEARCH PAPER
Available Online at www.ijarcs.info

Genetic Algorithm for optimization using MATLAB


Mr. Manish Saraswat Mr. Ajay Kumar Sharma
Research Scholar, Research Scholar,
Banasthali University, Banasthali (Rajasthan), India Mewar University, Chittorgarh (Rajasthan), India
manishsaraswat24@gmail.com profsharmaak@gmail.com
Abstract: As the applications of systems are increasing in various aspects of our daily life, it enhances the complexity of systems in
Software design (Program response according to environment) and hardware components (caches, branch predicting pipelines).Within
the past couple of years the Test Engineers have developed a new testing procedure for testing the correctness of systems: namely the
evolutionary test. The test is interpreted as a problem of optimization, and employs evolutionary computation to find the test data with
extreme execution times. Evolutionary testing denotes the use of evolutionary algorithms, e.g., Genetic Algorithms (GAs), to support
various test automation tasks. Since evolutionary algorithms are heuristics, their performance and output efficiency can vary across
multiple runs, there is strong need a environment that can be handle these complexities, Now a day’s MATLAB is widely used for this
purpose. This paper explore potential power of Genetic Algorithm for optimization by using new MATLAB based implementation of
Rastrigin’s function, throughout the paper we use this function as optimization problem to explain some key definitions of genetic
transformation like selection crossover and mutation.

Keywords: Rastrigin’s function, Evolutionary Testing, Genetic Algorithm (GA) , MatLab & Fitness.

scientist at MathWorks, Inc., to provide easy access to


I. INTRODUCTION matrix software developed in the LINPACK and
EISPACK projects [2]. MATLAB has a wide collection
Genetic algorithms are an approach to optimization and of functions useful to the genetic algorithm practitioner
learning based loosely on principles of biological and those wishing to experiment with the genetic
evolution, these are simple to construct, and its algorithm for the first time.
implementation does not require a large amount of In MATLAB’s high-level language, problems can be
storage, making them a sufficient choice for an coded in m-files in a fraction of the time that it would
optimization problems. Optimal scheduling is a take to create C or FORTRAN programs for the same
nonlinear problem that cannot be solved easily yet, a purpose. It also provide advanced data analysis,
GA could serve to find a decent solution in a limited visualization tools and special purpose application
amount of time Genetic algorithms are inspired by the domain toolboxes. This paper is organized into three
Darwin’s theory about the evolution “survival of parts: Part I describes the usefulness of GA and features
fittest”, it search the solution space of a function of new software MATLAB. Part II discusses the
through the use of simulated evolution (survival of the implementation issues of GA in various available
fittest) strategy. Generally the fittest individuals of any languages, tools and software. Finally GAs is
population have greater chance to reproduce and implemented using MATLAB for the Rastrigin’s
survive, to the next generation thus it contribute to function as case study for optimization. The Part III
improving successive generations However inferior concludes the objectives of paper.
individuals can by chance survive and also reproduce,
Genetic algorithms have been shown to solve linear and II. OVERVIEW OF PROGRAMMING
nonlinear problems by exploring all regions of the state LANGUAGES USED TO IMPLEMENTATION OF
space and exponentially exploiting promising areas GA
through the application of mutation, crossover and
selection operations to individuals in the population.The The implementation of genetic algorithm on high-
development of new software technology and the new performance computers is a difficult and time-
software environments (e.g. MATLAB) provide the consuming task. The implementing languages must be
platform to solving difficult problems in real time. It closely as possible to the mathematical description of
integrates numerical analysis, matrix computation and the problem, simple and easy-to-use procedural
graphics in an easy to use environment. language. The C/C++, FORTRAN are lower-level
MATLAB functions are simple text files of interpreted compiled programming languages (sometimes classified
instructions Therefore; these functions can be re- as a 3rd generation language) that is widely used in
implemented from one hardware architecture to another academia, industry, commerce and GA is also
without even a recompilation step. MATLAB (Matrix implemented by using these category of languages. The
Laboratory), a product of Mathworks, it is a scientific main advantage of compiled low-level languages is
software package developed to provide an integrated their execution speed and efficiency (for example
environment for numeric computation and graphics embedded systems)but now a days the MATLAB is
visualization in high-level programming language. often employed in research and industry and it is an
Originally it was written by Dr Cleve Moler, Chief example of a high-level “scripting” or “4th generation”
© 2010, IJARCS All Rights Reserved 155
“Advance Computing and Creating Entrepreneurs (ACCE2013)”
On 19-20 Feb 2013
Organized by
2nd SIG-WNs, Div IV & Udaipur Chapter , CSI , IEEE Computer Society Chapter India Council ,
IEEE Student Chapter Geetanjali Institute of Technical Studies, Udaipur, Rajasthan, India
Manish Saraswat et al, International Journal of Advanced Research in Computer Science, 4 (3) Special Issue, March 2013, 155-159
language. The most prominent difference between ready to go. The user should program (by writing m
compiled languages and interpreted languages is that files) any extended functionality required.
the interpreter program reads the source code and We will implement Rastrigin’s Functions in the proper
translates it into machine instructions on the fly, i.e. no field and number of variable is 2 and population type is
compilation is required. This decreases the execution double vector (figure 1). The equation of this
speed but it make the programmer free from memory function and Matlab (m-file) code is given as below
management, allows dynamic typing and interactive Ras(x) = 20+x12+x22-10(cos2πx1+cos2πx2)
sessions.
It is important to note that the programs written in
scripting languages are usually significantly shorter [3]
than equivalent programs written in compiled languages
and also take significantly less time to code and debug.
In short, there is a trade-off between the execution time
(small for compiled languages) and the development
time (small for interpreted languages). Another
important feature of MATLAB (and other interpreted
languages like Pythan) is the ability to have interactive
sessions. The user can type one or several commands at
the command prompt and after pressing return, these
commands are executed immediately. By this it allows
the programmer for interactive testing of small parts of
the code (without any delay stemming from
compilation) and encourages experimentation [9].
The MATLAB package comes with sophisticated Figure:1 GAs in Matlab's Optimization Toolbox
libraries for matrix operations, general numeric methods
MATLAB Code:
and plotting of data, therefore MATLAB become first
function y = rast(x)
choice of programmer to implement scientific, graphical
% the default value of n = 2.
and mathematical applications and for the GA
n = 2;
implementation MATLAB is come with special tool
s = 0;
that is GA-tool or Optimtool
for j = 1:n
III. THINGS TO CONSIDER FOR GENETIC s = s+(x(j)^2-10*cos(2*pi*x(j)));
ALGORITHMS IMPLEMENTATION IN end
MATLAB y = 10*n+s;
Now it is ready (the default settings in every-thing else
The first thing must do in order to use a GA is to decide is adequate). Press the Start button. The algorithm
if it is possible to automatically build solutions on starts, the plots are pop-up and soon the results are
problem. For example, in the Traveling Salesman displayed as in figure 2.
Problem, every route that passes through the cities in The best fitness function value (the smallest one since
question is potentially a solution, although probably not we minimize) and the termination condition met are
the optimal one. It is must to do that because a GA printed, together with the solution (Final Point – it is
requires an initial population P of solutions. very close to (0, 0)). Since the method is stochastic,
Then must decide what "gene" representation will don't expect to be able to reproduce any result found in
use we have a few alternatives like binary, integer, a different run. Now check the two plots on the left. It is
double, permutation, etc. The binary and double being obvious that the population converges, since the
the most commonly used since they are the most average distance between individuals (solutions) in term
flexible. After selecting the gene representation it must of the fitness value is reduced, as the generations pass.
be decide: This is a measure of the diversity of a population. It is
The method to select parents from the population P hard to avoid convergence but keeping it low or
(Cost Roulette Wheel, Stochastic Universal Sampling, postponing its appearance is better. Having diversity in
Rank Roulette Wheel, Tournament Selection, etc.), the the population allows the GA to search better in the
way these parents will "mate" to create descendants, solution space.
the mutation method (optional but useful), the method
will use to populate the next generation and the
algorithm's termination condition (number of
generations, time limit, acceptable quality threshold).
Now second thing is Processor and operating system
that must be capable of running the program the
algorithm is coded in MATLAB. Matlab provides an
optimization toolbox that includes a GA-based solver.
The toolbox can be start by typing optimtool in the
Matlab's command line and pressing enter. As soon as
the optimization window appears, we can select the
solver ga – Genetic Algorithm and now matlab are
Figure 2: Rastrigin’s function optimization with default setting
© 2010, IJARCS All Rights Reserved CONFERENCE PAPER II International Conference on 156
“Advance Computing and Creating Entrepreneurs (ACCE2013)”
On 19-20 Feb 2013
Organized by
2nd SIG-WNs, Div IV & Udaipur Chapter , CSI , IEEE Computer Society Chapter India Council ,
IEEE Student Chapter Geetanjali Institute of Technical Studies, Udaipur, Rajasthan, India
Manish Saraswat et al, International Journal of Advanced Research in Computer Science, 4 (3) Special Issue, March 2013, 155-159
It is seen from figure-2 the fitness value as it gradually
gets smaller. It is an indication that optimization takes
place since not only the fitness value of the best
individual was reduced, even the mean (average)
fitness of the population was also reduced (that is, in
terms of the fitness value, the whole population was
improved we have better solutions in the population, at
the end).
a. Population Diversity– size – range, fitness
scaling The performance of a GA is affected by
the diversity of the initial population. If the
average distance between individuals is large, it is
indication of high diversity; if the average
distance is small its represent low diversity in the Figure 4: Rastrigin’s function optimization with default setting,
population. except Stopping Criteria-Stall Generations set 100 and initial range
set [1; 100]
If the diversity is too high or too low, the genetic
algorithm might not perform well. We will explain this Generations in Stopping Criteria to 200) it will
by the following: By default, the Optimization Tool eventually find a better solution.
creates a random initial population using a creation Set Initial range to [1; 2] and run the GA. This returns
function. We can limit this by setting the Initial range the best fitness value of approximately 0.012 and
field in Population options. Set it to (1; 1.1). By this displays the plots that follow as in figure 5.
we actually make it harder for the GA to search equally
well in all the solutions space. Leave the rest settings as
previous (figure: 1) except Options-Stopping Criteria-
Stall Generations which should be set to 100. This will
allow the algorithm run for 100 generation providing us
with better results (and plots). Now click the Start
button.The GA returns the best fitness function value of
approximately 2 and displays the plots in as in figure 3.

Fig 5: Rastrigin’s function optimization with default setting, except


Stopping Criteria-Stall Generations set 100 & initial range set [1; 2]

The diversity in this case is better suited to the problem,


so the genetic algorithm returns a much better result
than in the previous two cases.
In all the examples above, we had the Population Size
Figure 3: Rastrigin’s function optimization with default setting, (Options-Population) set to 20 (the default). This value
except Stopping Criteria-Stall Generations set 100 and initial range
set [1; 1.1]
determines the size of the population at each generation.
Increasing the population size enables the genetic
The upper plot, which displays the best fitness at each algorithm to search more points and thereby obtain a
generation, show little progress in lowering the fitness better result. However, the larger the population size,
value (black dots). The lower plot shows the average the longer the genetic algorithm takes to compute each
distance between individuals at each generation, which generation.
is a good measure of the diversity of a population. For It is important to note that Population Size to be at least
this setting of initial range, there is too little diversity the value of Number of variables, so that the individuals
for the algorithm to make progress. The algorithm was in each population span the space being searched.
trapped in a local minimum due to the initial range Finally, another parameter that affects the diversity of
restriction. the population is the Fitness Scaling. If the fitness
Next, set Initial range to [1; 100] and run the algorithm values vary too widely Figure: 6, the individuals with
again. The GA returns the best fitness value of the lowest values (recall that we minimize) reproduce
approximately 3.3 and displays the following plots as in too rapidly, taking over the population pool too quickly
figure: 4. this time, the genetic algorithm makes and preventing the GA from searching other areas of the
progress, but because the average distance between solution space. On the other hand, if the values vary
individuals is so large, the best individuals are far from only a little, all individuals have approximately the
the optimal solution. Note though that if we let the GA same chance of reproduction and the search will
to run for more generations (by setting Generations and progress very slowly.
Stall

© 2010, IJARCS All Rights Reserved CONFERENCE PAPER II International Conference on 157
“Advance Computing and Creating Entrepreneurs (ACCE2013)”
On 19-20 Feb 2013
Organized by
2nd SIG-WNs, Div IV & Udaipur Chapter , CSI , IEEE Computer Society Chapter India Council ,
IEEE Student Chapter Geetanjali Institute of Technical Studies, Udaipur, Rajasthan, India
Manish Saraswat et al, International Journal of Advanced Research in Computer Science, 4 (3) Special Issue, March 2013, 155-159

Figure 6: Raw fitness value lower


Figure 8: Stochastic uniform selection method. For 6 parents we step
the selection line with steps equal to 15/6.

The default selection option, Stochastic Uniform, lays


out a line (Figure 8) in which each parent corresponds
to a section of the line of length proportional to its
scaled value. For example, assume a population of 4
individuals with scaled values 7, 4, 3 and 1. The
individual with the scaled value of 7 is the best and
should contribute its genes more than the rest. We
create a line of length 1+3+4+7=15. Now, let's say that
we need to select 6 individuals for parents. We step
over this line in steps of 15/6 and select the individual
for crossover.
The Reproduction panel in Options control how the GA
creates the next generation. Here you specify the
amount of elitism and the fraction of the population of
the next generation that is generated through mating
Figure 7: Raw fitness value Higher
(the rest is generated by mutation). The options are:
It is clear from the Figure: 6 Raw fitness values (lower Elite Count: the number of individuals with the best
is better) vary too widely on the. Scaled values (figure: fitness values in the current generation that are
7) do not alter the selection advantage of the good guaranteed to survive to the next generation. These
individuals (except that now bigger is better). They just individuals are called elite children. The default value
reduce the diversity we have on the above. This of Elite count is 2. Try to solve the Rastrigin's problem
prevents the GA from converging too early. by changing only this parameter. Try values of 10, 3
The Fitness Scaling adjusts the fitness values (scaled and 1. we will get results like those depicted in Figure
values) before the selection step of the GA. This is done 5. It is obvious that you should keep this value low. 1 or
without changing the ranking order, that is, the best 2 (depending on the population size).
individual based on the raw fitness value remains the
best in the scaled rank, as well. Only the values are
changed, and thus the probability of an individual to get
selected for mating by the selection procedure. This
prevents the GA from converging too fast which allows
the algorithm to better search the solution space. We
continue Rastrigin’s function implantation in
MATLAB, Use the following settings leaving every-
thing else in its default value (Fitness function:
@rastriginsfcn, Number of Variables: 2, Initial Range:
[1; 20], Plots: Best Fitness, Distance).
The Selection panel in Options controls the Selection
Function, that is, how individuals are selected to
become parents. Note that this mechanism works on the
scaled values, as described previously.
Most well-known methods are presented (uniform,
roulette and tournament). An individual can be selected
more than once as a parent, in which case it contributes
its genes to more than one child. Figure 9: Elite count 10

© 2010, IJARCS All Rights Reserved CONFERENCE PAPER II International Conference on 158
“Advance Computing and Creating Entrepreneurs (ACCE2013)”
On 19-20 Feb 2013
Organized by
2nd SIG-WNs, Div IV & Udaipur Chapter , CSI , IEEE Computer Society Chapter India Council ,
IEEE Student Chapter Geetanjali Institute of Technical Studies, Udaipur, Rajasthan, India
Manish Saraswat et al, International Journal of Advanced Research in Computer Science, 4 (3) Special Issue, March 2013, 155-159
experimental results show that GATool can improve
fitness value by providing quickly a set of near
optimum solutions. Concerning the effect of different
GA parameter configurations, it found that an increase
in population size can improve performance of the
system. The parameter of crossover rate does not affect
seriously the quality of the solution. Genetic Algorithms
are easy to apply to a wide range of optimization
problems, like the traveling salesperson problem,
inductive concept learning, scheduling, and layout
problems. The result shows that the proposed GAs with
the specification can find solutions with better quality in
shorter time. The developer uses this information to
search, locate, and debug the faults that caused the
failures. While each of these areas for future
consideration could be further investigated with respect
Figure 10: Elite count 3 to applicability for software testing, because it is also
an optimization problem with the objective that the
efforts consumed should be minimized and the number
of faults detected should be maximized. Finally, it
would be interesting for further research to test a series
of different systems in order to see the correlation
between genetic algorithm and system performances.

V. REFERENCES

[1]. D.E. Goldberg, Genetic Learning in optimization,


search and machine learning. Addisson Wesley,
1994.
[2]. J.J. Grefenstette. Genetic algorithms for changing
environments. In R. Manner abd B. Manderick,
editor, Parallel Problem Solving from Nature 2,
Figure 11: Elite count 1. pages 465-501. Elsevier Science Publishers.
[3]. Mathworks, The: Matlab - UserGuide. Natick,
From the figure 9, 10, 11 it clear that too much elitism
Mass.: The Mathworks, Inc., 1994-1999.
results in early convergence which can make the search
http://www.mathworks.com
less effective.
[4]. Henriksson, D., Cervin, A., Arzen, K.E.:
a. Crossover Fraction: is the fraction of individuals
TrueTime: Real-time control system simulation
in the next generation, other than elite children,
with MATLAB/Simulink. In: Proceedings of the
that are created by crossover (remaining is
Nordic MATLAB Conference, Copenhagen,
generated by mutation). A crossover fraction of ‘1’
Denmark (2005)
indicates means that all children other than elite
[5]. A.J. Chipperfield, P. J. Fleming and H. Pohlheim,
individuals are crossover children. A crossover
“A Genetic Algorithm Toolbox for MATLAB,”
fraction of ‘0’ indicates that all children are
Proc. International Conference on Systems
mutation children.
Engineering, Coventq, UK, 6-8 Sept 1998.
b. Two-point crossover- two crossover points are
[6]. Papadamou, S. and Stephanides, G., A New
selected, binary string from the beginning of the
Matlab-Based Toolbox For Computer Aided
chromosome to the first crossover point is copied
Dynamic Technical Trading,
from the first parent, the part from the first to the
[7]. K. Lakhotia, M. Harman, and P. McMinn. A
second crossover point is copied from the other
multi-objective approach to search-based test data
parent and the rest is copied from the first parent
generation. In Proc. 9th Annual Conf. on Genetic
again
and Evolutionary Computation (GECCO’07),
c. Mutation- It is the Random change one or more
pages 1098–1105, ACM, 2007.
digits in the string representing an individual.
[8]. Pohlheim, H.: Genetic and Evolutionary
IV. CONCLUSION Algorithm Toolbox for use with Matlab -
Documentation. Technical www.geatbx.com.
The main objective in this paper is to illustrate that how [9]. A Comparison of C, MATLAB, and Python as
the new technology of MATLAB can be used in order Teaching Languages in Engineering Hans Fangohr
to implement a genetic algorithm in optimization University of Southampton, Southampton SO17
problems. It uses the power of genetic algorithms to 1BJ, UK.
generate fast and efficient solutions in real time. The

© 2010, IJARCS All Rights Reserved CONFERENCE PAPER II International Conference on 159
“Advance Computing and Creating Entrepreneurs (ACCE2013)”
On 19-20 Feb 2013
Organized by
2nd SIG-WNs, Div IV & Udaipur Chapter , CSI , IEEE Computer Society Chapter India Council ,
View publication stats IEEE Student Chapter Geetanjali Institute of Technical Studies, Udaipur, Rajasthan, India

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy