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

Function generate_concentric_circles

examples/empirical_kernel_map_ex.cpp:313–352  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

311// ----------------------------------------------------------------------------------------
312
313void generate_concentric_circles (
314 std::vector<sample_type>& samples,
315 std::vector<double>& labels,
316 const int num
317)
318{
319 sample_type m(2,1);
320 samples.clear();
321 labels.clear();
322
323 dlib::rand rnd;
324
325 // make some samples near the origin
326 double radius = 1.0;
327 for (long i = 0; i < num; ++i)
328 {
329 double sign = 1;
330 if (rnd.get_random_double() < 0.5)
331 sign = -1;
332 m(0) = 2*radius*rnd.get_random_double()-radius;
333 m(1) = sign*sqrt(radius*radius - m(0)*m(0));
334
335 samples.push_back(m);
336 labels.push_back(1);
337 }
338
339 // make some samples in a circle around the origin but far away
340 radius = 5.0;
341 for (long i = 0; i < num; ++i)
342 {
343 double sign = 1;
344 if (rnd.get_random_double() < 0.5)
345 sign = -1;
346 m(0) = 2*radius*rnd.get_random_double()-radius;
347 m(1) = sign*sqrt(radius*radius - m(0)*m(0));
348
349 samples.push_back(m);
350 labels.push_back(2);
351 }
352}
353
354// ----------------------------------------------------------------------------------------
355

Callers 1

mainFunction · 0.85

Calls 4

get_random_doubleMethod · 0.80
sqrtFunction · 0.50
clearMethod · 0.45
push_backMethod · 0.45

Tested by

no test coverage detected