Hierarchical federal learning method oriented to resource isomerism
By introducing the hierarchical architecture of edge servers and cosine similarity clustering technology in federated learning, the problems of low training efficiency and poor generalization ability caused by data heterogeneity and resource heterogeneity in federated learning are solved, and more efficient data transmission and model convergence are achieved, and the accuracy and application effect of the model are improved.
Patent Information
- Application Number
- CN202510100937.4
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2025-01-22
- Publication Date
- 2025-06-13
AI Technical Summary
In federated learning, due to data heterogeneity and resource heterogeneity, the model training efficiency is low and the generalization ability is poor. Especially in educational institutions with poor network conditions, the data transmission speed is slow, which affects the update efficiency of the model.
A hierarchical federated learning method for resource heterogeneity was designed. By introducing edge servers, a three-layer architecture of cloud server-edge server-client was built. The edge server initially processed and aggregated the data of the local client, reducing unnecessary data transmission, improving data transmission efficiency, and improving the accuracy and generalization capabilities of the model through cosine similarity clustering clients.
It reduces communication costs, improves data transmission efficiency and model convergence speed, enhances the accuracy and generalization ability of the model, enables the trained model to have better application effects in different types of educational institutions, and provides more accurate personalized learning suggestions and academic development predictions.
Smart Images

Figure CN120146219A_ABST
Abstract
Description
Technical Field
[0001] The present invention relates to a hierarchical federated learning method for resource heterogeneity, belonging to the field of computer technology. Background Art
[0002] In the scenario of federated learning, due to the differences in factors such as the computing power, sample quantity, and environmental conditions of each client, the data collected by them often has the problem of heterogeneity in distribution, which is called the data heterogeneity problem. In addition, there may be the problem of the same data distribution among the clients participating in training each time, resulting in some representative clients never being selected, which causes instability in the convergence of the global model.
[0003] In some large-scale federated learning networks, such as in the education field, the network conditions of different educational institutions (such as schools, educational training institutions, etc.) vary widely. Some institutions have limited network bandwidth, and the data transmission speed is slow in traditional federated learning. Schools in some remote areas may not be able to upload a large amount of student learning data in time, resulting in delays in the training process and affecting the model update efficiency. Moreover, there are significant heterogeneities in educational data among different institutions, including data distribution, the type and range of features, etc. Traditional federated learning often has difficulty making full use of the characteristics of this data, which may lead to poor generalization ability of the trained model. For example, in the training of a student performance prediction model, factors such as the curriculum settings, teaching quality, and student bases of different schools make the data distribution vary significantly. Traditional federated learning may not be able to adapt well to this situation, resulting in unsatisfactory application effects of the model in some schools and being unable to accurately predict the learning performance and development trends of students.
[0004] In traditional federated learning, the server is set as the school principal, and the clients are students. If each student asks the principal for leave, the communication overhead and cost of the server are very high. Therefore, it is necessary to introduce the teacher as this layer of edge server to reduce the communication cost of the cloud server through the direct communication between students and teachers.
[0005] Hierarchical federated learning constructs a three - layer architecture of cloud server - edge server - client (educational institution) by introducing edge servers. The edge server can first perform preliminary processing and aggregation on the data of local clients (nearby schools or educational institutions). For example, schools within a specific area first upload their data to the regional edge server. The edge server filters out valuable data, integrates it, and then uploads it to the cloud server. This reduces a large amount of unnecessary data transmission, improves the efficiency of data transmission, alleviates the network bandwidth pressure, and is particularly beneficial to educational institutions with poor network conditions, ensuring that data can participate in model training in a timely and effective manner. Secondly, in dealing with data heterogeneity, hierarchical federated learning has significant advantages. The edge server can calculate the cosine similarity based on the model parameters uploaded by the clients, and cluster educational institutions with similar data distributions into a cluster. For example, clustering is carried out according to factors such as the teaching level and subject focus direction of the school, and then the client models in each cluster are fitted to obtain the cluster - center model parameters. Then, the cluster with the highest similarity to the global model parameters is selected to participate in the training. This method can better explore the internal laws of educational data, improve the accuracy and generalization ability of the model, enable the trained model to have good application effects in different types of educational institutions, and provide more accurate personalized learning suggestions and academic development predictions for students. Summary of the Invention
[0006] The present invention designs and develops a hierarchical federated learning method for resource heterogeneity, which can reduce communication costs, improve the efficiency and convergence speed of data transmission, and also improve the accuracy and generalization ability of the model, providing more accurate personalized learning suggestions and plans for students.
[0007] The technical solution provided by the present invention is as follows:
[0008] A hierarchical federated learning method for resource heterogeneity, comprising
[0009] Step 1: Establish a three - layer federated learning framework, including: a cloud server, an edge server, and a client;
[0010] Step 2: The edge server calculates the cosine similarity between the model parameters of each client according to the model parameters uploaded by the clients, and clusters the clients with similar data distributions into a cluster;
[0011] Step 3: Fit the client models in each cluster to obtain different cluster - center model parameters;
[0012] Step 4: Calculate the cluster with the highest similarity between the cluster - center model parameters of each cluster and the global model parameters through cosine similarity to participate in the training until the global model converges or reaches the required number of training rounds.
[0013] Preferably, the said Step 1 includes:
[0014] The cloud server initializes a global model and sends it to each edge server. The edge server then sends the received global model to all clients;
[0015] After receiving the global model, the client trains the model using local data;
[0016] After local training is completed, the client sends the model parameters to the edge server.
[0017] Preferably, it further includes;
[0018] It is set that the federated learning framework consists of: a cloud server C, M edge servers, and N clients;
[0019] The set of edge servers is: M = {m 1 , m 2 ,... m M};
[0020] The set of clients is: N = {n 1 , n 2 ,... n N};
[0021] The dataset of the client n covered by the edge server m is:
[0022]
[0023] In the formula, |D m,n | is the size of the data volume for the nth client under the edge server m to perform local training, and (x i , y i ) respectively represent the i-th input data sample and the corresponding label;
[0024] The calculation formula of the edge loss function F i (w) is:
[0025]
[0026] In the formula, j is the serial number of the client associated with the edge server m i , D i is the local datasets of all clients associated with the edge server m i , D i,j is the local dataset of the client n associated with the edge server m i , and f i i,j (w) is the local loss function;
[0027] The calculation formula of the global loss function F(w) is:
[0028]
[0029] Preferably, the calculation formula of the cosine similarity is as follows:
[0030]
[0031] In the formula, A i , B i respectively represent the components of vector A and vector B, ||·|| is the L 2 norm, and the value range of the cosine similarity is [-1, 1].
[0032] Preferably, the selection of the cloud server is implemented based on the method of the confusion matrix, including:
[0033] Calculating the precision Precision and recall Recall through the confusion matrix;
[0034]
[0035] In the formula, F 1 is the harmonic mean of the precision and recall;
[0036] Calculating the F 1 score, setting the F 1 score threshold, and judging the convergence trend of the global model through the threshold;
[0037]
[0038] When the F 1 score is greater than the threshold, the edge server will be aggregated by the cloud server, and the threshold is a dynamic threshold, which is 0.9 times the average value plus 0.1 times the standard deviation.
[0039] Preferably, the agglomerative hierarchical clustering method is adopted in the second step, including:
[0040] Regarding each sample as a cluster;
[0041] Calculating the similarity between any two samples to form a similarity matrix;
[0042] In each iteration process, merging the two clusters with the highest similarity into a new cluster;
[0043] Updating the similarity matrix according to the actual merging situation;
[0044] Repeating the merging and updating steps until all samples are clustered into one cluster, forming a clustering tree or reaching the required number of clusters.
[0045] Advantages of the present invention:
[0046] The hierarchical federated learning method for resource heterogeneity provided by the present invention reduces the direct communication between the client and the cloud server by introducing an edge server, reduces the communication cost, and improves the efficiency and convergence speed of data transmission. Then, by performing the selection of the edge server by the cloud server and the selection of the client by the edge server, the model performance is improved, the training time is reduced, and a faster convergence speed is obtained.
[0047] When facing clients with weak performance, such as collection, laptops, tablets, etc., there is no need to perform full-scale model training. Only local model training needs to be performed locally using limited resources and interact with the edge server, effectively solving the device performance bottleneck problem and improving the application effect and efficiency of federated learning in a resource heterogeneous environment. BRIEF DESCRIPTION OF THE DRAWINGS
[0048] Figure 1 It is a schematic diagram of the F1 score of each edge server according to the present invention.
[0049] Figure 2 It is a schematic diagram of the F1 score of each edge server after setting the threshold according to the present invention.
[0050] Figure 3 It is a test comparison result diagram of the present invention under the condition of independent and identical distribution of the CIFAR-10 dataset. DETAILED DESCRIPTION OF THE INVENTION
[0051] The following further describes the present invention in detail with reference to the drawings, so that those skilled in the art can implement it according to the description in the specification.
[0052] As Figures 1 - 3 shown, the present invention provides a hierarchical federated learning method for resource heterogeneity, which can reduce the communication cost and improve the efficiency and convergence speed of data transmission, including:
[0053] Step 1: Establish a three-layer federated learning framework, including: a cloud server, an edge server, and a client;
[0054] The cloud server initializes a global model and sends it to each edge server, and the edge server sends the received global model to all clients;
[0055] After receiving the global model, the client trains the model with local data;
[0056] After the local training is completed, the client sends the model parameters to the edge server.
[0057] Step 2: Based on the model parameters uploaded by the client, the edge server calculates the cosine similarity between the model parameters of each client, and clusters the clients with similar data distributions into one cluster;
[0058] Regard each sample as a cluster;
[0059] Calculate the similarity between any two samples to form a similarity matrix;
[0060] In each iteration process, merge the two clusters with the highest similarity into a new cluster;
[0061] Update the similarity matrix according to the actual merging situation;
[0062] Repeat the merging and updating steps until all samples are clustered into one cluster, forming a clustering tree or reaching the required number of clusters.
[0063] Step 3: Fit the client models in each cluster to obtain different cluster center model parameters;
[0064] Step 4: Calculate the cluster with the highest similarity between each cluster center model parameter and the global model parameter through cosine similarity to participate in training until the global model converges or reaches the required number of training rounds.
[0065] In the present invention, as a preference, it is set that the federated learning framework consists of a cloud server C, M edge servers, and N clients;
[0066] The set of edge servers is: M = {m 1 , m 2 ,... m M};
[0067] The set of clients is: N = {n 1 , n 2 ,... n N};
[0068] Each edge server m can cover multiple clients, and these clients are represented by N m , and the clients in the set N m all separately use local data to train local models. After training is completed, the clients in N m upload their respective models to the edge server m;
[0069] The dataset of the clients n covered by the edge server m is:
[0070]
[0071] wherein, |D m,n|The data volume size when performing local training for the nth client under the edge server m, (x i , y i ) represent the ith input data sample and its corresponding label respectively;
[0072] When the client performs local model training, set f i (x i , y i ; w) as the loss function of the ith data sample, and w is the parameter of the model. The goal of model training is to minimize the loss function based on the training dataset D, and its expression is:
[0073]
[0074] This problem is usually solved by the Stochastic Gradient Descent (SGD) method, that is, by iteratively updating the model parameters to minimize the loss function of the model on the training sample data. The update process of the model parameters is as follows:
[0075]
[0076] In the formula, t is the training round, η is the learning rate, is the gradient of the loss function f with respect to the parameter w at the point w t-1 .
[0077] In hierarchical federated learning, since the dataset is distributed among N clients and cannot be directly accessed by the edge server and the cloud server, the global loss function F(w) cannot be directly minimized. It is necessary to calculate the edge loss function F i associated with the client n j in the local dataset D i,j of the edge server m i,j (w) in the form of a weighted average of the local loss function f i (w);
[0078] The calculation formula of the edge loss function F i (w) is:
[0079]
[0080] In the formula, j is the serial number of the client associated with the edge server m i , D i is the local datasets of all clients associated with the edge server m i , D i,j is the local dataset of the client n i associated with the edge server m i , and f i,j (w) is the local loss function;
[0081] Then, the global loss function is obtained by the same calculation using the edge loss function F i (w). The formula for calculating the global loss function F(w) is as follows:
[0082] The formula for calculating the global loss function F(w) is:
[0083]
[0084] Cosine Similarity is a method for measuring the similarity between two vectors. It evaluates the degree of similarity by calculating the cosine value of the angle between the two vectors. In federated learning, the model parameters of each client can be regarded as a vector. Compared with other metric methods such as Manhattan distance and Euclidean distance, cosine similarity reflects the difference in the direction of model parameters, rather than the differences in size and position.
[0085] Let there be two attribute vectors, vector A and vector B. The formula for calculating their cosine similarity is:
[0086]
[0087] In the formula, A i and B i represent the respective components of vector A and vector B, ||·|| is the L 2 norm of the vector, and the value range of cosine similarity is [-1, 1].
[0088] The closer the cosine value is to 1, the closer the angle between the model parameters of the two clients is to 0 degrees, indicating that the data distributions of the two clients are more similar;
[0089] When the cosine value is close to 0 and the angle approaches 90 degrees, it means that the two vectors have no similarity.
[0090] Hierarchical clustering is a commonly used unsupervised learning algorithm. It constructs a hierarchical nested clustering tree by calculating the similarity between data points of different categories. Different from K-means clustering, this algorithm does not need to specify the number of clusters in advance. It can obtain the number of categories at any level, which is convenient for intuitively determining the class division, and can effectively handle outliers and noisy data.
[0091] Hierarchical clustering algorithms are divided into two types: agglomerative hierarchical clustering from bottom to top and divisive hierarchical clustering from top to bottom;
[0092] In the present invention, as a preference, the agglomerative hierarchical clustering algorithm is selected. First, all sample points are regarded as separate categories, and then the similarity between different samples is calculated pairwise. The two most similar clusters are gradually merged until the required number of clusters is reached or a clustering tree is generated, including:
[0093] (1) Initialization: Treat each sample as a cluster.
[0094] (2) Calculate similarity / distance: Calculate the similarity (or distance) between any two samples to form a similarity matrix (or distance matrix).
[0095] (3) Merge clusters: In each iteration, merge the two clusters with the highest similarity (or closest distance) into a new cluster.
[0096] (4) Update the similarity matrix (or distance matrix): Update the similarity matrix (or distance matrix) according to the actual merging situation to reflect the similarity (or distance) between the new cluster and other clusters.
[0097] (5) Repeat merging: Repeat steps (3) and (4) until all samples are clustered into one cluster to form a clustering tree, or until the required number of clusters is reached.
[0098] In the present invention, as a preference, a cosine similarity measurement method is selected to divide the similarity between clusters.
[0099] In the present invention, as a preference, a three - layer federated learning framework is established, including: a cloud server, an edge server, and a client. The specific steps are as follows:
[0100] A hierarchical federated learning method for resource heterogeneity proposed by this method first considers a three - layer federated learning framework, which includes a cloud server, an edge server, and a client. The main steps are as follows:
[0101] (1) Initialize the global model: The cloud server initializes a global model and sends it to each edge server; the edge server then sends the received global model to all clients.
[0102] (2) Local training: After receiving the global model, the client uses local data for model training.
[0103] (3) Upload updates: After local training is completed, the client sends the model parameters to the edge server.
[0104] (4) Client selection algorithm: Based on the model parameters uploaded by the client, the edge server calculates the cosine similarity, clusters the clients with similar data distributions, fits each cluster on this basis to find the cluster center, and finally calculates the similarity between the cluster center and the global model according to the cosine similarity, and selects the cluster (client set) with the highest similarity under each edge server.
[0105] (5) Edge aggregation: The edge server aggregates the received local models and uploads them to the cloud server.
[0106] (6) Edge server selection: The cloud server compares the global model parameters with the model parameters aggregated by the edge servers and selects a set of edge servers with smaller losses based on the confusion matrix for model update.
[0107] (7) Iterative training: This process is continuously repeated until the global model converges or reaches the required number of training rounds.
[0108]
[0109]
[0110] In each iteration of this algorithm, the cloud server performs the model update operation (line 4). In the first round of training, the cloud server broadcasts the initial global model parameters w 0 to all connected edge servers (line 5). If it is not the first round of iteration, Algorithm 2 is used to select edge servers. The cloud server then updates the global model based on the selected edge servers (lines 7 - 9). After receiving the model parameters broadcast by the edge servers, the client performs the local model update operation (lines 14 - 17). In each iteration, Algorithm 3 is used to select clients (line 18). The edge server aggregates the selected client models (line 19) and then sends the aggregated model to the cloud server (line 20). This iterative process is repeated until the model converges.
[0111] This algorithm uses a hierarchical federated learning method. Under the premise of ensuring data privacy and security, it utilizes its advantages to allow parallel local training on multiple edge servers. The cloud server is responsible for coordinating the update of the global model and the selection of edge servers, while the edge server is responsible for performing local training on its selected clients. In this way, this algorithm can protect the privacy of user data while using distributed computing resources to accelerate the model training process.
[0112] Regarding the problem of the cloud server's selection of edge servers, in the present invention, as a preference, a method based on the confusion matrix is used to implement, including:
[0113] Calculate the precision Precision and recall Recall through the confusion matrix;
[0114]
[0115] Calculate the F 1 score, set the F 1 score threshold, and judge the convergence trend of the global model through the threshold;
[0116]
[0117] where F1 The F-score is the harmonic mean of precision and recall, which is used to comprehensively consider the precision and recall scores.
[0118] When the F 1 score is greater than the threshold, the edge servers will be aggregated by the cloud server, so as to achieve the purpose of model cleaning.
[0119] In the present invention, as a preference, the threshold is selected in the way of a dynamic threshold, that is, 0.9 times the average value plus 0.1 times the standard deviation.
[0120] Among them, the four basic components of the confusion matrix are: True Positives (TP), True Negatives (TN), False Positives (FP), and False Negatives (FN).
[0121] True Positive, TP: The number of positive samples that the model correctly predicts as the positive class, which means that the model can accurately identify positive-class objects.
[0122] True Negative, FN: The number of negative samples that the model correctly predicts as the negative class, which means that the model can accurately identify negative-class objects and does not misclassify them as positive classes.
[0123] False Positive, FP: The number of negative samples that the model incorrectly predicts as the positive class, also known as false alarm, which means that the model incorrectly labels negative-class instances as positive classes.
[0124] False Negative FN: The number of positive samples that the model incorrectly predicts as the negative class, also known as missed alarm, which means that the model incorrectly labels positive classes as negative classes.
[0125]
[0126] Algorithm 2 is a process for the cloud server to screen edge servers during the global training process. In each iteration, the cloud server calculates the F1 score according to the accuracy and recall evaluation metrics, selects the set of edge servers with the best performance (lines 2 - 4), and by setting a threshold, compares the F1 scores of all edge servers with the threshold a. If the F1 score is lower than the threshold, it will be discarded and not be used as an edge server available for selection during the aggregation of the cloud server in this round; if the F1 score is higher than the threshold, the edge server will be added to the candidate set (lines 5 - 9).
[0127] In the present invention, as a preference, a hierarchical clustering algorithm based on cosine similarity is selected. The core of the algorithm lies in using cosine similarity to evaluate the similarity between different clients, and performing hierarchical clustering based on these similarities to select the clients participating in the global model update.
[0128] First, by calculating the cosine similarity between the model parameters of each client, the clients with similar data distributions are clustered into a cluster, aiming to improve the model accuracy, accelerate the model convergence, enhance the robustness, and solve the Non-IID problem. On this basis, the client models in each cluster are fitted to obtain different cluster center model parameters, and then the cluster with the highest similarity between the model parameters of each cluster center and the global model parameters is calculated through cosine similarity to participate in the training, thereby increasing the possibility of clients with representative data distributions participating in the training.
[0129]
[0130] Algorithm 3 is a hierarchical clustering algorithm that updates the weight vectors of the clients in an iterative manner and uses these weight vectors to construct or update a global model. First, the model parameters of each client are normalized (line 2). In order to eliminate the differences in the magnitudes of different model parameters, make the calculation of cosine similarity more accurate, and at the same time accelerate the algorithm convergence speed, improve the model stability and generalization ability. Calculate the cosine similarity between the clients based on the normalized model parameters, construct a similarity matrix (line 3), and obtain a nested clustering tree P using the agglomerative hierarchical clustering algorithm based on the calculated cosine similarity l , and finally obtain a clustering result where the clients with similar distributions are clustered into a cluster (line 4), fit the client models in each cluster to obtain the cluster centers (line 5), and then calculate the cosine similarity between the model parameters of each cluster center and the global model (line 6) to obtain a similarity result vector (line 6). Finally, select the most similar cluster of clients under each edge server for training (line 7).
[0131] Embodiment
[0132] 1. Experimental Setup
[0133] To evaluate the performance of a proposed hierarchical federated learning method HR-HFL for resource heterogeneity, two publicly available classification task datasets are used, as shown in Table 1.
[0134] Table 1 Dataset Statistical Table
[0135]
[0136] Baseline algorithms: The FedAvg algorithm and the FedCS algorithm are selected in this invention for comparison. Under the same experimental conditions, the performance of the three algorithms is evaluated using the global test accuracy and the number of communication rounds required to reach the target test accuracy as indicators respectively.
[0137] Datasets and data distributions: The MNIST dataset consists of a total of 70,000 28×28 pixel images, including 60,000 training images and 10,000 test images, with a total of 10 categories, and each category represents a number between 0 and 9. The CIFAR-10 dataset consists of 60,000 32×32 pixel color images, of which 50,000 images are used for training and 10,000 images are used for validation, with a total of 10 categories, including airplanes, cars, birds, cats, deer, dogs, frogs, horses, ships, and trucks. Two data distribution scenarios are simulated for the participating clients: IID and Non-IID settings. For the IID setting, this method uses a random partitioning method, that is, the data samples are randomly and evenly distributed to all clients. For the Non-IID setting, that is, there are different data distributions in the datasets among different clients. For the MNIST dataset: the same ill-conditioned non-independent and identically distributed partitioning method as FedAvg is adopted: first, the samples are sorted according to the digital labels, and then the samples are divided into multiple fragments, and a certain number of fragments are assigned to each client. For the CIFAR-10 dataset: the Dirichlet distribution is used to partition the dataset (Dir(α)). This method determines how the samples of each category are distributed among the clients by generating a proportional vector sampled from the Dirichlet distribution for each client. α is the concentration parameter (α>0), and this method assumes α = 1.0.
[0138] Models: Convolutional neural networks with eight layers and seven layers (Convolutional Neural Network, CNN) are trained on the MNIST and CIFAR-10 datasets respectively. For the MNIST dataset: the eight-layer CNN contains two convolutional layers, two pooling layers, and four fully connected layers. The seven-layer CNN contains two convolutional layers, two pooling layers, and three fully connected layers. The specific process is through two 5×5 convolutional kernels (with 32 and 64 channels respectively), the activation function is ReLU, and each convolutional layer is followed by a 2×2 max pooling layer to reduce the spatial dimension of the feature map, thereby reducing the number of parameters and the amount of computation, and then connected to a fully connected layer with 128 neurons and the ReLU activation function for data transmission, and finally connected to a fully connected layer with 10 neurons using the softmax activation function to output the probability distributions of 10 categories.
[0139] Hyperparameters: In the experiment, it is assumed that there are 10 edge servers and 100 clients. The parameter of the local training rounds of the clients is denoted as E, and through multiple experiments, it is determined that E = 5 is the optimal number of local training rounds for each client. The learning rate η is set to 0.03, the learning decay rate is 0.995, the batch sample size B for client training is 10, and the global training rounds are set to T = 300.
[0140] 2. Parameter Setting
[0141] Setting of the F1-Score Threshold for Edge Servers
[0142] Assuming that the local training rounds of the clients E = 5, the client batch sample size B = 10, and the learning rate η = 0.03, the F1 scores on each edge server were tested on the CIFAR-10 dataset (α = 1.0). Assuming there are 10 edge servers, after 100 rounds of training, the F1 scores of each edge server are as Figure 1 shown. It can be seen from the figure that during the training process, the F1 score values in similar rounds sometimes differ greatly, indicating that the model stability is poor. If we want to improve the generalization ability of the model and reduce the overfitting phenomenon, by setting a dynamic threshold to select well-performing edge servers to participate in the next round of training, the threshold is set as 9 + 1, that is, 0.9 times the average value plus 0.1 times the standard deviation. Taking the F1 score of the first edge server in the training as an example, it can be seen that after setting the threshold, the number of drastic changes in the F1 score on this edge server decreases, and the model performance is more stable, as Figure 2 shown.
[0143] 3. Resource Heterogeneity
[0144] To evaluate the effectiveness of this algorithm, through multiple experiments, it is determined that E = 5 is the optimal number of rounds for local client training, B = 10 is the optimal sample number for clients, η = 0.03 is the optimal learning rate. Taking the first round of training as an example, 0.092331633 is the optimal threshold for the F1 score of the edge server. On this basis, the three algorithms were compared under the Non-IID situation on the MNIST and CIFAR-10 datasets, as Figure 3As shown. It can be seen from the figure that, regardless of the dataset, compared with other baseline algorithms, the HR-HFL algorithm proposed in this method can always achieve higher accuracy and faster convergence. Especially for the CIFAR-10 dataset with relatively complex classification tasks, at the beginning of training, the accuracy of the HR-HFL algorithm exceeded that of the FedAvg and FedCS algorithms. Under the settings of three non-independent and identically distributed data, the highest accuracy of this algorithm reached 62.79%, 70.87%, and 76.16% respectively, while the highest accuracy of the FedAvg algorithm could only reach 51.50%, 65.99%, and 67.75%, and the highest accuracy of the FedCS algorithm could only reach 54.59%, 66.71%, and 69.98%.
[0145] Table 2 shows the model accuracies of three federated learning algorithms after 300 rounds of training on the MNIST and CIFAR-10 datasets under different conditions. It can be seen from the table that the HR-HFL algorithm proposed in this method shows good results in all cases, and the accuracy has been greatly improved. Taking the Non-IID of the CIFAR-10 dataset as an example, under the setting of case 1, the accuracy of the HR-HFL algorithm is improved by 12.14% and 6.22% compared with the FedAvg and FedCS algorithms respectively; under the setting of case 2, the accuracy of the HR-HFL algorithm is improved by 5.52% and 3.82% compared with the FedAvg and FedCS algorithms respectively; under the setting of case 3, it is improved by 3.58% and 1.99% respectively. The experimental results show that the performance of the HR-HFL algorithm is better than that of the baseline algorithm regardless of whether it is on the MNIST dataset or the CIFAR-10 dataset.
[0146] Table 2 Training model accuracies under different conditions
[0147]
[0148] Tables 3 and 4 show the number of communication rounds required for the three algorithms to reach the target test accuracy after 300 rounds of training on different datasets.
[0149] Taking the Non-IID situation of the MNIST dataset as an example, to reach an accuracy of 85%, the HR-HFL algorithm reduces the number of communication rounds by 14.29% compared with the FedCS algorithm; to reach an accuracy of 90%, the HR-HFL algorithm reduces the number of communication rounds by 20.59% and 23.94% compared with the FedAvg and FedCS algorithms respectively; to reach an accuracy of 95%, the HR-HFL algorithm reduces the number of communication rounds by 32.64% compared with the FedCS algorithm.
[0150] Taking the Non-IID situation of the CIFAR-10 dataset as an example, to achieve 40% accuracy, the HR-HFL algorithm reduces the number of communication rounds by 10.53% and 26.09% compared with the FedAvg and FedCS algorithms respectively; to achieve 50% accuracy, the HR-HFL algorithm reduces the number of communication rounds by 42.00% and 39.58% compared with the FedAvg and FedCS algorithms respectively; to achieve 60% accuracy, the HR-HFL algorithm reduces the number of communication rounds by 46.15% and 39.13% compared with the FedAvg and FedCS algorithms respectively; to achieve 70% accuracy, the HR-HFL algorithm requires 250 rounds, while the other two baseline algorithms fail to reach the target accuracy before training for 300 rounds.
[0151] The simulation of handwritten digit and image recognition tasks in actual applications is realized through the MNIST and CIFAR-10 datasets.
[0152] The experimental results show that on both datasets, whether in the IID or Non-IID situation, when reaching the same target accuracy, the HR-HFL algorithm proposed by this method always requires the fewest number of communication rounds, the convergence of the model is optimized, and the stability is improved.
[0153] Table 3 Number of communication rounds required to reach the target test accuracy on the MNIST dataset
[0154]
[0155] Table 4 Number of communication rounds required to reach the target test accuracy on the CIFAR-10 dataset
[0156]
[0157]
[0158] The hierarchical federated learning method for resource heterogeneity provided by the present invention, in order to simultaneously alleviate the impact of resources and Non-IID on federated learning, reduces the direct communication between the client and the cloud server by introducing an edge server, reduces the communication cost, and improves the efficiency and convergence speed of data transmission. By performing the selection of the edge server by the cloud server and the selection of the client by the edge server, the model performance is improved, the training time is reduced, and a faster convergence speed is obtained. Public datasets are selected for experiments, and the experiments show that the algorithm proposed by this method has stronger accuracy and convergence compared with traditional methods that only deal with resource heterogeneity or Non-IID.
[0159] Although the embodiments of the present invention have been disclosed as above, they are not limited to the applications listed in the specification and embodiments. It can be fully applied to various fields suitable for the present invention. For those skilled in the art, additional modifications can be easily made. Therefore, without departing from the general concept defined by the claims and their equivalents, the present invention is not limited to the specific details and the examples shown and described herein.
Claims
1. A hierarchical federated learning method for resource heterogeneity, characterized in that: include: Step 1: Establish a three-layer federated learning framework, including: cloud server, edge server and client; Step 2: The edge server calculates the cosine similarity between the model parameters of each client based on the model parameters uploaded by the client, and clusters the clients with similar data distribution into one cluster; Step 3: Fit the client model in each cluster to obtain different cluster center model parameters; Step 4: Calculate the cluster with the highest similarity between the center model parameters of each cluster and the global model parameters through cosine similarity to participate in training until the global model converges or reaches the required training rounds.
2. The hierarchical federated learning method for resource heterogeneity according to claim 1, characterized in that: The step one comprises: The cloud server initializes a global model and sends it to each edge server. The edge server sends the received global model to all clients. After receiving the global model, the client trains the model using local data; After local training is completed, the client sends the model parameters to the edge server.
3. The hierarchical federated learning method for resource heterogeneity according to claim 2 is characterized in that: Also includes; Setting up the federated learning framework; Cloud Server C , M Edge servers and N Clients The set of edge servers is: M = {m1,m2,...m M }; The client set is: N = {n1,n2,...n N }; Edge Server m Clients covered n The dataset is: In the formula, |D m,n | is the data size for local training of the nth client under edge server m, (x i ,y i ) represent the i-th input data sample and the corresponding label respectively; Margin loss function F i The calculation formula of (w) is: Where j is the edge server m i Associated client serial number, D i For edge server m i All associated client local data sets, D i,j For edge server m i Associated Clients n i The local dataset, f i,j (w) is the local loss function; The calculation formula of the global loss function F(w) is:
4. The hierarchical federated learning method for resource heterogeneity according to claim 3 is characterized in that: The calculation formula of the cosine similarity is: In the formula, A i , B i Represent the components of vector A and vector B respectively, || · || is the L2 norm of the vector, and the value range of cosine similarity is [-1,1].
5. The hierarchical federated learning method for resource heterogeneity according to claim 4 is characterized in that: The cloud server selection is implemented based on a confusion matrix method, including: The precision Precision and recall Recall are calculated through the confusion matrix; In the formula, F1 is the harmonic mean of precision and recall; Calculate the F1 score, set the F1 score threshold, and use the threshold to judge the convergence trend of the global model; When the F1 score is greater than the threshold, the edge server will be aggregated by the cloud server. The threshold is a dynamic threshold of 0.9 times the mean plus 0.1 times the standard deviation.
6. The hierarchical federated learning method for resource heterogeneity according to claim 5, characterized in that: In the step 2, an agglomerative hierarchical clustering method is used, including: Treat each sample as a cluster; Calculate the similarity between any two samples to form a similarity matrix; In each iteration, the two clusters with the highest similarity are merged into a new cluster; Update the similarity matrix according to the actual merging situation; Repeat the merging and updating steps until all samples are clustered into one cluster, forming a cluster tree or reaching the required number of clusters.
Citation Information
Cited By
Federal learning-based service deployment method and system
CN120528784A
Shield tunneling parameter early warning and recommendation method and system
CN120822050A
Defense method and device for defending federated learning backdoor attack and medium
CN121037123A
Asynchronous hierarchical federal learning method, system and device and medium
CN121119056A