## 4 Sequence-Matching Algorithm Review
### General Idea  
The main objective of the SMA is to allow the user to gain degrees of control without increasing the number of actual physical controls (e.g., buttons, gestures, sensors, etc.). Figure 8 presents a flowchart of the general idea of the algorithm.  
First, individual actions (gestures) are detected. They are stacked into a sequence. Then, the algorithm recognizes, in real-time, the sequence of actions and seeks to match it with a sequence that is among a set of sequences defined by the user. This set of user-defined sequences maps to a set of modes of an assistive technology (each sequence corresponds to a mode). Finally, the user can execute the commands that the mode offers. In the context of this project, hand gestures are considered individual actions, so the user-defined sequences are a short series of simple gestures. What follows is the mathematical formulation of the SMA using the previously developed gesture recognition with the five possible inputs. Let \(A\) be the set of all possible actions, then:  
Figure 8: Simplified representation of the general idea behind the sequence matching algorithm.  
\[A=\{0,1,2,3,4\} \tag{4}\]  
where the value of an integer \(a\in A\) is:  
\[a=\begin{cases}0,&\text{if hand tap}\\ 1,&\text{if thump tap}\\ 2,&\text{if tilt}\\ 3,&\text{if swipe left}\\ 4,&\text{if swipe right}\end{cases} \tag{5}\]  
Let \(s\) be the ordered sequence of individual actions performed by the user and \(S\) the set possible sequences defined by the user. Finally, let \(C\) be the set of different modes for the robotic arm and \(R\) the relation that maps \(S\) to \(C\). This relation, or rather the set \(S\), is dynamic and will narrow itself as the user inputs actions and \(s\) is built. For instance, if a user wants to control five modes on a computer, then arbitrarily:  
\[C=\{copy,paste,mouse\,right,mouse\,left,click\} \tag{6}\]  
\[S=\{(0,1),(3,4),(1,2),(2,1),(2,1,0)\} \tag{7}\]  
and the relation \(R\) with the initial \(S\) and \(C\) is represented by the following diagram:  
\[S\]  
(8)  
If the user makes a _tilt_, the algorithm will detect it and set \(s=(2)\). Simultaneously, the algorithm sorts out impossible sequences and the (8) becomes:  
\[S\]  
(9)  
If, right after that, the user makes a _thumb tap_, then \(s=(2,1)\), but the relation in (9) does not change, since both sequences of \(S\) begin with \(s\). At this point, the user must wait one second if he or she wants to enter the _mouse left_ mode or make a _hand tap_ (i.e., \(a=0\)) for the _click_ mode to be automatically selected.  
In this example, \(C\) only has five elements, but, in general, if the user chooses to have, at most, \(k\) actions in each sequence, then the cardinality of \(S\):  
\[|S|=\sum_{i=1}^{k}{(|A|)^{i}} \tag{10}\]with \(|A|\) being the cardinality of \(A\) (i.e., the number of possible actions). If \(R\) is a bijection, then \(|C|=|S|\). In practice, it is observed that \(k=3\) is suitable. Greater than that, the sequences become harder to execute correctly. Table 4 shows the values of \(|S|\), in functions of \(|A|\) and \(k\), obtained with Equation (10).  
The last row of Table 4 illustrates the example above. This means that it would theoretically be possible to control a technology of 155 modes with a five-dimension interface. Of course, in practice, this number drops because the interface would become cumbersome with a number of controls too high; still, \(|S|\approx 15\) is feasible.