• No se han encontrado resultados

Estrategias de intervención

In document El Colegio de la Frontera Sur (página 79-85)

In this Section we will show how a set of trees can be merged into one data structure F resulting in more efficient access. We present two data structures which have dif- ferent advantages and disadvantages. As an exemplary forest of tree-structures to be efficiently combined in one data structure we will use the 3 trees shown in Figure 6.1.

6.2.1

Merged Lists

As we use the formalism of [Moschitti, 2006b], the tree xτ for an example x must be given in ordered production list form – like stated in Algorithm 2. The production of every node of a tree xτexcept the leaf-nodes is contained in the list. The productions are the roots of certain subtrees. If the productions are stored in the list they will be

A B C D E F a) A B F D E b) A B F c) Figure 6.1: Three tree-structures

still linked to those subtrees. Figure 6.1 a) contains three such productions, namely (A (B) (C)), (B (D) (E)), (C (F)). The list of the productions linked to the corresponding trees is shown in Table 6.1. Figure 6.1 b) contains the productions (A (B) (F)), (B (D) (E)). The list of the productions linked to the corresponding trees is shown in Table 6.2. Figure 6.1 c) contains (A (B) (F)), and the corresponding list exposition is shown in Table 6.3. Production Tree (A (B) (C)) A B C D E F (B (D) (E)) B D E (C (F)) C F

Table 6.1: List exposition of the tree shown in Figure 6.1 a)

Given these sorted lists of productions – which are still linked to the corresponding (sub-) trees – allows to combine them by storing them together in one sorted list. The resulting list is: (A (B) (C)), (A (B) (F)), (A (B) (F)), (B (D) (E)), (B (D) (E)), (C (F)) and it is shown in Table 6.4. It is important to note that duplicate production entries cannot be easily merged. Having a look on the production (A (B) (F)), for instance, shows that equal productions can be linked to different trees. Those lists can be handled like any other tree xτ given by sorted production lists. Instead of calculating a sum of kernel

6.2. COMPRESSION OF TREE FORESTS Production Tree (A (B) (F)) A B F D E (B (D) (E)) B D E

Table 6.2: List exposition of the tree shown in Figure 6.1 b)

Production Tree

(A (B) (F))

A

B F

Table 6.3: List exposition of the tree shown in Figure 6.1 c)

calculations like in equation (6.1), the tree-structured values can be stored in one list F which can be processed by using just one kernel calculation for each class which is shown in equation (6.2).

Runtime analysis

In this Section we will show that in practical use the runtime of the kernel calculations on multiple lists is worse than the runtime of one kernel calculation on one list contain- ing all the individual lists together.

We assume that ψiis representing unique productions here. This means that production ψidoes not equal production ψj, where i 6= j. The production list shown in Table 6.4 is encoded to {ψ1, ψ2, ψ2, ψ3, ψ3, ψ4}, so that the production lists shown in Tables 6.1, 6.2 and 6.3 are encoded to {ψ1, ψ3, ψ4}; {ψ2, ψ3}; {ψ2}.

The crucial part of the processing is the construction of the node pairs (see Algorithm 2). Following the declaration of [Moschitti, 2006b] building such node pairs can be done in O(|N1||N2|) for the worst case. This case occurs if two trees are containing only one particular type of production. The list of such tree contains e.g. ψimultiple times. In that case, the pairs are built by iterating one time over the first list of produc- tions for each element of the second list of productions.

Production Tree (A (B) (C)) A B C D E F (A (B) (F)) A B F (A (B) (F)) A B F D E (B (D) (E)) B D E (B (D) (E)) B D E (C (F)) C F

6.2. COMPRESSION OF TREE FORESTS

In our example the kernel and respectively the node pair list is calculated |M | = 3 times, where M is the amount of trees contained in F . That leads to a runtime of O(|M || ¯N1||N2|) in the worst case, where ¯N1is the amount of nodes of the tree in M containing the most productions. Using only one list results in calculating only one node pair list, but one of the trees consists of all productions of the merged lists which leads toP|M |i=1|Ni| productions. This also leads to a runtime of O(|M || ¯N1||N2|) for the worst case, where ¯N1is the amount of nodes of the tree in M containing the most productions.

[Moschitti, 2006b] also states that the runtime of the node pair construction can need O(|N1| + |N2|) for special cases (see Section 5.5.2). As an example the tree consisting of the production ψ2like shown in Figure 6.1c) is going to be classified by the particu- lar tree-structure forest F presented in Table 6.4. A pointer on the merged production list is shifted until the production ψ2– being the first and only production of the tree to be classified – is found. As the list contains the production ψ2two times, two nodepairs (ψ2, ψ2) are constructed. The production-list of the example to be classified is shifted and the algorithm ends because the example to be classified does not contain any more productions. The productions contained in the nodepairs of course are still linked to the corresponding trees. This processing was done in O(|N1| + |N2|). Especially the shifting of the productions of the example to be classified has to be repeated for every new tree in a list of trees. Using just one structure F avoids such computational over- head.

To act on this assumption, the runtime of a method using a tree kernel on multiple lists is O(|M |(| ¯N1| + |N2|)) and the runtime of a method using just one list F is O(|M || ¯N1| + |N2|), where ¯N1is the amount of nodes of the tree in M containing the most productions.

6.2.2

Directed Acyclic Graphs

Another way to store multiple tree-structured values is to use a directed acyclic graph as presented by [Aiolli et al., 2007]. A minimal directed acyclic graph (DAG) con- taining a minimal number of vertices can be used to store all the tree structures which have been seen in the training set. The DAG G = (V, E) contains a set of vertices V and each vertex v ∈ V consists of a label (denoted by l(v)) on the one hand and a frequency value (denoted by f (v)) on the other hand. The DAG contains a set of directed edges E connecting some of the vertices. Nodes which are connected in the original tree-structures also are connected in the corresponding DAG.

A DAG containing all information of the trees apparent in Figure 6.1 is shown in Fig- ure 6.2. The algorithm to create a minimal DAG representing multiple trees is given in Algorithm 3. This algorithm converts every tree into its inverse topological ordered list of vertices (using the method invTopOrder(·). The first elements of the list are vertices with zero outdegree. After that vertices containing at most children with zero outdegree are contained in the list, and so on. The vertices are sorted in ascending order by the length of the longest path from each vertex to a leaf. The tree shown in

A, 1 B, 1 C, 1 A, 1 A, 1 B, 2 D, 2 E, 2 F, 3

Figure 6.2: A DAG containing the information given by the tree-structures shown in Figure 6.1

Figure 6.1 a) becomes list {D, E, F, B, C, A}, the tree shown in Figure 6.1 b) becomes {D, E, B, F, A}, and finally, the tree shown in Figure 6.1 c) becomes {B, F, A}. The lists are processed and for every vertex it is checked if it already exists in the DAG or if it is not. The formalism dag(u) ≡ dag(v) means that the DAG rooted at vertex u is equivalent to the DAG rooted at vertex v. If a particular vertex is already available in the DAG the frequency of the corresponding node in the DAG is incre- mented by the frequency of the vertex. If a tree is added to a DAG, the frequencies of the nodes in the tree are (usually) 1. Otherwise, a node containing label and frequency of the vertex is created in the DAG. After that all the corresponding children (denoted by ch[·]) of the new node are connected by edges. It is very important that the vertices of the trees are sorted because it is guaranteed that the children of a newly created node are already present in a DAG (if the created node has any).

In document El Colegio de la Frontera Sur (página 79-85)