NCBI C++ ToolKit
cuBaseClusterer.cpp
Go to the documentation of this file.

Go to the SVN repository for this file.

1 /* $Id: cuBaseClusterer.cpp 33815 2007-05-04 17:18:18Z kazimird $
2 * ===========================================================================
3 *
4 * PUBLIC DOMAIN NOTICE
5 * National Center for Biotechnology Information
6 *
7 * This software/database is a "United States Government Work" under the
8 * terms of the United States Copyright Act. It was written as part of
9 * the author's official duties as a United States Government employee and
10 * thus cannot be copyrighted. This software/database is freely available
11 * to the public for use. The National Library of Medicine and the U.S.
12 * Government have not placed any restriction on its use or reproduction.
13 *
14 * Although all reasonable efforts have been taken to ensure the accuracy
15 * and reliability of the software and data, the NLM and the U.S.
16 * Government do not and cannot warrant the performance or results that
17 * may be obtained by using this software or data. The NLM and the U.S.
18 * Government disclaim all warranties, express or implied, including
19 * warranties of performance, merchantability or fitness for any particular
20 * purpose.
21 *
22 * Please cite the author in any work or product based on this material.
23 *
24 * ===========================================================================
25 *
26 * Author: Chris Lanczycki
27 *
28 * File Description:
29 * Virtual base classes to perform clustering. The first is completely an API.
30 * The second is for distance-based clustering using an algorithm defined in the class.
31 * Clusters are constructed in terms of the indices of the underlying distance matrix.
32 * The implementing & calling classes are responsible for consistent interpretation
33 * of that index.
34 *
35 */
36 
37 #include <ncbi_pch.hpp>
39 
41 BEGIN_SCOPE(cd_utils)
42 
44 
45 // default implementation of virtual function
46 string CBaseClusterer::IdToString(const TId& id) const {
47  return "ID " + NStr::IntToString(id);
48 }
49 
51  return m_clusters[clusterId];
52 }
53 
54 bool CBaseClusterer::GetCluster(TClusterId clusterId, TCluster*& cluster) {
55  bool result = false;
56  cluster = NULL;
57  if (clusterId != INVALID_CLUSTER_ID && clusterId < m_clusters.size()) {
58  cluster = &(m_clusters[clusterId]);
59  result = true;
60  }
61  return result;
62 }
63 
66  TIdToClusterCit itemIt = m_idToClusterMap.find(itemId);
67  cluster = NULL;
68  if (itemIt != m_idToClusterMap.end()) {
69  result = itemIt->second;
70  if (result != INVALID_CLUSTER_ID) {
71  cluster = &(m_clusters[result]);
72  }
73  }
74  return result;
75 }
76 
77 void CBaseClusterer::InitializeClusters(unsigned int dim) {
78  if (dim <=0) dim = 1; // start off w/ at least one cluster
80  m_clusters.clear();
81  m_clusters.resize(dim);
82 
83 }
84 
85 unsigned int CBaseClusterer::NumItems() const {
86  unsigned int nItems = 0;
87  for (unsigned int i = 0; i < m_clusters.size(); ++i) {
88  nItems += m_clusters[i].size();
89  }
90  return nItems;
91 }
92 
93 void CBaseClusterer::ResetClusters(unsigned int dim) {
94  if (dim > 0) {
95  InitializeClusters(dim);
96  }
97 }
98 
99 END_SCOPE(cd_utils)
const TCluster & GetCluster(TClusterId clusterId) const
static const TClusterId INVALID_CLUSTER_ID
TIdToCluster m_idToClusterMap
virtual string IdToString(const TId &id) const
unsigned int TClusterId
unsigned int NumItems() const
void InitializeClusters(unsigned int dim=0)
TClusterId GetClusterForId(TId itemId, TCluster *&cluster)
void ResetClusters(unsigned int dim=0)
unsigned int TId
TIdToCluster::const_iterator TIdToClusterCit
const_iterator end() const
Definition: map.hpp:152
void clear()
Definition: map.hpp:169
const_iterator find(const key_type &key) const
Definition: map.hpp:153
Definition: set.hpp:45
#define NULL
Definition: ncbistd.hpp:225
#define END_NCBI_SCOPE
End previously defined NCBI scope.
Definition: ncbistl.hpp:103
#define END_SCOPE(ns)
End the previously defined scope.
Definition: ncbistl.hpp:75
#define BEGIN_NCBI_SCOPE
Define ncbi namespace.
Definition: ncbistl.hpp:100
#define BEGIN_SCOPE(ns)
Define a new scope.
Definition: ncbistl.hpp:72
static string IntToString(int value, TNumToStringFlags flags=0, int base=10)
Convert int to string.
Definition: ncbistr.hpp:5084
int i
else result
Definition: token2.c:20
Modified on Mon Jun 24 05:23:01 2024 by modify_doxy.py rev. 669887