ITK
4.1.0
Insight Segmentation and Registration Toolkit
|
#include <itkKdTreeBasedKmeansEstimator.h>
fast k-means algorithm implementation using k-d tree structure
It returns k mean vectors that are centroids of k-clusters using pre-generated k-d tree. k-d tree generation is done by the WeightedCentroidKdTreeGenerator. The tree construction needs to be done only once. The resulting k-d tree's non-terminal nodes that have their children nodes have vector sums of measurement vectors that belong to the nodes and the number of measurement vectors in addition to the typical node boundary information and pointers to children nodes. Instead of reassigning every measurement vector to the nearest cluster centroid and recalculating centroid, it maintain a set of cluster centroid candidates and using pruning algorithm that utilizes k-d tree, it updates the means of only relevant candidates at each iterations. It would be faster than traditional implementation of k-means algorithm. However, the k-d tree consumes a large amount of memory. The tree construction time and pruning algorithm's performance are important factors to the whole process's performance. If users want to use k-d tree for some purpose other than k-means estimation, they can use the KdTreeGenerator instead of the WeightedCentroidKdTreeGenerator. It will save the tree construction time and memory usage.
Note: There is a second implementation of k-means algorithm in ITK under the While the Kd tree based implementation is more time efficient, the GLA/LBG based algorithm is more memory efficient.
Recent API changes: The static const macro to get the length of a measurement vector, MeasurementVectorSize
has been removed to allow the length of a measurement vector to be specified at run time. It is now obtained from the KdTree set as input. You may query this length using the function GetMeasurementVectorSize().
Definition at line 77 of file itkKdTreeBasedKmeansEstimator.h.
typedef KdTreeNodeType::CentroidType itk::Statistics::KdTreeBasedKmeansEstimator< TKdTree >::CentroidType |
Definition at line 99 of file itkKdTreeBasedKmeansEstimator.h.
typedef itksys::hash_map< InstanceIdentifier, unsigned int > itk::Statistics::KdTreeBasedKmeansEstimator< TKdTree >::ClusterLabelsType |
Definition at line 162 of file itkKdTreeBasedKmeansEstimator.h.
typedef SmartPointer< const Self > itk::Statistics::KdTreeBasedKmeansEstimator< TKdTree >::ConstPointer |
Reimplemented from itk::Object.
Definition at line 85 of file itkKdTreeBasedKmeansEstimator.h.
typedef DistanceToCentroidMembershipFunctionType::Pointer itk::Statistics::KdTreeBasedKmeansEstimator< TKdTree >::DistanceToCentroidMembershipFunctionPointer |
Definition at line 116 of file itkKdTreeBasedKmeansEstimator.h.
typedef DistanceToCentroidMembershipFunction< MeasurementVectorType > itk::Statistics::KdTreeBasedKmeansEstimator< TKdTree >::DistanceToCentroidMembershipFunctionType |
Typedef requried to generate dataobject decorated output that can be plugged into SampleClassifierFilter
Definition at line 113 of file itkKdTreeBasedKmeansEstimator.h.
typedef TKdTree::InstanceIdentifier itk::Statistics::KdTreeBasedKmeansEstimator< TKdTree >::InstanceIdentifier |
Definition at line 97 of file itkKdTreeBasedKmeansEstimator.h.
typedef std::vector< ParameterType > itk::Statistics::KdTreeBasedKmeansEstimator< TKdTree >::InternalParametersType |
Definition at line 107 of file itkKdTreeBasedKmeansEstimator.h.
typedef TKdTree::KdTreeNodeType itk::Statistics::KdTreeBasedKmeansEstimator< TKdTree >::KdTreeNodeType |
Types for the KdTree data structure
Definition at line 91 of file itkKdTreeBasedKmeansEstimator.h.
typedef TKdTree::MeasurementType itk::Statistics::KdTreeBasedKmeansEstimator< TKdTree >::MeasurementType |
Definition at line 95 of file itkKdTreeBasedKmeansEstimator.h.
typedef unsigned int itk::Statistics::KdTreeBasedKmeansEstimator< TKdTree >::MeasurementVectorSizeType |
Typedef for the length of a measurement vector
Definition at line 102 of file itkKdTreeBasedKmeansEstimator.h.
typedef TKdTree::MeasurementVectorType itk::Statistics::KdTreeBasedKmeansEstimator< TKdTree >::MeasurementVectorType |
Definition at line 96 of file itkKdTreeBasedKmeansEstimator.h.
typedef MembershipFunctionType::ConstPointer itk::Statistics::KdTreeBasedKmeansEstimator< TKdTree >::MembershipFunctionPointer |
Definition at line 119 of file itkKdTreeBasedKmeansEstimator.h.
typedef MembershipFunctionBase< MeasurementVectorType > itk::Statistics::KdTreeBasedKmeansEstimator< TKdTree >::MembershipFunctionType |
Definition at line 118 of file itkKdTreeBasedKmeansEstimator.h.
typedef MembershipFunctionVectorObjectType::Pointer itk::Statistics::KdTreeBasedKmeansEstimator< TKdTree >::MembershipFunctionVectorObjectPointer |
Definition at line 124 of file itkKdTreeBasedKmeansEstimator.h.
typedef SimpleDataObjectDecorator< MembershipFunctionVectorType > itk::Statistics::KdTreeBasedKmeansEstimator< TKdTree >::MembershipFunctionVectorObjectType |
Definition at line 122 of file itkKdTreeBasedKmeansEstimator.h.
typedef std::vector< MembershipFunctionPointer > itk::Statistics::KdTreeBasedKmeansEstimator< TKdTree >::MembershipFunctionVectorType |
Definition at line 120 of file itkKdTreeBasedKmeansEstimator.h.
typedef Array< double > itk::Statistics::KdTreeBasedKmeansEstimator< TKdTree >::ParametersType |
Definition at line 108 of file itkKdTreeBasedKmeansEstimator.h.
typedef Array< double > itk::Statistics::KdTreeBasedKmeansEstimator< TKdTree >::ParameterType |
Parameters type. It defines a position in the optimization search space.
Definition at line 106 of file itkKdTreeBasedKmeansEstimator.h.
typedef SmartPointer< Self > itk::Statistics::KdTreeBasedKmeansEstimator< TKdTree >::Pointer |
Reimplemented from itk::Object.
Definition at line 84 of file itkKdTreeBasedKmeansEstimator.h.
typedef TKdTree::SampleType itk::Statistics::KdTreeBasedKmeansEstimator< TKdTree >::SampleType |
Definition at line 98 of file itkKdTreeBasedKmeansEstimator.h.
typedef KdTreeBasedKmeansEstimator itk::Statistics::KdTreeBasedKmeansEstimator< TKdTree >::Self |
Standard Self typedef.
Reimplemented from itk::Object.
Definition at line 82 of file itkKdTreeBasedKmeansEstimator.h.
typedef Object itk::Statistics::KdTreeBasedKmeansEstimator< TKdTree >::Superclass |
Reimplemented from itk::Object.
Definition at line 83 of file itkKdTreeBasedKmeansEstimator.h.
itk::Statistics::KdTreeBasedKmeansEstimator< TKdTree >::KdTreeBasedKmeansEstimator | ( | ) | [protected] |
virtual itk::Statistics::KdTreeBasedKmeansEstimator< TKdTree >::~KdTreeBasedKmeansEstimator | ( | ) | [inline, protected, virtual] |
Definition at line 168 of file itkKdTreeBasedKmeansEstimator.h.
void itk::Statistics::KdTreeBasedKmeansEstimator< TKdTree >::CopyParameters | ( | InternalParametersType & | source, |
InternalParametersType & | target | ||
) | [protected] |
copies the source parameters (k-means) to the target
void itk::Statistics::KdTreeBasedKmeansEstimator< TKdTree >::CopyParameters | ( | ParametersType & | source, |
InternalParametersType & | target | ||
) | [protected] |
copies the source parameters (k-means) to the target
void itk::Statistics::KdTreeBasedKmeansEstimator< TKdTree >::CopyParameters | ( | InternalParametersType & | source, |
ParametersType & | target | ||
) | [protected] |
copies the source parameters (k-means) to the target
virtual::itk::LightObject::Pointer itk::Statistics::KdTreeBasedKmeansEstimator< TKdTree >::CreateAnother | ( | void | ) | const [virtual] |
Create an object from an instance, potentially deferring to a factory. This method allows you to create an instance of an object that is exactly the same type as the referring object. This is useful in cases where an object has been cast back to a base class.
Reimplemented from itk::Object.
void itk::Statistics::KdTreeBasedKmeansEstimator< TKdTree >::FillClusterLabels | ( | KdTreeNodeType * | node, |
int | closestIndex | ||
) | [protected] |
void itk::Statistics::KdTreeBasedKmeansEstimator< TKdTree >::Filter | ( | KdTreeNodeType * | node, |
std::vector< int > | validIndexes, | ||
MeasurementVectorType & | lowerBound, | ||
MeasurementVectorType & | upperBound | ||
) | [protected] |
recursive pruning algorithm. the validIndexes vector contains only the indexes of the surviving candidates for the node
virtual double itk::Statistics::KdTreeBasedKmeansEstimator< TKdTree >::GetCentroidPositionChanges | ( | ) | const [virtual] |
virtual double itk::Statistics::KdTreeBasedKmeansEstimator< TKdTree >::GetCentroidPositionChangesThreshold | ( | ) | const [virtual] |
int itk::Statistics::KdTreeBasedKmeansEstimator< TKdTree >::GetClosestCandidate | ( | ParameterType & | measurements, |
std::vector< int > & | validIndexes | ||
) | [protected] |
get the index of the closest candidate to the measurements measurement vector
virtual int itk::Statistics::KdTreeBasedKmeansEstimator< TKdTree >::GetCurrentIteration | ( | ) | const [virtual] |
const TKdTree* itk::Statistics::KdTreeBasedKmeansEstimator< TKdTree >::GetKdTree | ( | ) | const |
virtual int itk::Statistics::KdTreeBasedKmeansEstimator< TKdTree >::GetMaximumIteration | ( | ) | const [virtual] |
Set/Get maximum iteration limit.
virtual MeasurementVectorSizeType itk::Statistics::KdTreeBasedKmeansEstimator< TKdTree >::GetMeasurementVectorSize | ( | ) | const [virtual] |
Get the length of measurement vectors in the KdTree
virtual const char* itk::Statistics::KdTreeBasedKmeansEstimator< TKdTree >::GetNameOfClass | ( | ) | const [virtual] |
Run-time type information (and related methods).
Reimplemented from itk::Object.
const MembershipFunctionVectorObjectType* itk::Statistics::KdTreeBasedKmeansEstimator< TKdTree >::GetOutput | ( | ) | const |
Output Membership function vector containing the membership functions with the final optimized parameters
virtual ParametersType itk::Statistics::KdTreeBasedKmeansEstimator< TKdTree >::GetParameters | ( | ) | const [virtual] |
Set the position to initialize the optimization.
void itk::Statistics::KdTreeBasedKmeansEstimator< TKdTree >::GetPoint | ( | ParameterType & | point, |
MeasurementVectorType | measurements | ||
) | [protected] |
imports the measurements measurement vector data to the point
double itk::Statistics::KdTreeBasedKmeansEstimator< TKdTree >::GetSumOfSquaredPositionChanges | ( | InternalParametersType & | previous, |
InternalParametersType & | current | ||
) | [protected] |
gets the sum of squared difference between the previous position and current postion of all centroid. This is the primary termination condition for this algorithm. If the return value is less than the value that was set by the SetCentroidPositionChangesThreshold method.
virtual bool itk::Statistics::KdTreeBasedKmeansEstimator< TKdTree >::GetUseClusterLabels | ( | ) | const [virtual] |
bool itk::Statistics::KdTreeBasedKmeansEstimator< TKdTree >::IsFarther | ( | ParameterType & | pointA, |
ParameterType & | pointB, | ||
MeasurementVectorType & | lowerBound, | ||
MeasurementVectorType & | upperBound | ||
) | [protected] |
returns true if the pointA is farther than pointB to the boundary
static Pointer itk::Statistics::KdTreeBasedKmeansEstimator< TKdTree >::New | ( | ) | [static] |
Method for creation through the object factory.
Reimplemented from itk::Object.
void itk::Statistics::KdTreeBasedKmeansEstimator< TKdTree >::PrintPoint | ( | ParameterType & | point | ) | [protected] |
void itk::Statistics::KdTreeBasedKmeansEstimator< TKdTree >::PrintSelf | ( | std::ostream & | os, |
Indent | indent | ||
) | const [protected, virtual] |
Methods invoked by Print() to print information about the object including superclasses. Typically not called by the user (use Print() instead) but used in the hierarchical print process to combine the output of several classes.
Reimplemented from itk::Object.
virtual void itk::Statistics::KdTreeBasedKmeansEstimator< TKdTree >::SetCentroidPositionChangesThreshold | ( | double | _arg | ) | [virtual] |
Set/Get the termination threshold for the squared sum of changes in centroid postions after one iteration
void itk::Statistics::KdTreeBasedKmeansEstimator< TKdTree >::SetKdTree | ( | TKdTree * | tree | ) |
Set/Get the pointer to the KdTree
virtual void itk::Statistics::KdTreeBasedKmeansEstimator< TKdTree >::SetMaximumIteration | ( | int | _arg | ) | [virtual] |
Set/Get maximum iteration limit.
virtual void itk::Statistics::KdTreeBasedKmeansEstimator< TKdTree >::SetParameters | ( | ParametersType | _arg | ) | [virtual] |
Set the position to initialize the optimization.
virtual void itk::Statistics::KdTreeBasedKmeansEstimator< TKdTree >::SetUseClusterLabels | ( | bool | _arg | ) | [virtual] |
void itk::Statistics::KdTreeBasedKmeansEstimator< TKdTree >::StartOptimization | ( | ) |
Start optimization Optimization will stop when it meets either of two termination conditions, the maximum iteration limit or epsilon (minimal changes in squared sum of changes in centroid positions)
CandidateVector itk::Statistics::KdTreeBasedKmeansEstimator< TKdTree >::m_CandidateVector [private] |
Definition at line 325 of file itkKdTreeBasedKmeansEstimator.h.
double itk::Statistics::KdTreeBasedKmeansEstimator< TKdTree >::m_CentroidPositionChanges [private] |
sum of squared centroid position changes at the current iteration
Definition at line 310 of file itkKdTreeBasedKmeansEstimator.h.
double itk::Statistics::KdTreeBasedKmeansEstimator< TKdTree >::m_CentroidPositionChangesThreshold [private] |
threshold for the sum of squared centroid position changes. termination criterion
Definition at line 314 of file itkKdTreeBasedKmeansEstimator.h.
ClusterLabelsType itk::Statistics::KdTreeBasedKmeansEstimator< TKdTree >::m_ClusterLabels [private] |
Definition at line 331 of file itkKdTreeBasedKmeansEstimator.h.
int itk::Statistics::KdTreeBasedKmeansEstimator< TKdTree >::m_CurrentIteration [private] |
current number of iteration
Definition at line 304 of file itkKdTreeBasedKmeansEstimator.h.
EuclideanDistanceMetric< ParameterType >::Pointer itk::Statistics::KdTreeBasedKmeansEstimator< TKdTree >::m_DistanceMetric [private] |
pointer to the euclidean distance funtion
Definition at line 320 of file itkKdTreeBasedKmeansEstimator.h.
bool itk::Statistics::KdTreeBasedKmeansEstimator< TKdTree >::m_GenerateClusterLabels [private] |
Definition at line 330 of file itkKdTreeBasedKmeansEstimator.h.
TKdTree::Pointer itk::Statistics::KdTreeBasedKmeansEstimator< TKdTree >::m_KdTree [private] |
pointer to the k-d tree
Definition at line 317 of file itkKdTreeBasedKmeansEstimator.h.
int itk::Statistics::KdTreeBasedKmeansEstimator< TKdTree >::m_MaximumIteration [private] |
maximum number of iteration. termination criterion
Definition at line 307 of file itkKdTreeBasedKmeansEstimator.h.
MeasurementVectorSizeType itk::Statistics::KdTreeBasedKmeansEstimator< TKdTree >::m_MeasurementVectorSize [private] |
Definition at line 332 of file itkKdTreeBasedKmeansEstimator.h.
MembershipFunctionVectorObjectPointer itk::Statistics::KdTreeBasedKmeansEstimator< TKdTree >::m_MembershipFunctionsObject [private] |
Definition at line 333 of file itkKdTreeBasedKmeansEstimator.h.
ParametersType itk::Statistics::KdTreeBasedKmeansEstimator< TKdTree >::m_Parameters [private] |
k-means
Definition at line 323 of file itkKdTreeBasedKmeansEstimator.h.
ParameterType itk::Statistics::KdTreeBasedKmeansEstimator< TKdTree >::m_TempVertex [private] |
Definition at line 327 of file itkKdTreeBasedKmeansEstimator.h.
bool itk::Statistics::KdTreeBasedKmeansEstimator< TKdTree >::m_UseClusterLabels [private] |
Definition at line 329 of file itkKdTreeBasedKmeansEstimator.h.