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 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149
|
/*!
@authors Andrei Novikov (pyclustering@yandex.ru)
@date 2014-2020
@copyright BSD-3-Clause
*/
#include <gtest/gtest.h>
#include <pyclustering/cluster/ttsas.hpp>
#include <pyclustering/utils/metric.hpp>
#include "samples.hpp"
#include "utenv_check.hpp"
using namespace pyclustering;
using namespace pyclustering::clst;
static void
template_ttsas_length_process_data(const dataset_ptr p_data,
const double & p_threshold1,
const double & p_threshold2,
const std::vector<size_t> & p_expected_cluster_length,
const distance_metric<point> & p_metric = distance_metric_factory<point>::euclidean()) {
ttsas_data output_result;
ttsas solver(p_threshold1, p_threshold2, p_metric);
solver.process(*p_data, output_result);
const dataset & data = *p_data;
const cluster_sequence & actual_clusters = output_result.clusters();
const representative_sequence & actual_repr = output_result.representatives();
for (auto & repr : actual_repr)
ASSERT_EQ(data[0].size(), repr.size());
ASSERT_EQ(actual_repr.size(), actual_clusters.size());
ASSERT_CLUSTER_SIZES(data, actual_clusters, p_expected_cluster_length);
}
TEST(utest_ttsas, allocation_sample_simple_01) {
const std::vector<size_t> expected_clusters_length = { 5, 5 };
template_ttsas_length_process_data(simple_sample_factory::create_sample(SAMPLE_SIMPLE::SAMPLE_SIMPLE_01), 1.0, 2.0, expected_clusters_length);
}
TEST(utest_ttsas, allocation_sample_simple_01_euclidean) {
const std::vector<size_t> expected_clusters_length = { 5, 5 };
template_ttsas_length_process_data(simple_sample_factory::create_sample(SAMPLE_SIMPLE::SAMPLE_SIMPLE_01), 1.0, 2.0, expected_clusters_length, distance_metric_factory<point>::euclidean());
}
TEST(utest_ttsas, allocation_sample_simple_01_euclidean_square) {
const std::vector<size_t> expected_clusters_length = { 5, 5 };
template_ttsas_length_process_data(simple_sample_factory::create_sample(SAMPLE_SIMPLE::SAMPLE_SIMPLE_01), 1.0, 2.0, expected_clusters_length, distance_metric_factory<point>::euclidean_square());
}
TEST(utest_ttsas, allocation_sample_simple_01_manhattan) {
const std::vector<size_t> expected_clusters_length = { 5, 5 };
template_ttsas_length_process_data(simple_sample_factory::create_sample(SAMPLE_SIMPLE::SAMPLE_SIMPLE_01), 1.0, 2.0, expected_clusters_length, distance_metric_factory<point>::manhattan());
}
TEST(utest_ttsas, allocation_sample_simple_01_chebyshev) {
const std::vector<size_t> expected_clusters_length = { 5, 5 };
template_ttsas_length_process_data(simple_sample_factory::create_sample(SAMPLE_SIMPLE::SAMPLE_SIMPLE_01), 1.0, 2.0, expected_clusters_length, distance_metric_factory<point>::chebyshev());
}
TEST(utest_ttsas, allocation_sample_simple_01_minkowski) {
const std::vector<size_t> expected_clusters_length = { 5, 5 };
template_ttsas_length_process_data(simple_sample_factory::create_sample(SAMPLE_SIMPLE::SAMPLE_SIMPLE_01), 1.0, 2.0, expected_clusters_length, distance_metric_factory<point>::minkowski(2.0));
}
TEST(utest_ttsas, allocation_sample_simple_01_user_defined) {
const std::vector<size_t> expected_clusters_length = { 5, 5 };
auto user_metric = [](const point & p1, const point & p2) { return euclidean_distance(p1, p2); };
template_ttsas_length_process_data(simple_sample_factory::create_sample(SAMPLE_SIMPLE::SAMPLE_SIMPLE_01), 1.0, 2.0, expected_clusters_length, distance_metric_factory<point>::user_defined(user_metric));
}
TEST(utest_ttsas, allocation_one_allocation_sample_simple_01) {
const std::vector<size_t> expected_clusters_length = { 10 };
template_ttsas_length_process_data(simple_sample_factory::create_sample(SAMPLE_SIMPLE::SAMPLE_SIMPLE_01), 10.0, 20.0, expected_clusters_length);
}
TEST(utest_ttsas, allocation_sample_simple_02) {
const std::vector<size_t> expected_clusters_length = { 5, 8, 10 };
template_ttsas_length_process_data(simple_sample_factory::create_sample(SAMPLE_SIMPLE::SAMPLE_SIMPLE_02), 1.0, 2.0, expected_clusters_length);
}
TEST(utest_ttsas, allocation_one_allocation_sample_simple_02) {
const std::vector<size_t> expected_clusters_length = { 23 };
template_ttsas_length_process_data(simple_sample_factory::create_sample(SAMPLE_SIMPLE::SAMPLE_SIMPLE_02), 10.0, 20.0, expected_clusters_length);
}
TEST(utest_ttsas, allocation_sample_simple_03) {
const std::vector<size_t> expected_clusters_length = { 10, 10, 10, 30 };
template_ttsas_length_process_data(simple_sample_factory::create_sample(SAMPLE_SIMPLE::SAMPLE_SIMPLE_03), 1.0, 2.0, expected_clusters_length);
}
TEST(utest_ttsas, allocation_one_dimension_points_1) {
const std::vector<size_t> expected_clusters_length = { 10, 10 };
template_ttsas_length_process_data(simple_sample_factory::create_sample(SAMPLE_SIMPLE::SAMPLE_SIMPLE_07), 1.0, 2.0, expected_clusters_length);
}
TEST(utest_ttsas, allocation_one_allocation_one_dimension_points_1) {
const std::vector<size_t> expected_clusters_length = { 20 };
template_ttsas_length_process_data(simple_sample_factory::create_sample(SAMPLE_SIMPLE::SAMPLE_SIMPLE_07), 10.0, 20.0, expected_clusters_length);
}
TEST(utest_ttsas, allocation_one_dimension_points_2) {
const std::vector<size_t> expected_clusters_length = { 10, 20 };
template_ttsas_length_process_data(simple_sample_factory::create_sample(SAMPLE_SIMPLE::SAMPLE_SIMPLE_09), 1.0, 2.0, expected_clusters_length);
}
TEST(utest_ttsas, allocation_one_allocation_one_dimension_points_2) {
const std::vector<size_t> expected_clusters_length = { 30 };
template_ttsas_length_process_data(simple_sample_factory::create_sample(SAMPLE_SIMPLE::SAMPLE_SIMPLE_09), 10.0, 20.0, expected_clusters_length);
}
TEST(utest_ttsas, allocation_three_dimension_points_2) {
const std::vector<size_t> expected_clusters_length = { 10, 10 };
template_ttsas_length_process_data(simple_sample_factory::create_sample(SAMPLE_SIMPLE::SAMPLE_SIMPLE_11), 1.0, 2.0, expected_clusters_length);
}
TEST(utest_ttsas, allocation_three_allocation_one_dimension_points_2) {
const std::vector<size_t> expected_clusters_length = { 20 };
template_ttsas_length_process_data(simple_sample_factory::create_sample(SAMPLE_SIMPLE::SAMPLE_SIMPLE_11), 10.0, 20.0, expected_clusters_length);
}
|