Download with a, x, z ∈ R. The minimal function set

Survey
yes no Was this document useful for you?
   Thank you for your participation!

* Your assessment is very important for improving the workof artificial intelligence, which forms the content of this project

Document related concepts

Genetic drift wikipedia , lookup

Microevolution wikipedia , lookup

Genetically modified food wikipedia , lookup

Population genetics wikipedia , lookup

Koinophilia wikipedia , lookup

Gene expression programming wikipedia , lookup

Transcript
Selected Topics in CI I
Genetic Programming
Dr. Widodo Budiharto 2014
Agenda
• Introduction to Genetic Programming
• Tree-Based Representation
Bina Nusantara University
2
introduction
• Genetic programming (GP) is one of the most useful,
general-purpose problem solving techniques available to
developers. It has been used to solve a wide range of
problems, such as symbolic regression, data mining,
optimization, and emergent behavior in biological
communities.
• GP is one instance of the class of techniques called
evolutionary algorithms, which are based on insights
from the study of natural selection and evolution.
Evolutionary algorithms solve problems not by explicit
design and analysis, but by a process akin to natural
selection.
Bina Nusantara University
3
introduction
• An evolutionary algorithm solves a problem by first
generating a large number of random problem solvers
(programs). Each problem solver is executed and rated
according to a fitness metric defined by the developer.
• In the same way that evolution in nature results from
natural selection, an evolutionary algorithm selects the
best problem solvers in each generation and breeds
them.
Bina Nusantara University
4
introduction
• Genetic programming and genetic algorithms are two
different evolutionary algorithms. Genetic algorithms
involve encoded strings that represent particular problem
solutions. These encoded strings are run through a
simulator and the best strings are mixed to form a new
generation. Genetic programming, follows a different
approach. Instead of encoding a representation of a
solution, GP breeds executable computer programs.
Bina Nusantara University
5
introduction
Bina Nusantara University
6
Introduction
• Originally, GP was developed by Koza to evolve
computer programs in1980s
• A specialization of GAs, where tree-based
representations are used
• Originally developed to evolve computer programs
• As part of the fitness function, each program is executed
to determine its outcomes
Bina Nusantara University
7
• Tree-based representations have a number of
implications that the reader should be aware of:
• Adaptive individuals: Contrary to GAs where the size
of individuals are usually fixed, a GP population will
usually have individuals of different size, shape and
complexity.
• Domain-specific grammar: A grammar needs to be
defined that accurately reflects the problem to be solved.
It should be possible to represent any possible solution
using the defined grammar.
Bina Nusantara University
8
grammar
• a grammar forms an important part of chromosome
representation. As part of the grammar, a terminal set,
function set, and semantic rules need to be defined.
• The terminal set specifies all the variables and
constants, while the function set contains all the
functions that can be applied to the elements of the
terminal set.
Bina Nusantara University
9
example
Bina Nusantara University
10
• Two examples are given next to illustrate GP
representations. One of the first applications of GP was
to evolve Boolean expressions. Consider the expression
• For this problem, the function set is defined as
{AND,OR,NOT}, and
• the terminal set is {x1, x2} where x1, x2 ∈ {0, 1}.
Bina Nusantara University
11
Bina Nusantara University
12
Bina Nusantara University
13
• The next example considers the problem of evolving a
mathematical expression. Consider the task of evolving
the program,
y:=x*ln(a)+sin(z)/exp(-x)-3.4;
• The terminal set is specified as {a, x, z, 3.4} with a, x, z ∈
R. The minimal function set is given as {−,+, ∗, /, sin,
exp, ln}. The global optimum is illustrated in Figure.
Bina Nusantara University
14
example
• The problem is to develop an artificial ant that will
efficiently walk a grid that has a weaving trail of food on
it.
• The objective is to breed the ant that will gather the
maximum amount of food in the minimum number of
steps.
Bina Nusantara University
15
example
• Develop an intelligent strategy to be used by a simple
artificial ant. The ant moves on a 32x32 grid, and if it
moves off one side it returns on the other side.
• The grid has a winding trail of food on it. The trail begins
at the [0,0] origin, which is also the starting position of
the ant. Each grid location in the trail can be empty,
contain food, or contain an indicator that it is a gap
between food locations. The trail must be continuous
from the origin. All food must be adjacent to at least one
point that has food or a marked gap.
Bina Nusantara University
16
example
• The ant has two elements that fully describe its state.
The first is its current location on the grid. The second is
the direction it is facing, which is either left, right, up, or
down. The ant has three possible things it can do. It can
turn left, turn right, or move to the square that it is facing.
It has only one sensor for its environment: a function
called FacingFood which will tell it if there is food in the
square that it is facing.
• When an ant moves to a square that contains food, it
removes the food from the grid and increments the total
food it has gathered. When it moves or turns, it
increments the number of steps it has taken to gather its
food.
17
Bina Nusantara University
example
• Generations The algorithm will stop after this number of
generations is produced.
• Population This is the number of ants each generation will have.
The population will be a mixture of the most efficient ants from the
previous generation, together with their children.
• Max Tree Depth The algorithm begins by generating random
ants. This setting controls how deep their expression trees can be.
• Food Goal and Step Goal We'd like to breed an ant that will
gather this much food in these few steps. By default, these will
reflect the food and gap counts in the active grid. However, the
computed Step Goal doesn't reflect the turn operations that an ant
will need to make when the trail changes direction.
Bina Nusantara University
18
problem
• The problem is to create an ant that will make an
intelligent series of moves and turns based on its
FacingFood function. An example would be:
if (FacingFood()) { Move(); } else { TurnRight(); Move(); }
Bina Nusantara University
19
Bina Nusantara University
20
Run it
Bina Nusantara University
21
Bina Nusantara University
22
• The GP algorithm begins by generating a population of
random expressions. One parameter that controls the
algorithm is population size. These expressions are then
executed and evaluated, using a fitness measure.
• I want to select efficient ants, those that gather a lot of
food with few steps, so the fitness measure weighs both
food gathered and the number of steps used. In my
implementation, I subtract the steps from the food
gathered and add 1000, so that fitness is always
positive. Hence an ant with a higher fitness measure is
going to be more successful than an ant with a lower
measure.
Bina Nusantara University
23
• When the initial, random first generation is completed,
the real work of GP begins. The first step is selection,
which is choosing the best ants and copying them to the
next generation.
• Subsequent generations begin with the pool of parents
that were replicated from the prior generation. Parents
are selected according to fitness. In general, fitter
parents are more likely to be selected to breed.
• The crossover algorithm (see Figure 5) is used to breed
a pair of children from a pair of parents.
Bina Nusantara University
24
Bina Nusantara University
25
• Most GP algorithms also implement mutation. This
involves making a random change in a small number of
offspring in order to maintain diversity in the population.
Mutation is essential because otherwise the population
becomes completely dominated by a few good
bloodlines, which makes it difficult to continue progress
beyond a certain point.
• This implementation performs a simple mutation step
during the crossover operation to introduce randomness.
When a terminal node is copied, a random terminal is
substituted two percent of the time.
Bina Nusantara University
26
Ant Class
• An Ant is initialized by passing it a reference to a grid,
integers that specify the food goal, and the maximum
number of steps:
public Void Init(Cell[,] grid, int StepLimit, int FoodGoal)
Bina Nusantara University
27
experiment
• Start the application, press the Get Grid
button, and open the code file (called
AlternateGrid.xml in the download). The
winding trail has 76 pieces of food, with
many gaps of one or two spaces. Change
the number of generations to 20 and click
the Generate button. When execution
completes, the generation summary will
show a clear increase in average fitness.
Select Generation 20, and then select its
best ant. Since the Generator works off of a
Random instance with a fixed seed, the best
ant in this generation will have gathered 65
items of food in 400 steps
Bina Nusantara University
28
Bina Nusantara University
29
exercise
• Create a report of program using Excel :
Bina Nusantara University
30