# An Application of the Associate Hopfield Network for Pattern Matching in Chart Analysis
## 3 Materials and Methods
### Pattern Matching Based on Segmentation and LAHN  
In this section, we will introduce our matching procedure in detail. Eleven basic patterns are chosen from 5 categories (Figure 5) that were summarized by [PERSON] et al. [2]. We take these predefined patterns as stored patterns of the LAHN. As the number of the neuron is fixed and predefined, the basic chart patterns would be firstly processed by the PIP algorithm to extract a fixed number of the data points and form the stored pattern (i.e., the template patterns).  
The basic template patterns would be represented by three representation methods described above, and then we design three different LAHNs accordingly. To illustrate our pattern matching process, we take Figure 6 for an example. The classic H&S chart pattern is represented in three different ways. As is shown in Figure 6, the PIP-TG method would extract a fixed number of data points and then TG is used to represent the pattern. According to [PERSON]'s paper, LAHN has the same characteristic as the traditional Hopfield network: the more neurons in the network, the higher the correct recall percentage. But it brings the higher computational cost at the same time. Therefore, we need to properly design the neuron number of each representation. The figure shows that there are 49 cells in the TG, so the neuron number of the LAHN would be 49. It is the same way for the N-equal-part TG. As for the Scaling-PIP, the neuron number would be the predefined total number of the data points after scaling and there would be 25 neurons in the case of Figure 6. In order to assign the stored pattern as the locally asymptotically stable equilibria, we fine-tune the parameters until the maximum eigenvalue of each \([H-A\Phi(X^{(i)})]\) is lower than 0. We choose the _tanh_ function as our activation function. The form is as follows: \(f(x)=\frac{(\epsilon^{\text{rx}}-\epsilon^{\text{-rx}})}{(\epsilon^{\text{ rx}}+\epsilon^{\text{-rx}})}\) and the exact value of the parameters would be described in Section 4.2.  
Each stored pattern can be resized as a 1-dimensional vector, so we can easily get the training label by multiplying the matrix \(A\). The training process is quite simple and efficient, after getting a satisfied squared error, a well-trained LAHN can be obtained. For the matching process, the incoming time series data would be segmented by one of the three representation methods as the initial state of the LAHN. The network dynamic evolves following the Equations (8)-(10). To avoid the oscillation, we constrain the growth rate into the range of \((0,0.5]\). Unlike other distance-based methods, after completing the iteration, the initial warping pattern would asymptotically converge to the most similar stored template pattern. It saves time in calculating the similarity between the input pattern and template patterns. Figure 7 shows the network structure of the LAHN and Figure 8 is the flow chart for training a LAHN.  
Figure 5: Eleven template patterns, each pattern is represented by 7 PIPs. (H&S, Triangles ascending, Cup with handle, Reverse cup with handle, Triple bottoms, Double tops, Double bottoms, Spike top, Spike bottom, Flag, Wedges).  
Figure 6: Three different representations. The value of the TG cell ranging from \([-1,1]\) is shown as the gray-level image for visualization. There would be only one cell value that was equal to \(1\) in each column. Here, the dimension of the grid is \(12\). The scaling PIP is generated by the scaling procedure and it will be described in detail in Section 4.  
Figure 7: The structure of LAHN resembles the traditional Hopfield network. The input \(x(t)\) denotes the neuron state in time step \(t\), the output of the network \(\dot{x}(t)\) is the momentum of the current state, we can get the next state (i.e., the input of the network in time step \((t+1)\) by Equation (10), and the stable state could be achieved if we evolve the network recursively.