[mlpack-git] master: Minor style changes. (4185aa0)
gitdub at mlpack.org
gitdub at mlpack.org
Mon Aug 8 14:56:29 EDT 2016
Repository : https://github.com/mlpack/mlpack
On branch : master
Link : https://github.com/mlpack/mlpack/compare/1e9f0f39ea4443f0d595c395871ea8c6b27443af...4185aa07bbdef80ccdc78a3a3e479499058933db
>---------------------------------------------------------------
commit 4185aa07bbdef80ccdc78a3a3e479499058933db
Author: Ryan Curtin <ryan at ratml.org>
Date: Mon Aug 8 14:56:29 2016 -0400
Minor style changes.
>---------------------------------------------------------------
4185aa07bbdef80ccdc78a3a3e479499058933db
.../vantage_point_tree/vantage_point_split.hpp | 62 +++++++++++++---------
.../vantage_point_split_impl.hpp | 52 +++++++++---------
.../vantage_point_tree/vantage_point_tree_impl.hpp | 17 +++---
3 files changed, 72 insertions(+), 59 deletions(-)
diff --git a/src/mlpack/core/tree/vantage_point_tree/vantage_point_split.hpp b/src/mlpack/core/tree/vantage_point_tree/vantage_point_split.hpp
index d9d600b..0542433 100644
--- a/src/mlpack/core/tree/vantage_point_tree/vantage_point_split.hpp
+++ b/src/mlpack/core/tree/vantage_point_tree/vantage_point_split.hpp
@@ -15,17 +15,20 @@ namespace tree /** Trees and tree-building procedures. */ {
template<typename BoundType,
typename MatType = arma::mat,
- size_t maxNumSamples = 100>
+ size_t MaxNumSamples = 100>
class VantagePointSplit
{
public:
+ //! The matrix element type.
typedef typename MatType::elem_type ElemType;
+ //! The bounding shape type.
typedef typename BoundType::MetricType MetricType;
+
/**
* Split the node according to the distance to a vantage point.
*
- * @param bound The bound used for this node.
- * @param data The dataset used by the binary space tree.
+ * @param bound The bound used by the tree.
+ * @param data The dataset used by the tree.
* @param begin Index of the starting point in the dataset that belongs to
* this node.
* @param count Number of points in this node.
@@ -41,8 +44,8 @@ class VantagePointSplit
/**
* Split the node according to the distance to a vantage point.
*
- * @param bound The bound used for this node.
- * @param data The dataset used by the binary space tree.
+ * @param bound The bound used by the tree.
+ * @param data The dataset used by the tree.
* @param begin Index of the starting point in the dataset that belongs to
* this node.
* @param count Number of points in this node.
@@ -59,15 +62,15 @@ class VantagePointSplit
std::vector<size_t>& oldFromNew);
private:
/**
- * Select the best vantage point i.e. the point with the largest second moment
- * of the distance from a number of random node points to the vantage point.
- * Firstly this methods selects no more than maxNumSamples random points.
- * Then it evaluates each point i.e. calcilates the corresponding second
- * moment and selects the point with the largest moment. Each random point
- * belongs to the node.
+ * Select the best vantage point, i.e., the point with the largest second
+ * moment of the distance from a number of random node points to the vantage
+ * point. Firstly this method selects no more than MaxNumSamples random
+ * points. Then it evaluates each point, i.e., calculates the corresponding
+ * second moment and selects the point with the largest moment. Each random
+ * point belongs to the node.
*
- * @param bound The bound used for this node.
- * @param data The dataset used by the binary space tree.
+ * @param metric The metric used by the tree.
+ * @param data The dataset used by the tree.
* @param begin Index of the starting point in the dataset that belongs to
* this node.
* @param count Number of points in this node.
@@ -75,23 +78,30 @@ class VantagePointSplit
* @param mu The median value of distance form the vantage point to
* a number of random points.
*/
- static void SelectVantagePoint(const MetricType& metric, const MatType& data,
- const size_t begin, const size_t count, size_t& vantagePoint, ElemType& mu);
+ static void SelectVantagePoint(const MetricType& metric,
+ const MatType& data,
+ const size_t begin,
+ const size_t count,
+ size_t& vantagePoint,
+ ElemType& mu);
/**
- * This method returns true if a point should be assigned to the left subtree
- * i.e. the distance from the point to the vantage point is less then
- * the median value. Otherwise it returns false.
+ * This method returns true if a point should be assigned to the left subtree,
+ * i.e., if the distance from the point to the vantage point is less then the
+ * median value. Otherwise it returns false.
*
- * @param bound The bound used for this node.
- * @param data The dataset used by the binary space tree.
+ * @param metric The metric used by the tree.
+ * @param data The dataset used by the tree.
* @param vantagePoint The vantage point.
* @param point The point that is being assigned.
* @param mu The median value.
*/
template<typename VecType>
- static bool AssignToLeftSubtree(const MetricType& metric, const MatType& mat,
- const VecType& vantagePoint, const size_t point, const ElemType mu)
+ static bool AssignToLeftSubtree(const MetricType& metric,
+ const MatType& mat,
+ const VecType& vantagePoint,
+ const size_t point,
+ const ElemType mu)
{
return (metric.Evaluate(vantagePoint, mat.col(point)) < mu);
}
@@ -99,9 +109,10 @@ class VantagePointSplit
/**
* Perform split according to the median value and the vantage point.
*
- * @param data The dataset used by the binary space tree.
+ * @param metric The metric used by the tree.
+ * @param data The dataset used by the tree.
* @param begin Index of the starting point in the dataset that belongs to
- * this node.
+ * this node.
* @param count Number of points in this node.
* @param vantagePoint The vantage point.
* @param mu The median value.
@@ -117,7 +128,8 @@ class VantagePointSplit
/**
* Perform split according to the median value and the vantage point.
*
- * @param data The dataset used by the binary space tree.
+ * @param metric The metric used by the tree.
+ * @param data The dataset used by the tree.
* @param begin Index of the starting point in the dataset that belongs to
* this node.
* @param count Number of points in this node.
diff --git a/src/mlpack/core/tree/vantage_point_tree/vantage_point_split_impl.hpp b/src/mlpack/core/tree/vantage_point_tree/vantage_point_split_impl.hpp
index 6e5b1a2..92e00b9 100644
--- a/src/mlpack/core/tree/vantage_point_tree/vantage_point_split_impl.hpp
+++ b/src/mlpack/core/tree/vantage_point_tree/vantage_point_split_impl.hpp
@@ -14,18 +14,18 @@
namespace mlpack {
namespace tree {
-template<typename BoundType, typename MatType, size_t maxNumSamples>
-bool VantagePointSplit<BoundType, MatType, maxNumSamples>::
+template<typename BoundType, typename MatType, size_t MaxNumSamples>
+bool VantagePointSplit<BoundType, MatType, MaxNumSamples>::
SplitNode(const BoundType& bound, MatType& data, const size_t begin,
const size_t count, size_t& splitCol)
{
ElemType mu = 0;
size_t vantagePointIndex;
- // Find the best vantage point
+ // Find the best vantage point.
SelectVantagePoint(bound.Metric(), data, begin, count, vantagePointIndex, mu);
- // All points are equal
+ // If all points are equal, we can't split.
if (mu == 0)
return false;
@@ -40,24 +40,24 @@ SplitNode(const BoundType& bound, MatType& data, const size_t begin,
return true;
}
-template<typename BoundType, typename MatType, size_t maxNumSamples>
-bool VantagePointSplit<BoundType, MatType, maxNumSamples>::
+template<typename BoundType, typename MatType, size_t MaxNumSamples>
+bool VantagePointSplit<BoundType, MatType, MaxNumSamples>::
SplitNode(const BoundType& bound, MatType& data, const size_t begin,
const size_t count, size_t& splitCol, std::vector<size_t>& oldFromNew)
{
ElemType mu = 0;
size_t vantagePointIndex;
- // Find the best vantage point
+ // Find the best vantage point.
SelectVantagePoint(bound.Metric(), data, begin, count, vantagePointIndex, mu);
- // All points are equal
+ // If all points are equal, we can't split.
if (mu == 0)
return false;
// The first point of the left child is centroid.
data.swap_cols(begin, vantagePointIndex);
- size_t t = oldFromNew[begin];
+ const size_t t = oldFromNew[begin];
oldFromNew[begin] = oldFromNew[vantagePointIndex];
oldFromNew[vantagePointIndex] = t;
@@ -71,9 +71,9 @@ SplitNode(const BoundType& bound, MatType& data, const size_t begin,
return true;
}
-template<typename BoundType, typename MatType, size_t maxNumSamples>
+template<typename BoundType, typename MatType, size_t MaxNumSamples>
template <typename VecType>
-size_t VantagePointSplit<BoundType, MatType, maxNumSamples>::PerformSplit(
+size_t VantagePointSplit<BoundType, MatType, MaxNumSamples>::PerformSplit(
const MetricType& metric,
MatType& data,
const size_t begin,
@@ -124,9 +124,9 @@ size_t VantagePointSplit<BoundType, MatType, maxNumSamples>::PerformSplit(
return left;
}
-template<typename BoundType, typename MatType, size_t maxNumSamples>
+template<typename BoundType, typename MatType, size_t MaxNumSamples>
template<typename VecType>
-size_t VantagePointSplit<BoundType, MatType, maxNumSamples>::PerformSplit(
+size_t VantagePointSplit<BoundType, MatType, MaxNumSamples>::PerformSplit(
const MetricType& metric,
MatType& data,
const size_t begin,
@@ -184,16 +184,16 @@ size_t VantagePointSplit<BoundType, MatType, maxNumSamples>::PerformSplit(
return left;
}
-template<typename BoundType, typename MatType, size_t maxNumSamples>
-void VantagePointSplit<BoundType, MatType, maxNumSamples>::
+template<typename BoundType, typename MatType, size_t MaxNumSamples>
+void VantagePointSplit<BoundType, MatType, MaxNumSamples>::
SelectVantagePoint(const MetricType& metric, const MatType& data,
const size_t begin, const size_t count, size_t& vantagePoint, ElemType& mu)
{
arma::uvec vantagePointCandidates;
- arma::Col<ElemType> distances(maxNumSamples);
+ arma::Col<ElemType> distances(MaxNumSamples);
- // Get no more than max(maxNumSamples, count) vantage point candidates
- math::ObtainDistinctSamples(begin, begin + count, maxNumSamples,
+ // Get no more than max(MaxNumSamples, count) vantage point candidates
+ math::ObtainDistinctSamples(begin, begin + count, MaxNumSamples,
vantagePointCandidates);
ElemType bestSpread = 0;
@@ -202,16 +202,16 @@ SelectVantagePoint(const MetricType& metric, const MatType& data,
// Evaluate each candidate
for (size_t i = 0; i < vantagePointCandidates.n_elem; i++)
{
- // Get no more than min(maxNumSamples, count) random samples
- math::ObtainDistinctSamples(begin, begin + count, maxNumSamples, samples);
+ // Get no more than min(MaxNumSamples, count) random samples
+ math::ObtainDistinctSamples(begin, begin + count, MaxNumSamples, samples);
- // Calculate the second moment of the distance to the vantage point candidate
- // using these random samples
+ // Calculate the second moment of the distance to the vantage point
+ // candidate using these random samples.
distances.set_size(samples.n_elem);
for (size_t j = 0; j < samples.n_elem; j++)
distances[j] = metric.Evaluate(data.col(vantagePointCandidates[i]),
- data.col(samples[j]));
+ data.col(samples[j]));
const ElemType spread = arma::sum(distances % distances) / samples.n_elem;
@@ -219,10 +219,10 @@ SelectVantagePoint(const MetricType& metric, const MatType& data,
{
bestSpread = spread;
vantagePoint = vantagePointCandidates[i];
- // Calculate the median value of the distance from the vantage point candidate
- // to these samples
+ // Calculate the median value of the distance from the vantage point
+ // candidate to these samples.
mu = arma::median(distances);
- }
+ }
}
assert(bestSpread > 0);
}
diff --git a/src/mlpack/core/tree/vantage_point_tree/vantage_point_tree_impl.hpp b/src/mlpack/core/tree/vantage_point_tree/vantage_point_tree_impl.hpp
index fc5c571..f139a0a 100644
--- a/src/mlpack/core/tree/vantage_point_tree/vantage_point_tree_impl.hpp
+++ b/src/mlpack/core/tree/vantage_point_tree/vantage_point_tree_impl.hpp
@@ -583,13 +583,13 @@ template<typename MetricType,
template<typename SplitBoundType, typename SplitMatType, size_t...>
class SplitType>
inline VantagePointTree<MetricType, StatisticType, MatType, BoundType,
- SplitType>&
+ SplitType>&
VantagePointTree<MetricType, StatisticType, MatType, BoundType,
- SplitType>::Child(const size_t child) const
+ SplitType>::Child(const size_t child) const
{
if (child == 0)
return *central;
- else if(child == 1)
+ else if (child == 1)
return *inner;
else
return *outer;
@@ -605,7 +605,7 @@ template<typename MetricType,
template<typename SplitBoundType, typename SplitMatType, size_t...>
class SplitType>
inline size_t VantagePointTree<MetricType, StatisticType, MatType, BoundType,
- SplitType>::NumPoints() const
+ SplitType>::NumPoints() const
{
if (!IsLeaf())
return 0;
@@ -624,7 +624,7 @@ template<typename MetricType,
template<typename SplitBoundType, typename SplitMatType, size_t...>
class SplitType>
inline size_t VantagePointTree<MetricType, StatisticType, MatType, BoundType,
- SplitType>::NumDescendants() const
+ SplitType>::NumDescendants() const
{
return count;
}
@@ -639,7 +639,7 @@ template<typename MetricType,
template<typename SplitBoundType, typename SplitMatType, size_t...>
class SplitType>
inline size_t VantagePointTree<MetricType, StatisticType, MatType, BoundType,
- SplitType>::Descendant(const size_t index) const
+ SplitType>::Descendant(const size_t index) const
{
return (begin + index);
}
@@ -654,7 +654,7 @@ template<typename MetricType,
template<typename SplitBoundType, typename SplitMatType, size_t...>
class SplitType>
inline size_t VantagePointTree<MetricType, StatisticType, MatType, BoundType,
- SplitType>::Point(const size_t index) const
+ SplitType>::Point(const size_t index) const
{
return (begin + index);
}
@@ -786,13 +786,14 @@ SplitNode(std::vector<size_t>& oldFromNew,
outer = new VantagePointTree(this, splitCol, begin + count - splitCol,
oldFromNew, splitter, maxLeafSize);
-
// Calculate parent distances for those two nodes.
ElemType parentDistance;
if (parent)
+ {
parentDistance = MetricType::Evaluate(dataset->col(parent->begin),
dataset->col(begin));
+ }
else
{
arma::vec center;
More information about the mlpack-git
mailing list