15 #ifndef MLPACK_METHODS_KMEANS_DUAL_TREE_KMEANS_HPP 16 #define MLPACK_METHODS_KMEANS_DUAL_TREE_KMEANS_HPP 37 template<
typename TreeMetricType,
38 typename TreeStatType,
45 typedef TreeType<MetricType, DualTreeKMeansStatistic, MatType>
Tree;
47 template<
typename TreeMetricType,
48 typename IgnoredStatType,
51 TreeType<TreeMetricType, DualTreeKMeansStatistic, TreeMatType>;
72 double Iterate(
const arma::mat& centroids,
73 arma::mat& newCentroids,
74 arma::Col<size_t>& counts);
83 const MatType& datasetOrig;
87 const MatType& dataset;
92 size_t distanceCalculations;
97 arma::vec upperBounds;
99 arma::vec lowerBounds;
101 std::vector<bool> prunedPoints;
103 arma::Row<size_t> assignments;
105 std::vector<bool> visited;
107 arma::mat lastIterationCentroids;
109 arma::vec clusterDistances;
111 arma::mat interclusterDistances;
115 void UpdateTree(Tree& node,
116 const arma::mat& centroids,
117 const double parentUpperBound = 0.0,
118 const double adjustedParentUpperBound = DBL_MAX,
119 const double parentLowerBound = DBL_MAX,
120 const double adjustedParentLowerBound = 0.0);
123 void ExtractCentroids(Tree& node,
124 arma::mat& newCentroids,
125 arma::Col<size_t>& newCounts,
126 const arma::mat& centroids);
128 void CoalesceTree(Tree& node,
const size_t child = 0);
129 void DecoalesceTree(Tree& node);
134 template<
typename TreeType>
143 template<
typename TreeType>
150 template<
typename TreeType>
153 TreeType>::BinaryTree>* junk = 0);
156 template<
typename TreeType>
159 TreeType>::BinaryTree>* junk = 0);
163 template<
typename MetricType,
typename MatType>
168 template<
typename MetricType,
typename MatType>
175 #include "dual_tree_kmeans_impl.hpp" void HideChild(TreeType &node, const size_t child, const typename std::enable_if_t< !tree::TreeTraits< TreeType >::BinaryTree > *junk=0)
Utility function for hiding children.
typename enable_if< B, T >::type enable_if_t
Linear algebra utility functions, generally performed on matrices or vectors.
size_t & DistanceCalculations()
Modify the number of distance calculations.
void RestoreChildren(TreeType &node, const typename std::enable_if_t<!tree::TreeTraits< TreeType >::BinaryTree > *junk=0)
Utility function for restoring children to a non-binary tree.
An algorithm for an exact Lloyd iteration which simply uses dual-tree nearest-neighbor search to find...
size_t DistanceCalculations() const
Return the number of distance calculations.
TreeType< MetricType, DualTreeKMeansStatistic, MatType > Tree
Convenience typedef.
TreeType< TreeMetricType, DualTreeKMeansStatistic, TreeMatType > NNSTreeType
The TreeTraits class provides compile-time information on the characteristics of a given tree type...
~DualTreeKMeans()
Delete the tree constructed by the DualTreeKMeans object.
double Iterate(const arma::mat ¢roids, arma::mat &newCentroids, arma::Col< size_t > &counts)
Run a single iteration of the dual-tree nearest neighbor algorithm for k-means, updating the given ce...
BinarySpaceTree< MetricType, StatisticType, MatType, bound::HRectBound, MidpointSplit > KDTree
The standard midpoint-split kd-tree.
DualTreeKMeans(const MatType &dataset, MetricType &metric)
Construct the DualTreeKMeans object, which will construct a tree on the points.
A cover tree is a tree specifically designed to speed up nearest-neighbor computation in high-dimensi...