use of genetic algorithm to resolve the problem of finite state machine construction

18

Upload: devendra-sharma

Post on 05-Apr-2018

227 views

Category:

Documents


0 download

TRANSCRIPT

8/2/2019 Use of Genetic Algorithm to Resolve the Problem of Finite State Machine Construction

http://slidepdf.com/reader/full/use-of-genetic-algorithm-to-resolve-the-problem-of-finite-state-machine-construction 1/18

8/2/2019 Use of Genetic Algorithm to Resolve the Problem of Finite State Machine Construction

http://slidepdf.com/reader/full/use-of-genetic-algorithm-to-resolve-the-problem-of-finite-state-machine-construction 2/18

Finite State Machine 

Finite state machine is an abstract machine that can bein any one of the finite number of states. Given aninput A the output B depends on the current state. Foreach input FSM can also make a transition to anotherstate.

The following simplistic FSM will do bit wise inversion

of given input. If input is 1001 the output will be 0110.

8/2/2019 Use of Genetic Algorithm to Resolve the Problem of Finite State Machine Construction

http://slidepdf.com/reader/full/use-of-genetic-algorithm-to-resolve-the-problem-of-finite-state-machine-construction 3/18

Finite State Machine Diagram

8/2/2019 Use of Genetic Algorithm to Resolve the Problem of Finite State Machine Construction

http://slidepdf.com/reader/full/use-of-genetic-algorithm-to-resolve-the-problem-of-finite-state-machine-construction 4/18

Mealy machine 

Most commonly Mealy machine is used to model problems indigital circuits. Mealy machine is a finite state machine whoseoutput is determined by both its current state as well as itscurrent input.

Formally, mealy machine has input alphabet (Σ)  output alphabet (Λ)  finite set of states (S) start state (also called initial state) S0 which is an element of (S) transition function (T : S × Σ→ S) mapping pairs of a state and

an input symbol to the corresponding next state. output function (G : S × Σ→  Λ) mapping pairs of a state and an

input symbol to the corresponding output symbol.

8/2/2019 Use of Genetic Algorithm to Resolve the Problem of Finite State Machine Construction

http://slidepdf.com/reader/full/use-of-genetic-algorithm-to-resolve-the-problem-of-finite-state-machine-construction 5/18

Grammatical inference 

This paper is about one of the approaches to createFSM based on accept/reject samples provided.

The process of finding the underlying FSM/Grammerfrom samples is called Grammatical inference.Grammatical inference is of immense use in patternrecognition, data compression, machine learning etc.

 We have used genetic algorithm to create FSM.

8/2/2019 Use of Genetic Algorithm to Resolve the Problem of Finite State Machine Construction

http://slidepdf.com/reader/full/use-of-genetic-algorithm-to-resolve-the-problem-of-finite-state-machine-construction 6/18

Genetic Algorithm 

Genetic algorithm is inspired by biological evolution. Forthe problem to be solved we maintain a ‘population’ of solutions. In each generation we try to ‘cross over’ somesolutions by merging different parts from the two‘chromosomes’ that ‘cross over’. We also introduce randomchange in few members of the population by ‘mutation’.

 After each ‘generation’ we discard extra members from thepopulation based on their ‘fitness’. 

Genetic algorithms are suitable for solving problems where

greedy algorithm will be exponentially expensive likeTravelling Salesman Problem. Furthermore it is guidedrandomized search so we are likely to get a solution closerto global maxima.

8/2/2019 Use of Genetic Algorithm to Resolve the Problem of Finite State Machine Construction

http://slidepdf.com/reader/full/use-of-genetic-algorithm-to-resolve-the-problem-of-finite-state-machine-construction 7/18

GA for creating FSM 

Earlier work on creating FSM create ‘chromosomes’that encode both transition function as well as outputfunction.

Our approach is to only encode transition functionand try to create output function to match targetmachine. This approach reduces the size of 

chromosome and helps in faster convergence.

8/2/2019 Use of Genetic Algorithm to Resolve the Problem of Finite State Machine Construction

http://slidepdf.com/reader/full/use-of-genetic-algorithm-to-resolve-the-problem-of-finite-state-machine-construction 8/18

 

Chromosome Representation.

Each chromosome represents all possible transitionsin the machine. So its size is m X n where m is numberof states and n is number of alphabets in input. We use

matrix to represent each chromosome. As we can seefrom start state we can only transition to state 1 oritself. We can reach state 2 with input sequence BA orCA.

8/2/2019 Use of Genetic Algorithm to Resolve the Problem of Finite State Machine Construction

http://slidepdf.com/reader/full/use-of-genetic-algorithm-to-resolve-the-problem-of-finite-state-machine-construction 9/18

8/2/2019 Use of Genetic Algorithm to Resolve the Problem of Finite State Machine Construction

http://slidepdf.com/reader/full/use-of-genetic-algorithm-to-resolve-the-problem-of-finite-state-machine-construction 10/18

Reproduction 

 We use single point crossover with probability of 50%. That isevery chromosome has 50% chance to participate inreproduction in each generation. We use low mutation rate of 1%.

Lets represent the chromosome in string form:011211001

Lets say another chromosome chosen for crossover is:021210211

 We chose point of crossover randomly. Lets say it is 4th index.

Then we get following chromosomes after crossover: 011210211 021211001 For mutation we randomly pick an index and put a new random

state from the set of states.

8/2/2019 Use of Genetic Algorithm to Resolve the Problem of Finite State Machine Construction

http://slidepdf.com/reader/full/use-of-genetic-algorithm-to-resolve-the-problem-of-finite-state-machine-construction 11/18

Fitness 

For each chromosome(solution) we try to retrofit theoutput function required. We create an output counttable. The OC Is three dimensional array m X n X o where m is number of states, n is number of inputsand o is number of outputs. OC[M,N, X] = number of times X appears in output when current state of machine is M and N is the input symbol.

8/2/2019 Use of Genetic Algorithm to Resolve the Problem of Finite State Machine Construction

http://slidepdf.com/reader/full/use-of-genetic-algorithm-to-resolve-the-problem-of-finite-state-machine-construction 12/18

Example:

Input output sequence:

{(0,0),(0,1),(1,1),(0,0),(1,0),(0,0),(1,0)}.

8/2/2019 Use of Genetic Algorithm to Resolve the Problem of Finite State Machine Construction

http://slidepdf.com/reader/full/use-of-genetic-algorithm-to-resolve-the-problem-of-finite-state-machine-construction 13/18

Initially OC[] is initialized with zeros.

 We are at A, our first input is 0 and output is 0 so we

increase OC[A,0,0] by one. Now we are at B, nextinput is 0 and output is 1 so we increment OC[B,0,1] by one. Now we are still at B, next input is 1 and output is1 so we increment OC[B,1,1] and so on… 

8/2/2019 Use of Genetic Algorithm to Resolve the Problem of Finite State Machine Construction

http://slidepdf.com/reader/full/use-of-genetic-algorithm-to-resolve-the-problem-of-finite-state-machine-construction 14/18

Output Count Table.

8/2/2019 Use of Genetic Algorithm to Resolve the Problem of Finite State Machine Construction

http://slidepdf.com/reader/full/use-of-genetic-algorithm-to-resolve-the-problem-of-finite-state-machine-construction 15/18

In the above table we see that for state B and input 1 wesometimes want 0 as output and sometimes what 1 asoutput. Our goal is to produce a solution where wehave minimal such conflicts. If there has to be aconflict 4:1 conflict is better than 3:2. Based on this wedefine the fitness function as:

8/2/2019 Use of Genetic Algorithm to Resolve the Problem of Finite State Machine Construction

http://slidepdf.com/reader/full/use-of-genetic-algorithm-to-resolve-the-problem-of-finite-state-machine-construction 16/18

 

This function will give score of 5 if there is no conflict,4 when there is 4:1 conflict and 3 when there is 3:1conflict. Thus our fitness function gives incentivetowards producing lesser conflicts.

8/2/2019 Use of Genetic Algorithm to Resolve the Problem of Finite State Machine Construction

http://slidepdf.com/reader/full/use-of-genetic-algorithm-to-resolve-the-problem-of-finite-state-machine-construction 17/18

Experimental results 

Eliminating the output function from chromosomesgreatly simplifies the implementation of GA.

 As the size of chromosomes is smaller our search space

is smaller and hence we converge faster. We compared running the modified algorithm against

encoding both transition and output function for sameset of inputs and target FSM. We were able to find

optimal solution within 70% of number of generationsused by former approach. However as out fitnesscomputation is a bit costly we required about 80% of time required by the former approach.

8/2/2019 Use of Genetic Algorithm to Resolve the Problem of Finite State Machine Construction

http://slidepdf.com/reader/full/use-of-genetic-algorithm-to-resolve-the-problem-of-finite-state-machine-construction 18/18

Thanks