ITK
5.0.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.
Classes | |
class | CandidateVector |
Public Member Functions | |
virtual ::itk::LightObject::Pointer | CreateAnother () const |
virtual double | GetCentroidPositionChanges () const |
virtual double | GetCentroidPositionChangesThreshold () const |
virtual int | GetCurrentIteration () const |
const TKdTree * | GetKdTree () const |
virtual MeasurementVectorSizeType | GetMeasurementVectorSize () const |
virtual const char * | GetNameOfClass () const |
const MembershipFunctionVectorObjectType * | GetOutput () const |
virtual bool | GetUseClusterLabels () const |
virtual void | SetCentroidPositionChangesThreshold (double _arg) |
void | SetKdTree (TKdTree *tree) |
virtual void | SetUseClusterLabels (bool _arg) |
void | StartOptimization () |
virtual void | SetParameters (ParametersType _arg) |
virtual ParametersType | GetParameters () const |
virtual void | SetMaximumIteration (int _arg) |
virtual int | GetMaximumIteration () const |
Public Member Functions inherited from itk::Object | |
unsigned long | AddObserver (const EventObject &event, Command *) |
unsigned long | AddObserver (const EventObject &event, Command *) const |
virtual void | DebugOff () const |
virtual void | DebugOn () const |
Command * | GetCommand (unsigned long tag) |
bool | GetDebug () const |
MetaDataDictionary & | GetMetaDataDictionary () |
const MetaDataDictionary & | GetMetaDataDictionary () const |
virtual ModifiedTimeType | GetMTime () const |
virtual const TimeStamp & | GetTimeStamp () const |
bool | HasObserver (const EventObject &event) const |
void | InvokeEvent (const EventObject &) |
void | InvokeEvent (const EventObject &) const |
virtual void | Modified () const |
void | Register () const override |
void | RemoveAllObservers () |
void | RemoveObserver (unsigned long tag) |
void | SetDebug (bool debugFlag) const |
void | SetReferenceCount (int) override |
void | UnRegister () const noexceptoverride |
void | SetMetaDataDictionary (const MetaDataDictionary &rhs) |
void | SetMetaDataDictionary (MetaDataDictionary &&rrhs) |
virtual void | SetObjectName (std::string _arg) |
virtual const std::string & | GetObjectName () const |
Public Member Functions inherited from itk::LightObject | |
virtual void | Delete () |
virtual int | GetReferenceCount () const |
itkCloneMacro (Self) | |
void | Print (std::ostream &os, Indent indent=0) const |
Static Public Member Functions | |
static Pointer | New () |
Static Public Member Functions inherited from itk::Object | |
static bool | GetGlobalWarningDisplay () |
static void | GlobalWarningDisplayOff () |
static void | GlobalWarningDisplayOn () |
static Pointer | New () |
static void | SetGlobalWarningDisplay (bool flag) |
Static Public Member Functions inherited from itk::LightObject | |
static void | BreakOnError () |
static Pointer | New () |
Protected Member Functions | |
void | CopyParameters (InternalParametersType &source, InternalParametersType &target) |
void | CopyParameters (ParametersType &source, InternalParametersType &target) |
void | CopyParameters (InternalParametersType &source, ParametersType &target) |
void | FillClusterLabels (KdTreeNodeType *node, int closestIndex) |
void | Filter (KdTreeNodeType *node, std::vector< int > validIndexes, MeasurementVectorType &lowerBound, MeasurementVectorType &upperBound) |
int | GetClosestCandidate (ParameterType &measurements, std::vector< int > &validIndexes) |
void | GetPoint (ParameterType &point, MeasurementVectorType measurements) |
double | GetSumOfSquaredPositionChanges (InternalParametersType &previous, InternalParametersType ¤t) |
bool | IsFarther (ParameterType &pointA, ParameterType &pointB, MeasurementVectorType &lowerBound, MeasurementVectorType &upperBound) |
KdTreeBasedKmeansEstimator () | |
void | PrintPoint (ParameterType &point) |
void | PrintSelf (std::ostream &os, Indent indent) const override |
~KdTreeBasedKmeansEstimator () override=default | |
Protected Member Functions inherited from itk::Object | |
Object () | |
bool | PrintObservers (std::ostream &os, Indent indent) const |
virtual void | SetTimeStamp (const TimeStamp &time) |
~Object () override | |
Protected Member Functions inherited from itk::LightObject | |
virtual LightObject::Pointer | InternalClone () const |
LightObject () | |
virtual void | PrintHeader (std::ostream &os, Indent indent) const |
virtual void | PrintTrailer (std::ostream &os, Indent indent) const |
virtual | ~LightObject () |
Private Attributes | |
CandidateVector | m_CandidateVector |
double | m_CentroidPositionChanges {0.0} |
double | m_CentroidPositionChangesThreshold {0.0} |
ClusterLabelsType | m_ClusterLabels |
int | m_CurrentIteration {0} |
EuclideanDistanceMetric < ParameterType >::Pointer | m_DistanceMetric |
bool | m_GenerateClusterLabels {false} |
TKdTree::Pointer | m_KdTree |
int | m_MaximumIteration {100} |
MeasurementVectorSizeType | m_MeasurementVectorSize {0} |
MembershipFunctionVectorObjectPointer | m_MembershipFunctionsObject |
ParametersType | m_Parameters |
ParameterType | m_TempVertex |
bool | m_UseClusterLabels {false} |
Additional Inherited Members | |
Protected Attributes inherited from itk::LightObject | |
std::atomic< int > | m_ReferenceCount |
using itk::Statistics::KdTreeBasedKmeansEstimator< TKdTree >::CentroidType = typename KdTreeNodeType::CentroidType |
Definition at line 99 of file itkKdTreeBasedKmeansEstimator.h.
using itk::Statistics::KdTreeBasedKmeansEstimator< TKdTree >::ClusterLabelsType = itksys::hash_map< InstanceIdentifier, unsigned int > |
Definition at line 158 of file itkKdTreeBasedKmeansEstimator.h.
using itk::Statistics::KdTreeBasedKmeansEstimator< TKdTree >::ConstPointer = SmartPointer< const Self > |
Definition at line 85 of file itkKdTreeBasedKmeansEstimator.h.
using itk::Statistics::KdTreeBasedKmeansEstimator< TKdTree >::DistanceToCentroidMembershipFunctionPointer = typename DistanceToCentroidMembershipFunctionType::Pointer |
Definition at line 114 of file itkKdTreeBasedKmeansEstimator.h.
using itk::Statistics::KdTreeBasedKmeansEstimator< TKdTree >::DistanceToCentroidMembershipFunctionType = DistanceToCentroidMembershipFunction<MeasurementVectorType> |
Typedef requried to generate dataobject decorated output that can be plugged into SampleClassifierFilter
Definition at line 112 of file itkKdTreeBasedKmeansEstimator.h.
using itk::Statistics::KdTreeBasedKmeansEstimator< TKdTree >::InstanceIdentifier = typename TKdTree::InstanceIdentifier |
Definition at line 97 of file itkKdTreeBasedKmeansEstimator.h.
using itk::Statistics::KdTreeBasedKmeansEstimator< TKdTree >::InternalParametersType = std::vector< ParameterType > |
Definition at line 107 of file itkKdTreeBasedKmeansEstimator.h.
using itk::Statistics::KdTreeBasedKmeansEstimator< TKdTree >::KdTreeNodeType = typename TKdTree::KdTreeNodeType |
Types for the KdTree data structure
Definition at line 94 of file itkKdTreeBasedKmeansEstimator.h.
using itk::Statistics::KdTreeBasedKmeansEstimator< TKdTree >::MeasurementType = typename TKdTree::MeasurementType |
Definition at line 95 of file itkKdTreeBasedKmeansEstimator.h.
using itk::Statistics::KdTreeBasedKmeansEstimator< TKdTree >::MeasurementVectorSizeType = unsigned int |
Typedef for the length of a measurement vector
Definition at line 102 of file itkKdTreeBasedKmeansEstimator.h.
using itk::Statistics::KdTreeBasedKmeansEstimator< TKdTree >::MeasurementVectorType = typename TKdTree::MeasurementVectorType |
Definition at line 96 of file itkKdTreeBasedKmeansEstimator.h.
using itk::Statistics::KdTreeBasedKmeansEstimator< TKdTree >::MembershipFunctionPointer = typename MembershipFunctionType::ConstPointer |
Definition at line 117 of file itkKdTreeBasedKmeansEstimator.h.
using itk::Statistics::KdTreeBasedKmeansEstimator< TKdTree >::MembershipFunctionType = MembershipFunctionBase< MeasurementVectorType > |
Definition at line 116 of file itkKdTreeBasedKmeansEstimator.h.
using itk::Statistics::KdTreeBasedKmeansEstimator< TKdTree >::MembershipFunctionVectorObjectPointer = typename MembershipFunctionVectorObjectType::Pointer |
Definition at line 120 of file itkKdTreeBasedKmeansEstimator.h.
using itk::Statistics::KdTreeBasedKmeansEstimator< TKdTree >::MembershipFunctionVectorObjectType = SimpleDataObjectDecorator<MembershipFunctionVectorType> |
Definition at line 119 of file itkKdTreeBasedKmeansEstimator.h.
using itk::Statistics::KdTreeBasedKmeansEstimator< TKdTree >::MembershipFunctionVectorType = std::vector< MembershipFunctionPointer > |
Definition at line 118 of file itkKdTreeBasedKmeansEstimator.h.
using itk::Statistics::KdTreeBasedKmeansEstimator< TKdTree >::ParametersType = Array< double > |
Definition at line 108 of file itkKdTreeBasedKmeansEstimator.h.
using itk::Statistics::KdTreeBasedKmeansEstimator< TKdTree >::ParameterType = Array< double > |
Parameters type. It defines a position in the optimization search space.
Definition at line 106 of file itkKdTreeBasedKmeansEstimator.h.
using itk::Statistics::KdTreeBasedKmeansEstimator< TKdTree >::Pointer = SmartPointer< Self > |
Definition at line 84 of file itkKdTreeBasedKmeansEstimator.h.
using itk::Statistics::KdTreeBasedKmeansEstimator< TKdTree >::SampleType = typename TKdTree::SampleType |
Definition at line 98 of file itkKdTreeBasedKmeansEstimator.h.
using itk::Statistics::KdTreeBasedKmeansEstimator< TKdTree >::Self = KdTreeBasedKmeansEstimator |
Standard Self type alias.
Definition at line 82 of file itkKdTreeBasedKmeansEstimator.h.
using itk::Statistics::KdTreeBasedKmeansEstimator< TKdTree >::Superclass = Object |
Definition at line 83 of file itkKdTreeBasedKmeansEstimator.h.
|
protected |
|
overrideprotecteddefault |
|
protected |
copies the source parameters (k-means) to the target
|
protected |
copies the source parameters (k-means) to the target
|
protected |
copies the source parameters (k-means) to the target
|
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.
|
protected |
|
protected |
recursive pruning algorithm. the validIndexes vector contains only the indexes of the surviving candidates for the node
|
virtual |
|
virtual |
|
protected |
get the index of the closest candidate to the measurements measurement vector
|
virtual |
const TKdTree* itk::Statistics::KdTreeBasedKmeansEstimator< TKdTree >::GetKdTree | ( | ) | const |
|
virtual |
Set/Get maximum iteration limit.
|
virtual |
Get the length of measurement vectors in the KdTree
|
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 |
Set the position to initialize the optimization.
|
protected |
imports the measurements measurement vector data to the point
|
protected |
gets the sum of squared difference between the previous position and current position 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 |
|
protected |
returns true if the pointA is farther than pointB to the boundary
|
static |
Method for creation through the object factory.
|
protected |
|
overrideprotectedvirtual |
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 |
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 |
Set/Get maximum iteration limit.
|
virtual |
Set the position to initialize the optimization.
|
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)
|
private |
Definition at line 322 of file itkKdTreeBasedKmeansEstimator.h.
|
private |
sum of squared centroid position changes at the current iteration
Definition at line 307 of file itkKdTreeBasedKmeansEstimator.h.
|
private |
threshold for the sum of squared centroid position changes. termination criterion
Definition at line 311 of file itkKdTreeBasedKmeansEstimator.h.
|
private |
Definition at line 328 of file itkKdTreeBasedKmeansEstimator.h.
|
private |
current number of iteration
Definition at line 301 of file itkKdTreeBasedKmeansEstimator.h.
|
private |
pointer to the euclidean distance function
Definition at line 317 of file itkKdTreeBasedKmeansEstimator.h.
|
private |
Definition at line 327 of file itkKdTreeBasedKmeansEstimator.h.
|
private |
pointer to the k-d tree
Definition at line 314 of file itkKdTreeBasedKmeansEstimator.h.
|
private |
maximum number of iteration. termination criterion
Definition at line 304 of file itkKdTreeBasedKmeansEstimator.h.
|
private |
Definition at line 329 of file itkKdTreeBasedKmeansEstimator.h.
|
private |
Definition at line 330 of file itkKdTreeBasedKmeansEstimator.h.
|
private |
k-means
Definition at line 320 of file itkKdTreeBasedKmeansEstimator.h.
|
private |
Definition at line 324 of file itkKdTreeBasedKmeansEstimator.h.
|
private |
Definition at line 326 of file itkKdTreeBasedKmeansEstimator.h.