FairRoot/PandaRoot
PndMvaCluster.h
Go to the documentation of this file.
1 /* ***************************************
2  * Clustering algorithms *
3  * Author: M.Babai@rug.nl *
4  * Version: *
5  * LICENSE: *
6  * ***************************************
7  */
8 //#pragma once
9 #ifndef PND_MVA_CLUSTER_H
10 #define PND_MVA_CLUSTER_H
11 
12 #include <iostream>
13 #include <cassert>
14 #include <vector>
15 #include <set>
16 #include <limits>
17 
18 // Local includes
19 #include "PndMvaUtil.h"
20 
21 #define PNDMVA_CLUSTER_DEBUG 0
22 
24 typedef std::vector< std::pair<std::string, std::vector<float>*> > DataPoints;
25 
27 typedef enum ClusteringType{
29  KMEANS_SOFT = 1// Not Implemented yet.
31 
32 //---------------- Class definition --------------
34 {
35  //--------------------------------------------
36  // -------------- public members -------------
37  public:
43  explicit PndMvaCluster( DataPoints const& InputData, size_t nCluster);
44 
52  explicit PndMvaCluster( DataPoints const& InputData, size_t nCluster,
53  bool const prune, bool const forceLabels);
54 
58  virtual ~PndMvaCluster();
59 
65  virtual DataPoints* Cluster( ClusteringType const ClType = KMEANS_HARD);
66 
74  virtual DataPoints* ClusterAndLabel( ClusteringType const ClType,
75  std::vector<std::string> const& labels);
76 
77  //------- Getters
82  inline size_t GetNumberOfClusters() const;
83 
88  inline size_t GetClusterDimension() const;
89 
90  //------- Setters
95  inline void SetNumberOfClusters(size_t val);
96 
102  inline void Setprune (bool const prune = false);
103 
110  inline void SetForceToLabel (bool const forceLabel = false);
111 
112  //__________________ DEBUG FUNCTIONS ______________
113 #if (PNDMVA_CLUSTER_DEBUG > 0)
114 
117  void printStructs();
118 #endif
119  //--------------------------------------------
120  //protected:
121  // -------------- private members ------------
122  private:
124  PndMvaCluster(const PndMvaCluster& other);
125  PndMvaCluster& operator=(const PndMvaCluster& other);
126 
127  // Functions & Procedures
128  // Performs the actual hard K-Means clustering.
129  DataPoints* K_Means();
130 
131  // Initialize the centroids before clustering.
132  void InitCentroids();
133 
134  // Partitions the data points among the current cluster centroids.
135  void InitialPartition();
136 
137  // Compute (modify) the coordinates of centroids.
138  void ComputeCentroids();
139 
140  // Set all dimensions to zero
141  void ResetCenteroids();
142 
143  // Clear the currently used data structures.
144  void ClearStructures();
145 
146  // Init empty Centroid to the furthest point.
147  void ReInitEmptyCenter(size_t centerIdx);
148 
149  // Variables
152  size_t m_dimension;
153 
154  // Container to hold the centroid.
156 
157  // Connection of each point to a centroid.
158  std::vector <size_t> m_PointsToClusters;
159 
160  // Responsibility list of each centroid.
161  std::vector< std::set<size_t>* > m_ClustersToPoints;
162 
163  bool m_prune;// If prune the current cluster.
164  bool m_forceToLabel;// Force to label the current mean
165 };
166 
167 //__________________ Inlines ____________
168 
170 {
171  return m_num_Cluster;
172 };
173 
175 {
176  return m_dimension;
177 };
178 
180 {
181  m_num_Cluster = val;
182 };
183 
184 inline void PndMvaCluster::Setprune (bool const prune)
185 {
186  m_prune = prune;
187 };
188 inline void PndMvaCluster::SetForceToLabel (bool const label)
189 {
190  m_forceToLabel = label;
191 };
192 #endif// End interface
void SetForceToLabel(bool const forceLabel=false)
std::vector< std::set< size_t > * > m_ClustersToPoints
void ReInitEmptyCenter(size_t centerIdx)
PndMvaCluster(DataPoints const &InputData, size_t nCluster)
Double_t val[nBoxes][nFEBox]
Definition: createCalib.C:11
DataPoints * K_Means()
virtual DataPoints * Cluster(ClusteringType const ClType=KMEANS_HARD)
DataPoints m_Centroids
Data points dimension.
virtual DataPoints * ClusterAndLabel(ClusteringType const ClType, std::vector< std::string > const &labels)
PndMvaCluster & operator=(const PndMvaCluster &other)
void InitCentroids()
std::vector< std::string > labels
void ResetCenteroids()
virtual ~PndMvaCluster()
size_t GetClusterDimension() const
size_t m_dimension
input data points.
void ComputeCentroids()
void SetNumberOfClusters(size_t val)
ClusteringType
Clustering types.
Definition: PndMvaCluster.h:27
void Setprune(bool const prune=false)
size_t GetNumberOfClusters() const
std::vector< std::pair< std::string, std::vector< float > * > > DataPoints
Data structure of the space points and the cluster centers.
Definition: PndMvaCluster.h:24
void ClearStructures()
size_t m_num_Cluster
std::vector< size_t > m_PointsToClusters
DataPoints m_PointSet
number of cluster centers.
void InitialPartition()