| 417 | } |
| 418 | |
| 419 | void test_vector_correlation() |
| 420 | { |
| 421 | const double scales[] = {1e-9, 1e-100, 1e100}; |
| 422 | for (const double x_scale : scales) |
| 423 | { |
| 424 | for (const double y_scale : scales) |
| 425 | { |
| 426 | const std::vector<double> x = {-x_scale, 0, x_scale}; |
| 427 | const std::vector<double> y = {-y_scale, 0, y_scale}; |
| 428 | const std::vector<double> negative = {y_scale, 0, -y_scale}; |
| 429 | const std::vector<double> partial = {0, -y_scale, y_scale}; |
| 430 | DLIB_TEST(std::abs(correlation(x,y)-1) < 1e-14); |
| 431 | DLIB_TEST(std::abs(r_squared(x,y)-1) < 1e-14); |
| 432 | DLIB_TEST(std::abs(correlation(x,negative)+1) < 1e-14); |
| 433 | DLIB_TEST(std::abs(r_squared(x,negative)-1) < 1e-14); |
| 434 | DLIB_TEST(std::abs(correlation(x,partial)-0.5) < 1e-14); |
| 435 | DLIB_TEST(std::abs(r_squared(x,partial)-0.25) < 1e-14); |
| 436 | } |
| 437 | } |
| 438 | const std::vector<double> constant(3, 1); |
| 439 | const std::vector<double> varying = {-1, 0, 1}; |
| 440 | DLIB_TEST(correlation(constant,varying) == 0); |
| 441 | DLIB_TEST(correlation(varying,constant) == 0); |
| 442 | DLIB_TEST(correlation(constant,constant) == 0); |
| 443 | DLIB_TEST(r_squared(constant,varying) == 0); |
| 444 | } |
| 445 | |
| 446 | void test_running_stats() |
| 447 | { |
nothing calls this directly
no test coverage detected