Finding a Sorting Algorithm Using Genetic Programming May 22, 2003 Hyunkoo Jee.

Slides:



Advertisements
Similar presentations
Selection Sort Wei Guo. Selection sort Algorithm 1 1 st. Find the index of the largest element and exchange the position with the element at the last.
Advertisements

1 Genetic Algorithms Contents 1. Basic Concepts 2. Algorithm 3. Practical considerations.
MATH 224 – Discrete Mathematics
CS6800 Advanced Theory of Computation
Genetic Algorithms Contents 1. Basic Concepts 2. Algorithm
Quicksort CS 3358 Data Structures. Sorting II/ Slide 2 Introduction Fastest known sorting algorithm in practice * Average case: O(N log N) * Worst case:
Quicksort COMP171 Fall Sorting II/ Slide 2 Introduction * Fastest known sorting algorithm in practice * Average case: O(N log N) * Worst case: O(N.
CMPS1371 Introduction to Computing for Engineers SORTING.
7.Quicksort Hsu, Lih-Hsing. Computer Theory Lab. Chapter 7P Description of quicksort Divide Conquer Combine.
Spie98-1 Evolutionary Algorithms, Simulated Annealing, and Tabu Search: A Comparative Study H. Youssef, S. M. Sait, H. Adiche
CS Section 600 CS Section 002 Dr. Angela Guercio Spring 2010.
Simple Sorting Algorithms
COMP305. Part II. Genetic Algorithms. Genetic Algorithms.
CSE 830: Design and Theory of Algorithms
Artificial Intelligence Genetic Algorithms and Applications of Genetic Algorithms in Compilers Prasad A. Kulkarni.
CSC344: AI for Games Lecture 4: Informed search
CS2420: Lecture 8 Vladimir Kulyukin Computer Science Department Utah State University.
Genetic Algorithm What is a genetic algorithm? “Genetic Algorithms are defined as global optimization procedures that use an analogy of genetic evolution.
Chapter 6: Transform and Conquer Genetic Algorithms The Design and Analysis of Algorithms.
Value Iteration 0: step 0. Insertion Sort Array index67 Iteration i. Repeatedly swap element i with.
Simple Sorting Algorithms. 2 Bubble sort Compare each element (except the last one) with its neighbor to the right If they are out of order, swap them.
Simple Sorting Algorithms. 2 Outline We are going to look at three simple sorting techniques: Bubble Sort, Selection Sort, and Insertion Sort We are going.
Advance Data Structure 1 College Of Mathematic & Computer Sciences 1 Computer Sciences Department م. م علي عبد الكريم حبيب.
HOW TO SOLVE IT? Algorithms. An Algorithm An algorithm is any well-defined (computational) procedure that takes some value, or set of values, as input.
Genetic Algorithm.
SOFT COMPUTING (Optimization Techniques using GA) Dr. N.Uma Maheswari Professor/CSE PSNA CET.
Chapter 7 Quicksort Ack: This presentation is based on the lecture slides from Hsu, Lih- Hsing, as well as various materials from the web.
Fall 2013 Instructor: Reza Entezari-Maleki Sharif University of Technology 1 Fundamentals of Programming Session 17 These.
Lecture 4. RAM Model, Space and Time Complexity
Zorica Stanimirović Faculty of Mathematics, University of Belgrade
Design of an Evolutionary Algorithm M&F, ch. 7 why I like this textbook and what I don’t like about it!
More on Heuristics Genetic Algorithms (GA) Terminology Chromosome –candidate solution - {x 1, x 2,...., x n } Gene –variable - x j Allele –numerical.
CS 61B Data Structures and Programming Methodology July 28, 2008 David Sun.
Applying Genetic Algorithm to the Knapsack Problem Qi Su ECE 539 Spring 2001 Course Project.
Christoph F. Eick: Using EC to Solve Transportation Problems On Initialization and Mutation 1.Values t ij have to be between 0 and min(source(i),distination(j))
Christoph F. Eick: Using EC to Solve Transportation Problems Transportation Problems.
Fundamentals of Algorithms MCS - 2 Lecture # 15. Bubble Sort.
DYNAMIC FACILITY LAYOUT : GENETIC ALGORITHM BASED MODEL
Genetic Algorithms What is a GA Terms and definitions Basic algorithm.
ECE 103 Engineering Programming Chapter 52 Generic Algorithm Herbert G. Mayer, PSU CS Status 6/4/2014 Initial content copied verbatim from ECE 103 material.
Quicksort CSE 2320 – Algorithms and Data Structures Vassilis Athitsos University of Texas at Arlington 1.
Genetic Algorithms. The Basic Genetic Algorithm 1.[Start] Generate random population of n chromosomes (suitable solutions for the problem) 2.[Fitness]
Coevolutionary Automated Software Correction Josh Wilkerson PhD Candidate in Computer Science Missouri S&T.
Adaptive Sorting “A Dynamically Tuned Sorting Library” “Optimizing Sorting with Genetic Algorithms” By Xiaoming Li, Maria Jesus Garzaran, and David Padua.
GENETIC ALGORITHM Basic Algorithm begin set time t = 0;
CS 162 Intro to Programming II Insertion Sort 1. Assume the initial sequence a[0] a[1] … a[k] is already sorted k = 0 when the algorithm starts Insert.
Computer Science 1620 Sorting. cases exist where we would like our data to be in ascending (descending order) binary searching printing purposes selection.
1 Contents 1. Basic Concepts 2. Algorithm 3. Practical considerations Genetic Algorithm (GA)
1 Comparative Study of two Genetic Algorithms Based Task Allocation Models in Distributed Computing System Oğuzhan TAŞ 2005.
Developing resource consolidation frameworks for moldable virtual machines in clouds Author: Liang He, Deqing Zou, Zhang Zhang, etc Presenter: Weida Zhong.
CS6045: Advanced Algorithms Sorting Algorithms. Sorting Input: sequence of numbers Output: a sorted sequence.
Constraints Satisfaction Edmondo Trentin, DIISM. Constraint Satisfaction Problems: Local Search In many optimization problems, the path to the goal is.
1 Genetic Algorithms Contents 1. Basic Concepts 2. Algorithm 3. Practical considerations.
Genetic Algorithms.
USING MICROBIAL GENETIC ALGORITHM TO SOLVE CARD SPLITTING PROBLEM.
Data Structures and Algorithms
Who cares about implementation and precision?
Simple Sorting Algorithms
Hash Functions/Review
Genetic Algorithms CPSC 212 Spring 2004.
CS621: Artificial Intelligence
Algorithm design and Analysis
Ch 7: Quicksort Ming-Te Chi
Multi-Objective Optimization
Sorting … and Insertion Sort.
Searching for solutions: Genetic Algorithms
Simple Sorting Algorithms
Simple Sorting Algorithms
Algorithms and Data Structures
Presentation transcript:

Finding a Sorting Algorithm Using Genetic Programming May 22, 2003 Hyunkoo Jee

Defining a Virtual Machine and the Syntax of the Programming Language (1/4) Resources that can be used by the VM Array of registers : A[0], …, A[N-1] Index registers : I1, I2 (initial value : 0) Machine Instructions and the Syntax Syntax One instruction (and its operands) per one line An instruction can have at most two operands Line number is assigned as 0, 1, 2, …

Defining a Virtual Machine and the Syntax of the Programming Language (2/4) Example 0: PUT I2 ← I1 1: INC I2 2: EXCH 3: BR (I2 >= N-1) 5 4: BR (I1 < I2) 1 5: INC I1 6: BR (I1 < I2) 0

Defining a Virtual Machine and the Syntax of the Programming Language (3/4) Instructions EXCH : (Exchange) First, it compares A[I1] and A[I2]. And, if there is an inversion, it exchanges the values of A[I1] and A[I2]. If “0<=I1<=N-1 and 0<=I2<=N-1” is not satisfied, this instruction doesn’t do anything. INC operand1 : (Increase) It increases the value of the register specified in operand1. Operand1 can be I1 or I2. DEC operand1 : (Decrease) It decreases the value of the register specified in operand1. Operand1 can be I1 or I2. PUT operand1 : It copies the value of a register into another register. Operand1 can be “I2 ← I1” or “I1 ← I2”. BR operand1 operand2 : (Conditional branch) If the condition specified in operand1 is true, jump to the line specified in operand2. operand1 can be… I1 <= 0 I2 <= 0 I1 >= N-1 I2 >= N-1 I1 < I2 I1 > I2 I1 = I2 operand2 is the line number to jump to.

Defining a Virtual Machine and the Syntax of the Programming Language (4/4) A priori constraints that the programs must satisfy Use the instruction “EXCH” exactly one time

Defining the Cost Function (or Fitness Function) Weighted sum of Inversion = #( {(i,j) | i A[j], 0<=i,j<=N-1} ) Runtime = (how many instructions executed) Length = (how many lines)

Evaluation Implement the virtual machine, or an emulating program Execute the individual candidates(=programs) on this VM, and compute the cost function of each candidates. Here we generate T arrays, each array has N elements. Let each individual sort these T arrays. And we compute the average of the T cost values of each individual. If “runtime” exceed some threshold, stop the VM (unless it would run an infinite loop).

Defining the Evolutionary Operations 4 Mutation Methods Insert a new line When inserting a line including “BR”, the “operand2” should be in an adequate range. Don’t insert “EXCH” line. Delete a line Don’t delete “EXCH” line. Swap two lines Mutate a line Do not touch the instruction. Mutate the operands only. To mutate an individual candidate, randomly apply these 4 methods, O times.

Selection (how to generate the next generation)

Summary of the Procedure Make P initial individual candidates At first, each individual(=program) has only one line, i.e. “EXCH” To generate the initial population, apply the mutation methods I times to each individual. Evaluate the cost function Generate T arrays, each of them has N elements. Put these T arrays to each individual in current generation. And evaluate the cost function f for each individual. Selection Classify the individuals in the current generation as : best group(S candidates), worst group(S), ordinary group(P-2S) (according to the cost-function ranking) Make the next generation with : best group, mutated best group, mutated ordinary group (Here we apply the mutation method O times, in order to mutate an individual) Jump to “Evaluate the cost function” again, and repeat

Experimental Condition T = 20 How many sample arrays, needed to evaluate the cost function of a candidate? N = 10 How many elements in each array? I = 20 How many times we apply the mutation methods, when we generate the initial population? O = 5 How many times we apply the mutation methods, when we mutate an individual? W runtime = W inversion = W length = P = 500 How many individuals in a generation? S = 120 How many individuals in the best group (preserved for the next generation)? = How many individuals in the worst group?

Experimental Results

After the 2000th generation, the best individual doesn't change. The best individual 0: DEC I2 1: BR (I2 <= 0) 12 2: PUT I1 ← I2 3: DEC I1 4: EXCH 5: BR (I1 <= 0) 0 6: DEC I1 7: BR (I1 < I2) 4 8: INC I1 9: PUT I2 ← I1 10: BR (I1 >= N-1) 3 11: INC I1 12: BR (I1 > I2) 8 Runtime = 224, Inversion = 0, Length = 13 Cost Function = 0.177

Experimental Results After the 2000th generation, the best individual doesn't change. The best individual 0: DEC I2 1: BR (I2 <= 0) 12 2: PUT I1 ← I2 3: DEC I1 4: EXCH 5: BR (I1 <= 0) 0 6: DEC I1 7: BR (I1 < I2) 4 8: INC I1 9: PUT I2 ← I1 10: BR (I1 >= N-1) 3 11: INC I1 12: BR (I1 > I2) 8 Runtime = 224, Inversion = 0, Length = 13 Cost Function = 0.177

Experimental Results After the 2000th generation, the best individual doesn't change. The best individual 0: DEC I2 1: BR (I2 <= 0) 12 2: PUT I1 ← I2 3: DEC I1 4: EXCH 5: BR (I1 <= 0) 0 6: DEC I1 7: BR (I1 < I2) 4 8: INC I1 9: PUT I2 ← I1 10: BR (I1 >= N-1) 3 11: INC I1 12: BR (I1 > I2) 8 Runtime = 224, Inversion = 0, Length = 13 Cost Function = 0.177

Experimental Results After the 2000th generation, the best individual doesn't change. The best individual 0: DEC I2 1: BR (I2 <= 0) 12 2: PUT I1 ← I2 3: DEC I1 4: EXCH 5: BR (I1 <= 0) 0 6: DEC I1 7: BR (I1 < I2) 4 8: INC I1 9: PUT I2 ← I1 10: BR (I1 >= N-1) 3 11: INC I1 12: BR (I1 > I2) 8 Runtime = 224, Inversion = 0, Length = 13 Cost Function = I1 과 I2 를 N-1 까지 증가시키는 루프

Experimental Results After the 2000th generation, the best individual doesn't change. The best individual 0: DEC I2 1: BR (I2 <= 0) 12 2: PUT I1 ← I2 3: DEC I1 4: EXCH 5: BR (I1 <= 0) 0 6: DEC I1 7: BR (I1 < I2) 4 8: INC I1 9: PUT I2 ← I1 10: BR (I1 >= N-1) 3 11: INC I1 12: BR (I1 > I2) 8 Runtime = 224, Inversion = 0, Length = 13 Cost Function = 0.177

Experimental Results After the 2000th generation, the best individual doesn't change. The best individual 0: DEC I2 1: BR (I2 <= 0) 12 2: PUT I1 ← I2 3: DEC I1 4: EXCH 5: BR (I1 <= 0) 0 6: DEC I1 7: BR (I1 < I2) 4 8: INC I1 9: PUT I2 ← I1 10: BR (I1 >= N-1) 3 11: INC I1 12: BR (I1 > I2) 8 Runtime = 224, Inversion = 0, Length = 13 Cost Function = I1 을 계속 감소시키면서, A[I1] 과 A[I2] 가 inversion 된 경우 이 둘을 exchange 결국 A[0]~A[I2] 중 가장 큰 값이 A[I2] 로 들어 가게 된다

Experimental Results After the 2000th generation, the best individual doesn't change. The best individual 0: DEC I2 1: BR (I2 <= 0) 12 2: PUT I1 ← I2 3: DEC I1 4: EXCH 5: BR (I1 <= 0) 0 6: DEC I1 7: BR (I1 < I2) 4 8: INC I1 9: PUT I2 ← I1 10: BR (I1 >= N-1) 3 11: INC I1 12: BR (I1 > I2) 8 Runtime = 224, Inversion = 0, Length = 13 Cost Function = 0.177

Experimental Results After the 2000th generation, the best individual doesn't change. The best individual 0: DEC I2 1: BR (I2 <= 0) 12 2: PUT I1 ← I2 3: DEC I1 4: EXCH 5: BR (I1 <= 0) 0 6: DEC I1 7: BR (I1 < I2) 4 8: INC I1 9: PUT I2 ← I1 10: BR (I1 >= N-1) 3 11: INC I1 12: BR (I1 > I2) 8 Runtime = 224, Inversion = 0, Length = 13 Cost Function = 0.177

Experimental Results After the 2000th generation, the best individual doesn't change. The best individual 0: DEC I2 1: BR (I2 <= 0) 12 2: PUT I1 ← I2 3: DEC I1 4: EXCH 5: BR (I1 <= 0) 0 6: DEC I1 7: BR (I1 < I2) 4 8: INC I1 9: PUT I2 ← I1 10: BR (I1 >= N-1) 3 11: INC I1 12: BR (I1 > I2) 8 Runtime = 224, Inversion = 0, Length = 13 Cost Function = 0.177

Experimental Results After the 2000th generation, the best individual doesn't change. The best individual 0: DEC I2 1: BR (I2 <= 0) 12 2: PUT I1 ← I2 3: DEC I1 4: EXCH 5: BR (I1 <= 0) 0 6: DEC I1 7: BR (I1 < I2) 4 8: INC I1 9: PUT I2 ← I1 10: BR (I1 >= N-1) 3 11: INC I1 12: BR (I1 > I2) 8 Runtime = 224, Inversion = 0, Length = 13 Cost Function = 0.177

Experimental Results After the 2000th generation, the best individual doesn't change. The best individual 0: DEC I2 1: BR (I2 <= 0) 12 2: PUT I1 ← I2 3: DEC I1 4: EXCH 5: BR (I1 <= 0) 0 6: DEC I1 7: BR (I1 < I2) 4 8: INC I1 9: PUT I2 ← I1 10: BR (I1 >= N-1) 3 11: INC I1 12: BR (I1 > I2) 8 Runtime = 224, Inversion = 0, Length = 13 Cost Function = I1 을 계속 감소시키면서, A[I1] 과 A[I2] 가 inversion 된 경우 이 둘을 exchange 결국 A[0]~A[I2] 중 가장 큰 값이 A[I2] 로 들어 가게 된다

Experimental Results After the 2000th generation, the best individual doesn't change. The best individual 0: DEC I2 1: BR (I2 <= 0) 12 2: PUT I1 ← I2 3: DEC I1 4: EXCH 5: BR (I1 <= 0) 0 6: DEC I1 7: BR (I1 < I2) 4 8: INC I1 9: PUT I2 ← I1 10: BR (I1 >= N-1) 3 11: INC I1 12: BR (I1 > I2) 8 Runtime = 224, Inversion = 0, Length = 13 Cost Function = 0.177

Experimental Results After the 2000th generation, the best individual doesn't change. The best individual 0: DEC I2 1: BR (I2 <= 0) 12 2: PUT I1 ← I2 3: DEC I1 4: EXCH 5: BR (I1 <= 0) 0 6: DEC I1 7: BR (I1 < I2) 4 8: INC I1 9: PUT I2 ← I1 10: BR (I1 >= N-1) 3 11: INC I1 12: BR (I1 > I2) 8 Runtime = 224, Inversion = 0, Length = 13 Cost Function = 0.177

Experimental Results After the 2000th generation, the best individual doesn't change. The best individual 0: DEC I2 1: BR (I2 <= 0) 12 2: PUT I1 ← I2 3: DEC I1 4: EXCH 5: BR (I1 <= 0) 0 6: DEC I1 7: BR (I1 < I2) 4 8: INC I1 9: PUT I2 ← I1 10: BR (I1 >= N-1) 3 11: INC I1 12: BR (I1 > I2) 8 Runtime = 224, Inversion = 0, Length = 13 Cost Function = 0.177

Experimental Results After the 2000th generation, the best individual doesn't change. The best individual 0: DEC I2 1: BR (I2 <= 0) 12 2: PUT I1 ← I2 3: DEC I1 4: EXCH 5: BR (I1 <= 0) 0 6: DEC I1 7: BR (I1 < I2) 4 8: INC I1 9: PUT I2 ← I1 10: BR (I1 >= N-1) 3 11: INC I1 12: BR (I1 > I2) 8 Runtime = 224, Inversion = 0, Length = 13 Cost Function = 0.177

Experimental Results After the 2000th generation, the best individual doesn't change. The best individual 0: DEC I2 1: BR (I2 <= 0) 12 2: PUT I1 ← I2 3: DEC I1 4: EXCH 5: BR (I1 <= 0) 0 6: DEC I1 7: BR (I1 < I2) 4 8: INC I1 9: PUT I2 ← I1 10: BR (I1 >= N-1) 3 11: INC I1 12: BR (I1 > I2) 8 Runtime = 224, Inversion = 0, Length = 13 Cost Function = I1 을 계속 감소시키면서, A[I1] 과 A[I2] 가 inversion 된 경우 이 둘을 exchange 결국 A[0]~A[I2] 중 가장 큰 값이 A[I2] 로 들어 가게 된다

Experimental Results After the 2000th generation, the best individual doesn't change. The best individual 0: DEC I2 1: BR (I2 <= 0) 12 2: PUT I1 ← I2 3: DEC I1 4: EXCH 5: BR (I1 <= 0) 0 6: DEC I1 7: BR (I1 < I2) 4 8: INC I1 9: PUT I2 ← I1 10: BR (I1 >= N-1) 3 11: INC I1 12: BR (I1 > I2) 8 Runtime = 224, Inversion = 0, Length = 13 Cost Function = 0.177

Analysis of the Results selection sort (putting the correct value from right to left) Time complexity : O(N 2 ) Not the optimal solution, but not so bad Diversity preserved It is important to define the virtual machine and its instructions adequately Future works Using crossover Using simulated annealing Using general x86 machine instruction modular structure (make sub-routines and call them) Recursive call → O(N logN) algorithm Generalization → apply to other problems

Conclusion 주어진 문제를 해결하는 알고리즘을 찾기 위하여, EA(Evolutionary Algorithm) 를 이용하여 컴퓨터 프로그램을 진화 시키는 전략 (Genetic Programming) 적절한 알고리즘을 찾아내기 어려운 문제가 주어진 경우, 문제에 어느 정도 접근한 간단한 프로그램을 작성한 뒤에, 이 프로그램을 진화시켜 볼 수 있다. 그러면 문제를 더욱 잘 푸는 새로운 알고리즘을 찾을 수 있 을 것이다. 다항 시간 (polynomail time) 내에 푸는 알고리즘이 없는 NP class 나 그 밖의 문제들을 풀기 위해선, 휴리스틱 (heuristic) 방법을 사용하여 어느 정도 타당한 해를 구하는 방법을 많이 쓴다. 이때 사용하는 휴리스틱 알 고리즘을 잘 선택하는 것이 성능에 큰 영향을 미친다. 이런 경우 역시 EA 를 이용하여 더 좋은 휴리스틱 알고리즘을 찾아낼 수 있을 것이다. 최적화 (optimization) 가 아닌 다양성 (diversity) 을 목적으로 EA 를 사용한 다면, 기대하지 못했던 새로운 기능을 하는 프로그램이 창발 (emergence) 할 수도 있을 것이다.