This repository was archived by the owner on Jan 28, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathtest_diffusion_maps.cpp
More file actions
53 lines (40 loc) · 1.49 KB
/
test_diffusion_maps.cpp
File metadata and controls
53 lines (40 loc) · 1.49 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
#include <cmath>
#include <functional>
#include <random>
#include <criterion/criterion.h>
#include "diffusion_maps/diffusion_maps.hpp"
#include "diffusion_maps/kernel.hpp"
#include "diffusion_maps/matrix.hpp"
#define PI 3.14159265358979323846
Test(diffusion_maps, diffusion_maps_helix) {
// Data: helix
// Dimensions after reduction: 1
// Expected result: a straight line
// Generate data.
diffusion_maps::Matrix helix(1000, 3);
for (std::size_t i = 0; i < 1000; ++i) {
const double t = 8 * PI * (i / 999.);
const double x = std::cos(t);
const double y = std::sin(t);
const double z = t / (4 * PI) - 1;
helix(i, 0) = x;
helix(i, 1) = y;
helix(i, 2) = z;
}
// Compute diffusion maps.
std::default_random_engine rng(std::random_device{}());
const auto result = diffusion_maps::diffusion_maps(
helix, 1, diffusion_maps::kernel::Gaussian(50), 1, rng);
// Check the dimensions.
cr_assert_eq(result.n_rows(), 1000, "Number of data points %zu is incorrect",
result.n_rows());
cr_assert_eq(result.n_cols(), 1, "Number of dimensions %zu is incorrect",
result.n_cols());
// Check that result is monotonic.
auto cmp = result(0, 0) < result(1, 0)
? std::function<bool(double, double)>(std::less<double>())
: std::function<bool(double, double)>(std::greater<double>());
for (std::size_t i = 0; i < 999; ++i) {
cr_assert(cmp(result(i, 0), result(i + 1, 0)), "Result is not monotonic");
}
}