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

Function test_bottom_up_clustering

dlib/test/clustering.cpp:223–304  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

221 }
222
223 void test_bottom_up_clustering()
224 {
225 std::vector<dpoint> pts;
226 pts.push_back(dpoint(0.0,0.0));
227 pts.push_back(dpoint(0.5,0.0));
228 pts.push_back(dpoint(0.5,0.5));
229 pts.push_back(dpoint(0.0,0.5));
230
231 pts.push_back(dpoint(3.0,3.0));
232 pts.push_back(dpoint(3.5,3.0));
233 pts.push_back(dpoint(3.5,3.5));
234 pts.push_back(dpoint(3.0,3.5));
235
236 pts.push_back(dpoint(7.0,7.0));
237 pts.push_back(dpoint(7.5,7.0));
238 pts.push_back(dpoint(7.5,7.5));
239 pts.push_back(dpoint(7.0,7.5));
240
241 matrix<double> dists(pts.size(), pts.size());
242 for (long r = 0; r < dists.nr(); ++r)
243 for (long c = 0; c < dists.nc(); ++c)
244 dists(r,c) = length(pts[r]-pts[c]);
245
246
247 matrix<unsigned long,0,1> truth(12);
248 truth = 0, 0, 0, 0,
249 1, 1, 1, 1,
250 2, 2, 2, 2;
251
252 std::vector<unsigned long> labels;
253 DLIB_TEST(bottom_up_cluster(dists, labels, 3) == 3);
254 DLIB_TEST(mat(labels) == truth);
255 DLIB_TEST(bottom_up_cluster(dists, labels, 1, 4.0) == 3);
256 DLIB_TEST(mat(labels) == truth);
257 DLIB_TEST(bottom_up_cluster(dists, labels, 1, 4.95) == 2);
258 truth = 0, 0, 0, 0,
259 0, 0, 0, 0,
260 1, 1, 1, 1;
261 DLIB_TEST(mat(labels) == truth);
262 DLIB_TEST(bottom_up_cluster(dists, labels, 1) == 1);
263 truth = 0, 0, 0, 0,
264 0, 0, 0, 0,
265 0, 0, 0, 0;
266 DLIB_TEST(mat(labels) == truth);
267
268 dists.set_size(0,0);
269 DLIB_TEST(bottom_up_cluster(dists, labels, 3) == 0);
270 DLIB_TEST(labels.size() == 0);
271 DLIB_TEST(bottom_up_cluster(dists, labels, 1) == 0);
272 DLIB_TEST(labels.size() == 0);
273
274 dists.set_size(1,1);
275 dists = 1;
276 DLIB_TEST(bottom_up_cluster(dists, labels, 3) == 1);
277 DLIB_TEST(labels.size() == 1);
278 DLIB_TEST(labels[0] == 0);
279 DLIB_TEST(bottom_up_cluster(dists, labels, 1) == 1);
280 DLIB_TEST(labels.size() == 1);

Callers 1

perform_testMethod · 0.85

Calls 8

bottom_up_clusterFunction · 0.85
lengthFunction · 0.50
matFunction · 0.50
push_backMethod · 0.45
sizeMethod · 0.45
nrMethod · 0.45
ncMethod · 0.45
set_sizeMethod · 0.45

Tested by

no test coverage detected