Points Groups (k-Means-ish)

I’m currently trying to figure out a method to create an efficient grouping of 2D points. The scenario is as follows:

I have 96 points which I need to cluster into groups of 24 groups of 4, with the efficiency based on minimizing the distance between points within their respective groups. I have looked through numerous posts that takes k-means clustering as an approach for group points efficiently into a set number of groups, however the number of points in the resulting groups is never strictly defined in those approaches.

I don’t currently see a way to approach this problem linearly and I’m not sure its possible. I’ve attached my attempt at a basic approach to grouping the points into sets of 4 but since it is a linear approach it does not provide an efficient grouping for the points as a whole.

Does anyone have some insight on this problem?

Point_Groups_4.gh (12.6 KB)

@old_taz time to come out of retirement

You summoned? Looks like someone is learning Python!

OP for the topic below is asking the same question you are (I think?). And it looks like Laurent upgraded the K-means clustering topic from the old forum.

Even so I don’t think that answers your question since you want each cluster to have the same number of points?

This requires a “custom” filtering/stop in the classic K-Means algo (plus some other things). But my game is C# and there’s no way to auto translate it to P. Maybe if there’s time available in this w/e I’ll do it.

BTW: In the mean time Google CLOPE (or go to Code Project)

Yeah. Saw that. Definitely in line with what I’m trying to do but you’re right the classic K-Means isnt enough as it doesnt limit group sizes or strictly define them.

Wouldn’t mind taking a look at what you have. I’m not language exclusive, logic is logic is logic. Also googling CLOPE, besides finding a new word for a cigarette butt, seems like i have some reading to do.

Hey Guys! I have spent hours before I found this topic! I have exactly the same problem! I need to cluster group of points with K-Means but in different size clusters. Lets say 100 point in 5 cluster of predefinded sizes (10, 10, 20, 30, 30).

Any ideas how to do it in c#?

I suppose that you have already some working classic K-Means in C# on hand. This task of yours MAY have a solution or not (speaking having the general case in mind).

Assume that you have 3 rational clusters because the point topology is suitable (meaning that visually are “separated” in such a way that there’s a rational 3 cluster solution).

Now assume that some points move and that visual separation is not “obvious” any more.

What could be the rule for that kind of soft clustering? Or we are taking in fact about HAC clustering? (with some post actions with regard the population per cluster).

Other than that:


(PS: You can extend the above in order to produce clusters of the desired sizes instead of the average size)