The start state(S0) of my NFA has 2 outgoing epsilon transitions to S1 and S2, and, S1 and S2 have further transitions, and are disjoint of each other. So do I consider {S1,S2} as one state while converting it to DFA?
The start state(S0) of my NFA has 2 outgoing epsilon transitions to S1 and S2. S1 and S2 have further transitions, and are disjoint of each other.
We consider {S1,S2} as one state while converting €-NFA to DFA. This is because the transition has € closure and they move from the same state.
For example, we have 7 states:
Q={q0,q1,q2,q3,q4,q5,q6}
Δ={0,1}
We have epsilon transitions for:
{q0,q3,q6,q1}
We have two outgoing epsilon transitions
q5,q2 from q1, i.e., ε-closure(q1)={q2,q5}
From the above example we have to convert ε-nfa to dfa.
Epsilon NFA to DFA
Continued
Final DFA
Related
Consider there is a minimized DFA that accepts the language L. The problem is to find the minimum number of states in its complement.
Now if I take the complement of this DFA i;e if I make the non-final states as final and final states as non-final, do I also need to worry about minimizing this complemented DFA?
DFA - Deterministic Finite Automata
Lets start with that is accepted by a minimum DFA . Then we can retrieve the DFA of the complement (as you have mentioned). So let's derive a DFA which accepts which has the same amount of states as .
Now Lets assume that is not a minimum DFA of
we should be able to reduce the number of states in it further to get a DFA . But getting the complement of should give us a new DFA which accepts which is but has less states than making it not a minimum DFA of .
So our assumption that not being the miniumum of is wrong.
This is in response to an answer given in this question:
How to create a good evaluation function for a game?, particularly by #David (it is the first answer).
Background: I am using a genetic algorithm to optimize the hyper parameters in a game playing agent that is using minimax / alpha beta pruning (with iterative deepening). In particular, I would like to optimize the heuristic (evaluation) function parameters using a genetic algorithm. The evaluation function I use is:
f(w) = w * num_my_moves - (1-w) * num_opponent_moves
The only parameter to optimize is w in [0,1].
Here's how I programmed the genetic algorithm:
Create a random population of say 100 agents
Let them play 1000 games at random with replacement.
Let the parents be the top performing agents with some poorer performing agents mixed in for genetic diversity.
Randomly breed some parents to create children. * Breeding process: We define a child to be an average of the weights of its parents.
i.e. childWeight = 0.5(father.w+ mother.w)
The new population is formed by the parents and the newly created children.
Randomly mutate 1% of the population as follows: newWeight = agent.x + random.uniform(-0.01,0.01) and account for trivial border cases (i.e. less than zero and greater than one, appropriately).
Evolve 10 times (i.e. repeat for new population)
My question: Please evaluate the bold points above. In particular, does anyone have a better way to breed (rather than trivially averaging the parent weights), and does anyone have a better way to mutate, rather than just adding random.uniform(-0.01,0.01)?
It looks like you're not actually applying a genetic-algorithm to your agents, but rather just simple evolution directly on the phenotype/weights. I suggest you try introducing a genetic representation of your weights, and evolve this genome instead. An example would be to represent your weights as a binary string, and apply evolution on each bit of the string, meaning there is a likelihood that each bit gets mutated. This is called point mutations. There are many other mutations you can apply, but it would do as a start.
What you will notice is that your agents don't get stuck in local minima as much because sometimes a small genetic change can vastly change the phenotype/weights.
Ok, that might sound complicated, it's not really. Let me give you an example:
Say you have a weight of 42 in base 10. This would be 101010 in binary. Now you have implemented a 1% mutation rate on each bit of the binary representation. Let's say the last bit is flipped. Then we have 101011 in binary, or 43 in decimal. Not such a big change. Doing the same with the second bit on the other hand gives you 111010 in binary or 58 decimal. Notice the big jump. This is what we want, and lets your agent population search a larger part of the solution space faster.
With regard to breeding. You can try crossover. Lets assume you have many weights each with a genetic encoding. If you represent the whole genome (all the binary data) as one long binary string you can combine sections of the two parents genome. Example, again. The following is the "father" and "mother" genome and phenotype:
Weight Name: W1 W2 W3 W4 W5
Father Phenotype: 43 15 34 17 14
Father Genome: 101011 001111 100010 010001 001110
Mother Genome: 100110 100111 011001 010100 101000
Mother Phenotype: 38 39 25 20 40
What you can do is draw arbitrary lines through both genomes at the same place, and assign the segments arbitrarily to the child. This is a version of crossover.
Weight Name: W1 W2 W3 W4 W5
Father Genome: 101011 00.... ...... .....1 001110
Mother Genome: ...... ..0111 011001 01010. ......
Child Genome: 101011 000111 011001 010101 001110
Child Phenotype: 43 7 25 21 14
Here the first 8 and the last 7 bits come from the father, and the middle comes from the mother. Notice how weight W1 and W5 are entirely from the father, and W3 is entirely from the mother. While W2 and W4 are combinations. W4 had hardly any change, while W2 has changed drastically.
I hope this gives you some insight in how to do genetic algorithms. That said, I recommend using a modern library instead of implementing it yourself, unless you are doing it to learn.
Edit: More on handling the weights/binary representation:
If you need fractions, you can do this by separating the numerator and denominator as different weights, or have one of them as a constant, e.g., 42 and 10 gives 4.2.)
Larger than 0 constraints come free. To actually get negative numbers you need to negate your weights.
Less than 1 constraint you can get by dividing the weight by the maximum possible value for that bit string length. In the examples above you have 6 bits, which can become a maximum of 63. If you then after mutation get a binary string of 101010 or 42 in base 10, you do 42/63 getting 0.667 and can only ever get as high as 1.0, when 63/63.
Two weights' sum equal to 1? If you get 101010 and 001000 for W1 and W2, it gives 42 and 8, then you can go W1_scaled = W1 / (W1 + W2) = 0.84 and W2_scaled = W2 / (W1 + W2) = 0.16. This should give you W1_scaled + W2_scaled = 1 always.
Since I was mentioned.
Rather than averaging the parent weights, I picked random numbers using the parent weights as a min/max. I additionally found I had to widen the range slightly (compensating for the reduction in standard deviation when I'd average two uniform random numbers, or sqrt(2), but I probably wasn't exact) to resist the pull toward the average. Otherwise the population converges toward the average and can't escape.
So if the parents' weights were 0.1 and 0.2, it might pick a random number between 0.08 and 0.22 for the child weight.
Late edit: A more accepted, studied, understood approach that I didn't know at the time is something called "Differential Evolution".
I just started learning Theory of Computation this semester and a bit confused by the phrase "DFA for a language". If it is asked to construct a DFA for some collection of binary strings L, does it mean to find DFA M with L(M)=L or just $L(M)\supset L$?
Most compiler/theory courses tend to have different styles surrounding teaching definitions of deterministic finite automata and formal languages, but I'll try to make this description as agnostic as possible.
The phrase "DFA for a language" loosely means: a DFA which accepts every word in the language and rejects every word not in the language.
The way I was taught DFAs is to have final/accepting states and regular states which removes the necessity for an implicit error state.
This means that a DFA accepts a word if the state it is in at the end of input is accepting and it rejects the word if the state is not accepting.
Ex:
Let's define L as the language which contains an even number of 1s. These will be binary strings so the symbols are just 0 and 1.
00, 110, 111, 1111, etc are examples of words in this language. Notice that the empty string is in this language.
We can have two states in our DFA. The starting state, let's call it even 1s, is also an accepting state because 0 ones is even. The other state is odd 1s, this is not accepting.
As for transitions, when even 1s receives a 1, it transitions to odd 1s. And when odd 1s receives a 1, it transitions to even 1s.
Now, the number of 0s doesn't matter, so in either state, it transitions to itself.
Apologies for the double arrow, this website is great but I couldn't figure out how to separate the transitions between even 1s and odd 1s
Deterministic Finite Automaton (DFA)
In DFA, for each input symbol, one can determine the state to which the machine will move. Hence, it is called Deterministic Automaton. As it has a finite number of states, the machine is called a Deterministic Finite Machine or Deterministic Finite Automaton.
Formal Definition of a DFA
A DFA can be represented by a 5-tuple (Q, ∑, δ, q0, F) where −
-> Q is a finite set of states.
-> ∑ is a finite set of symbols called the alphabet.
-> δ is the transition function where δ: Q × ∑ → Q
-> q0 is the initial state from where any input is processed (q0 ∈ Q).
-> F is a set of final state/states of Q (F ⊆ Q).
Write your question in precise way. here DFA for a language means that you need to construct machine for particular language only not it's subset or superset. construct DFA maachine for which L(M)= L.
Can´t find anything affirmative about it. And a NFA with any epsilon transition is a epsilon-NFA ?
Thanks.
DFA doesn't have epsilon transitions.If it had it, it could transit from current state to other state without any input i.e. with nothing , not even {} or phi. And as definition , we know that the input must be from the input set.
Hope this cleared your doubt ...
From the definition of DFA ,"Deterministic Finite Automata is a machine that can't move on other state without getting any input".And since epsilon means nothing.Hence DFA can't move on epsilon moves.
Whereas from the definition of NFA,"Non deterministic Finite Automata is a machine that may move on other state without getting any input".So NFA can move on epsilon moves.
DFA must have a definite input symbol to move from one state to another state. Epsilon move isn't allow in DFA, because it'll change DFA into NFA. For e.g., suppose you are in state Q1, and you have a transition (Q1, e) = Q2, in this case you can directly go to Q2 without apply any input or you can stay in Q1 state, so you have two choosing opportunity at state Q1. In case of DFA you mustn't have any choosing criteria. That's why DFA don't have epsilon moves.
If the start state is also an end state then the fa accepts lamda. Also, if the fa specifically shows a transition from one state to the next with lamda then lamda can be considered an input.
I am to construct a DFA from the intersection of two simpler DFAs. The first simpler DFA recognizes languages of all strings that have at least three 0s, and the second simpler language DFA recognizes languages of strings of at most two 1s. The alphabet is (0,1). I'm not sure how to construct a larger DFA combining the two. Thanks!
Here's a general idea:
The most straightforward way to do this is to have different paths for counting your 0s that are based on the number of 1s you've seen, such that they are "parallel" to each other. Move from one layer of the path to the next any time you see a 1, and then move from the last layer to a trap state if you see a third 1. Depending on the exact nature of the assignment you might be able to condense this, but once you have a basic layout you can determine that. Typically you can combine states from the first DFA with states in the second DFA to produce a smaller end result.
Here's a more mathematical explanation:
Constructing automata for the
intersection operation.
Assume we are
given two DFA M1 = (S1, q(1) 0 , T1,
F1) and M2 = (S2, q(2) 0 , T2, F2).
These two DFA recognize languages L1 =
L(M1) and L2 = L(M2). We want to
design a DFA M= (S, q0, T, F) that
recognizes the intersection L1 ∩L2. We
use the idea of constructing the DFA
for the union of languages. Given an
input w, we run M1 and M2 on w
simultaneously as we explained for the
union operation. Once we finish the
runs of M1 and of M2 on w, we look at
the resulting end states of these two
runs. If both end states are accepting
then we accept w, otherwise we reject
w.
When constructing the new transition function, the easy way to think of it is by using pairs of states. For example, consider the following DFAs:
Now, we can start combining these by traversing both DFAs at the same time. For example, both start at state 1. Now what happens if we see an a as input? Well, DFA1 will go from 1->2, and DFA2 will go from 1->3. When combining, then, we can say that the intersection will go from state "1,1" (both DFAs are in state 1) to state "2,3". State 2 is an accept state in DFA1 and state 3 is an accept state in DFA2, so state "2,3" is an accept state in our new DFA3. We can repeat this for all states/transitions and end up with:
Does that make sense?
Reference: Images found in this assignment from Cornell University.
The simplest way would be using the 2DFA model: from the end state of the first DFA(the one testing for at least 3 zeros) jump to the start state of the second one, and reverse to the beginning of the input. Then let the second DFA test the string.