hi...,

im having set of points... i need to form a cluster of those points.... i will get another set of points ... and i have to check whether those set of points lies in that cluster or not. please help me how to cluster points i have....

thanks in advance

Dani AI

Generated

As asked: you have a cloud of points, need clusters, then must test whether another set of points "lies in" those clusters. Quick clarifications from earlier replies: 's Set code is useful for exact membership of identical points but not for distance-based grouping. 's boundary question is important — do you want a region that encloses a cluster (shape) or just a cluster label (centroid + radius)? The choice changes the algorithm and the membership test.

K-means (centroid-based) — good when clusters are roughly spherical. Basic steps: choose k, initialize centroids, assign each point to nearest centroid, recompute centroids, repeat until stable; restart several times to avoid bad seeds. Scale features first. To test a new point, compute distance to nearest centroid and compare to a threshold (for example the 95th-percentile training distance or max distance seen in the cluster). Example helpers:

double sqDist(double[] a, double[] b) {
  double s = 0;
  for (int i = 0; i < a.length; i++) { double d = a[i] - b[i]; s += d * d; }
  return s;
}

boolean insideCentroid(double[] p, double[] centroid, double radius) {
  return sqDist(p, centroid) <= radius * radius;
}

Hierarchical (agglomerative) — start with each point as a cluster and merge. Linkage choices give different inter-cluster distances:

  • single-link: min_{i in A, j in B} dist(i,j)
  • complete-link: max_{i in A, j in B} dist(i,j)
  • average-link: mean_{i in A, j in B} dist(i,j)
  • centroid: dist(mean(A), mean(B))

Pick the linkage based on whether you want chaining (single-link) or compact clusters (complete-link). For non-convex shapes, use density methods (DBSCAN) or compute a convex hull and do point-in-polygon tests.

Practical tips: normalize coordinates, handle outliers (trim or use density clustering), choose thresholds from training distances (percentiles), run multiple k-means restarts, and for large n use KD-trees or mini-batch variants. To decide whether a whole set of points "lies in" a cluster, test each point against the cluster region (centroid+radius or hull) and require a proportion (e.g., 90%) to pass — that balances noise and membership.

Recommended Answers

All 5 Replies

Your question is not clear;

I think you are looking for something like "set"

// Create the set
Set set = new HashSet();
// Add elements to the set
set.add("a");
set.add("b");
set.add("c"); 

...

// Determining if an element is in the set
boolean b = set.contains("a"); // true
b = set.contains("d"); // false

Can you define what a cluster is?
Do the points enclose a shape such that a line connecting the outer most points forms a boundary for a region?

i nead code for k-means or hierarchical clustering of points.... and ..... is any one know abt how to find the distance between two clusters

Sorry, I thought you wanted help designing and writing this program.
If you want help, could you define "k-means or hierarchical clustering of points"?
Can you define what a cluster is?

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.