An equalization clustering method and device, electronic equipment and computer storage medium
By allocating samples in k-means clustering using an improved auction algorithm, the problem of unbalanced cluster size in the traditional k-means algorithm is solved, and a uniform distribution of samples in each cluster is achieved, which is suitable for occasions such as drone swarm grouping.
Patent Information
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- NANJING UNIV OF AERONAUTICS & ASTRONAUTICS
- Filing Date
- 2023-07-17
- Publication Date
- 2026-05-15
AI Technical Summary
Traditional k-means clustering algorithm cannot achieve a balance in cluster size, resulting in large differences in the number of samples in different clusters, which cannot meet the needs of balanced clustering in some situations.
An improved auction algorithm is used in the k-means clustering process. Initial cluster centers are randomly selected, and samples are allocated to each cluster center using an auction algorithm. Combined with price update rules, allocation conflicts are avoided, ensuring that the samples are evenly distributed.
It achieves a balanced cluster size, avoids sample allocation conflicts, and is suitable for any situation where a balanced cluster size is required.
Smart Images

Figure CN116821740B_ABST
Abstract
Description
Technical Field
[0001] This invention relates to a balanced clustering method, apparatus, electronic device, and computer storage medium, which can achieve balanced clustering of samples based on an improved auction algorithm. Background Technology
[0002] Conventional clustering algorithms often produce imbalanced clusters, meaning that the number of samples in different clusters can vary significantly. However, many clustering problems involve balanced priors in the problem domain and imbalance biases during data collection. This gives rise to the balanced graph partitioning problem: which aims to partition the vertices of a given graph into k nearly equal clusters.
[0003] The k-means clustering algorithm is an iterative clustering analysis algorithm. Its steps are as follows: First, the data is pre-divided into k groups. Then, k objects are randomly selected as initial cluster centers. Next, the distance between each object and each seed cluster center is calculated, and each object is assigned to the nearest cluster center. The cluster centers and the objects assigned to them represent a cluster. After each assignment, the cluster centers are recalculated based on the existing objects in the cluster. This process is repeated until a certain termination condition is met.
[0004] Traditional k-means clustering algorithms typically result in clusters of varying sizes. Given a fixed number of cluster centers (k), they merely minimize the distance from samples to the cluster centers, leading to clearly distinguishable clusters. However, in some situations where cluster sizes are required to be comparable, traditional clustering methods cannot achieve this. Summary of the Invention
[0005] Technical objective: To address the aforementioned technical problems, this invention proposes a balanced clustering method, apparatus, electronic device, and computer storage medium, which can be applied to any situation requiring balanced clustering scale.
[0006] Technical solution: To achieve the above technical objectives, the present invention adopts the following technical solution:
[0007] A balanced clustering method, characterized by comprising the following steps:
[0008] S1. Randomly select K samples from the sample set to be clustered as the initial K cluster centers;
[0009] S2. Select k samples from the remaining samples in the sample set, where k is less than or equal to K. Use an improved auction algorithm to assign the selected k samples to the K cluster centers. Set the value of the assigned samples to 0 to complete one auction allocation process.
[0010] S3. Repeat step S2 until all samples in the sample set are assigned, resulting in K clusters;
[0011] In step S2, the auction allocation process includes:
[0012] S2.1 For the selected k samples, calculate the distance (d) from each sample to each cluster center. ij );
[0013] S2.2, According to the distance (d) ij ), calculate the value of each sample relative to each cluster center (w) ij );
[0014] S2.3. Select a single sample from the selected k samples one by one, and execute steps S2.31 to S2.33:
[0015] S2.31 Initialization: Initialize the bid (p) of the current sample for each cluster center. i (0)), and store;
[0016] S2.32, Bidding: Based on the value of the current sample relative to each cluster center (w) ij ) and the price of the currently stored sample (p i (0); p i (τ)) calculates the profile of the current sample to each cluster center. ij The system determines the cluster center with the highest profit and submits a quote accordingly, while simultaneously updating the price of the current sample (p). i (τ+1)) and store it;
[0017] S2.33, Auction: Determine whether the cluster center with the highest profit determined in step S2.32 has been auctioned off by other samples among the selected k samples in this auction allocation process. If it has not been auctioned off, allocate the current sample to the cluster center with the highest profit, and the auction is successful; if it has been auctioned off, that is, there is a conflicting sample, return the conflicting sample, and re-bid for allocation.
[0018] Preferably, in step S2.33, the price of the sample is updated using the following formula:
[0019] p i (τ+1)=(w ij -p i (τ))-(w kj -p k (τ))+ε+p i (τ)
[0020] Among them, w ij -p i(τ) represents the j-th cluster center t j The maximum benefit in; w kj -p k (τ) represents the j-th cluster center t j The second largest return in the process; ε represents the growth rate;
[0021] p i (τ) represents the price of the i-th sample in the τ-th iteration; p k (τ) represents the price of the k-th sample at the τ-th iteration of the i-th sample, u i u k These represent the i-th sample and the k-th sample in the sample set, respectively; completing steps S2.31 to S2.33 constitutes one iteration.
[0022] Preferably, in step S2.33, the current sample bids against the conflicting sample, including the following steps:
[0023] Calculate the profit of the current sample and the conflicting sample relative to the cluster center with the highest profit;
[0024] The sample with the greater benefit among the current sample and the conflicting samples is assigned to the cluster center with the greatest benefit, and the price of the sample with the greater benefit is updated.
[0025] Return to step S2.32 and re-bid for the sample that has not been assigned a cluster center between the current sample and the conflicting sample.
[0026] Preferably, in step S2.2, the value of each sample relative to each cluster center is expressed as:
[0027] w ij =maxd ij -d ij
[0028] d ij Represents the i-th sample u in the sample set i To the j-th cluster center t j The distance, i = 1, 2, 3, ..., N, where N represents the number of samples in the sample set, maxd ij It is the maximum distance of each sample relative to each cluster center.
[0029] Preferably, the method further includes: step S4, calculating the centroid of each cluster, and ending the clustering process if the centroid does not change or the maximum number of auction allocation processes is reached.
[0030] A balanced clustering device, characterized in that it comprises:
[0031] The cluster center determination module is used to randomly select K samples from the sample set to be clustered as the initial K cluster centers;
[0032] The auction allocation module is used to select k samples from the remaining samples in the sample set, where k is less than or equal to K, and use an improved auction algorithm to allocate the selected k samples to the K cluster centers. The value of the allocated samples is set to 0, thus completing one auction allocation process.
[0033] The loop and output module is used to call the auction module until the allocation of all samples in the sample set is completed, resulting in K clusters.
[0034] An electronic device, characterized in that: the electronic device includes a processor and a memory; wherein the memory is used to store a computer program, the computer program being loaded and executed by the processor to implement the method.
[0035] A computer-readable storage medium, characterized in that a computer program is stored on the computer-readable storage medium, and the computer program implements the method when executed by a processor.
[0036] Beneficial effects: Due to the adoption of the above technical solution, the present invention has the following beneficial effects:
[0037] This invention can solve the problems of traditional k-means clustering algorithm, and can also solve the problem of multiple samples competing for the same cluster center in auction algorithm. It has no allocation conflict and is applicable to any occasion where the cluster size balance is required. Attached Figure Description
[0038] Figure 1 This is a flowchart of the balanced clustering method of the present invention;
[0039] Figure 2 for Figure 1 The flowchart of an auction algorithm called in the process. Detailed Implementation
[0040] The embodiments of the present invention will now be described in detail with reference to the accompanying drawings.
[0041] This invention proposes a balanced clustering method based on k-means clustering. The value of k is chosen based on the needs of the practical problem, and the number of samples is evenly distributed among the clusters. During the iterative process of the k-means algorithm, it is necessary to select the nearest center for each sample. An auction algorithm is introduced in this step, where k optimal samples are selected in each round for auction to choose their clusters, until every sample is assigned.
[0042] 1. Problem Description
[0043] A set U = {u1, u2, ..., u3} consisting of N samples N The clusters need to be divided into K clusters, with the cluster center set T = {t1, t2, ..., t3}. K The number of samples in each cluster is the average vector number:
[0044]
[0045] in It represents rounding up.
[0046] When executing the k-means clustering algorithm, the distance from each sample location to the cluster center is calculated sequentially, and the sample is assigned to the nearest cluster center. This method cannot control the number of data points in each cluster to achieve balanced clustering. Only by assigning one data point to each cluster simultaneously can uniform clustering be achieved. Essentially, this problem is an optimization problem: each time, k data points are selected from the data pool and assigned to k clusters to minimize the sum of their distances to their respective centroids (cluster centers). In the next round of assignment, previously assigned points are not considered again until all points have been assigned.
[0047] The optimization objectives for each allocation are as follows:
[0048]
[0049]
[0050] st
[0051]
[0052]
[0053] Equation (1) is the objective function, representing the minimum total distance, d ij Represents the i-th sample u i To the j-th cluster center t j The distance. Equations (2) to (3) are constraints. Equation (2) means that each class must be assigned a sample, and Equation (3) means that each sample can be assigned to at most one cluster.
[0054] After all samples have been assigned, the cluster centers are recalculated.
[0055] 2. K-means equilibrium clustering based on auction algorithm
[0056] The algorithm treats the current cluster center as the auction agent and each sample as the intelligent bidder. In each iteration, each sample solves the optimization problem, bidding for the nearest cluster center. The algorithm stops when the price vector no longer changes. Of course, multiple samples may compete for the same cluster center, in which case price updates are needed to ensure algorithm convergence and avoid allocation conflicts. The price vector is a term used for multi-dimensional data; essentially, it represents the price of each cluster.
[0057] The number of cluster points is N; the number of cluster centers is K, with the relationship N>K. The optimization objective is to assign one sample to each cluster center to maximize the total benefit.
[0058] Assume u i The price is p i Each sample relative to each cluster center t j The value is:
[0059] w ij =maxd ij -d ij ,
[0060] d for each sample ij They are all different, maxd ij It is the d of each sample relative to each cluster center. ij The maximum value of w. Because we need to maximize the total profit, and the smaller the distance, the greater the total profit. ij =d ij Therefore, the greater the distance, the greater the benefit, which is calculated by w. ij =maxd ij -d ij Therefore, the smaller the distance, the greater the value.
[0061] The corresponding benefit is profile ij =w ij -p i .
[0062] In the auction algorithm, each cluster center t j For each sample u i The bidding process, therefore, makes the price update rule the core of the auction algorithm. Assume that in the τth iteration, sample u... i The price is denoted as p i (τ), the price update formula is as follows:
[0063] p i (τ+1)=(w ij -p i (τ))-(w kj -p k (τ))+ε+p i(τ)
[0064] Where w ij -p i (τ) represents the cluster center t j Maximum profit, w kj -p k (τ) represents the second-largest return, and i and k represent the sample u, respectively. i u k .
[0065] To avoid several samples competing for clusters of equal value while the bid remains unchanged, the algorithm gets stuck in an infinite loop. A given increment is introduced to break the loop, which requires that the bid price for each item must increase by at least ε compared to the previous bid price, where ε>0.
[0066] The algorithm steps are as follows:
[0067] Step 1: Initialization, let p i (0) = 0, i = 1, ..., N.
[0068] Step 2 involves bidding. For the current sample, the cluster center with the highest potential profit is calculated. It is then determined whether this center has already been bid for. If not, the current sample is assigned to that cluster center. j At the same time, update the price of the current sample; if it has been auctioned off by other samples, it means that there is a conflicting sample, then proceed to Step 3, and auction the current sample against the conflicting sample;
[0069] Step 3 of the bidding process involves returning to the cluster center t that yields the highest return. j The sample ui with the highest profit among the current sample and conflicting samples is selected for bidding. In other words, the sample u with the highest profit... i Assigned to cluster center t j At the same time, update its price p i (τ+1), then return to step 2 and re-bid on the other sample of the two.
[0070] Step 4: Once a sample has been selected for all cluster centers, the process ends.
[0071] The following example, which deals with drone swarm grouping, illustrates the method of the present invention:
[0072] For example, if the sample set contains a total of 10,000 samples: u1, u2, ..., u 10000 It needs to be clustered into 10 clusters t1, t2, ..., t 10 .
[0073] First, 10 samples are randomly selected as 10 initial cluster centers, t1, t2, ..., t3.10
[0074] For unassigned u1, u2, ..., u 10000 All samples were processed individually:
[0075] Using the bidding method described above, for the current sample u i (1≤i≤100000), calculate the profit of each cluster center, and select the sample t with the highest profit. p (1≤p≤10), conduct bidding and update cluster center t. p The price.
[0076] When for sample u j (1≤j≤100000, j≠i) When calculating the revenue for bidding on each cluster center, if the cluster center with the highest current revenue is t... q (1≤q≤10, q≠p), then u j Assigned to t q In the middle, and update the cluster center t q The price is used to allocate the next sample; if the sample u is... j The clustering with the highest current return is also t. p (There is a conflict), then return to the conflicting sample u i Reassignment;
[0077] Using the above method, complete u1 to u one by one. 10000 The bidding and auction will include samples Assign cluster centers t1, t2, ..., t 10 ;
[0078] Repeat the above allocation process, and the already allocated samples (such as...) ) does not participate in the allocation, and 10 samples are allocated each time. To 10 cluster centers t1, t2, ..., t 10 This process continues until all samples are assigned to a cluster center, thus achieving a balanced clustering process.
[0079] (3) Algorithm Implementation
[0080] The idea behind the balanced K-means clustering method based on the auction algorithm is to use an auction algorithm to allocate K points to K cluster centers at a time when assigning each point to the nearest cluster center, until all points are assigned to one cluster.
[0081] The algorithm pseudocode is as follows:
[0082] Step 1: Randomly select K samples as initial cluster centers;
[0083] repeat
[0084] Step 2 calls the auction algorithm described above to assign a sample to each cluster center and sets the value of the assigned samples to 0.
[0085] Step 3: Repeat Step 2 until all samples are placed into one cluster;
[0086] Step 4: Recalculate the centroid of each cluster;
[0087] until the centroid remains unchanged or the maximum number of iterations is reached, where the maximum number of iterations can be an empirical value.
[0088] In the specific calculation process, the value of ε is crucial. While maximizing the value of ε to achieve approximate optimal allocation will reduce computational workload and accelerate algorithm completion, an excessively large value of ε will cause the algorithm to converge too quickly, making it difficult to obtain an approximate optimal solution. For complete allocation, generally taking ε < 1 / K yields an approximate optimal solution.
[0089] This invention is applicable to any situation requiring balanced cluster size, such as drone swarm grouping and handwritten digit grouping. The processing flow is the same for different data types; the difference lies in the fact that, for drone swarm grouping, the distance calculation is the physical distance from the drone to the cluster center; while for handwritten digit grouping, the image is represented in binary, and the distance is the difference between the multidimensional data vectors.
[0090] The foregoing has shown and described the basic principles, main features, and advantages of the present invention. Those skilled in the art should understand that the above embodiments do not limit the present invention in any way, and all technical solutions obtained by equivalent substitution or equivalent transformation fall within the protection scope of the present invention.
Claims
1. A balanced clustering method, characterized in that, The method is applied to drone swarm grouping and includes the following steps: S1. Randomly select K samples from the sample set to be clustered as the initial K cluster centers, wherein the samples are drones; S2. Select k samples from the remaining samples in the sample set, where k is less than or equal to K. Use an improved auction algorithm to assign the selected k samples to the K cluster centers. Set the value of the assigned samples to 0 to complete one auction allocation process. S3. Repeat step S2 until all samples in the sample set are assigned, resulting in K clusters; In step S2, the auction allocation process includes: S2.1 For the selected k samples, calculate the distance from each sample to each cluster center. The distance It is the physical distance from each drone to each cluster center; S2.2, Based on the distance Calculate the value of each sample relative to each cluster center. ; S2.
3. Select a single sample from the selected k samples one by one, and execute steps S2.31 to S2.33: S2.31 Initialization: Initialize the bids of the current sample for each cluster center. and store; S2.32, Bidding: Based on the value of the current sample relative to each cluster center. And the price of the currently stored samples Calculate the benefit of the current sample to each cluster center. It then identifies the cluster center with the highest profit and quotes a price accordingly, while simultaneously updating the price of the current sample. And store; S2.33, Auction: Determine whether the cluster center with the highest profit determined in step S2.32 has been auctioned off by other samples among the selected k samples in this auction allocation process. If it has not been auctioned off, allocate the current sample to the cluster center with the highest profit, and the auction is successful; if it has been auctioned off, that is, there is a conflicting sample, return the conflicting sample, and re-bid for allocation.
2. The balanced clustering method according to claim 1, characterized in that, In step S2.32, the price of the sample is updated using the following formula: in, Indicates the first Cluster centers The maximum benefit in; Indicates the first Cluster centers The second largest gain; Indicates the amount of growth; Indicates the first The first sample The price at the next iteration; Indicates the first The sample at the th The first sample The price at the next iteration , Representing the first in the sample set respectively The sample, the first One sample; completing steps S2.31 to S2.33 constitutes one iteration. .
3. The balanced clustering method according to claim 1, characterized in that, In step S2.2, the value of each sample relative to each cluster center is expressed as: In the sample set, the first... Sample To the Cluster centers distance, , This indicates the number of samples in the sample set. It is the maximum distance of each sample relative to each cluster center.
4. The balanced clustering method according to claim 1, characterized in that, It also includes: Step S4, calculating the centroid of each cluster. If the centroid does not change or the maximum number of times the auction allocation process is reached, the clustering process ends.
5. A balanced clustering apparatus, performing the method according to any one of claims 1-4, characterized in that, The device is used for drone swarm grouping and includes: The cluster center determination module is used to randomly select K samples from the sample set to be clustered as the initial K cluster centers, wherein the samples are drones; The auction allocation module is used to select k samples from the remaining samples in the sample set, where k is less than or equal to K, and use an improved auction algorithm to allocate the selected k samples to the K cluster centers. The value of the allocated samples is set to 0, thus completing one auction allocation process. The loop and output module is used to call the auction allocation module until the allocation of all samples in the sample set is completed, resulting in K clusters, that is, K groups of drones.
6. An electronic device, characterized in that: The electronic device includes a processor and a memory; wherein the memory is used to store a computer program, which is loaded and executed by the processor to implement the method as described in any one of claims 1 to 4.
7. A computer-readable storage medium, characterized in that, The computer-readable storage medium stores a computer program that, when executed by a processor, implements the method as described in any one of claims 1 to 4.