Main Page | Modules | Namespace List | Class Hierarchy | Alphabetical List | Class List | Directories | File List | Namespace Members | Class Members | File Members | Related Pages

qgar::GenKMeans< T > Class Template Reference
[Classification]

#include <qgarlib/GenKMeans.H>

List of all members.


Detailed Description

template<class T>
class qgar::GenKMeans< T >

Template class for partitioning a list of objects of type T into a (given) number of clusters using a k-means algorithm.

Warning:
The class is not supposed to be derived: The destructor (as any other function) is not virtual.
Author:
Gérald Masini
Date:
July 3, 2001 15:57
Since:
Qgar 2.1

Definition at line 235 of file GenKMeans.H.

Public Types

Types
typedef T value_type
 Type of the objects to be partitioned.
typedef value_typereference
 Reference to qgar::GenKMeans::value_type.
typedef const value_typeconst_reference
 Constant reference to qgar::GenKMeans::value_type.
typedef value_typepointer
 Pointer to qgar::GenKMeans::value_type.
typedef const value_typeconst_pointer
 Constant pointer to qgar::GenKMeans::value_type.
Signatures
typedef double(* DistanceFunction )(const_reference, const_reference)
 Signature of the distance function.

Public Member Functions

Constructors
 GenKMeans (const std::vector< value_type > &anObjVect, DistanceFunction aDistFunction, int aClusterCnt=3) throw (qgar::QgarErrorAlgorithm)
 Construct a partition of clusters using a distance function.
 GenKMeans (const std::vector< value_type > &anObjVect, DistanceFunction aDistFunction, const std::vector< value_type > &aCenterVector, int aClusterCnt=3) throw (qgar::QgarErrorAlgorithm)
 Construct a partition of clusters of given centers, using a distance function.
Destructor
 ~GenKMeans ()
 Destructor.
Access
int clusterCnt () const
 Get number of resulting clusters.
const std::vector< int > & clusterSizes () const
 Get the vector storing the resulting cluster sizes.
const std::vector< const_pointer > & clusterCenters () const
 Get the vector storing the resulting cluster centers.
const std::vector< std::vector<
const_pointer > > & 
accessClusterElts () const
 Get the vector storing the elements of the clusters.
std::vector< std::vector<
const_pointer > > 
clusterElts () const
 Get a copy of the vector storing the elements of the clusters.
const std::vector< GenCluster<
value_type > > & 
accessClusters () const
 Get the vector storing the clusters.
std::vector< GenCluster< value_type > > clusters () const
 Get a copy of the vector storing the clusters.

Protected Attributes

Representation of a cluster
const int _clusterCnt
 Number of clusters.
std::vector< std::vector<
const_pointer > > 
_clusterElts
 Vector storing the values of the clusters.
std::vector< int > _clusterSizes
 Vector of clusters sizes.
std::vector< const_pointer_clusterCenters
 Vector of cluster centers.
std::vector< const_pointer_objVect
 Vector of objects to be partitioned.
std::vector< GenCluster< value_type > > _clusters
 Vector storing the final clusters.
const DistanceFunction _distance
 The distance function.

Private Member Functions

Auxiliaries
void PRIVATEinitCenters () throw (qgar::QgarErrorAlgorithm)
 Initialize cluster centers.
void PRIVATEdistributeIntoClusters ()
 Distribute objects into clusters.
void PRIVATEgetCenters (std::vector< const_pointer > &aNewCenterVector) throw (qgar::QgarErrorAlgorithm)
 Compute new cluster centers.
void PRIVATEgetClusters ()
 Loop on constructing clusters until getting stable centers.
void PRIVATEconsFinalClusters ()
 Construct the final clusters in _clusters from _clustersElts.
Disabled
 GenKMeans (const GenKMeans &)
 Disabled copy constructor.
GenKMeansoperator= (const GenKMeans &)
 Disabled assignment operator.


Member Typedef Documentation

template<class T>
typedef const value_type* qgar::GenKMeans< T >::const_pointer
 

Constant pointer to qgar::GenKMeans::value_type.

Definition at line 269 of file GenKMeans.H.

template<class T>
typedef const value_type& qgar::GenKMeans< T >::const_reference
 

Constant reference to qgar::GenKMeans::value_type.

Definition at line 259 of file GenKMeans.H.

template<class T>
typedef double(* qgar::GenKMeans< T >::DistanceFunction)(const_reference, const_reference)
 

Signature of the distance function.

Definition at line 281 of file GenKMeans.H.

template<class T>
typedef value_type* qgar::GenKMeans< T >::pointer
 

Pointer to qgar::GenKMeans::value_type.

Definition at line 264 of file GenKMeans.H.

template<class T>
typedef value_type& qgar::GenKMeans< T >::reference
 

Reference to qgar::GenKMeans::value_type.

Definition at line 254 of file GenKMeans.H.

template<class T>
typedef T qgar::GenKMeans< T >::value_type
 

Type of the objects to be partitioned.

Definition at line 249 of file GenKMeans.H.


Constructor & Destructor Documentation

template<class T>
qgar::GenKMeans< T >::GenKMeans const std::vector< value_type > &  anObjVect,
DistanceFunction  aDistFunction,
int  aClusterCnt = 3
throw (qgar::QgarErrorAlgorithm)
 

Construct a partition of clusters using a distance function.

Parameters:
anObjVect vector of the objects to be partitioned
aDistFunction distance function f(T*,T*)
aClusterCnt number of resulting clusters (default 3)
Exceptions:
qgar::QgarErrorAlgorithm if an error occurred while creating clusters

Definition at line 167 of file GenKMeans.TCC.

template<class T>
qgar::GenKMeans< T >::GenKMeans const std::vector< value_type > &  anObjVect,
DistanceFunction  aDistFunction,
const std::vector< value_type > &  aCenterVector,
int  aClusterCnt = 3
throw (qgar::QgarErrorAlgorithm)
 

Construct a partition of clusters of given centers, using a distance function.

Parameters:
anObjVect vector of the objects to be partitioned
aDistFunction distance function f(T*,T*)
aCenterVector vector of the initial centers of the clusters
aClusterCnt number of resulting clusters (default 3)
Exceptions:
qgar::QgarErrorAlgorithm if an error occurred while creating clusters

Definition at line 200 of file GenKMeans.TCC.

template<class T>
qgar::GenKMeans< T >::~GenKMeans  ) 
 

Destructor.

It is not virtual as the class is not supposed to be derived.

Definition at line 234 of file GenKMeans.TCC.

template<class T>
qgar::GenKMeans< T >::GenKMeans const GenKMeans< T > &   )  [private]
 

Disabled copy constructor.


Member Function Documentation

template<class T>
const std::vector< std::vector< const T * > > & qgar::GenKMeans< T >::accessClusterElts  )  const [inline]
 

Get the vector storing the elements of the clusters.

Each element of the returned vector represents a cluster. Each cluster is itself represented by a vector, storing pointers to the elements of the cluster.

Definition at line 279 of file GenKMeans.TCC.

References qgar::GenKMeans< T >::_clusterElts.

template<class T>
const std::vector< GenCluster< T > > & qgar::GenKMeans< T >::accessClusters  )  const
 

Get the vector storing the clusters.

Each element of the returned vector represents a cluster. Each cluster is represented by an instance of class qgar::GenCluster.

Definition at line 299 of file GenKMeans.TCC.

References qgar::GenKMeans< T >::_clusters, and qgar::GenKMeans< T >::PRIVATEconsFinalClusters().

template<class T>
const std::vector< const T * > & qgar::GenKMeans< T >::clusterCenters  )  const [inline]
 

Get the vector storing the resulting cluster centers.

Definition at line 269 of file GenKMeans.TCC.

References qgar::GenKMeans< T >::_clusterCenters.

template<class T>
int qgar::GenKMeans< T >::clusterCnt  )  const [inline]
 

Get number of resulting clusters.

Definition at line 249 of file GenKMeans.TCC.

References qgar::GenKMeans< T >::_clusterCnt.

template<class T>
std::vector< std::vector< const T * > > qgar::GenKMeans< T >::clusterElts  )  const [inline]
 

Get a copy of the vector storing the elements of the clusters.

Each element of the returned vector represents a cluster. Each cluster is itself represented by a vector, storing pointers to the elements of the cluster.

Definition at line 289 of file GenKMeans.TCC.

References qgar::GenKMeans< T >::_clusterElts.

template<class T>
std::vector< GenCluster< T > > qgar::GenKMeans< T >::clusters  )  const
 

Get a copy of the vector storing the clusters.

Each element of the returned vector represents a cluster. Each cluster is represented by an instance of class qgar::GenCluster.

Definition at line 310 of file GenKMeans.TCC.

References qgar::GenKMeans< T >::_clusters, and qgar::GenKMeans< T >::PRIVATEconsFinalClusters().

template<class T>
const std::vector< int > & qgar::GenKMeans< T >::clusterSizes  )  const [inline]
 

Get the vector storing the resulting cluster sizes.

Definition at line 259 of file GenKMeans.TCC.

References qgar::GenKMeans< T >::_clusterSizes.

template<class T>
GenKMeans& qgar::GenKMeans< T >::operator= const GenKMeans< T > &   )  [private]
 

Disabled assignment operator.

template<class T>
void qgar::GenKMeans< T >::PRIVATEconsFinalClusters  )  [private]
 

Construct the final clusters in _clusters from _clustersElts.

Definition at line 552 of file GenKMeans.TCC.

References qgar::GenKMeans< T >::_clusterCenters, qgar::GenKMeans< T >::_clusterElts, qgar::GenKMeans< T >::_clusters, and qgar::GenKMeans< T >::_clusterSizes.

Referenced by qgar::GenKMeans< T >::accessClusters(), and qgar::GenKMeans< T >::clusters().

template<class T>
void qgar::GenKMeans< T >::PRIVATEdistributeIntoClusters  )  [private]
 

Distribute objects into clusters.

Definition at line 385 of file GenKMeans.TCC.

References qgar::GenKMeans< T >::_clusterCenters, qgar::GenKMeans< T >::_clusterCnt, qgar::GenKMeans< T >::_clusterElts, qgar::GenKMeans< T >::_clusterSizes, and qgar::GenKMeans< T >::_objVect.

Referenced by qgar::GenKMeans< T >::PRIVATEgetClusters().

template<class T>
void qgar::GenKMeans< T >::PRIVATEgetCenters std::vector< const_pointer > &  aNewCenterVector  )  throw (qgar::QgarErrorAlgorithm) [private]
 

Compute new cluster centers.

Parameters:
aNewCenterVector vector of resulting cluster centers
Exceptions:
qgar::QgarErrorAlgorithm 

Referenced by qgar::GenKMeans< T >::PRIVATEgetClusters().

template<class T>
void qgar::GenKMeans< T >::PRIVATEgetClusters  )  [private]
 

Loop on constructing clusters until getting stable centers.

Definition at line 493 of file GenKMeans.TCC.

References qgar::GenKMeans< T >::_clusterCenters, qgar::GenKMeans< T >::_clusterElts, qgar::GenKMeans< T >::_clusterSizes, qgar::GenKMeans< T >::PRIVATEdistributeIntoClusters(), and qgar::GenKMeans< T >::PRIVATEgetCenters().

template<class T>
void qgar::GenKMeans< T >::PRIVATEinitCenters  )  throw (qgar::QgarErrorAlgorithm) [private]
 

Initialize cluster centers.

Use a given number of the first objects of the given list of objects.

Exceptions:
qgar::QgarErrorAlgorithm 

Definition at line 327 of file GenKMeans.TCC.

References qgar::GenKMeans< T >::_clusterCenters, qgar::GenKMeans< T >::_clusterCnt, qgar::GenKMeans< T >::_clusterSizes, qgar::GenKMeans< T >::_distance, qgar::GenKMeans< T >::_objVect, and qgar::qgEq0().


Member Data Documentation

template<class T>
std::vector<const_pointer> qgar::GenKMeans< T >::_clusterCenters [protected]
 

Vector of cluster centers.

Definition at line 438 of file GenKMeans.H.

Referenced by qgar::GenKMeans< T >::clusterCenters(), qgar::GenKMeans< T >::PRIVATEconsFinalClusters(), qgar::GenKMeans< T >::PRIVATEdistributeIntoClusters(), qgar::GenKMeans< T >::PRIVATEgetClusters(), and qgar::GenKMeans< T >::PRIVATEinitCenters().

template<class T>
const int qgar::GenKMeans< T >::_clusterCnt [protected]
 

Number of clusters.

Definition at line 419 of file GenKMeans.H.

Referenced by qgar::GenKMeans< T >::clusterCnt(), qgar::GenKMeans< T >::PRIVATEdistributeIntoClusters(), and qgar::GenKMeans< T >::PRIVATEinitCenters().

template<class T>
std::vector< std::vector<const_pointer> > qgar::GenKMeans< T >::_clusterElts [protected]
 

Vector storing the values of the clusters.

Each element of this vector represents a cluster. Each cluster is also represented by a vector, storing the pointers to the elements of the cluster.

Definition at line 428 of file GenKMeans.H.

Referenced by qgar::GenKMeans< T >::accessClusterElts(), qgar::GenKMeans< T >::clusterElts(), qgar::GenKMeans< T >::PRIVATEconsFinalClusters(), qgar::GenKMeans< T >::PRIVATEdistributeIntoClusters(), and qgar::GenKMeans< T >::PRIVATEgetClusters().

template<class T>
std::vector< GenCluster<value_type> > qgar::GenKMeans< T >::_clusters [mutable, protected]
 

Vector storing the final clusters.

Each element of this vector represents a cluster. Each cluster is represented by an instance of class qgar::GenCluster.

Definition at line 452 of file GenKMeans.H.

Referenced by qgar::GenKMeans< T >::accessClusters(), qgar::GenKMeans< T >::clusters(), and qgar::GenKMeans< T >::PRIVATEconsFinalClusters().

template<class T>
std::vector<int> qgar::GenKMeans< T >::_clusterSizes [protected]
 

Vector of clusters sizes.

Definition at line 433 of file GenKMeans.H.

Referenced by qgar::GenKMeans< T >::clusterSizes(), qgar::GenKMeans< T >::PRIVATEconsFinalClusters(), qgar::GenKMeans< T >::PRIVATEdistributeIntoClusters(), qgar::GenKMeans< T >::PRIVATEgetClusters(), and qgar::GenKMeans< T >::PRIVATEinitCenters().

template<class T>
const DistanceFunction qgar::GenKMeans< T >::_distance [protected]
 

The distance function.

Definition at line 457 of file GenKMeans.H.

Referenced by qgar::GenKMeans< T >::PRIVATEinitCenters().

template<class T>
std::vector<const_pointer> qgar::GenKMeans< T >::_objVect [protected]
 

Vector of objects to be partitioned.

Definition at line 443 of file GenKMeans.H.

Referenced by qgar::GenKMeans< T >::PRIVATEdistributeIntoClusters(), and qgar::GenKMeans< T >::PRIVATEinitCenters().


The documentation for this class was generated from the following files: