Clustering center updating method and K-means clustering algorithm acceleration system

By replacing traditional memory read and write operations with matrix operations, the delay problem in updating the cluster center in the K-means clustering algorithm is solved, parallel processing is achieved, and the efficiency of cluster center update is improved.

CN118606735APending Publication Date: 2024-09-06XIAMEN UNIV
View PDF 0 Cites 0 Cited by

Patent Information

Application Number
CN202410648268.X
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2024-05-23
Publication Date
2024-09-06

AI Technical Summary

Technical Problem

The traditional K-means clustering algorithm has frequent read and write memory operations when updating the cluster center, causing latency problems. In multi-threaded or parallel environments, data cannot be processed in parallel due to memory consistency, resulting in low efficiency.

Method used

Matrix operations are used to replace conventional memory read and write operations, and new clustering centers are calculated through the multiplication and accumulation of data point matrices and number matrices, avoiding the multiple memory searches and address mapping operations required in traditional methods, and achieving Parallel processing.

Benefits of technology

It effectively reduces the delay caused by multiple reads and writes of memory, solves the problem of memory consistency that cannot process data in parallel, and improves the efficiency of cluster center updates.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN118606735A
    Figure CN118606735A
Patent Text Reader

Abstract

The invention discloses a clustering center updating method and a K-means clustering algorithm acceleration system. The updating method comprises the following steps: successively obtaining data points and serial numbers; storing the data points obtained each time into a data point matrix; storing the serial number obtained each time into a serial number matrix; multiplying the data point matrix stored at the same time by the transposed number matrix to obtain an input matrix; successively accumulating the input matrixes to obtain an accumulated matrix; gradually accumulating the number matrixes to obtain a number matrix; and dividing the accumulation matrix by the quantity matrix to obtain a clustering matrix. According to the updating method, matrix operation is adopted to replace memory read-write operation, and the delay problem caused by frequent memory read-write and the memory consistency problem during parallel data processing are solved.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present invention relates to the technical field of clustering algorithms, and in particular to a cluster center updating method and a K-means clustering algorithm acceleration system. Background Art

[0002] In the traditional K-means clustering algorithm, the algorithm steps can be roughly described as follows:

[0003] 1. Initialization: First, randomly select an initial cluster center for each cluster. These centers are usually data points or carefully selected by a specific algorithm (such as K-means++).

[0004] 2. Distance calculation: Next, traverse each data point in the data set, calculate its Euclidean distance (i.e. L2 distance) to all cluster centers, and then assign each data point to the class to which the nearest cluster center belongs.

[0005] 3. Classification: For each class, count all the data points assigned to it. For each dimension within the class, add up the values ​​of these data points on that dimension to form a cumulative sum.

[0006] 4. Update the cluster center: After the accumulation is completed, for each cluster, divide the cumulative sum of each dimension of all data points in the class by the number of members of the class (that is, the number of data points belonging to the class) to obtain the coordinate value of the new cluster center. In short, each dimension of the new cluster center is the mean of all data point values ​​in that dimension.

[0007] 5. Repeat: Repeat steps 2 to 4 until the change in the cluster center is less than a certain threshold, or the preset number of iterations is reached, and the algorithm ends.

[0008] This process is essentially to achieve the purpose of data clustering by gradually adjusting the location of the cluster center through continuous iterations to minimize the total distance from the data points to the center in each cluster. In each iteration, the update of the cluster center depends on the distribution of the current data points, and the distribution of data points depends on the location of the cluster center. The two influence each other until convergence.

[0009] In traditional hardware implementations, the step of updating the cluster center usually involves processing each cluster one by one, and requires accessing the memory to read and update the coordinate values ​​of the cluster center, which involves a large number of read and write memory operations. In a multi-threaded or parallel environment, memory consistency issues will also be encountered. Summary of the invention

[0010] The purpose of the present invention is to overcome the above-mentioned defects or problems existing in the background technology, and to provide a cluster center updating method and a K-means clustering algorithm acceleration system, which can improve the delay problem caused by frequent reading and writing of memory in the method of updating cluster centers in the prior art, as well as the problem of being unable to process data in parallel due to memory consistency.

[0011] To achieve the above object, the present invention adopts the following technical solutions:

[0012] Technical Solution 1: A cluster center updating method, which is used to update the cluster center in the K-means clustering algorithm; before the K-means clustering algorithm performs the cluster center updating step, it also includes initialization, distance calculation and classification steps; the initialization step sets a number of classes, each class includes an initial cluster center; the distance calculation step calculates the distance between all data points and each cluster center; the classification step assigns a number corresponding to the class to which each data point belongs based on the distance obtained in the distance calculation step; the cluster center updating step includes: successively acquiring data points processed in parallel and the numbers corresponding to each data point; assigning the data points acquired each time to the cluster center; The points are stored in a data point matrix, the rows of the data point matrix correspond to the data points processed in parallel, and the columns correspond to the dimensions of each data point; the numbers obtained each time are stored in a number matrix, the rows of the number matrix correspond to the numbers processed in parallel, and the columns correspond to the classes corresponding to each number; the data point matrix stored at the same time is multiplied with the transposed number matrix to obtain an input matrix; the input matrix is ​​accumulated one by one to obtain an accumulated matrix; the number matrix is ​​accumulated one by one to obtain a quantity matrix; the accumulated matrix is ​​divided by the quantity matrix to obtain a clustering matrix; the rows of the clustering matrix correspond to the classes, and the columns correspond to the dimensions of the cluster centers of each class.

[0013] Technical Solution 2 based on Technical Solution 1: Each acquired number is processed by the following formula and stored in the number matrix: Number matrix = ReLU ((A-number) · (2-A+number)); wherein the ReLU function formula is: A=[1,2,3,4,5,6…,Kmax], Kmax is the maximum number of cluster centers; in the numbering matrix, the position of element 1 in each row represents the class corresponding to the number.

[0014] Technical solution three based on technical solution one: the size of the data point matrix is ​​(Pd, Dmax), Pd is the data point parallelism, indicating the number of data points processed in parallel, and Dmax is the maximum dimension of the data point; when the dimension of the data point acquired each time is less than Dmax, the elements in the insufficient positions are set to 0.

[0015] Technical solution 4 based on technical solution 1: after each acquisition of all parallel processed data points, the data point matrix outputs the storage result and clears all elements to restart the acquisition of the next parallel processed data points.

[0016] Technical solution five based on technical solution one: after each time the numbering matrix obtains the numbers corresponding to all the data points processed in parallel, it outputs the stored results and clears all elements to restart obtaining the numbers corresponding to the data points processed in parallel next time.

[0017] Technical solution six based on technical solution one: the acquired data points are counted by a counter to realize the successive acquisition of the data points for parallel processing; the preset value of the counter is the dimension of the data point, and the counter is reset each time a data point is acquired. When the number of reset times of the counter is consistent with the number of data points for parallel processing, the acquisition of the data points for parallel processing is completed once.

[0018] Technical solution seven based on technical solution one: after obtaining the clustering matrix, each element in the clustering matrix is ​​extracted and stored for use in the next iteration.

[0019] In addition, the present invention also provides technical solution eight: a K-means clustering algorithm acceleration system, which is used to accelerate the K-means clustering algorithm, and includes: an input component, which includes a data point storage module and a cluster center storage module, the data point storage module stores all data points, and the cluster center storage module stores all cluster centers; a distance measurement component, which includes a plurality of distance measurement modules, the distance measurement modules receive data points transmitted by the data point storage module and cluster centers transmitted by the cluster center storage module, and calculate the distance between each data point and each cluster center; a classification component, which includes a plurality of comparison modules, the comparison module is used to compare the distance calculated by the distance measurement component to obtain the cluster center closest to the data point, and assign the class number corresponding to the cluster center to the distance point; and an update component, which uses the cluster center update method described in any one of claims 1-7 to update the cluster center, the data points and numbers received by it are respectively from the input component and the classification component, and the updated cluster center is transmitted to the cluster center storage module.

[0020] Technical solution nine based on technical solution eight: the update component includes: a data point transmission module, which is used to receive and successively output parallel processed data points; an update module, which is used to obtain the parallel processed data points successively output by the data point transmission module and the numbers corresponding to the data points, and update the cluster center according to the cluster center update method described in any one of technical solutions one to seven.

[0021] Technical solution 10 based on technical solution 8: In the ranging component, the ranging modules are divided into two groups to simultaneously calculate the distance between a data point and two cluster centers, and each group includes ranging modules consistent with the number of data points processed in parallel to simultaneously calculate the distances between multiple data points and cluster centers; in the classification component, the number of comparison modules is consistent with the number of data points processed in parallel to compare multiple data points at the same time.

[0022] It can be seen from the above description of the present invention that, compared with the prior art, the present invention has the following beneficial effects:

[0023] The cluster center updating method provided by the present invention adopts matrix operations to replace conventional memory read and write operations, thereby improving the delay problem caused by frequent memory reading and writing in the cluster center updating method in the prior art, and the problem of being unable to process data in parallel due to memory consistency.

[0024] After obtaining the data points and the corresponding numbers, the cluster center update method forms a data point matrix and a number matrix, and then multiplies the two to obtain an input matrix. The input matrix is ​​accumulated to obtain an accumulation matrix, and the number matrix is ​​accumulated to obtain a quantity matrix; wherein, the accumulation matrix stores the accumulated value information of the data points belonging to the same class, and the quantity matrix stores the number of accumulated data points in each class. The cluster matrix is ​​obtained by dividing the data points and classification information stored in the two respectively, and the cluster matrix stores the information of the new cluster center. The data point matrix is ​​used to integrate the data points processed in parallel into a matrix to facilitate subsequent parallel computing operations; the number matrix is ​​to splice the number information corresponding to the data points in a matrix manner, and is used to multiply the data point matrix to obtain a new input matrix. In the process of processing the matrix, the input matrix accumulation means that after each input matrix is ​​obtained, the input matrix obtained this time is added to the previous accumulation matrix to obtain a new accumulation matrix; the accumulation of the quantity matrix is ​​similar.

[0025] By multiplying the data point matrix and the number matrix, the data points can be assigned to the corresponding positions, avoiding the need to perform memory search by number in the conventional update method to place the data points in the corresponding positions; on the other hand, the data points assigned to the same position will undergo matrix addition, thereby aggregating multiple memory read and write operations required in the conventional update method into one operation, effectively reducing the delay caused by multiple memory read and write operations; each time the accumulation matrix is ​​added, the information of the multiple data points obtained and processed in parallel can be added to the information of the data points in the original accumulation matrix, so that multiple read and write operations required in the conventional update method can be replaced by one matrix addition.

[0026] In addition, the numbers are stored in a number matrix through conversion processing. This processing method can process multiple numbers in parallel and can also replace the address mapping operation. The number matrix is ​​then obtained through matrix addition to summarize multiple cumulative calculations, which can reduce the delay caused by frequent memory reading and writing in conventional update methods.

[0027] The present invention also provides a K-means clustering algorithm acceleration system, in which the update component adopts the above-mentioned cluster center update method, which improves the delay problem caused by frequent reading and writing of memory in the method of updating cluster centers in the prior art, and the problem of being unable to process data in parallel due to memory consistency.

[0028] In addition, the acceleration system can also adjust the parallelism of data point processing by setting multiple ranging modules and comparison modules to meet different processing requirements. BRIEF DESCRIPTION OF THE DRAWINGS

[0029] In order to more clearly illustrate the technical solutions of the embodiments of the present invention, the following briefly introduces the drawings required for use in the description of the embodiments. Obviously, the drawings described below are some embodiments of the present invention. For ordinary technicians in this field, other drawings can be obtained based on these drawings without creative work.

[0030] Figure 1 A schematic diagram of a module of a K-means clustering algorithm acceleration system provided by the present invention;

[0031] Figure 2 A schematic diagram of the flow of the cluster center updating method provided by the present invention.

[0032] Description of main reference numerals:

[0033] Input component 1; ranging component 2; classification component 3; update component 4. DETAILED DESCRIPTION

[0034] The technical solutions in the embodiments of the present invention will be described clearly and completely below in conjunction with the accompanying drawings in the embodiments of the present invention. Obviously, the described embodiments are preferred embodiments of the present invention and should not be regarded as excluding other 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.

[0035] In the claims, description and the above-mentioned drawings of the present invention, unless otherwise clearly defined, the use of terms such as "first", "second" or "third" etc. are for distinguishing different objects rather than for describing a specific order.

[0036] In the claims, specification and the above-mentioned drawings of the present invention, unless otherwise explicitly defined, directional words, such as the terms "center", "lateral", "longitudinal", "horizontal", "vertical", "top", "bottom", "inside", "outside", "up", "down", "front", "back", "left", "right", "clockwise", "counterclockwise", etc., indicating directions or positional relationships are based on the directions and positional relationships shown in the drawings, and are only for the convenience of describing the present invention and simplifying the description, rather than indicating or implying that the device or element referred to must have a specific direction or be constructed and operated in a specific direction, and therefore cannot be understood as limiting the specific protection scope of the present invention.

[0037] In the claims, specification and the above drawings of the present invention, unless otherwise clearly defined, if the term "fixed connection" or "fixed connection" is used, it should be understood in a broad sense, that is, any connection method without a displacement relationship and relative rotation relationship between the two, that is to say, including non-detachable fixed connection, detachable fixed connection, integrated connection and fixed connection through other devices or elements.

[0038] In the claims, description and drawings of the present invention, if the terms "include", "have" and their variations are used, they are intended to mean "including but not limited to".

[0039] An embodiment of the present invention provides a K-means clustering algorithm acceleration system, which mainly adopts a new cluster center update method, which will be explained in detail below.

[0040] Reference Figure 1 The K-means clustering algorithm acceleration system provided in the embodiment of the present invention is used to accelerate the K-means clustering algorithm, which mainly includes an input component 1, a ranging component 2, a classification component 3 and an update component 4.

[0041] Among them, the input component 1 includes a data point storage module and a cluster center storage module, the data point storage module stores all data points, and the cluster center storage module stores all cluster centers; the distance measurement component 2 includes a plurality of distance measurement modules, the distance measurement modules receive the data points transmitted by the data point storage module and the cluster centers transmitted by the cluster center storage module, and calculate the distance between each data point and each cluster center; the classification component 3 includes a plurality of comparison modules, the comparison module is used to compare the distance calculated by the distance measurement component 2 to obtain the cluster center closest to the data point, and assign the class number corresponding to the cluster center to the distance point; the update component 4 uses the above-mentioned cluster center update method to update the cluster center, and the data points and numbers received are respectively from the input component 1 and the classification component 3, and the updated cluster center is transmitted to the cluster center storage module.

[0042] Specifically, the update component 4 includes a data point transmission module and an update module; the data point transmission module is used to receive and successively output the parallel processed data points; the update module is used to obtain the parallel processed data points successively output by the data point transmission module and the numbers corresponding to the data points, and update the cluster center according to the above-mentioned cluster center update method.

[0043] The K-means clustering algorithm acceleration system and the cluster center update method are described below according to the processing flow of the K-means clustering algorithm.

[0044] As we all know, the K-means clustering algorithm mainly includes the steps of initialization, distance calculation, classification, and updating cluster centers. The data points are classified through repeated iterations to minimize the total distance from the data points within the class to their respective cluster centers.

[0045] During the initialization process, K initial cluster centers are selected and stored in the cluster center storage module; all data points to be processed are stored in the data point storage module, and the data point storage module and the cluster center storage module constitute the input component 1. The selection of the initial cluster center can be random selection or selection using the K-means++ method, which is not limited here. Obviously, the data point storage module and the cluster center storage module are physically memories such as memory, flash memory, and hard disk.

[0046] The distance calculation step is performed by the distance measurement component 2 in the acceleration system. Distance calculation generally calculates the L2 distance between all data points and all cluster centers, and its formula is: Where D represents the dimension, C[i] represents the value of the cluster center in the i-dimensional space, and P[i] represents the value of the data point in the i-dimensional space, that is, the L2 distance is the square root of the sum of the squares of the differences in each dimension.

[0047] In addition to several distance measurement modules, the distance measurement component 2 also includes two first-in first-out memories, namely Figure 1 FIFO1 and FIFO2 in the storage unit both use the single-dimensional data of the data point as the storage unit, can support the simultaneous input and output of multiple units, and have an internal counter to calculate the output quantity. Each time the output is performed, the counter value is subtracted from the output quantity. When the counter value is 0, an end signal can be output. Among them, FIFO1 is used to store and output the cluster center, and the preset value of its counter is the dimension of the data point. When the output quantity reaches the dimension of one data point, an end signal is sent to the ranging module, indicating that one cluster center has been output; FIFO2 is used to store and output the data points to be processed, and the preset value of its counter is the dimension of the data point multiplied by the number of data points processed in parallel. When all the dimensional data of the data points processed in parallel are output, a completion signal is sent to the ranging module, indicating that all the data points processed in parallel have been output.

[0048] In the distance measurement component 2, the distance measurement modules are divided into multiple groups to simultaneously calculate the distance between a data point and multiple cluster centers. Each group includes distance measurement modules that are consistent with the number of data points processed in parallel to simultaneously calculate the distance between multiple data points and cluster centers. Parallel processing here refers to the number of data points for which distance calculations are performed simultaneously. In this embodiment, the parallelism of the data points is 2, that is, the number of data points processed in parallel is 2. In addition, a data point can also perform distance calculations with multiple cluster centers in parallel. In this embodiment, the parallelism of the cluster centers is 2, that is, a data point performs distance calculations with two cluster centers in parallel. Figure 1 , FIFO1 transmits the two cluster centers to two groups of ranging modules respectively. The two groups of ranging modules include two ranging modules, namely ranging modules 1A and 1B, and ranging modules 2A and 2B, where the numbers correspond to the cluster centers of parallel calculations, and the letters correspond to the data points of parallel calculations. In other embodiments, more groups of ranging modules can be set, for example, 3 groups, 4 groups, etc., and the corresponding degree of parallelism of cluster centers is 3 or 4; each group of ranging modules can include more ranging modules, for example, 3 or 4 groups, etc., and the corresponding degree of parallelism of data points is 3 or 4.

[0049] The input and output bandwidths of the two FIFO memories in the ranging component 2 are configurable. Generally, in order to ensure high throughput, the input bandwidth is the maximum output bandwidth of the previous level output module, for example Figure 1 The input bandwidth of FIFO2 is the maximum output bandwidth of the data point storage module. The output bandwidth of the first-in-first-out memory is related to the parallelism. For example, the output bandwidth of FIFO1 is the cluster center parallelism multiplied by the dimension, and the output bandwidth of FIFO2 is the data point parallelism multiplied by the dimension. The two first-in-first-out memories have three output states, namely, the output bandwidth is greater than, equal to, and less than the counter value inside the first-in-first-out memory; when the output bandwidth is less than or equal to the counter value, the first-in-first-out memory outputs according to the output bandwidth, and the current counter minus the output bandwidth is used as the counter value after output. When the output bandwidth is greater than the counter value, the output is performed according to the counter value, and the counter value is reset after the output is completed. The two first-in-first-out memories have two input states. When the free space is greater than or equal to the input bandwidth, the input data is accepted; when the free space is less than the input bandwidth, the input data is not accepted.

[0050] Each ranging module also includes multiple ranging submodules. The number of ranging submodules in each ranging module is equal to the dimension of the data point. Each ranging submodule only calculates the distance of one dimensional space. After each sub-ranging module completes the calculation, the data of all dimensions are added through summation and accumulator. When FIFO2 gives a completion signal, the ranging module outputs the distance between the data point in the accumulator and the cluster center. After the ranging module completes the distance calculation, it will output an end signal, indicating that the distance between the input data point and all cluster centers has been obtained.

[0051] After obtaining the distance between the data point and the cluster center, the data point can be classified by the classification component 3. The classification component 3 obtains the cluster center with the shortest distance to the data point by comparing the distance, and classifies the data point into the class corresponding to the cluster center, and assigns the class number to the data point, that is, the class number is sent to the update component 4 accordingly. In the classification component 3, the number of comparison modules is consistent with the number of data points processed in parallel so as to compare multiple data points at the same time.

[0052] Reference Figure 1 , the classification component 3 mainly includes several comparison modules, each of which is responsible for comparing the distance between a data point and all cluster centers, and classifying the data point after finding the minimum distance. The number of comparison modules is the same as the parallelism of the data points. The interior of the comparison module consists of two counters, a comparator and a register. The first counter is used to count the distance between the data point and the cluster center input by the retaining wall, and the counter value is added to the two bytes after the distance as the class number. When the counter value exceeds the number of all classes, the distance is filled with the maximum value and the number is filled with 0. When the end signal from the ranging module is received, the first counter value is reset to 0 and the next count begins. The second counter is used to count how many data points have been compared. When the end signal from the ranging module is received, the new counter value is equal to the current counter value plus the parallelism of the data points. When the counter value is greater than or equal to the number of data points, it is considered that a traversal of the data points has been completed. At this time, the second counter value is reset to 0, and the comparison module outputs an end signal to the update component 4. The comparator is used to compare the input distance with the data stored in the register, and save the smaller value to the register. The register always stores the minimum distance obtained by the current comparison, and the last two bytes of the distance store the number corresponding to the distance. When the end signal of the ranging module is received, the register outputs the last two bytes, that is, the number of the class to which the data point belongs. After that, the distance value stored in the register is set to the maximum value, and the next classification begins.

[0053] After distance calculation and classification are completed, the cluster center can be updated. The cluster center is updated by the updating component 4, which is used to average the data points with the same number and return the average value as the new cluster center to the cluster center storage module.

[0054] The update component 4 includes a data point transmission module and an update module. Figure 2 ,The update module uses a new cluster center update method to update the cluster center.

[0055] The cluster center updating method provided in an embodiment of the present invention is used to update the cluster centers in the K-means clustering algorithm. Before performing the cluster center updating step, the K-means clustering algorithm also includes initialization, distance calculation and classification steps; the initialization step sets several categories, each category includes an initial cluster center; the distance calculation step calculates the distance between all data points and each cluster center; the classification step assigns each data point a number corresponding to the category to which it belongs based on the distance obtained in the distance calculation step.

[0056] Reference Figure 2 , the cluster center update step includes: successively acquiring data points processed in parallel and numbers corresponding to each data point; storing the data points acquired each time into a data point matrix, wherein the rows of the data point matrix correspond to the data points processed in parallel, and the columns correspond to the dimensions of each data point; storing the numbers acquired each time into a number matrix, wherein the rows of the number matrix correspond to the numbers processed in parallel, and the columns correspond to the classes corresponding to each number; multiplying the data point matrix stored at the same time with the transposed number matrix to obtain an input matrix; successively accumulating the input matrix to obtain an accumulation matrix; successively accumulating the number matrix to obtain a quantity matrix; dividing the accumulation matrix with the quantity matrix to obtain a clustering matrix; the rows of the clustering matrix correspond to the classes, and the columns correspond to the dimensions of the cluster center of each class.

[0057] The data points processed in parallel and the numbers corresponding to the data points are acquired one by one through the data point transmission module and the acquisition module. The data point transmission module is also a first-in first-out memory, which receives the data points transmitted by the data point storage module. The acquisition module simultaneously receives the data points and the numbers corresponding to the data points, and the acquisition module can simultaneously receive multiple data points and numbers according to the parallelism of the data points. A counter is provided in the data point transmission module, and the acquired data points are counted by the counter to achieve the sequential acquisition of the data points processed in parallel; the preset value of the counter is the dimension of the data point, and the counter is reset each time a data point is acquired. When the number of resets of the counter is consistent with the number of data points processed in parallel, the acquisition of the data points processed in parallel is completed.

[0058] Each acquired data point will be stored in the data point matrix. The size of the data point matrix is ​​(Pd, Dmax). Pd is the data point parallelism, which indicates the number of data points processed in parallel. Dmax is the maximum dimension of the data point. When the dimension of the data point acquired each time is less than Dmax, the elements of the insufficient position are set to 0. After each acquisition of all parallel processed data points, the data point matrix outputs the storage result and clears all elements to restart the acquisition of the next parallel processed data point. Specifically, after the data point transmission module transmits a data point, it will send an end signal to the update module, and the update module will start splicing the next data point. For example, before receiving the end signal for the first time, the update module will save the received data point in (0, Dmax) of the data point matrix. After receiving the end signal for the first time, the update module will save the received data point in (1, Dmax) of the data point matrix, and so on until the end signal equal to the number of data point parallelism is received, all elements of the data point matrix are cleared, and the data points are received and spliced ​​again. Since the input data may be less than Dmax, the insufficient elements are filled with 0. At this point, we have concatenated the matrices to aggregate the data points that traditionally need to be written into memory multiple times in the update module into one matrix.

[0059] After receiving the number, the update module stores the number obtained each time into the number matrix. Each number obtained is processed by the following formula and stored into the number matrix: Number matrix = ReLU ((A-number) · (2-A+number)); wherein the ReLU function formula is: A=[1,2,3,4,5,6…,Kmax], Kmax is the maximum number of cluster centers; in the numbering matrix, the position of element 1 in each row represents the class corresponding to the number. After each acquisition of the numbers corresponding to all parallel processed data points, the numbering matrix outputs the storage result and clears all elements to restart the acquisition of the numbers corresponding to the next parallel processed data points.

[0060] This method can convert the number information into a mask of size (1, Kmax). For example, if the number is 0, the converted mask is [1, 0, 0, 0, 0…], where the 0th dimension element is 1 and the rest are 0. In this way, multiple input numbers can be processed in parallel. After obtaining the mask, the mask is spliced, and after accumulating Pd codes, a number matrix of size (Pd, Kmax) is finally formed. For example, the input data point [3, 7, 9…] is classified as 2, and the corresponding mask is [0, 0, 1, 0…]. By converting the number into a mask, the address mapping operation can be replaced, and then the number matrix is ​​obtained by matrix addition to summarize multiple cumulative calculations, which can effectively avoid the delay problem caused by frequent memory operations in traditional update methods. Because matrix operations are used, multiple input numbers can be processed in parallel, thereby avoiding the delay caused by the traditional sequential search and processing of data due to consistency problems.

[0061] After obtaining the data point matrix and the number matrix, multiply the data point matrix stored at the same time and the transposed number matrix to obtain the input matrix, the size of the input matrix is ​​(Kmax, Dmax). This operation can assign data points to corresponding positions, avoiding the need to search the memory by number in the conventional update method to put the data points into the corresponding position; on the other hand, the data points assigned to the same position will perform matrix addition, thereby aggregating the multiple read and write operations required for the memory in the conventional update method into one operation, effectively reducing the delay caused by multiple read and write operations to the memory.

[0062] After that, the input matrix is ​​accumulated one by one to obtain the accumulation matrix, and the number matrix is ​​accumulated one by one to obtain the quantity matrix. After all data points and numbers are input, the final accumulation matrix and quantity matrix are obtained. After that, the accumulation matrix and the quantity matrix are divided to obtain a clustering matrix of size (Kmax, Dmax). The rows of the clustering matrix correspond to each class, and the columns correspond to each dimension of the cluster center of each class. For example, the clustering matrix (1,3) represents the value of dimension 3 of the cluster center of class 1.

[0063] After obtaining the clustering matrix, extract and store each element in the clustering matrix for the next iteration. Each element in the clustering matrix will be stored in the cluster center storage module. The cluster center storage module will compare the data of the new cluster center input and the originally stored cluster center to see if they are consistent. If they are completely consistent and the stored information has not changed, no iteration signal will be issued and the algorithm calculation will be completed; if there is inconsistency, the new cluster center input will be stored, and the iteration signal will be output to start the next iteration.

[0064] The cluster center updating method provided by the present invention adopts matrix operations to replace conventional memory read and write operations, thereby improving the delay problem caused by frequent memory reading and writing in the cluster center updating method in the prior art, and the problem of being unable to process data in parallel due to memory consistency.

[0065] The description of the above specification and embodiments is used to explain the protection scope of the present invention, but does not constitute a limitation on the protection scope of the present invention. Through the enlightenment of the present invention or the above embodiments, ordinary technicians in this field can obtain modifications, equivalent substitutions or other improvements to the embodiments of the present invention or part of the technical features thereof through logical analysis, reasoning or limited experiments, which should be included in the protection scope of the present invention.

Claims

1. A cluster center updating method, which is used to update the cluster center in the K-means clustering algorithm; The K-means clustering algorithm further includes initialization, distance calculation and classification steps before performing the cluster center update step; The initialization step sets a number of categories, each category includes an initial cluster center; The distance calculation step calculates the distance between all data points and each cluster center; The classification step assigns a number corresponding to the class to which each data point belongs based on the distance obtained in the distance calculation step; Its characteristics are: The cluster center updating step comprises: Successively obtain the data points processed in parallel and the numbers corresponding to the data points; The data points acquired each time are stored in a data point matrix, wherein the rows of the data point matrix correspond to the data points processed in parallel, and the columns correspond to the dimensions of each data point; The numbers obtained each time are stored in a number matrix, wherein the rows of the number matrix correspond to the numbers processed in parallel, and the columns correspond to the classes corresponding to each number; The data point matrix stored at the same time is multiplied with the transposed number matrix to obtain an input matrix; the input matrices are accumulated one by one to obtain an accumulated matrix; The number matrix is ​​accumulated one by one to obtain the quantity matrix; The accumulation matrix is ​​divided by the quantity matrix to obtain a clustering matrix; the rows of the clustering matrix correspond to the various classes, and the columns correspond to the dimensions of the cluster center of each class.

2. A cluster center updating method as claimed in claim 1, characterized in that: Each acquired number is processed by the following formula and stored in the number matrix: number matrix = ReLU ((A-number) · (2-A+number)); wherein the ReLU function formula is: A=[1,2,3,4,5,6…,Kmax], Kmax is the maximum number of cluster centers; in the numbering matrix, the position of element 1 in each row represents the class corresponding to the number.

3. A cluster center updating method as claimed in claim 1, characterized in that: The size of the data point matrix is ​​(Pd, Dmax), where Pd is the data point parallelism, indicating the number of data points processed in parallel, and Dmax is the maximum dimension of the data point; when the dimension of the data point obtained each time is less than Dmax, the elements in the insufficient position are set to 0.

4. A cluster center updating method as claimed in claim 1, characterized in that: After all the data points for parallel processing are acquired each time, the data point matrix outputs the stored result and clears all elements to restart the acquisition of the next data points for parallel processing.

5. A cluster center updating method as claimed in claim 1, characterized in that: After each acquisition of the numbers corresponding to all the data points processed in parallel, the numbering matrix outputs the stored results and clears all elements to restart the acquisition of the numbers corresponding to the data points processed in parallel next time.

6. A cluster center updating method as claimed in claim 1, characterized in that: The acquired data points are counted by a counter to achieve successive acquisition of data points for parallel processing; the preset value of the counter is the dimension of the data point, and the counter is reset each time a data point is acquired. When the number of reset times of the counter is consistent with the number of data points for parallel processing, the acquisition of data points for parallel processing is completed once.

7. A cluster center updating method as claimed in claim 1, characterized in that: After the clustering matrix is ​​obtained, each element in the clustering matrix is ​​extracted and stored for use in the next iteration.

8. A K-means clustering algorithm acceleration system, which is used to accelerate the K-means clustering algorithm, characterized in that: include: An input component (1), comprising a data point storage module and a cluster center storage module, wherein the data point storage module stores all data points, and the cluster center storage module stores all cluster centers; A distance measuring component (2), comprising a plurality of distance measuring modules, wherein the distance measuring modules receive data points transmitted by the data point storage module and cluster centers transmitted by the cluster center storage module, and calculate the distance between each data point and each cluster center; A classification component (3), comprising a plurality of comparison modules, wherein the comparison modules are used to compare the distances calculated by the distance measurement component (2) to obtain a cluster center closest to the data point, and assign a class number corresponding to the cluster center to the distance point; and An update component (4) updates the cluster center using the cluster center update method according to any one of claims 1 to 7, wherein the data points and numbers received by the update component (4) are respectively from the input component (1) and the classification component (3), and the updated cluster center is transmitted to the cluster center storage module.

9. A K-means clustering algorithm acceleration system as claimed in claim 8, characterized in that: The updating component (4) comprises: a data point transmission module, which is used to receive and successively output the parallel processed data points; An updating module is used to obtain the parallel processed data points and the numbers corresponding to the data points output successively by the data point transmission module, and to update the cluster center according to the cluster center updating method according to any one of claims 1 to 7.

10. A K-means clustering algorithm acceleration system as claimed in claim 8, characterized in that: In the distance measurement component (2), the distance measurement modules are divided into multiple groups to simultaneously calculate the distance between a data point and multiple cluster centers, and each group includes distance measurement modules consistent with the number of data points processed in parallel to simultaneously calculate the distance between multiple data points and cluster centers; in the classification component (3), the number of comparison modules is consistent with the number of data points processed in parallel to simultaneously compare multiple data points.