## 3 Temperature Sensor Clustering Method
### Optimization of the Parameters  
It can be found that two parameters in this method remain uncertain: the weight coefficient \(\alpha\) and the number of the clusters \(\lambda\). The weight coefficient determines the form of the distance matrix, which influences the result of the clustering. The number of the clusters determines the number of the temperature sensors being selected for the thermal error model, and then influences the accuracy of the model. Thus, it is necessary to derive the optimized value of these two parameters. Genetic Algorithm (GA)  
A genetic algorithm is an intelligent algorithm that simulates Darwinian evolution theory, in which the combination of the parameters to be optimized are considered as \"individuals\" in nature. Firstly, some random value of the parameters were generated to form a population. Secondly, they were encoded by a binary coding method so the value of the parameters were transformed into a format that is more like gene. Thirdly, these \"individuals\" were crossed to generate the next generation, and some of them also mutated to derive new \"individuals\". Fourthly, these \"individuals\" was selected by a fitness function and \"individuals\" who derive a smaller value of fitness function survive. The above steps were repeated several times until all \"individuals\" in the population derive the approximate smallest fitness function. The value of these individuals were considered as the optimized value. Deriving a fitness function that can better reflect the goodness of the \"individual\" is the key of the GA. The fitness function can be expressed as:  
\[f=\mathrm{F}([\alpha,\,\lambda]) \tag{14}\]  
in which:  
\(f\) is the value of the fitness function;  
\([\alpha,\,\lambda]\) is the combination of the weight coefficient and the number of the clusters, which is the \"individual\". The fitness function should reflect both the accuracy and the stability of the model derived from the \"individuals\". Thus, the fitness function was constructed according to the following steps:  
1. The machine tool was firstly operated at the rotation speed of 1300 rpm, obtaining the temperature of the sensors \(\mathbf{X}_{1}\), and the thermal error \(\mathbf{e}_{1}\);  
Figure 4: Flowchart of the hierarchical clustering method. According to the clustering method in Sections 3.2 and 3.3 and the two parameters \([\alpha,\,\lambda]\), all temperature sensors are clustered into \(\lambda\) clusters: \(\mathbf{X}_{1}^{(1)},\mathbf{X}_{1}^{(2)},\ldots,\mathbf{X}_{1}^{(\lambda)}\);
3. Choose one temperature sensor from each cluster to form a combination. Thus, we derive a set of all possible combinations, denoted as \(\mathbf{\Omega_{1}}\). For each combination of temperature sensors, a thermal error model can be derived;
4. The machine tool was operated at two different rotation speeds, 600 rpm and 2200 rpm, respectively, obtaining \(\mathbf{X}_{2}\), \(\mathbf{e}_{2}\) and \(\mathbf{X}_{3}\), \(\mathbf{e}_{3}\);
5. Corresponding to \(\mathbf{\Omega_{1}}\), combinations of the temperature sensors in \(\mathbf{X}_{2}\) and \(\mathbf{X}_{3}\) were obtained. For each combination of temperature sensors, a 0.5 \({}^{\circ}\)C of disturbance was added to simulate the disturbance, then they were used to derive the predicted thermal error \(\widetilde{\mathbf{e}_{2}}\) and \(\widetilde{\mathbf{e}_{3}}\) according to the corresponding thermal error model obtained in step 3. Thus, a set of average root mean square errors (RMSE) were derived, each of them is expressed as: \[f=\frac{1}{2}\left(\sqrt{\frac{(\mathbf{e}_{2}-\widetilde{\mathbf{e}_{2}})^{T}(\mathbf{e }_{2}-\widetilde{\mathbf{e}_{2}})}{l_{2}}}+\sqrt{\frac{(\mathbf{e}_{3}-\widetilde\mathbf{{e}_{3}})^{T}(\mathbf{e}_{3}-\widetilde{\mathbf{e}_{3}})}{l_{3}}}\right)\] (15) where \(l_{2}\) and \(l_{3}\) are the number of the elements in \(\mathbf{e}_{2}\) and \(\mathbf{e}_{3}\), respectively;
6. Among the set of the average RMSEs, find the minimum one, \(f_{\min}\), which is considered as the value of the fitness function.