# A Seismic Phase Recognition Algorithm Based on Time Convolution Networks
## 3 Neural Network Structure
### Temporal Convolutional Network  
Traditional time series neural networks, such as RNNs, long short-term memory (LSTM) and other models, have certain problems, such as being time-consuming, poor parallelism and long-term dependencies. However, TCNs can solve these problems. TCNs, which is short for temporal convolutional networks, consist of dilated and causal 1D convolutional layers that have the same input and output lengths.  
The design of TCNs is based on two principles: (1) the input and output of the network are the same length; (2) there is no \"leakage\" of past information. To achieve the same input length, TCNs use 1D fully convolutional networks (1D FCNs), in which each hidden layer is the same length as the input layer. Then, zero-padding (kernel size 1) is added to ensure that all of the layers have the same length. To achieve the same output length, TCNs use causal convolution, in which the output at time t is only convolved with earlier elements from time t and the previous layer. In a nutshell, TCNs = 1D FCNs + causal convolution. Dilated convolution is also used in TCNs. The advantage of using dilated convolution is an increase in the receptive fields without a loss of information in the pooling operations, so each convolution output contains a large range of information. The structure of a generic TCN is shown in Figure 7.  
Figure 6: An original waveform (the red vertical line represents the arrival of the P wave and the blue vertical line represents the arrival of the S wave).  
Figure 7: A structure diagram of a generic TCN network: (**a**) the expansion coefficients d = 1, 2 and 4 and the dilated convolution with a kernel size k = 3 enable the receptive field to cover all of the values in the input sequence; (**b**) the TCN residual block (when residual inputs and outputs have different dimensions, a 1 \(\times\) 1 convolution is added); (**c**) an example of residual connections (the blue line shows the convolution kernel in the residual function and the green line represents the identity map).  
By analyzing Figure 7, it can be seen that TCNs utilize the 1D FCN structure and that TCNs have a stronger ability to retain long-term historical information than LSTM. To maintain the same time step, the input and output of each hidden layer have the same length. Specifically, in the first hidden layer, when the input is n time steps, then the output is also n time steps, regardless of the kernel size and dilation. Similarly, the input and output time steps of other hidden layers are all n, which is very similar to the structure in RNNs. No matter the layer, the input of each time step has a corresponding output.  
TCNs use causal convolution. Causal convolution for the output data at time t means that the input can be t or the time before t. This structure is shown in Figure 8. For filter F = (f1, f2,..., fx) and sequence X = (x1, x2,..., xT), the causal convolution at x\({}_{t}\) is defined as:  
\[(F*X)(x_{t})=\sum_{k=1}^{K}f_{k}x_{(t-K+k)} \tag{2}\]  
For filter F = (f1, f2,..., fx) and sequence X = (x1, x2,..., xT), the dilated convolution at x\({}_{t}\) with a dilation factor d is defined as:  
\[(F*dX)(x_{t})=\sum_{k=1}^{K}f_{k}x_{(t-(K-k)d)} \tag{3}\]  
Dilated convolution enables networks to process various inputs, so deeper networks are required. To solve the problem of deeper networks potentially causing gradient disappearance, dilated convolution uses a difference block structure, similar to the structure in ResNet [23], through which TCNs can gain a higher generalization ability. As shown in Figure 7c, the residual structure replaces the simple connections between the TCN layers. Since the number of channels in x and F(x) is different, a 1 x 1 Conv has been designed to enable a simple transformation of x, so that the transformed x and F(x) can be added.