File: utest-syncnet.cpp

package info (click to toggle)
python-pyclustering 0.10.1.2-2
  • links: PTS, VCS
  • area: main
  • in suites: bookworm, forky, sid, trixie
  • size: 11,128 kB
  • sloc: cpp: 38,888; python: 24,311; sh: 384; makefile: 105
file content (135 lines) | stat: -rwxr-xr-x 3,734 bytes parent folder | download | duplicates (2)
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
/*!

@authors Andrei Novikov (pyclustering@yandex.ru)
@date 2014-2020
@copyright BSD-3-Clause

*/


#include <gtest/gtest.h>

#include "samples.hpp"

#include <pyclustering/cluster/syncnet.hpp>


using namespace pyclustering::clst;


static void template_create_delete(const unsigned int size) {
    std::vector<std::vector<double> > sample;
    for (unsigned int i = 0; i < size; i++) {
        sample.push_back( { 0.0 + (double) i } );
    }

    syncnet * network = new syncnet(&sample, 2.0, false, initial_type::EQUIPARTITION);

    ASSERT_EQ(size, network->size());

    delete network;
}

TEST(utest_syncnet, create_delete_network_1) {
    template_create_delete(1);
}

TEST(utest_syncnet, create_delete_network_10) {
    template_create_delete(10);
}

TEST(utest_syncnet, create_delete_network_100) {
    template_create_delete(100);
}

TEST(utest_syncnet, one_cluster) {
    bool result_testing = false;

    for (std::size_t attempt = 0; attempt < 3; attempt++) {
        std::vector<std::vector<double> > sample;

        sample.push_back( { 0.1, 0.1 } );
        sample.push_back( { 0.2, 0.1 } );
        sample.push_back( { 0.0, 0.0 } );

        syncnet network(&sample, 0.5, false, initial_type::EQUIPARTITION);

        syncnet_analyser analyser;
        network.process(0.998, solve_type::FORWARD_EULER, true, analyser);

        syncnet_cluster_data clusters;
        analyser.allocate_clusters(0.1, clusters);

        if (1 != clusters.size()) {
            continue;
        }

        result_testing = true;
    }

    ASSERT_TRUE(result_testing);
}

static void template_two_cluster_allocation(const solve_type solver, const bool collect_dynamic, const bool ena_conn_weight) {
    bool result_testing = false;

    for (std::size_t attempt = 0; attempt < 3; attempt++) {
        std::vector<std::vector<double> > sample;

        sample.push_back( { 0.1, 0.1 } );
        sample.push_back( { 0.2, 0.1 } );
        sample.push_back( { 0.0, 0.0 } );

        sample.push_back( { 2.2, 2.1 } );
        sample.push_back( { 2.3, 2.0 } );
        sample.push_back( { 2.1, 2.4 } );

        syncnet network(&sample, 0.5, ena_conn_weight, initial_type::EQUIPARTITION);

        syncnet_analyser analyser;
        network.process(0.995, solver, true, analyser);

        ensemble_data<syncnet_cluster> ensembles;
        analyser.allocate_clusters(0.1, ensembles);

        if (2 != ensembles.size()) {
            continue;
        }

        result_testing = true;
    }

    ASSERT_TRUE(result_testing);
}

TEST(utest_syncnet, two_clusters_fast_solver_with_collection) {
    template_two_cluster_allocation(solve_type::FORWARD_EULER, true, false);
}

TEST(utest_syncnet, two_clusters_rk4_solver_with_collection) {
    template_two_cluster_allocation(solve_type::RUNGE_KUTTA_4, true, false);
}

TEST(utest_syncnet, two_clusters_rkf45_solver_with_collection) {
    template_two_cluster_allocation(solve_type::RUNGE_KUTTA_FEHLBERG_45, true, false);
}

TEST(utest_syncnet, two_clusters_fast_solver_without_collection) {
    template_two_cluster_allocation(solve_type::FORWARD_EULER, false, false);
}

TEST(utest_syncnet, two_clusters_rk4_solver_without_collection) {
    template_two_cluster_allocation(solve_type::RUNGE_KUTTA_4, false, false);
}

#ifndef VALGRIND_ANALYSIS_SHOCK

TEST(utest_syncnet, two_clusters_rkf45_solver_without_collection) {
    template_two_cluster_allocation(solve_type::RUNGE_KUTTA_FEHLBERG_45, false, false);
}

TEST(utest_syncnet, two_clusters_fast_solver_conn_weight) {
    template_two_cluster_allocation(solve_type::FORWARD_EULER, false, true);
}

#endif