MCPcopy Create free account
hub / github.com/davisking/dlib / angular_cluster

Function angular_cluster

tools/imglab/src/cluster.cpp:32–69  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

30};
31
32std::vector<assignment> angular_cluster (
33 std::vector<matrix<double,0,1> > feats,
34 const unsigned long num_clusters
35)
36{
37 DLIB_CASSERT(feats.size() != 0, "The dataset can't be empty");
38 for (unsigned long i = 0; i < feats.size(); ++i)
39 {
40 DLIB_CASSERT(feats[i].size() == feats[0].size(), "All feature vectors must have the same length.");
41 }
42
43 // find the centroid of feats
44 const matrix<double,0,1> m = mean(mat(feats));
45
46 // Now center feats and then project onto the unit sphere. The reason for projecting
47 // onto the unit sphere is so pick_initial_centers() works in a sensible way.
48 for (auto& f : feats)
49 {
50 f = normalize(f-m);
51 }
52
53 // now do angular clustering of the points
54 std::vector<matrix<double,0,1> > centers;
55 pick_initial_centers(num_clusters, centers, feats, linear_kernel<matrix<double,0,1> >(), 0.05);
56 find_clusters_using_angular_kmeans(feats, centers);
57
58 // and then report the resulting assignments
59 std::vector<assignment> assignments;
60 for (unsigned long i = 0; i < feats.size(); ++i)
61 {
62 assignment temp;
63 temp.c = nearest_center(centers, feats[i]);
64 temp.dist = length(feats[i] - centers[temp.c]);
65 temp.idx = i;
66 assignments.push_back(temp);
67 }
68 return assignments;
69}
70std::vector<assignment> chinese_cluster (
71 std::vector<matrix<double,0,1> > feats,
72 unsigned long &num_clusters

Callers 1

cluster_datasetFunction · 0.85

Calls 9

meanFunction · 0.85
pick_initial_centersFunction · 0.85
nearest_centerFunction · 0.85
matFunction · 0.50
normalizeFunction · 0.50
lengthFunction · 0.50
sizeMethod · 0.45
push_backMethod · 0.45

Tested by

no test coverage detected