You are on page 1of 18

Finite State Machine

Finite state machine is an abstract machine that can be

in any one of the finite number of states. Given an input A the output B depends on the current state. For each input FSM can also make a transition to another state. The following simplistic FSM will do bit wise inversion of given input. If input is 1001 the output will be 0110.

Finite State Machine Diagram

Mealy machine
Most commonly Mealy machine is used to model problems in

digital circuits. Mealy machine is a finite state machine whose output is determined by both its current state as well as its current 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.

Grammatical inference
This paper is about one of the approaches to create

FSM based on accept/reject samples provided. The process of finding the underlying FSM/Grammer from samples is called Grammatical inference. Grammatical inference is of immense use in pattern recognition, data compression, machine learning etc. We have used genetic algorithm to create FSM.

Genetic Algorithm
Genetic algorithm is inspired by biological evolution. For

the problem to be solved we maintain a population of solutions. In each generation we try to cross over some solutions by merging different parts from the two chromosomes that cross over. We also introduce random change in few members of the population by mutation. After each generation we discard extra members from the population based on their fitness. Genetic algorithms are suitable for solving problems where greedy algorithm will be exponentially expensive like Travelling Salesman Problem. Furthermore it is guided randomized search so we are likely to get a solution closer to global maxima.

GA for creating FSM


Earlier work on creating FSM create chromosomes

that encode both transition function as well as output function. Our approach is to only encode transition function and try to create output function to match target machine. This approach reduces the size of chromosome and helps in faster convergence.

Chromosome Representation.
Each chromosome represents all possible transitions

in the machine. So its size is m X n where m is number of states and n is number of alphabets in input. We use matrix to represent each chromosome. As we can see from start state we can only transition to state 1 or itself. We can reach state 2 with input sequence BA or CA.

Reproduction
We use single point crossover with probability of 50%. That is

every chromosome has 50% chance to participate in reproduction 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.

Fitness
For each chromosome(solution) we try to retrofit the

output function required. We create an output count table. The OC Is three dimensional array m X n X o where m is number of states, n is number of inputs and 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.

Example:
Input output sequence: {(0,0),(0,1),(1,1),(0,0),(1,0),(0,0),(1,0)}.

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, next input 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 is 1 so we increment OC[B,1,1] and so on

Output Count Table.

In the above table we see that for state B and input 1 we

sometimes want 0 as output and sometimes what 1 as output. Our goal is to produce a solution where we have minimal such conflicts. If there has to be a conflict 4:1 conflict is better than 3:2. Based on this we define the fitness function as:

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:1 conflict. Thus our fitness function gives incentive towards producing lesser conflicts.

Experimental results
Eliminating the output function from chromosomes

greatly 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 same set of inputs and target FSM. We were able to find optimal solution within 70% of number of generations used by former approach. However as out fitness computation is a bit costly we required about 80% of time required by the former approach.

Thanks

You might also like