3. WHAT IS GENETIC ALGORITHM?
• In computer science and operations research, a genetic algorithm (GA) is a
metaheuristic inspired by the process of natural selection that belongs to the larger
class of evolutionary algorithms (EA). Genetic algorithms are commonly used to
generate high-quality solutions to optimization and search problems by relying on
bio-inspired operators such as mutation, crossover and selection –Wikipedia-
4. EXAMPLE OF GENETIC ALGORITHMS
• Swing, Pathfinding, Image generation, compression and so on.
5. DEMO : SWING
• It’s difficult to create an algorithm to get the most efficient ride on the swing.
• What people can do,
• Bending, Standing up and so on.
• What’s the most efficient behavior?
• To reach the highest position!
• Do not use external forces(no hack!)
13. MATING, BREEDING
• In the same way as real nature
• What if pretty woman, handsome man are married and get the baby,
• You can have pretty or handsome baby(well… not 100%)
• What if smartest woman, man are married and get the baby,
• Maybe he/she will be smart…(well… not 100%)
• What if most skilled people who is good at swing are married and get the baby,
• There are many different mating algorithms.
• 50% DNA from father and 50% DNA from mother…
• There are many different algorithms for this particular jobs.
14. OK, NOW WE HAVE SECOND GENERATIONS.
• Randomly crossed among N groups to make N children.
• This is the first generation.
• After that, make them to swing!
• Based on theirs's score, crossover, mutation, breeding and prepare the next
generations.
• If we continue this steps N times, we can say that the generation is changed N times.
20. LET’S THINK FOR A SECOND
• What does it take to have a child?
• Spouse
• To meet spouse,
• Pretty
• Handsome
• Lots of money
• Good heart
• Smart
• Cooking skill
• Random…
• And so on
21. THINK MORE
• Would early mankind have an eye?
• Would early mankind have a nose?
• If you are good at fighting, is there better chance to get marry?
• Do people need legs in the future? Do we really need legs?
22. WHAT WE CAN DO WITH GENETIC
ALGORITHM?
• Image generation
• Pathfinding
• Creative Gameplay
• Compression
• etc.
24. NUMBER OF PIXELS REQUIRED TO
REPRESENT AN IMAGE
• Width * Height * Byte per pixel
• For example
• 512 x 512 x 4 = 1048576 bytes needs.
25.
26. DIFFERENT WAY TO REPRESENT AN IMAGE
• To draw circle,
• x, y, radius, color needs.
• 4 elements.
• To draw rectangle,
• x, y, width, height, color needs
• 5 elements.
27. • Assume one property consume 4 bytes,
• To draw one circle, we need 16 bytes
• 4 x 4 = 16 bytes
• To draw one rectangle, we need 20 bytes
• 4 x 5 = 20 bytes
• There are 2 rectangles so we need 40 bytes.
• Total bytes needs : 56 bytes
• It is 1800 times better!
31. HOW TO DRAW?
• Randomly choose x, y coordinates.
• Randomly choose color.
• Randomly choose radius.
• Randomly choose move.
• Randomly choose add more shapes.
• Randomly choose remove shapes.
• Draw
32. EVALUATE SCORE(FITNESS)
• Let original image is o and DNA’s image is p.
𝐹𝑖𝑡𝑛𝑒𝑠𝑠 =
𝑦
ℎ
𝑥
𝑤
𝑝 𝑥,𝑦 − 𝑜 𝑥,𝑦
• Low 𝐹𝑖𝑡𝑛𝑒𝑠𝑠 means good.
• Higher fitness means, difference between two images are high.
• Of course there are many different ways to compare two images.
• For instance, we can use histogram of the images.
35. CHOOSE BEST IMAGE
• What’s the best image?
• Lowest fitness image
• Difference between two image are low which means two images are similar!
• Crossover, Mutation
• My program does not use crossover, only used mutation.
36. COMPARE TWO IMAGES.
• If new image’s (using different DNA) fitness is lower than previous DNA image, it
means new image is more similar than previous image.
• If so update current DNA
44. DISADVANTAGE
• To get a similar image, it took lot of time.
• There is no guarantee that the exact same image will come out.
• If we do it infinitely?
45. THINK ABOUT : CAN WE APPLY IT TO
GAMEPLAY MECHANISM?
Producer : Wow… this is cool. What we can make with this technology?
Programmer : Hmm… that is you should let me know…