File: kmeans_data.hpp

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 (157 lines) | stat: -rwxr-xr-x 3,710 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
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
/*!

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

*/

#pragma once


#include <memory>
#include <vector>

#include <pyclustering/cluster/cluster_data.hpp>

#include <pyclustering/definitions.hpp>


namespace pyclustering {

namespace clst {


/*!

@class    kmeans_data kmeans_data.hpp pyclustering/cluster/kmeans_data.hpp

@brief    Clustering results of K-Means algorithm that consists of information about allocated
           clusters and centers of each cluster.

*/
class kmeans_data : public cluster_data {
private:
    dataset       m_centers   = { };

    bool          m_observed  = false;

    double        m_wce       = 0.0;

    std::vector<dataset> m_evolution_centers            = { };
    std::vector<cluster_sequence> m_evolution_clusters  = { };

public:
    /*!
    
    @brief    Default constructor that creates empty clustering data.
    @details  In case of default constructor clusters and centers are not stored on each clustering iteration.
    
    */
    kmeans_data() = default;

    /*!
    
    @brief    Constructor that provides flag to specify that clusters and centers changes are stored on each step.
    
    @param[in] p_iteration_observe: if 'true' then cluster and centers changes on each iteration are collected.
    
    */
    explicit kmeans_data(const bool p_iteration_observe);

    /*!
    
    @brief    Copy constructor that creates clustering data that is the same to specified.
    
    @param[in] p_other: another clustering data.
    
    */
    kmeans_data(const kmeans_data & p_other) = default;

    /*!
    
    @brief    Move constructor that creates clustering data from another by moving data.
    
    @param[in] p_other: another clustering data.
    
    */
    kmeans_data(kmeans_data && p_other) = default;

    /*!
    
    @brief    Default destructor that destroys clustering data.
    
    */
    virtual ~kmeans_data() = default;

public:
    /*!
    
    @brief    Returns reference to centers that correspond to allocated clusters.
    
    */
    dataset & centers() { return m_centers; }

    /*!
    
    @brief    Returns constant reference to centers that correspond to allocated clusters.
    
    */
    const dataset & centers() const { return m_centers; };

    /*!
    
    @brief    Returns 'true' if clusters and centers are collected during process of clustering.
    
    */
    bool is_observed() const { return m_observed; }

    /*!
    
    @brief    Returns total within-cluster errors.
    
    */
    double & wce() { return m_wce; }

    /*!
    
    @brief    Returns constant total within-cluster errors.
    
    */
    const double & wce() const { return m_wce; }

    /*!
    
    @brief    Returns reference to evolution of centers.
    @details  The evolution does not contain initial centers.
    
    */
    std::vector<dataset> & evolution_centers() { return m_evolution_centers; }

    /*!
    
    @brief    Returns constant reference to evolution of centers.
    @details  The evolution does not contain initial centers.
    
    */
    const std::vector<dataset> & evolution_centers() const { return m_evolution_centers; }

    /*!
    
    @brief    Returns reference to evolution of clusters.
    
    */
    std::vector<cluster_sequence> & evolution_clusters() { return m_evolution_clusters; }

    /*!
    
    @brief    Returns constant reference to evolution of clusters.
    
    */
    const std::vector<cluster_sequence> & evolution_clusters() const { return m_evolution_clusters; }
};


}

}