ATLAS Offline Software
Public Types | Public Member Functions | Private Attributes | List of all members
TrigVSI::DBScan< pointType > Class Template Reference

Class for operating DBSCAN clustering. More...

#include <DBScan.h>

Collaboration diagram for TrigVSI::DBScan< pointType >:

Public Types

using RegionFunc = std::function< std::vector< pointType >(const pointType &, double)>
 Function type for region query function. More...
 

Public Member Functions

 DBScan (const std::unordered_set< pointType > &, RegionFunc)
 Normal Constructor. More...
 
 DBScan ()
 Default constructor. More...
 
 ~DBScan ()
 
DBScanoperator= (DBScan &&) noexcept=default
 Move assignment operator. More...
 
 DBScan (DBScan &&) noexcept=default
 Move constructor. More...
 
std::vector< Cluster< pointType > > getClusters () const
 Retrun the list of clusters along with noise clusters. More...
 
size_t nClusters () const
 
const Cluster< pointType > & getCluster (size_t) const
 Retrieve cluster. More...
 
void clusterize (double, size_t)
 Generate clusters with DBSCAN algorithim. More...
 

Private Attributes

RegionFunc m_regionQuery
 
std::unordered_map< pointType, bool > m_pointsVisited
 
std::vector< Cluster< pointType > > m_clusters
 
std::unordered_set< pointType > m_noises
 
std::vector< Cluster< pointType > > m_noisesCluster
 

Detailed Description

template<typename pointType>
class TrigVSI::DBScan< pointType >

Class for operating DBSCAN clustering.

Pass set of points on construction, then execute clusterize() once. Set of points can only be read on construction so you need to make new DBSCAN instance when you want to add new points.

Definition at line 43 of file DBScan.h.

Member Typedef Documentation

◆ RegionFunc

template<typename pointType >
using TrigVSI::DBScan< pointType >::RegionFunc = std::function<std::vector<pointType>(const pointType&, double)>

Function type for region query function.

Definition at line 45 of file DBScan.h.

Constructor & Destructor Documentation

◆ DBScan() [1/3]

template<typename pointType >
TrigVSI::DBScan< pointType >::DBScan ( const std::unordered_set< pointType > &  set,
RegionFunc  regionQuery 
)

Normal Constructor.

Parameters
[in]setSet of points to be clustered.
[in]regionQueryRegion query function, which defines the algorithm to pick points nearby.

Definition at line 83 of file DBScan.h.

83  :
84 m_regionQuery(regionQuery)
85 {
86  m_pointsVisited.clear();
87  for (const auto& point : set) {
88  m_pointsVisited.emplace(point, false);
89  }
90 }

◆ DBScan() [2/3]

template<typename pointType >
TrigVSI::DBScan< pointType >::DBScan

Default constructor.

Definition at line 97 of file DBScan.h.

98 {
99 
100 }

◆ ~DBScan()

template<typename pointType >
TrigVSI::DBScan< pointType >::~DBScan ( )
inline

Definition at line 48 of file DBScan.h.

48 {};

◆ DBScan() [3/3]

template<typename pointType >
TrigVSI::DBScan< pointType >::DBScan ( DBScan< pointType > &&  )
defaultnoexcept

Move constructor.

Member Function Documentation

◆ clusterize()

template<typename pointType >
void TrigVSI::DBScan< pointType >::clusterize ( double  eps,
size_t  minN 
)

Generate clusters with DBSCAN algorithim.

Parameters
[in]epsRadius of region to find neighbor points.
[in]minNThreshold to determine point as core.

Definition at line 142 of file DBScan.h.

143 {
144  m_clusters.clear();
145  m_noisesCluster.clear();
146  for (auto& pair : m_pointsVisited) {
147  const pointType& point = pair.first;
148 
149  if ( pair.second ) continue; // Continue when the point is visited
150  pair.second = true; // Set the point as visited
151  std::vector<pointType> neighbor_points = m_regionQuery(point, eps);
152  if ( neighbor_points.size() < minN ) {
153  m_noises.emplace(point);
154  continue;
155  }
156 
157  m_clusters.emplace_back( std::vector<pointType>{point} );
158  Cluster<pointType>& cls = *(--m_clusters.end());
159 
160  for (size_t i = 0; i < neighbor_points.size(); i++) {
161  const auto& q = neighbor_points[i];
162 
163  // Check if q is labeled as noise
164  // If so, remove q from noise lists and add q to cluster
165  auto q_itr_noise = m_noises.find(q);
166  if ( q_itr_noise != m_noises.end() ) {
167  m_noises.erase(q_itr_noise);
168  cls.Points().emplace_back(q);
169  }
170 
171  // Check if q had been visited before
172  // If visited, q is already labeled as a noise or added to other cluster so skip it
173  // If not visited, label q as visited and add it to cluster
174  auto q_itr = m_pointsVisited.find(q);
175  if ( q_itr == m_pointsVisited.end() ) continue;
176  if ( q_itr->second ) continue;
177  q_itr->second = true;
178  cls.Points().emplace_back(q);
179 
180  std::vector<pointType> q_neighbor_points = m_regionQuery(q, eps);
181  if ( q_neighbor_points.size() >= minN ) neighbor_points.insert( neighbor_points.end(), q_neighbor_points.begin(), q_neighbor_points.end() );
182  }
183 
184  }
185 
186  // Convert noises to one point clusters
187  for (const auto& q : m_noises) {
188  m_noisesCluster.emplace_back( std::vector<pointType>{q} );
189  }
190 }

◆ getCluster()

template<typename pointType >
const Cluster< pointType > & TrigVSI::DBScan< pointType >::getCluster ( size_t  icls) const
inline

Retrieve cluster.

Parameters
[in]iclsIndex of the cluster.

Return different type of clusters depending on icls.

  • icls < size of cluster list; Return cluster
  • size of cluster list <= icls < (size of cluster list) + (size of noise list); Return cluster made from (icls - size of cluster list)th noise.

Definition at line 128 of file DBScan.h.

129 {
130  const Cluster<pointType>& cls_tmp = ( icls < m_clusters.size() )? m_clusters[icls] : m_noisesCluster[icls-m_clusters.size()];
131  return cls_tmp;
132 }

◆ getClusters()

template<typename pointType >
std::vector< Cluster< pointType > > TrigVSI::DBScan< pointType >::getClusters
inline

Retrun the list of clusters along with noise clusters.

Definition at line 107 of file DBScan.h.

108 {
109  auto tmp = m_clusters;
110  const auto& tmp_noise = m_noisesCluster;
111  tmp.insert( tmp.end(), tmp_noise.begin(), tmp_noise.end() );
112  return tmp;
113 }

◆ nClusters()

template<typename pointType >
size_t TrigVSI::DBScan< pointType >::nClusters ( ) const
inline

Definition at line 54 of file DBScan.h.

54 { return m_clusters.size() + m_noisesCluster.size(); };

◆ operator=()

template<typename pointType >
DBScan& TrigVSI::DBScan< pointType >::operator= ( DBScan< pointType > &&  )
defaultnoexcept

Move assignment operator.

Member Data Documentation

◆ m_clusters

template<typename pointType >
std::vector<Cluster<pointType> > TrigVSI::DBScan< pointType >::m_clusters
private

Definition at line 62 of file DBScan.h.

◆ m_noises

template<typename pointType >
std::unordered_set<pointType> TrigVSI::DBScan< pointType >::m_noises
private

Definition at line 63 of file DBScan.h.

◆ m_noisesCluster

template<typename pointType >
std::vector<Cluster<pointType> > TrigVSI::DBScan< pointType >::m_noisesCluster
private

Definition at line 64 of file DBScan.h.

◆ m_pointsVisited

template<typename pointType >
std::unordered_map<pointType, bool> TrigVSI::DBScan< pointType >::m_pointsVisited
private

Definition at line 61 of file DBScan.h.

◆ m_regionQuery

template<typename pointType >
RegionFunc TrigVSI::DBScan< pointType >::m_regionQuery
private

Definition at line 60 of file DBScan.h.


The documentation for this class was generated from the following file:
TrigVSI::DBScan::m_regionQuery
RegionFunc m_regionQuery
Definition: DBScan.h:60
TrigVSI::DBScan::m_noises
std::unordered_set< pointType > m_noises
Definition: DBScan.h:63
CaloClusterListBadChannel.cls
cls
Definition: CaloClusterListBadChannel.py:8
TrigVSI::DBScan::m_noisesCluster
std::vector< Cluster< pointType > > m_noisesCluster
Definition: DBScan.h:64
lumiFormat.i
int i
Definition: lumiFormat.py:85
TrigVSI::DBScan::m_clusters
std::vector< Cluster< pointType > > m_clusters
Definition: DBScan.h:62
DeMoUpdate.tmp
string tmp
Definition: DeMoUpdate.py:1167
CxxUtils::set
constexpr std::enable_if_t< is_bitmask_v< E >, E & > set(E &lhs, E rhs)
Convenience function to set bits in a class enum bitmask.
Definition: bitmask.h:232
TrigVSI::DBScan::m_pointsVisited
std::unordered_map< pointType, bool > m_pointsVisited
Definition: DBScan.h:61
extractSporadic.q
list q
Definition: extractSporadic.py:98