Escuela Politécnica Nacional
MSc. Adrián Égüez
Escuela Politécnica Nacional
MSc. Adrián Égüez
Discriminar los diferentes paradigmas de programación y sus campos de aplicación.
Escuela Politécnica Nacional
MSc. Adrián Égüez
Abstraer problemas de tal manera que le permitan crear soluciones basadas en uno o varios paradigmas de programación.
Escuela Politécnica Nacional
MSc. Adrián Égüez
Practicar la ética investigativa, responsabilidad social y rigurosidad científica en la generación de prototipos y asesoría sobre los paradigmas, metodologías y lenguajes de programación demostrando honestidad, responsabilidad, dedicación y colaboración.
Escuela Politécnica Nacional
MSc. Adrián Égüez
¿Qué es paradigma?
An example that serves as pattern or model.
A pattern that serves as a school of thoughts for programming of computers
Escuela Politécnica Nacional
MSc. Adrián Égüez
¿Qué es una técnica de programación?
Related to an algorithmic idea for solving a particular class of problems
EX: Divide and conquer
Escuela Politécnica Nacional
MSc. Adrián Égüez
EX: Program development by stepwise refinement
Escuela Politécnica Nacional
MSc. Adrián Égüez
In each step, one or several instruction of the given program are decomposed into more detailed instructions. This successive decomposition or refinement of specifications terminates when all instructions are expressed in terms of an underlying computer or programming language, and must therefore be guided by the facilities available on that computer or language.
Escuela Politécnica Nacional
MSc. Adrián Égüez
¿Qué es estilo de programación?
The way we express ourselves in a computer program
Related to elegance or lack of elegance
Escuela Politécnica Nacional
MSc. Adrián Égüez
¿Qué es cultura de programación?
The totality of programming behavior, which often is tightly related to a family of programming languages
The sum of a main paradigm, programming styles, and certain programming techniques
Escuela Politécnica Nacional
MSc. Adrián Égüez
First do this and next do that
Adjective:
Expressing a command or plea
Noun: Command or an order.
Escuela Politécnica Nacional
MSc. Adrián Égüez
Meassurable effect program state
Basic idea is the command: ->
Order is Important
Escuela Politécnica Nacional
MSc. Adrián Égüez
Incremental change of the program state as a function of time
Discipline and idea
Similar to descriptions of everyday routines
Assignment, IO, procedure calls
Escuela Politécnica Nacional
MSc. Adrián Égüez
Fortran, Algol, Pascal, Basic, C
Escuela Politécnica Nacional
MSc. Adrián Égüez
Abstracts one or more actions to a procedure, which can be called as a single command
Escuela Politécnica Nacional
MSc. Adrián Égüez
Memory locations and programmers can modify the contents of variables using assignments
Escuela Politécnica Nacional
MSc. Adrián Égüez
Describe a particular class of problems itself
Are equipped with tools that allow them to abstract from details of the implementation
Concentrate on details of the problem
Escuela Politécnica Nacional
MSc. Adrián Égüez
Hiding implementation details can be considered a handicap for programmers because access to low-level details provides a high degree of flexibility
Escuela Politécnica Nacional
MSc. Adrián Égüez
However, a lot of flexibility implies a lot of potential for errors, and, more importantly, less potential for abstraction
Escuela Politécnica Nacional
MSc. Adrián Égüez
EX:
Web App C
Web App Assembly
Escuela Politécnica Nacional
MSc. Adrián Égüez
An imperative program means to execute commands
Functional program means to evaluate expressions
Escuela Politécnica Nacional
MSc. Adrián Égüez
Functions in a functional program are functions in a mathematical sense
Escuela Politécnica Nacional
MSc. Adrián Égüez
The result of a function call depends only on the values of the arguments
Escuela Politécnica Nacional
MSc. Adrián Égüez
Imperative Programming
Functions
Output
Input
Other variables
Escuela Politécnica Nacional
MSc. Adrián Égüez
Imperative Programming
Functions
Output
Input
Other variables
SIDE EFFECTS
Changed values of other variables
Escuela Politécnica Nacional
MSc. Adrián Égüez
Functional Programming
Output
Input
NO
SIDE EFFECTS
NO
OTHER VARIABLES
Escuela Politécnica Nacional
MSc. Adrián Égüez
The result of evaluating an expression is determined only by the parts of the expression
-
Not by evaluation order
Escuela Politécnica Nacional
MSc. Adrián Égüez
length::[a] -> Int
The type a used as argument to the list type constructor [ ] represents an arbitrary type
Escuela Politécnica Nacional
MSc. Adrián Égüez
Type polymorphism allows us to use type variables that represent arbitrary types
Helps to make defined functions more generally applicable
Escuela Politécnica Nacional
MSc. Adrián Égüez
Functions in a functional program can not only map data to data
Helps to make defined functions more generally applicable
f o g -> f ( g (x) )
Escuela Politécnica Nacional
MSc. Adrián Égüez
Delays the evaluation of an expression until its value is needed
Can be faster than eager evaluation because unnecessary computations are skipped
Escuela Politécnica Nacional
MSc. Adrián Égüez
Most programming languages use eager evaluation
All expressions are evaluated as soon as they are bound to a variable
Each argument is evaluated exactly once
Escuela Politécnica Nacional
MSc. Adrián Égüez
Don't support if / else / switch
Abstraction, Encapsulation, Inheritance, and Polymorphism
Use function calls
Escuela Politécnica Nacional
MSc. Adrián Égüez
Easy to test
No mutable / Parallel Programming
No state / No errors
Escuela Politécnica Nacional
MSc. Adrián Égüez
Uses Mutable data
Follows Imperative Programming Model
Escuela Politécnica Nacional
MSc. Adrián Égüez
Focus is on POO “How you are doing” / FP "What are you doing"
Its methods can produce serious side effects
Escuela Politécnica Nacional
MSc. Adrián Égüez
Flow control is done using loops and conditional statements.
Its methods can produce serious side effects
Escuela Politécnica Nacional
MSc. Adrián Égüez
POO Loop vs FP Recursion for iterate Collection Data
Execution order of statement is very important
Escuela Politécnica Nacional
MSc. Adrián Égüez
Automatic programming
Method to evolve computer programs
Escuela Politécnica Nacional
MSc. Adrián Égüez
The most potential as a way to automatically write computer programs
Give the computer a problem and ask the computer to build a program to solve it
Escuela Politécnica Nacional
MSc. Adrián Égüez
Survival of the fittest
Follows Darwin’s theory of evolution
Escuela Politécnica Nacional
MSc. Adrián Égüez
Reproduce with each other
There is a population of computer programs
(Individuals)
Escuela Politécnica Nacional
MSc. Adrián Égüez
Eventually evolve to do well in the given environment
The best individuals will survive
Escuela Politécnica Nacional
MSc. Adrián Égüez
On a field about the size of half a table-tennis table
Robotic soccer is played with three to five robots per team
Escuela Politécnica Nacional
MSc. Adrián Égüez
Bunting it with the front of their chasis
They chase around an orange golf ball
Escuela Politécnica Nacional
MSc. Adrián Égüez
It would be quite possible to use genetic programming to “design” a strategy for an entire team to play soccer
Escuela Politécnica Nacional
MSc. Adrián Égüez
The robots should “know” how to follow the ball
Before a soccer-playing team could evolve
Escuela Politécnica Nacional
MSc. Adrián Égüez
How can genetic programming be used to evolve code so that a robot will follow the ball
THE PROBLEM?
Escuela Politécnica Nacional
MSc. Adrián Égüez
Good ball-following somehow needs to be measured
We need the ability to rate an individual’s performance
Escuela Politécnica Nacional
MSc. Adrián Égüez
Produces a value called raw fitness
This measure is called a fitness test
Escuela Politécnica Nacional
MSc. Adrián Égüez
Then we’re in a position to start the evolutionary process
If we have the ability to create a random program that has some amount of control over the robot
Escuela Politécnica Nacional
MSc. Adrián Égüez
Evaluate Individual and give it a rank
Population 5000 (Individual) random programs.
Escuela Politécnica Nacional
MSc. Adrián Égüez
These individuals would reproduce with one another to produce a new population
Good individuals, that follow the ball closely, would rank highly
Escuela Politécnica Nacional
MSc. Adrián Égüez
The average performance of the new population will be better than the average of the previous population
If reproduction is biased so that highly ranked individuals reproduce more frequently
Escuela Politécnica Nacional
MSc. Adrián Égüez
It could also be expected that the best individual in the new population would be better than the best individual of the previous population
Escuela Politécnica Nacional
MSc. Adrián Égüez
After sufficient generations, the best individual in the last population would be an excellent solution to the problem
Escuela Politécnica Nacional
MSc. Adrián Égüez
It could be used to evolve computer program solutions for any problem domain so long as individual solutions can be compared and ranked
Escuela Politécnica Nacional
MSc. Adrián Égüez
The massive disadvantage of GP is the phenomenal computing resources required before any real-world problem can be tackled
Escuela Politécnica Nacional
MSc. Adrián Égüez
Which come together to form code
The fundamental elements of an individual are its genes
Escuela Politécnica Nacional
MSc. Adrián Égüez
Terminals
Functions
Escuela Politécnica Nacional
MSc. Adrián Égüez
Functions: nodes with children
Terminals: Are leaves without branches
Escuela Politécnica Nacional
MSc. Adrián Égüez
The function’s children provide the arguments for the function
Escuela Politécnica Nacional
MSc. Adrián Égüez
There are 5 terminals
Escuela Politécnica Nacional
MSc. Adrián Égüez
This is what returns
Escuela Politécnica Nacional
MSc. Adrián Égüez
The genes that will be available to the GP system must be selected or created by the user
Escuela Politécnica Nacional
MSc. Adrián Égüez
Poor selection may well render the system incapable of evolving a solution
Escuela Politécnica Nacional
MSc. Adrián Égüez
Koza specifies three techniques: namely grow, full and ramped-halfand-half
Escuela Politécnica Nacional
MSc. Adrián Égüez
The initial population will not have duplicate individuals
Escuela Politécnica Nacional
MSc. Adrián Égüez
An individual created with this method may be a tree of any depth up to a specified maximum, m
Creates one individual at a time
Escuela Politécnica Nacional
MSc. Adrián Égüez
Starting from the root of the tree every node is randomly chosen as either a function or terminal
random:
function or terminal
Escuela Politécnica Nacional
MSc. Adrián Égüez
If the node is a terminal, a random terminal is chosen
Choosen node "Y" :
Y / X / 7 / 11 / 2.2
Escuela Politécnica Nacional
MSc. Adrián Égüez
If the node is a function, a random function is chosen
Choosen node "-" :
Y / X / 7 / 11 / 2.2
Escuela Politécnica Nacional
MSc. Adrián Égüez
Individuals need to be assessed for their fitness
This is a problem specific issue:
how good (or bad) is this individual?
Escuela Politécnica Nacional
MSc. Adrián Égüez
The question could be replaced with an algorithm like
let the individual play soccer for five minutes; the fitness value is the same as the number of goals scored
Escuela Politécnica Nacional
MSc. Adrián Égüez
This could be an acceptable test as it can distinguish between different levels of ability
A good player may score six goals, while an excellent player may score ten
Escuela Politécnica Nacional
MSc. Adrián Égüez
“yes, at least one goal was scored” or “no, zero goals were scored”
The fitness test gives as detailed answer as possible
Escuela Politécnica Nacional
MSc. Adrián Égüez
In this case, the greater the value the better the individual
Escuela Politécnica Nacional
MSc. Adrián Égüez
The sum of the distances between the robot and the ball for a number of discrete times
For a ball-follower a good fitness test
Escuela Politécnica Nacional
MSc. Adrián Égüez
Apply the fitness test to all the individuals in the initial random population
The evolutionary process starts
Escuela Politécnica Nacional
MSc. Adrián Égüez
Individuals in the new population are formed by two main methods: reproduction and crossover.
Escuela Politécnica Nacional
MSc. Adrián Égüez
Reproduction is where a selected individual copies itself into the new population
Is effectively the same as one individual surviving into the next generation
Escuela Politécnica Nacional
MSc. Adrián Égüez
Koza allowed 10% of the population to reproduce
A reproduced individual does not need to be tested, as the result is already known
Escuela Politécnica Nacional
MSc. Adrián Égüez
If the fitness test does not change, reproduction can have a significant effect on the total time required for GP because a reproduced individual will have an identical fitness score to that of its parent
Escuela Politécnica Nacional
MSc. Adrián Égüez
A fitness test that has a random component, which is effectively a test that does not initialise to exactly the same starting scenario, would not apply for this increase in efficiency
Escuela Politécnica Nacional
MSc. Adrián Égüez
The selection of an individual to undergo reproduction is the responsibility of the selection function
Escuela Politécnica Nacional
MSc. Adrián Égüez
Crossover requires two individuals and produces two different individuals for the new population
Escuela Politécnica Nacional
MSc. Adrián Égüez
Genetic material from two individuals is mixed to form offspring
Koza uses crossover on 90% of the population
Escuela Politécnica Nacional
MSc. Adrián Égüez
It provides the source of new (and eventually better) individuals
It is the more important of the two methods
Escuela Politécnica Nacional
MSc. Adrián Égüez
There are a few other evolutionary operations: editing, mutation, permutation, encapsulation and decimation
Escuela Politécnica Nacional
MSc. Adrián Égüez
The user must make a number of decisions before the GP system may begin
Escuela Politécnica Nacional
MSc. Adrián Égüez
Firstly, the available genes need to be selected and created
Escuela Politécnica Nacional
MSc. Adrián Égüez
Secondly, the user must specify a number of control parameters
Escuela Politécnica Nacional
MSc. Adrián Égüez
The decisions are critically important as they have a limiting effect on the search space of possible programs
Escuela Politécnica Nacional
MSc. Adrián Égüez
Having too many limits may remove all chance of evolving an acceptable individual
Escuela Politécnica Nacional
MSc. Adrián Égüez
Not restricting the search-space sufficiently has its own issues
Escuela Politécnica Nacional
MSc. Adrián Égüez
If it is not possible to solve the problem given the available genes
What hope has the system got to evolve a solution?
Escuela Politécnica Nacional
MSc. Adrián Égüez
It is important to include every necessary function and terminal
Escuela Politécnica Nacional
MSc. Adrián Égüez
If it is not possible to solve the problem given the available genes
What hope has the system got to evolve a solution?
Escuela Politécnica Nacional
MSc. Adrián Égüez