Suggestions to implement a DFA to classify binary strings with a genetic algorithms strategy

108 views Asked by At

I am trying to resolve this problem (http://cswww.essex.ac.uk/staff/sml/gecco/NoisyDFA.html) where consist in classify a this type of raw file data:

5000 2
0 9 1 1 0 1 0 0 1 1 0
1 15 1 1 1 1 0 1 0 1 1 1 0 0 0 1 0
0 15 1 1 0 1 1 0 1 0 0 0 1 1 1 0 1
1 15 1 0 0 1 1 1 1 1 1 0 0 0 1 1 0
0 15 0 0 1 1 1 1 1 0 1 1 0 0 1 1 1
0 13 1 1 0 0 1 0 0 0 0 1 1 1 0
1 15 1 0 0 0 1 0 1 1 0 1 0 0 0 1 0
1 15 1 1 1 0 0 1 0 0 1 1 0 1 0 1 1
0 15 0 0 0 0 0 1 0 0 1 1 1 0 0 1 1
0 15 1 0 0 0 0 1 1 1 0 1 0 0 1 0 0
0 15 1 1 1 0 1 0 0 0 1 1 0 0 0 1 1
1 15 1 0 0 1 1 1 0 1 0 0 0 1 1 1 1
0 15 1 0 1 1 1 1 0 0 1 0 0 1 0 0 1
0 15 0 1 0 0 0 1 1 0 1 1 1 0 0 1 0
0 14 1 1 0 1 0 1 1 0 0 1 1 1 1 0 

Where the first row is the length in lines of the file and the next is the number of labels in the file. The first column is the correct label, the second one is the length and the last one column is the binary string to be classified (in 0 or 1). To do this, the idea is generate a Deterministic Finite Automata (DFA), but the implementations suggests a predeterminate number of states. In the case of this data, the states are 10, 20, 30, and 50. Also, I need to include a evolutionary algorithm strategy, but I can't understand How can I determinate a fitness function or apply different operators on the automata. I am trying to implement this to classify this file in Java:

 /*
     * To change this license header, choose License Headers in Project Properties.
     * To change this template file, choose Tools | Templates
     * and open the template in the editor.
    */
    package DFA;
    import java.util.Scanner;

    /**
     *
     * @author Cristian
     */
    public class DFACristian {

    protected final int state3 = 3;
    protected final int state2 = 2;
    protected final int state1 = 1;
    protected final int state0 = 0;
    protected final int deadState = -1;
    protected int currentState = 0;

    public void update(String edge) {
        if (currentState == state3 && edge.equals("c")) {
            currentState = state3;
        } else if (currentState == state2 && edge.equals("b")) {
            currentState = state2;
        } else if (currentState == state2 && edge.equals("c")) {
            currentState = state3;
        } else if (currentState == state1 && edge.equals("a")) {
            currentState = state1;
        } else if (currentState == state1 && edge.equals("b")) {
            currentState = state2;
        } else if (currentState == state1 && edge.equals("c")) {
            currentState = state3;
        } else if (currentState == state0 && edge.equals("a")) {
            currentState = state1;
        } else {
            currentState = deadState;
        }
    }

    public boolean matches() {
        if ((currentState == state3 || currentState == state2 || currentState == state1)) {
            return true;
        } else {
            return false;
        }
    }

    public static void main(String[] args) {
        Tutorial automaton = new Tutorial();
        char nextInt;
        System.out.print("Enter the input string: ");
        Scanner scanner = new Scanner(System.in);
        String input = scanner.nextLine();
        for (int i = 0; i < input.length(); i++) {
            nextInt = input.charAt(i);
            automaton.update(nextInt + "");
        }
        String message = "";
        if (automaton.matches()) {
            message = "1" + " " + input;
        } else {
            message = "0" + " " + input;
        }
        System.out.println(message);
    }
    }

I need some suggestions to implement this solution, because exist an approach did by Gomez (http://cswww.essex.ac.uk/staff/sml/gecco/results/NoisyDFA/entries/) but it is in a .jar file.

1

There are 1 answers

0
user207421 On

No. The way to implement a DFA by hand is a switch within a loop. Switch on the current state, then in each case change the current state according to the next input. At the final state, break out of the loop altogether, or just return.