• No results found

The L ∗ Algorithm

1.1 Model Learning for Software Systems

1.1.6 The L ∗ Algorithm

In her seminal work, Angluin introduced an efficient algorithm for the MAT framework: the L∗algorithm. Variants of this algorithm are still widely used today. Let us present the variant introduced by Rivest and Shapire [119], because it is one of the easiest to understand. This variant of the algorithm

Chapter 1 Learner Teacher MQ input sequence output sequence EQ hypothesis counterexample

Figure 1.6: The minimally adequate teacher framework

is for learning DFAs, but it is applicable to other flavours of automata as well with minor modifications.

Let us assume that the teacher knows a DFA A = (I, QA, qA, δA, FA), and

that we want to infer this DFA using the L∗ algorithm. For the purpose of this example, let us introduce an output function λA: QA→ {accept, reject}

for A, such that:

λA(q) = accept ⇐⇒ q ∈ FA for all q ∈ QA

The core data structure of the L∗ algorithm is called the observation table. The rows and columns of an observation table are labelled by prefixes and suffixes of input sequences respectively, and the cells are filled with the teacher’s label in response to this input sequence (i.e. accept or reject). Membership queries are posed to fill the table. Some example observation tables are shown in Figure 1.7. These observation tables will be explained later.

The rows of an observation table are split in two groups. The top part is labeled by access sequences, and is used to identify the different states and the transitions required to reach these states. The bottom part is labeled by one-input extensions, and is used to map the remaining transitions. The columns are labeled by separating sequences that are used to discriminate rows in the top part of the table.

Formally, an observation table can be described by a triple (X, E, row), where:

– X ⊂ I∗ is a finite, prefix-closed set of access sequences, extended to include the one-input extensions X ∪ (X · I),

– E ⊂ I∗ is a finite, suffix-closed set of separating sequences, and

– row : (X ∪ (X · I) → E) → {accept, reject} is a function mapping these prefixes and suffixes to their output.

Initially, X and E contain the empty sequence .

A hypothesis can be constructed from the observation table if it is closed. This is the case if for each row labeled with a one-input extension there exists a row labeled by an access sequence that has an identical value in every column. If there is a row labeled with a one-input extension for which this is not the case, it is added as an access sequence. This continues until the table is closed.

Formally, the table is closed if for all x ∈ X · I there is a y ∈ X such that row(x) = row(y). If there is a row x ∈ X · I and there is no y ∈ X such that row(x) = row(y), then x is added to X.

Let H = (I, QH, qH, δH, FH) be a hypothesis DFA for A, and let λH :

QH → {accept, reject} be an output function for H. H can be constructed

from a closed observation table (X, E, row) as follows: – I is given

– QH = {row(x)|x ∈ X},

– qH = row(),

– δH(row(x), a) = row(x · a) for a ∈ I and x ∈ X, and

– λH(row(x)) = row(x)().

This hypothesis is presented to the teacher in an equivalence query. If the hypothesis DFA is not the same as the teacher’s, an input sequence c is returned as a counterexample. This can be any input sequence for which the hypothesis and the teacher’s DFA produce a different label, i.e. λA(δA(qA, c)) 6= λH(δH(qH, c)).

Several different methods for handling counterexamples exist (for an overview, see [131]). In the variant that we are concerned with, the coun- terexample and all of its suffixes are added to the table as suffixes (i.e. to E), and membership queries are used to fill the cells. This will violate the closedness of the observation table. Therefore, at least one new row will be

Chapter 1

added to the top part of the table, and the next hypothesis will have at least one extra state. Indeed, each subsequent hypothesis will have more states than the one before.

This procedure iterates until no counterexample can be found. At this point, H is equivalent to A.

Example 1.8. Let us assume that we do not know the sequences of method calls to a stack of size 2 that are error free, but we have access to a teacher that knows the DFA of Figure 1.3.

Our initial observation table is shown in Figure 1.7a. This table is not closed, because there are no rows labeled by an access sequence that are identical to row pop. Therefore, we add pop to the top part of the table, and its one-input extensions to the bottom part of the table.

The resulting table is shown in Figure 1.7b. This table is closed, and can be used to construct the hypothesis shown in Figure 1.8a.

A counterexample for this hypothesis is push pop, because the hypothesis rejects this sequence, whilst the actual automaton accepts it. We handle the counterexample by adding it and all of its suffixes to the table as suffixes (i.e. to E). Membership queries are posed to fill the empty cells. The resulting observation table is shown in Figure 1.7c.

This table is not closed, because there is no rows labeled by an access sequence that is identical to row push. Therefore, we add push to the top part of the table, and its one-input extensions to the bottom part of the table.

The resulting table is shown in Figure 1.7d. Again, this table is not closed because of row push push. After handling this row we obtain the closed observation table shown in Figure 1.7e. The corresponding hypothesis for this table is shown in Figure 1.8b. Observe that this is the same DFA as that of Figure 1.3. Therefore, we have successfully learned a model for sequences of method calls to a stack of size 2 that are error free.