Industrial user water consumption prediction method
Using the same initial global model and clustering technology, we predict water consumption for industry users, solving the problems of small user local data and heterogeneous distribution of water consumption data, and training a high-precision intra-cluster global model to meet the needs of users in different industries. forecast demand.
Patent Information
- Application Number
- CN202410648163.4
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2024-05-23
- Publication Date
- 2024-08-27
AI Technical Summary
The existing technology is difficult to scientifically and accurately predict the water consumption of industry users, especially when the user's local data is small, resulting in large model differences, and the water consumption data of users in different industries are not independently and identically distributed, making it difficult to train a model that satisfies the requirements. A global model of all user requirements.
The same initial global model is used to predict the water consumption data of users in various industries, and the user industry information is used to cluster, and finally the global model within the cluster is trained, and the differences in the models trained using the water consumption data of users in the same cluster are Smaller to improve prediction accuracy. Specific steps include the parameter server initializing the global model, the user updating and uploading the local model, and performing preliminary and secondary clustering aggregation to form the final global model within the cluster.
It achieves the unification and simplification of water consumption prediction methods for users in different industries, trains a global model within the cluster with high prediction accuracy, reduces the differences in user models in the same industry, improves the prediction effect, and facilitates users to adjust water use plans and production Task.
Smart Images

Figure CN118551889A
Abstract
Description
Technical Field
[0001] The present invention relates to the field of machine learning, and in particular to a method for predicting water consumption by industry users. Background Art
[0002] With the development of society and the improvement of people's living standards, the daily water consumption of residents and the industrial water consumption of various industries are increasing, resulting in an increasingly prominent problem of water shortage. In order to alleviate the problem of water shortage, various regions have successively issued industry water quota standards, divided water consumption into grades, and controlled water consumption by increasing the cost of excess water use. Scientific and accurate prediction of water consumption is of great significance for carrying out water supply planning and helping users control water costs.
[0003] Currently, users in various industries mainly use water consumption monitoring equipment to count water consumption, but this method cannot provide advance warning of water consumption exceeding the limit, and it is difficult to promptly remind users to adjust future water use plans and production task arrangements. In order to better predict, there is currently a prediction model method that uses LSTM neural network to train the model. However, when the LSTM neural network is trained using user local data, due to the small size of the user's local data, the model trained for each user may be quite different, making it difficult to train a neural network with good results.
[0004] Moreover, the existing federated learning methods are difficult to achieve good results in prediction problems, and the water consumption data of users in different industries are not independent and identically distributed. It is difficult to use general federated learning methods to train a single global model to meet the prediction requirements of all users, so it needs to be solved urgently. Summary of the invention
[0005] In order to avoid and overcome the technical problems existing in the prior art, the present invention provides a method for predicting water consumption of industry users. The present invention predicts the water consumption data of users in various industries through the same initial global model, and through the user industry information and multiple clustering, the finally trained intra-cluster global model can meet the prediction requirements of all users for water consumption, and the water consumption data distribution of users in the same cluster is similar, and the model trained using the water consumption data of users in the same cluster has little difference, and finally trains an intra-cluster global model with high prediction accuracy.
[0006] To achieve the above object, the present invention provides the following technical solutions:
[0007] A method for predicting water consumption of industry users.
[0008] S1, the parameter server randomly initializes a global model to obtain the initial global model;
[0009] S2, the user receives the initial global model broadcast by the parameter server, and uses the local water consumption data to train and update the initial global model to obtain a local model;
[0010] S3: The user uploads the local model and industry user information to the parameter server. The parameter server performs preliminary clustering on the local model based on the industry user information, so that users with similar industry user information are grouped into the same cluster.
[0011] S4, weighted aggregation of local models within the same cluster to obtain the global model within the cluster;
[0012] S5, the user receives the in-cluster global model broadcasted by the parameter server, updates the model parameters of the local model using the in-cluster global model to obtain the local in-cluster model, trains the local in-cluster model using the local water consumption data to obtain the updated local in-cluster model, and uploads the model parameters of the updated local in-cluster model to the parameter server;
[0013] S6, the parameter server receives the model parameters of the updated local cluster model and performs further clustering and aggregation to obtain an updated cluster global model; the user receives the updated cluster global model broadcasted by the parameter server, and completes the water consumption prediction by implementing the updated cluster global model after secondary clustering.
[0014] As a further solution of the present invention: the specific preliminary clustering training steps in step S3 are as follows:
[0015] S31: The parameter server receives model parameters and industry user information of the local model uploaded by n users, where the model parameters include network weight parameters and bias parameters;
[0016] S32: traverse the industry user information uploaded by all users, and judge the industry user information uploaded by each user to determine whether the parameter server already has a cluster corresponding to the industry;
[0017] If it exists, add the user to the cluster;
[0018] If it does not exist, create a new cluster and add the user to the new cluster;
[0019] S33: After the traversal is completed, n users are divided into m clusters, where n>=m, and the clustering is completed. n represents the number of user samples.
[0020] As a further solution of the present invention: since the user's water consumption data can only be stored locally and trained by the user himself, the specific training steps of further clustering and aggregation in step S6 are as follows:
[0021] S61. Calculate the model parameter difference by subtracting the model parameters of the updated local intra-cluster model uploaded by each user to the parameter server from the model parameters of the intra-cluster global model before the update. Calculate the corresponding L2 norm for each user based on the model parameter difference, and calculate the average L2 norm and the maximum L2 norm for each cluster.
[0022] S62. Determine whether both the average L2 norm and the maximum L2 norm in each cluster meet the set threshold conditions.
[0023] If both meet the conditions, calculate the cosine similarity using the model parameter difference, and perform hierarchical clustering on the cluster. During the clustering process, achieve sub-clustering so that the water consumption data in the user terminals within the same cluster conforms to independent and identically distributed. After aggregation, execute S63.
[0024] Otherwise, do not perform clustering on the cluster. After aggregation, execute S63.
[0025] S63. Determine whether the set aggregation rounds have been reached or whether there is a significant improvement in the accuracy of the coefficient of determination.
[0026] If not, repeat steps S5 to S6.
[0027] If so, stop training, achieve secondary sub-clustering, and obtain the final intra-cluster global model. A total of x clusters are finally divided in the secondary sub-clustering, where m < x < n, n represents the number of user samples, and m represents the number of clusters after preliminary sub-clustering.
[0028] As a further solution of the present invention: In step S1, use the same initial global model to predict the water consumption of all users. The structures of all user local models are consistent with the model structure of the parameter server. The model is divided into two layers. The first layer is a long short-term memory neural network layer, i.e., LSTM, and the second layer is a linear layer.
[0029] As a further solution of the present invention: In step S61, the L2 norm ||dw|| 2 is calculated as follows:
[0030]
[0031] where there are N model parameter differences, and dw i refers to the i-th model parameter difference among the model parameter differences dw.
[0032] As a further solution of the present invention: In step S62, the cosine similarity is calculated as follows:
[0033]
[0034] Among them, vector A and vector B are both model parameter differences;
[0035] A=(a 1 ,a 2 ,…,a N ); B = (b 1 ,b 2 ,…,b N ).
[0036] As a further solution of the present invention: In step S5, the user uses the local in-cluster model to make predictions on the test set, using the determination coefficient R 2 To judge the accuracy of the model, the determination coefficient R 2 As the number of model training times in the local cluster increases, the accuracy of the model gradually improves, and the determination coefficient R 2 The formula is as follows:
[0037]
[0038] Among them, K represents the amount of data of a single user, y k represents the real value of the k-th water consumption of the user, is the user's k-th water consumption prediction value, Indicates the actual average water consumption of users.
[0039] As a further solution of the present invention: after step S63, step S7 is further included.
[0040] S7, after stopping the training, the parameter server notifies the user that the training is finished, and the parameter server no longer receives the local final in-cluster global model uploaded by the user.
[0041] As a further solution of the present invention: when the user receives the model from the parameter server and trains and updates the received model locally, the loss function is used to calculate the loss according to the predicted water consumption value and the actual water consumption value, and then back propagation is performed to complete the model update.
[0042] As a further solution of the present invention: the loss function uses a mean square error loss function to obtain the average value of the sum of squares of the difference between the predicted water consumption value and the actual water consumption value, and its formula is as follows:
[0043]
[0044] Among them, K represents the amount of data of a single user, y k represents the real value of the k-th water consumption of the user, is the k-th water consumption prediction value of the user.
[0045] Compared with the prior art, the present invention has the following beneficial effects:
[0046] 1. The present invention uses the same initial global model to complete preliminary model training for water consumption data of users in different industries, so that the prediction method for water consumption data is more unified and simple; at the parameter server, multiple clustering is completed using user industry information uploaded by multiple users and model parameters obtained by the model after local water consumption data training, so that the same initial global model can finally obtain the in-cluster global model that best fits the actual water consumption data of the user itself after multiple rounds of clustering, so as to train a better local in-cluster model to meet the prediction requirements of users in different industries, that is, the same initial global model can be used to complete the model training for users in different industries, which is more convenient; and the final in-cluster global model has sufficient water consumption data when trained at the parameter server in the early stage, so as to reduce the difference in models trained by users in the same industry, and when other users need to predict water consumption, they can have a more accurate model for training, which is more convenient.
[0047] 2. The present invention utilizes the cluster federated learning method so that different users with less local water consumption data can jointly train a long short-term memory network model, namely, an LSTM neural network model, thereby improving the prediction effect of the neural network model.
[0048] 3. The present invention utilizes a cluster federated learning method to cluster users from different industries. First, the initial clustering is performed on users from different industries according to their industry information, so that customers with similar industry information are grouped into the same cluster, to preliminarily ensure that the water consumption data of users in the same cluster are independent and identically distributed. Secondary clustering is then performed based on the model parameter values of the pre-trained in-cluster global model and the trained in-cluster global model uploaded by the user. After multiple rounds of aggregation, the final in-cluster global model is obtained, so that the water consumption data of users in the same cluster can train a same in-cluster global model, thereby further obtaining a high-precision prediction effect. BRIEF DESCRIPTION OF THE DRAWINGS
[0049] Figure 1 The present invention is a flow chart of a method for predicting water consumption of industry users.
[0050] Figure 2 It is a schematic diagram of the system architecture in the present invention.
[0051] Figure 3 A schematic diagram of the process of a user using local data to train a local model in the present invention.
[0052] Figure 4 This is a schematic diagram of initial clustering in the present invention.
[0053] Figure 5 Schematic diagram of secondary clustering in the present invention.
[0054] Figure 6 The determination coefficient R2 of FL before clustering and the determination coefficient R of CFL after clustering in the present invention are 2 Schematic diagram for comparison of test results.
[0055] Figure 7 The determination coefficient R2 of FL before clustering and the determination coefficient R of CFL after clustering in the present invention are 2 Another comparison diagram of test results.
[0056] Figure 8 The determination coefficient R2 of FL before clustering and the determination coefficient R of CFL after clustering in the present invention are 2 Schematic diagram for comparison of test results.
[0057] Fig. 9 The determination coefficient R2 of FL before clustering and the determination coefficient R of CFL after clustering in the present invention are 2 Schematic diagram for comparison of test results. DETAILED DESCRIPTION
[0058] The following will be combined with the drawings in the embodiments of the present invention to clearly and completely describe the technical solutions in the embodiments of the present invention. Obviously, the described embodiments are only part of the embodiments of the present invention, not all of the embodiments. Based on the embodiments of the present invention, all other embodiments obtained by ordinary technicians in this field without creative work are within the scope of protection of the present invention.
[0059] See also Figure 1 to Figure 5 In an embodiment of the present invention, a method for predicting water consumption of industry users is provided.
[0060] S1, the parameter server randomly initializes a global model to obtain the initial global model;
[0061] S2, the user receives the initial global model broadcast by the parameter server, and uses the local water consumption data to train and update the initial global model to obtain a local model. A total of n different users conduct model training, and their industries include mining, food and fermentation, papermaking, textile, thermal power, etc.;
[0062] Compared with the existing method that requires uploading user data to the parameter server for model training, this method greatly improves the protection of data privacy, avoids the risk of sensitive data flow being hacked on the Internet, and is more secure;
[0063] S3. The user uploads the local model and industry user information to the parameter server. The parameter server performs preliminary clustering on the local model according to the industry user information, so that users with similar industry user information are assigned to the same cluster. A total of m clusters are obtained through the preliminary clustering, where 0 < m < n, and users with similar industry information are assigned to the same cluster;
[0064] The specific training steps for the preliminary clustering in step S3 are as follows:
[0065] S31: The parameter server receives the model parameters and industry user information of the local models uploaded by n users. The model parameters include the network weight (weights) parameters and bias (biases) parameters;
[0066] S32: Traverse all the industry user information uploaded by users, and judge each piece of industry user information uploaded by a user to determine whether there is already a cluster corresponding to this industry in the parameter server;
[0067] If it exists, add this user to this cluster;
[0068] If it does not exist, create a new cluster and add this user to the new cluster;
[0069] S33: After the traversal, n users are assigned to m clusters, where n >= m. The clustering is completed, and n represents the number of user samples.
[0070] S4. Perform weighted aggregation on the local models within the same cluster to obtain the intra-cluster global model;
[0071] According to the uploaded industry user information, perform preliminary clustering on the local models uploaded by different industry users, so that customers with similar industry user information are assigned to the same cluster, and complete the weighted aggregation, so that the intra-cluster global model updated on the parameter server can initially meet the water consumption requirements of each industry, initially solving the problem that due to the small local data of each user, the models trained by different users in the same industry have large differences, and initially improving the prediction effect of the trained model on the water consumption of users;
[0072] At the same time, the preliminary clustering also enables users in different industries to reduce the influence of the water consumption information of users in industries with a large span on the local models trained by them when training the local water consumption data through the intra-cluster global model. Compared with the local models obtained when training using the initial global model, the accuracy of the data predicted by using the intra-cluster global model is initially improved, enabling a more suitable local intra-cluster model for the water consumption of this industry to be trained locally, initially overcoming the problem that using the same initial global model cannot meet the prediction requirements of different industry users;
[0073] S5, the user receives the in-cluster global model broadcasted by the parameter server, updates the model parameters of the local model using the in-cluster global model to obtain the local in-cluster model, trains the local in-cluster model using the local water consumption data to obtain the updated local in-cluster model, and uploads the model parameters of the updated local in-cluster model to the parameter server;
[0074] In step S5, the user uses the local cluster model to make predictions on the test set and uses the determination coefficient R 2 To judge the accuracy of the model, the determination coefficient R 2 As the number of model training times in the local cluster increases, the accuracy of the model gradually improves, and the determination coefficient R 2 The formula is as follows:
[0075]
[0076] Among them, K represents the amount of data of a single user, y k represents the real value of the k-th water consumption of the user, is the user's k-th water consumption prediction value, Indicates the actual average water consumption of users.
[0077] In the present invention, the determination coefficient R 2 To judge the accuracy of the model, according to R 2 The output result is r2_score, which can judge the quality of the model and measure the accuracy of the model in predicting water consumption data;
[0078] When r2_score = 1, the predicted water consumption value in the user sample is completely equal to the actual water consumption value, without any error, indicating that the better the explanation of the independent variable to the dependent variable in the regression analysis, the higher the accuracy of the water consumption data prediction;
[0079] When r2_score=0, the determination coefficient R 2 The numerator and denominator of are equal, and each water consumption forecast value of the user sample is equal to the actual average water consumption;
[0080] When r2_score<0, the accuracy of the model is too low and the deviation is too large.
[0081] As the subsequent models are rotated multiple times due to further clustering, the coefficient of determination R 2 It will become larger and larger, so that the accuracy of the global model in the cluster finally obtained by the parameter server for predicting water consumption data can meet the user's usage needs.
[0082] S6, the parameter server receives the updated model parameters of the local cluster model and further clusters and aggregates them to obtain an updated cluster global model. The water consumption prediction is completed by implementing the updated cluster global model after secondary clustering.
[0083] After further clustering and aggregation, after completing the secondary clustering and aggregation and obtaining the final cluster global model, the users divided in each cluster are basically aligned with the industry, so as to minimize the impact of water consumption data of users in different industries on the cluster global model trained by users in the industry. At the same time, it better ensures that the water consumption data of users in various industries for training models is sufficient, so that users in various industries can use the cluster update model to predict water consumption more accurately, so as to remind users to adjust water use plans and production task arrangements in the future more timely, and also can achieve better prediction effects.
[0084] Since the user's water consumption data can only be stored locally and trained by the user himself, the specific training steps for further clustering and aggregation in step S6 are as follows:
[0085] S61, according to the model parameter difference obtained by subtracting the model parameters of the global model in the cluster before the update from the model parameters of the updated local cluster model uploaded by each user to the parameter server, the corresponding second norm of each user is calculated based on the model parameter difference, and the average second norm and the maximum second norm in each cluster are calculated;
[0086] Two-norm||dw|| 2 The calculation formula is as follows:
[0087]
[0088] Among them, there are N model parameter differences in total, and dw refers to the model parameter difference obtained by subtracting the model parameters of the global model in the cluster after training from the model parameters of each user before training. i It refers to the i-th model parameter difference in the model parameter difference dw.
[0089] After calculating the bi-norm of all users, in the m clusters obtained by the preliminary clustering, the bi-norm of the users contained in each cluster is compared to obtain the maximum bi-norm in each cluster, and the average bi-norm of the users contained in each cluster is calculated;
[0090] In the present invention, the bi norm is used to measure the change in the model parameters of each user, and the average bi norm and the maximum bi norm of all users in each cluster are compared with the set threshold to ensure that the overall error is minimized. Through further clustering, the difference in the distribution of water consumption data of users included in each cluster is reduced. Not only can users from different industries be clustered, but users of different magnitudes in the same industry can also be clustered. This allows each user to have sufficient water consumption data for model training, and also reduces the impact of data from users of different magnitudes in the same industry on the model trained by itself, making the prediction result more accurate.
[0091] S62, judging whether the average bi-norm and the maximum bi-norm in each cluster meet the set threshold conditions. The selection of the threshold varies according to actual needs. In this embodiment, it is specifically judged that the average bi-norm in each cluster is less than the set threshold 1, and the maximum bi-norm is greater than the set threshold 2;
[0092] If all of them are satisfied, it means that the water consumption data distribution of the users included in the cluster is quite different, and it is necessary to perform clustering operation on the cluster, calculate the cosine similarity using the model parameter difference, and perform clustering operation on the cluster using the cosine similarity, complete clustering in the clustering process, divide the cluster into two, complete clustering once, so that the water consumption data of the users in the same cluster conform to independent and identical distribution, and execute step S63 after the aggregation is completed, and obtain a more accurate model through re-training;
[0093] The Agglomerative Clustering algorithm is used to cluster all users in the clusters that need to be further clustered, and the complete-linkage method is used in the algorithm to calculate the distance to merge the clusters. In the complete-linkage method, the distance between two clusters is defined as the distance between the farthest two points in the two clusters (i.e., user A and user B), and the distance between any two points is the inverse of the cosine similarity.
[0094] When a cluster needs to be sub-clustered, it is divided into two. The data point refers to all the users in the cluster. Assuming that there are h users (or data points) in the cluster, then in the first step, these h users (or data points) are considered to be one cluster, and then these h clusters are hierarchically clustered. The result of clustering is to cluster these h clusters into two clusters, that is, clustering sub-clustering is achieved; for the cluster that initially needs to be clustered, this cluster is divided into two clusters, but the clustering process is actually the clustering effect of a clusters, so this process is called clustering sub-clustering process.
[0095] The calculation formula of cosine similarity is as follows:
[0096]
[0097] Wherein, vector A and vector B are model parameter difference vectors of user A and user B respectively, and the calculation method of dw in step S62 is the same;
[0098] A=(a 1 ,a 2 ,…,a N ); B = (b 1 ,b 2 ,…,b N ).
[0099] The specific steps for hierarchical clustering based on cosine similarity are as follows:
[0100] Step 1: Consider each data point in the cluster as a cluster, so there are h clusters (where h is the number of data points, i.e., the number of users contained in the cluster). Create a dendrogram with h leaf nodes, and each data point is a leaf node in the dendrogram.
[0101] Step 2: Calculate the mutually reachable distance between data points: Establish a distance matrix based on the cosine similarity between any two data points. The distance between any two data points is the opposite of the cosine similarity. Find the two nearest clusters and merge them, then the number of clusters is reduced by one (that is, the number of merged clusters is less than h); create a new node in the dendrogram (representing the merged cluster), and the two child nodes of this node are the two nearest clusters.
[0102] Step 3: Repeat step 2 until clustering ends when only one cluster containing all data points remains, and a clustering tree is obtained.
[0103] Step 4: Traverse the left and right subtrees of the root node respectively. The data points corresponding to all leaf nodes of the left subtree of the root node are one cluster, and the data points corresponding to all leaf nodes of the right subtree of the root node are the second cluster. In this way, all the data points in the cluster (that is, a cluster that initially needs to be clustered) are divided into two clusters through clustering operation. The cluster is finally divided into two, that is, the secondary clustering is completed.
[0104] Since the secondary clustering is to divide a cluster that initially needs to be clustered into two, the total number of clusters will increase. After the initial clustering, a total of m clusters are obtained. If some of the m clusters need to be further clustered, the cluster will be divided into two clusters, increasing the number of clusters. When the secondary clustering is finally completed, x clusters are obtained, so x>m.
[0105] If the condition is not met, it indicates that the water consumption data distribution of the users included in this cluster is similar. Therefore, there is no need to cluster this cluster. Instead, directly execute step S63 after aggregation. The global model within the cluster obtained after training can better fit the water consumption data of each user within the cluster, making the final prediction result more accurate.
[0106] S63, determine whether the set number of aggregation rounds has been reached or whether the accuracy of the coefficient of determination has been significantly improved;
[0107] If not, repeat steps S5 to S6;
[0108] After multiple rounds of repeated training, when the set number of aggregation rounds has been reached or the accuracy of the coefficient of determination has been significantly improved, stop the training to achieve secondary clustering. A total of x clusters are finally divided in the secondary clustering, where m < x < n, to obtain the final global model within the cluster. Compared with the initial clustering, the model parameters in each cluster after the secondary clustering are less different, making the prediction accuracy of the final global model within the cluster higher (it should be noted that the global model within the cluster obtained in step S61 is different from the final global model within the cluster obtained in step S63).
[0109] S7, after stopping the training, the parameter server notifies the user that the training is over, and the parameter server no longer receives the updated global model within the local cluster uploaded by the user.
[0110] After stopping the training, the user can obtain the final global model within the cluster from the parameter server. However, after obtaining the model, the user will no longer train the model and will not upload the local model within the cluster to the parameter server either, that is, the parameter server can pass it to the user, but the user cannot pass it to the parameter server;
[0111] Whether it is the updated local model within the cluster saved by the user or the final global model within the cluster saved by the parameter server, they are the latest training models that best suit the water consumption levels of various industries. The user can accurately predict their own water consumption data based on the local model within the cluster saved locally; and other new users can also download the global model within the cluster saved by the parameter server to train the local data and can also obtain relatively accurate prediction results.
[0112] It should be noted that in the present invention, the same initial global model is used to predict the water consumption of users. Therefore, the structures of all user local models are consistent with the model structure of the parameter server;
[0113] The model is divided into two layers. The first layer is a long short-term memory neural network layer, that is, LSTM, and the second layer is a linear layer;
[0114] LSTM is composed of each cell, each of which has three gates, including input gate, forget gate and output gate; each cell has 4 feedforward network layers, which are actually 4 activation functions, namely σ, σ, tanh and σ; these feedforward network layers also have neurons, namely hidden neurons; the number of hidden neurons in each feedforward network layer is the same, namely num_unitis, also written as hidden_size;
[0115] The input at the current time t is X t , X t The dimension of xt is input_size, or input_dim. The dimension of xt is defined by yourself and can be changed according to actual needs. In NLP, it is the dimension of the word vector. Each column (each X t ) represents a word vector.
[0116] In LSTM, both the current input and the past information must be considered at all times, so the input to the cell is H t-1 and X t The combination is concat, which is actually to put the two together directly, for example, H t-1 is 128 bits, X t is 28 bits, then the input vector is 156 bits.
[0117] The formula for the first layer of LSTM is as follows:
[0118] I t =σ(X t W xi +H t-1 W hi +b i ),
[0119] F t =σ(X t W xf +H t-1 W hf +b f ),
[0120] O t =σ(X t W xo +H t-1 W ho +b o ),
[0121]
[0122]
[0123] Ht =O t ⊙tanh(C t ).
[0124] Among them, I t ,F t ,O t , C t They are the input gate, forget gate, output gate, candidate memory element and memory element at time t, respectively. t is the hidden state at time t; W xi ,W xf ,W xo ,W hi ,W hf ,W ho ,W xc and W hc is the weight parameter, b i ,b f ,b o and b c is the bias parameter;
[0125] σ refers to the Sigmoid activation function, and its formula is as follows:
[0126]
[0127] For example, in I t middle, I t =σ(X t W xi +H t-1 W hi +b i ),
[0128] because,
[0129]
[0130] so,
[0131]
[0132] Candidate memory element Using the tanh function as the activation function, the formula is as follows:
[0133]
[0134] As can be seen from the above formula, each feedforward network layer has two parameters, W and b. The dimension of the weight parameter W is [hidden_size+input_size, hidden_size], and the dimension of the bias parameter b is hidden_size. Therefore, the dimension of each cell is [hidden_size+input_size, 4*hidden_size]. The weights of the cells are shared, and the LSTM at num_steps moments all share a set of parameters, that is, there are num_steps LSTM units, and in fact, this LSTM unit is executed num_steps times.
[0135] The formula for the second linear layer is as follows:
[0136]
[0137] Among them, H t is the hidden state at time t, is the output of the model, i.e. the predicted water consumption of the user sample, b y is the bias parameter, W h is the weight parameter.
[0138] In this embodiment, the dimension of the input feature of the first layer is input_size=5, the hidden state maintenance is hidden_size=32, the number of loop layers is num_layers=2, and the dimension order of the input data is (batch, seq_len, input_size);
[0139] Among them, batch is the number of samples selected for one training, seq_len is the length of the input sequence, and each water consumption data in this embodiment selects 5 dimensions, including the maximum hourly water consumption, the total daily water consumption, the minimum hourly water consumption, the first hourly water consumption, and the last hourly water consumption, so the input feature dimension is 5;
[0140] The input feature dimension of the second linear layer is 32, which is consistent with the hidden state dimension hidden_size of the first layer, that is, the input of the second layer is the hidden state of the first layer; the output dimension is 1;
[0141] In summary, the overall input dimension of the model is (batch, seq_len, input_size), and the output dimension is (batch, 1); it should be noted that the input feature dimension of the first layer can be changed, depending on how many dimensions the user's water consumption data has, and the hidden state dimension and the number of loop layers can be changed. Different hidden state dimensions and numbers of loop layers will have different effects on the training effect. The number of loop layers can be set to 1-4. In other embodiments, it can be changed according to actual needs, and the output dimension of the second layer cannot be changed and must be the same as the dimension of the hidden state of the first layer.
[0142] Since all users use the same initial global model, and when users use local water consumption data to train the model, they do so locally rather than directly on the parameter server, which involves multiple updates to the model. When users receive the model from the parameter server and train and update the received model locally, they use the loss function to calculate the loss based on the predicted water consumption value and the actual water consumption value, and then perform back propagation to complete the model update; the loss function uses the MSELoss (mean square error) loss function to obtain the average value of the sum of the squares of the difference between the predicted water consumption value and the actual water consumption value. The formula is as follows:
[0143]
[0144] Among them, K represents the amount of data of a single user, y k represents the real value of the k-th water consumption of the user, Represents the k-th water consumption forecast value of the user.
[0145] The test data are as follows:
[0146] In the setting of cluster federated learning, i.e. CFL, after the global model in the cluster makes predictions on the test sets of all users, each user calculates the r2_score, max r2_score, mean r2_score, and minr2_score of the model on its own test set, which refer to the maximum, average, and minimum r2_score of all users’ r2_scores, respectively;
[0147] In the setting of federated learning (FL), after the unified initial global model is predicted on the test sets of all users, each user calculates the r2_score, max r2_score, mean r2_score, and minr2_score of the model on its own test set, which refer to the maximum, average, and minimum r2_score of all users' r2_scores respectively;
[0148] Epoch refers to the number of rounds of local training by the user before uploading the local model, batch_size refers to the number of data samples captured in the training, and lr is the learning rate; round refers to the round of the FL or CFL aggregation model. The horizontal axis of the comparison diagram of each test result represents the communication rounds, the vertical axis represents the output result of the determination coefficient r2_score, and Clusters represents the number of clients participating in the training;
[0149] Reference Figure 6 :
[0150] When epoch=3, communication round com_round=800, batch_size=256, learning rate lr=0.0001, and a total of 12 clients participate in the training, after the training, the mean r2_score after CFL clustering is improved compared with the mean r2_score of FL, especially the min r2_score is significantly improved, and the max r2_score is not much different.
[0151] Reference Figure 7 :
[0152] When epoch=1, communication round com_round=1800, batch_size=256, learning rate lr=0.0007, and a total of 22 clients participate in the training, after the training, the mean r2_score after CFL clustering is improved compared with the mean r2_score of FL, especially the min r2_score is significantly improved, and the max r2_score is not much different.
[0153] Reference Figure 8 :
[0154] When epoch=25, communication round com_round=61, batch_size=256, learning rate lr=0.0001, and a total of 11 clients participated in the training, after the training, the mean r2_score, min r2_score and max r2_score of CFL clustering were improved compared with FL.
[0155] Reference Fig. 9 :
[0156] Set epoch = 4, communication round com_round = 300, batch_size = 256, learning rate lr = 0.0001, and a total of 11 clients participate in the training. At the end of the training, the mean r2_score, minr2_score and max r2_score of the CFL clustering are improved compared with those of FL.
[0157] In summary, after using CFL clustering, compared with FL, the determination coefficient R 2 The results obtained are getting bigger and bigger, that is, the prediction accuracy is getting higher and higher. Users can use this model to predict water consumption data and obtain higher prediction accuracy.
[0158] Of course, it is obvious to those skilled in the art that the present invention is not limited to the details of the exemplary embodiments described above, but also includes the same or similar structures that can be implemented in other specific forms without departing from the spirit or essential features of the present invention. Therefore, no matter from which point of view, the embodiments should be regarded as exemplary and non-limiting, and the scope of the present invention is defined by the appended claims rather than the above description, and it is intended that all changes falling within the meaning and scope of the equivalent elements of the claims are included in the present invention. Any reference numerals in the claims should not be regarded as limiting the claims involved.
[0159] In addition, it should be understood that although this specification is described in accordance with the implementation modes, not every implementation mode contains only one independent technical solution. This description of the specification is only for the sake of clarity. Those skilled in the art should regard the specification as a whole. The technical solutions in each embodiment can also be appropriately combined to form other implementation modes that can be understood by those skilled in the art. The technology, shape, and structure parts not described in detail in the present invention are all well-known technologies.
Claims
1. A method for predicting water consumption by industry users, characterized in that: S1, the parameter server randomly initializes a global model to obtain the initial global model; S2, the user receives the initial global model broadcast by the parameter server, and uses the local water consumption data to train and update the initial global model to obtain a local model; S3: The user uploads the local model and industry user information to the parameter server. The parameter server performs preliminary clustering on the local model based on the industry user information, so that users with similar industry user information are grouped into the same cluster. S4, weighted aggregation of local models within the same cluster to obtain the global model within the cluster; S5, the user receives the in-cluster global model broadcasted by the parameter server, updates the model parameters of the local model using the in-cluster global model to obtain the local in-cluster model, trains the local in-cluster model using the local water consumption data to obtain the updated local in-cluster model, and uploads the model parameters of the updated local in-cluster model to the parameter server; S6, the parameter server receives the model parameters of the updated local cluster model and performs further clustering and aggregation to obtain an updated cluster global model; the user receives the updated cluster global model broadcasted by the parameter server, and completes the water consumption prediction by implementing the updated cluster global model after secondary clustering.
2. A method for predicting water consumption of industry users according to claim 1, characterized in that: The specific preliminary clustering training steps in step S3 are as follows: S31: The parameter server receives model parameters and industry user information of the local model uploaded by n users, where the model parameters include network weight parameters and bias parameters; S32: traverse the industry user information uploaded by all users, and judge the industry user information uploaded by each user to determine whether the parameter server already has a cluster corresponding to the industry; If it exists, add the user to the cluster; If it does not exist, create a new cluster and add the user to the new cluster; S33: After the traversal is completed, n users are divided into m clusters, where n>=m, and the clustering is completed. n represents the number of user samples.
3. The method for predicting water consumption of industry users according to claim 1, characterized in that: Since the user's water consumption data can only be stored locally and trained by the user himself, the specific training steps for further clustering and aggregation in step S6 are as follows: S61, according to the model parameter difference obtained by subtracting the model parameters of the global model in the cluster before the update from the model parameters of the updated local cluster model uploaded by each user to the parameter server, the corresponding second norm of each user is calculated based on the model parameter difference, and the average second norm and the maximum second norm in each cluster are calculated; S62, determining whether the average two-norm and the maximum two-norm in each cluster both meet the set threshold conditions; If all conditions are satisfied, the cosine similarity is calculated by using the model parameter difference, and the cluster is hierarchically clustered using the cosine similarity. Clustering is achieved in the clustering process so that the water consumption data of the user terminals in the same cluster conform to independent and identical distribution. After the aggregation is completed, S63 is executed; Otherwise, the cluster is not clustered, and S63 is executed after the clustering is completed; S63, determining whether the set number of polymerization rounds has been reached or whether the accuracy of the determination coefficient has been significantly improved; If no, then repeat steps S5 to S6; If so, stop the training, implement the secondary clustering, and obtain the final global model within the cluster. A total of x clusters are finally divided in the secondary clustering, where m < x < n, n represents the number of user samples, and m represents the number of clusters after the preliminary clustering.
4. The method for predicting water consumption of industry users according to claim 1, characterized in that: In step S1, the same initial global model is used to predict the water consumption of all users. The structures and parameters of all user local models are consistent with the model structure of the parameter server. The model is divided into two layers. The first layer is a long short-term memory neural network layer, i.e., LSTM, and the second layer is a linear layer.
5. The method for predicting water consumption of industry users according to claim 3, characterized in that: In step S61, the calculation formula of the second norm ||dw||2 is as follows: Among them, there are N model parameter differences, dw i It refers to the i-th model parameter difference in the model parameter difference dw.
6. A method for predicting water consumption of industry users according to claim 4, characterized in that: In step S62, the calculation formula of the cosine similarity is as follows: Among them, both vector A and vector B are the differences in model parameters; <h2 style=";text-align:left;direction:ltr">A = (a1, a2,…, a)<h2 style=";text-align:left;direction:ltr"> N <h2 style=";text-align:left;direction:ltr"> );B=(b1,b2,…,b<h2 style=";text-align:left;direction:ltr"> N <h2 style=";text-align:left;direction:ltr"> )。 7. The method for predicting water consumption of industry users according to claim 1, characterized in that: In step S5, the user uses the local cluster model to make predictions on the test set and uses the determination coefficient R 2 To judge the accuracy of the model, the determination coefficient R 2 As the number of model training times in the local cluster increases, the accuracy of the model gradually improves, and the determination coefficient R 2 The formula is as follows: Among them, K represents the amount of data of a single user, y k represents the real value of the k-th water consumption of the user, is the user's k-th water consumption prediction value, Indicates the actual average water consumption of users.
8. The method for predicting water consumption of industry users according to claim 3, characterized in that: After step S63, step S7 is further included. S7. After stopping the training, the parameter server notifies the user that the training is over, and the parameter server no longer receives the local final global model within the cluster uploaded by the user.
9. The method for predicting water consumption of industry users according to claim 1, characterized in that: When the user receives the model from the parameter server and trains and updates the received model locally, the loss function is used to calculate the loss based on the predicted water consumption value and the actual water consumption value, and then backpropagation is performed to complete the update of the model.
10. A method for predicting water consumption of industry users according to claim 9, characterized in that: The mean squared error loss function is used as the loss function to obtain the average of the sum of the squares of the differences between the predicted water consumption value and the actual water consumption value. The formula is as follows: Among them, K represents the amount of data of a single user, y k represents the real value of the k-th water consumption of the user, is the k-th water consumption prediction value of the user.
