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 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172
|
/*!
@authors Andrei Novikov (pyclustering@yandex.ru)
@date 2014-2020
@copyright BSD-3-Clause
*/
#include <gtest/gtest.h>
#include <pyclustering/cluster/agglomerative.hpp>
#include "samples.hpp"
#include <algorithm>
using namespace pyclustering;
using namespace pyclustering::clst;
static void
template_length_process_data(const std::shared_ptr<dataset> & data,
const size_t number_clusters,
const agglomerative::type_link link,
const std::vector<size_t> & expected_cluster_length) {
agglomerative solver(number_clusters, link);
cluster_data results_data;
solver.process(*data.get(), results_data);
cluster_sequence & results = results_data.clusters();
/* Check number of clusters */
ASSERT_EQ(expected_cluster_length.size(), results.size());
/* Check cluster sizes */
std::vector<size_t> obtained_cluster_length;
for (size_t i = 0; i < results.size(); i++) {
obtained_cluster_length.push_back(results[i].size());
}
std::sort(obtained_cluster_length.begin(), obtained_cluster_length.end());
std::vector<size_t> sorted_expected_cluster_length(expected_cluster_length);
std::sort(sorted_expected_cluster_length.begin(), sorted_expected_cluster_length.end());
for (size_t i = 0; i < obtained_cluster_length.size(); i++) {
ASSERT_EQ(obtained_cluster_length[i], sorted_expected_cluster_length[i]);
}
}
TEST(utest_agglomerative, clustering_sampl_simple_01_two_cluster_link_average) {
std::vector<size_t> expected_clusters_length_1 = {5, 5};
template_length_process_data(simple_sample_factory::create_sample(SAMPLE_SIMPLE::SAMPLE_SIMPLE_01), 2, agglomerative::type_link::AVERAGE_LINK, expected_clusters_length_1);
}
TEST(utest_agglomerative, clustering_sampl_simple_01_one_cluster_link_average) {
std::vector<size_t> expected_clusters_length_2 = {10};
template_length_process_data(simple_sample_factory::create_sample(SAMPLE_SIMPLE::SAMPLE_SIMPLE_01), 1, agglomerative::type_link::AVERAGE_LINK, expected_clusters_length_2);
}
TEST(utest_agglomerative, clustering_sampl_simple_01_two_cluster_link_centroid) {
std::vector<size_t> expected_clusters_length_1 = {5, 5};
template_length_process_data(simple_sample_factory::create_sample(SAMPLE_SIMPLE::SAMPLE_SIMPLE_01), 2, agglomerative::type_link::CENTROID_LINK, expected_clusters_length_1);
}
TEST(utest_agglomerative, clustering_sampl_simple_01_one_cluster_link_centroid) {
std::vector<size_t> expected_clusters_length_2 = {10};
template_length_process_data(simple_sample_factory::create_sample(SAMPLE_SIMPLE::SAMPLE_SIMPLE_01), 1, agglomerative::type_link::CENTROID_LINK, expected_clusters_length_2);
}
TEST(utest_agglomerative, clustering_sampl_simple_01_two_cluster_link_complete) {
std::vector<size_t> expected_clusters_length_1 = {5, 5};
template_length_process_data(simple_sample_factory::create_sample(SAMPLE_SIMPLE::SAMPLE_SIMPLE_01), 2, agglomerative::type_link::COMPLETE_LINK, expected_clusters_length_1);
}
TEST(utest_agglomerative, clustering_sampl_simple_01_one_cluster_link_complete) {
std::vector<size_t> expected_clusters_length_2 = {10};
template_length_process_data(simple_sample_factory::create_sample(SAMPLE_SIMPLE::SAMPLE_SIMPLE_01), 1, agglomerative::type_link::COMPLETE_LINK, expected_clusters_length_2);
}
TEST(utest_agglomerative, clustering_sampl_simple_01_two_cluster_link_single) {
std::vector<size_t> expected_clusters_length_1 = {5, 5};
template_length_process_data(simple_sample_factory::create_sample(SAMPLE_SIMPLE::SAMPLE_SIMPLE_01), 2, agglomerative::type_link::SINGLE_LINK, expected_clusters_length_1);
}
TEST(utest_agglomerative, clustering_sampl_simple_01_one_cluster_link_single) {
std::vector<size_t> expected_clusters_length_2 = {10};
template_length_process_data(simple_sample_factory::create_sample(SAMPLE_SIMPLE::SAMPLE_SIMPLE_01), 1, agglomerative::type_link::SINGLE_LINK, expected_clusters_length_2);
}
TEST(utest_agglomerative, clustering_sampl_simple_02_three_cluster_link_average) {
std::vector<size_t> expected_clusters_length_1 = {5, 8, 10};
template_length_process_data(simple_sample_factory::create_sample(SAMPLE_SIMPLE::SAMPLE_SIMPLE_02), 3, agglomerative::type_link::AVERAGE_LINK, expected_clusters_length_1);
}
TEST(utest_agglomerative, clustering_sampl_simple_02_one_cluster_link_average) {
std::vector<size_t> expected_clusters_length_2 = {23};
template_length_process_data(simple_sample_factory::create_sample(SAMPLE_SIMPLE::SAMPLE_SIMPLE_02), 1, agglomerative::type_link::AVERAGE_LINK, expected_clusters_length_2);
}
TEST(utest_agglomerative, clustering_sampl_simple_02_three_cluster_link_centroid) {
std::vector<size_t> expected_clusters_length_1 = {5, 8, 10};
template_length_process_data(simple_sample_factory::create_sample(SAMPLE_SIMPLE::SAMPLE_SIMPLE_02), 3, agglomerative::type_link::CENTROID_LINK, expected_clusters_length_1);
}
TEST(utest_agglomerative, clustering_sampl_simple_02_one_cluster_link_centroid) {
std::vector<size_t> expected_clusters_length_2 = {23};
template_length_process_data(simple_sample_factory::create_sample(SAMPLE_SIMPLE::SAMPLE_SIMPLE_02), 1, agglomerative::type_link::CENTROID_LINK, expected_clusters_length_2);
}
TEST(utest_agglomerative, clustering_sampl_simple_02_three_cluster_link_complete) {
std::vector<size_t> expected_clusters_length_1 = {5, 8, 10};
template_length_process_data(simple_sample_factory::create_sample(SAMPLE_SIMPLE::SAMPLE_SIMPLE_02), 3, agglomerative::type_link::COMPLETE_LINK, expected_clusters_length_1);
}
TEST(utest_agglomerative, clustering_sampl_simple_02_one_cluster_link_complete) {
std::vector<size_t> expected_clusters_length_2 = {23};
template_length_process_data(simple_sample_factory::create_sample(SAMPLE_SIMPLE::SAMPLE_SIMPLE_02), 1, agglomerative::type_link::COMPLETE_LINK, expected_clusters_length_2);
}
TEST(utest_agglomerative, clustering_sampl_simple_02_three_cluster_link_single) {
std::vector<size_t> expected_clusters_length_1 = {5, 8, 10};
template_length_process_data(simple_sample_factory::create_sample(SAMPLE_SIMPLE::SAMPLE_SIMPLE_02), 3, agglomerative::type_link::SINGLE_LINK, expected_clusters_length_1);
}
TEST(utest_agglomerative, clustering_sampl_simple_02_one_cluster_link_single) {
std::vector<size_t> expected_clusters_length_2 = {23};
template_length_process_data(simple_sample_factory::create_sample(SAMPLE_SIMPLE::SAMPLE_SIMPLE_02), 1, agglomerative::type_link::SINGLE_LINK, expected_clusters_length_2);
}
TEST(utest_agglomerative, clustering_sampl_simple_03_four_cluster_link_average) {
std::vector<size_t> expected_clusters_length_1 = {10, 10, 10, 30};
template_length_process_data(simple_sample_factory::create_sample(SAMPLE_SIMPLE::SAMPLE_SIMPLE_03), 4, agglomerative::type_link::AVERAGE_LINK, expected_clusters_length_1);
}
TEST(utest_agglomerative, clustering_sampl_simple_03_one_cluster_link_average) {
std::vector<size_t> expected_clusters_length_2 = {60};
template_length_process_data(simple_sample_factory::create_sample(SAMPLE_SIMPLE::SAMPLE_SIMPLE_03), 1, agglomerative::type_link::AVERAGE_LINK, expected_clusters_length_2);
}
TEST(utest_agglomerative, clustering_sampl_simple_03_four_cluster_link_centroid) {
std::vector<size_t> expected_clusters_length_1 = {10, 10, 10, 30};
template_length_process_data(simple_sample_factory::create_sample(SAMPLE_SIMPLE::SAMPLE_SIMPLE_03), 4, agglomerative::type_link::CENTROID_LINK, expected_clusters_length_1);
}
TEST(utest_agglomerative, clustering_sampl_simple_03_one_cluster_link_centroid) {
std::vector<size_t> expected_clusters_length_2 = {60};
template_length_process_data(simple_sample_factory::create_sample(SAMPLE_SIMPLE::SAMPLE_SIMPLE_03), 1, agglomerative::type_link::CENTROID_LINK, expected_clusters_length_2);
}
TEST(utest_agglomerative, clustering_sampl_simple_03_four_cluster_link_complete) {
std::vector<size_t> expected_clusters_length_1 = {10, 10, 10, 30};
template_length_process_data(simple_sample_factory::create_sample(SAMPLE_SIMPLE::SAMPLE_SIMPLE_03), 4, agglomerative::type_link::COMPLETE_LINK, expected_clusters_length_1);
}
TEST(utest_agglomerative, clustering_sampl_simple_03_one_cluster_link_complete) {
std::vector<size_t> expected_clusters_length_2 = {60};
template_length_process_data(simple_sample_factory::create_sample(SAMPLE_SIMPLE::SAMPLE_SIMPLE_03), 1, agglomerative::type_link::COMPLETE_LINK, expected_clusters_length_2);
}
TEST(utest_agglomerative, clustering_sampl_simple_03_four_cluster_link_single) {
std::vector<size_t> expected_clusters_length_1 = {10, 10, 10, 30};
template_length_process_data(simple_sample_factory::create_sample(SAMPLE_SIMPLE::SAMPLE_SIMPLE_03), 4, agglomerative::type_link::SINGLE_LINK, expected_clusters_length_1);
}
TEST(utest_agglomerative, clustering_sampl_simple_03_one_cluster_link_single) {
std::vector<size_t> expected_clusters_length_2 = {60};
template_length_process_data(simple_sample_factory::create_sample(SAMPLE_SIMPLE::SAMPLE_SIMPLE_03), 1, agglomerative::type_link::SINGLE_LINK, expected_clusters_length_2);
}
|