[mlpackgit] master: Very minor fixes. (616f117)
gitdub at mlpack.org
gitdub at mlpack.org
Sun Aug 28 10:43:39 EDT 2016
Repository : https://github.com/mlpack/mlpack
On branch : master
Link : https://github.com/mlpack/mlpack/compare/1797a49c8f76d65814fec4a122d0d2fea01fc2d9...9e5cd0ac9c5cde9ac141bc84e7327bd11e19d42e
>
commit 616f117707bc15a59a126229ec17ec362d7d63a1
Author: Mikhail Lozhnikov <lozhnikovma at gmail.com>
Date: Sun Aug 28 17:43:39 2016 +0300
Very minor fixes.
>
616f117707bc15a59a126229ec17ec362d7d63a1
src/mlpack/core/tree/address.hpp  35 ++++++++++++
.../core/tree/binary_space_tree/mean_split.hpp  9 ++++
.../core/tree/binary_space_tree/midpoint_split.hpp  9 ++++
.../core/tree/binary_space_tree/perform_split.hpp  8 ++
.../tree/binary_space_tree/rp_tree_max_split.hpp  9 ++++
.../tree/binary_space_tree/rp_tree_mean_split.hpp  9 ++++
src/mlpack/core/tree/binary_space_tree/typedef.hpp  2 +
.../core/tree/binary_space_tree/ub_tree_split.hpp  8 ++++
.../tree/binary_space_tree/vantage_point_split.hpp  15 ++++++++
src/mlpack/core/tree/cellbound_impl.hpp  4 +
10 files changed, 73 insertions(+), 35 deletions()
diff git a/src/mlpack/core/tree/address.hpp b/src/mlpack/core/tree/address.hpp
index 72202e3..9fe3897 100644
 a/src/mlpack/core/tree/address.hpp
+++ b/src/mlpack/core/tree/address.hpp
@@ 39,8 +39,8 @@ namespace addr {
*
* The function maps each floating point coordinate to an equalsized unsigned
* integer datatype in such a way that the transform preserves the ordering
 * (i.e. lower coordinates correspond to lower integers). Thus, the mapping
 * saves the exponent and the mantissa of each floating point value
+ * (i.e. lower floating point values correspond to lower integers). Thus,
+ * the mapping saves the exponent and the mantissa of each floating point value
* consequently, furthermore the exponent is stored before the mantissa. In the
* case of negative numbers the resulting integer value should be inverted.
* In the multidimensional case, after we transform the representation, we
@@ 54,7 +54,14 @@ template<typename AddressType, typename VecType>
void PointToAddress(AddressType& address, const VecType& point)
{
typedef typename VecType::elem_type VecElemType;
 typedef typename AddressType::elem_type AddressElemType;
+ // Check that the arguments are compatible.
+ typedef typename std::conditional<sizeof(VecElemType) * CHAR_BIT <= 32,
+ uint32_t,
+ uint64_t>::type AddressElemType;
+
+ static_assert(std::is_same<typename AddressType::elem_type,
+ AddressElemType>::value == true, "The vector element type does not "
+ "correspond to the address element type.");
arma::Col<AddressElemType> result(point.n_elem);
constexpr size_t order = sizeof(AddressElemType) * CHAR_BIT;
@@ 116,6 +123,8 @@ void PointToAddress(AddressType& address, const VecType& point)
address.zeros(point.n_elem);
+ // Interleave the bits of the new representation across all the elements
+ // in the address vector.
for (size_t i = 0; i < order; i++)
for (size_t j = 0; j < point.n_elem; j++)
{
@@ 141,7 +150,14 @@ template<typename AddressType, typename VecType>
void AddressToPoint(VecType& point, const AddressType& address)
{
typedef typename VecType::elem_type VecElemType;
 typedef typename AddressType::elem_type AddressElemType;
+ // Check that the arguments are compatible.
+ typedef typename std::conditional<sizeof(VecElemType) * CHAR_BIT <= 32,
+ uint32_t,
+ uint64_t>::type AddressElemType;
+
+ static_assert(std::is_same<typename AddressType::elem_type,
+ AddressElemType>::value == true, "The vector element type does not "
+ "correspond to the address element type.");
constexpr size_t order = sizeof(AddressElemType) * CHAR_BIT;
// Calculate the number of bits for the exponent.
@@ 237,17 +253,6 @@ template<typename AddressType1, typename AddressType2, typename AddressType3>
bool Contains(const AddressType1& address, const AddressType2& loBound,
const AddressType3& hiBound)
{
 static_assert(std::is_same<typename AddressType1::elem_type,
 typename AddressType2::elem_type>::value == true, "We aren't able to "
 "compare adresses of distinct types");

 static_assert(std::is_same<typename AddressType1::elem_type,
 typename AddressType3::elem_type>::value == true, "We aren't able to "
 "compare adresses of distinct types");

 assert(address.n_elem == loBound.n_elem);
 assert(address.n_elem == hiBound.n_elem);

return ((CompareAddresses(loBound, address) <= 0) &&
(CompareAddresses(hiBound, address) >= 0));
}
diff git a/src/mlpack/core/tree/binary_space_tree/mean_split.hpp b/src/mlpack/core/tree/binary_space_tree/mean_split.hpp
index 4c07627..7d7e67a 100644
 a/src/mlpack/core/tree/binary_space_tree/mean_split.hpp
+++ b/src/mlpack/core/tree/binary_space_tree/mean_split.hpp
@@ 54,7 +54,9 @@ class MeanSplit
/**
* Perform the split process according to the information about the
 * split.
+ * split. This will order the dataset such that points that belong to the left
+ * subtree are on the left of the split column, and points from the right
+ * subtree are on the right side of the split column.
*
* @param bound The bound used for this node.
* @param data The dataset used by the binary space tree.
@@ 74,7 +76,10 @@ class MeanSplit
/**
* Perform the split process according to the information about the split and
 * return the list of changed indices.
+ * return the list of changed indices. This will order the dataset such that
+ * points that belong to the left subtree are on the left of the split column,
+ * and points from the right subtree are on the right side of the split
+ * column.
*
* @param bound The bound used for this node.
* @param data The dataset used by the binary space tree.
diff git a/src/mlpack/core/tree/binary_space_tree/midpoint_split.hpp b/src/mlpack/core/tree/binary_space_tree/midpoint_split.hpp
index 66c3043..f898c42 100644
 a/src/mlpack/core/tree/binary_space_tree/midpoint_split.hpp
+++ b/src/mlpack/core/tree/binary_space_tree/midpoint_split.hpp
@@ 54,7 +54,9 @@ class MidpointSplit
/**
* Perform the split process according to the information about the
 * split.
+ * split. This will order the dataset such that points that belong to the left
+ * subtree are on the left of the split column, and points from the right
+ * subtree are on the right side of the split column.
*
* @param bound The bound used for this node.
* @param data The dataset used by the binary space tree.
@@ 74,7 +76,10 @@ class MidpointSplit
/**
* Perform the split process according to the information about the split and
 * return the list of changed indices.
+ * return the list of changed indices. This will order the dataset such that
+ * points that belong to the left subtree are on the left of the split column,
+ * and points from the right subtree are on the right side of the split
+ * column.
*
* @param bound The bound used for this node.
* @param data The dataset used by the binary space tree.
diff git a/src/mlpack/core/tree/binary_space_tree/perform_split.hpp b/src/mlpack/core/tree/binary_space_tree/perform_split.hpp
index 78311be..acb8c90 100644
 a/src/mlpack/core/tree/binary_space_tree/perform_split.hpp
+++ b/src/mlpack/core/tree/binary_space_tree/perform_split.hpp
@@ 35,9 +35,7 @@ size_t PerformSplit(MatType& data,
const typename SplitType::SplitInfo& splitInfo)
{
// This method modifies the input dataset. We loop both from the left and
 // right sides of the points contained in this node. The points less than
 // splitVal should be on the left side of the matrix, and the points greater
 // than splitVal should be on the right side of the matrix.
+ // right sides of the points contained in this node.
size_t left = begin;
size_t right = begin + count  1;
@@ 98,9 +96,7 @@ size_t PerformSplit(MatType& data,
std::vector<size_t>& oldFromNew)
{
// This method modifies the input dataset. We loop both from the left and
 // right sides of the points contained in this node. The points less than
 // splitVal should be on the left side of the matrix, and the points greater
 // than splitVal should be on the right side of the matrix.
+ // right sides of the points contained in this node.
size_t left = begin;
size_t right = begin + count  1;
diff git a/src/mlpack/core/tree/binary_space_tree/rp_tree_max_split.hpp b/src/mlpack/core/tree/binary_space_tree/rp_tree_max_split.hpp
index d556cb5..8bd513d 100644
 a/src/mlpack/core/tree/binary_space_tree/rp_tree_max_split.hpp
+++ b/src/mlpack/core/tree/binary_space_tree/rp_tree_max_split.hpp
@@ 57,7 +57,9 @@ class RPTreeMaxSplit
/**
* Perform the split process according to the information about the
 * split.
+ * split. This will order the dataset such that points that belong to the left
+ * subtree are on the left of the split column, and points from the right
+ * subtree are on the right side of the split column.
*
* @param bound The bound used for this node.
* @param data The dataset used by the binary space tree.
@@ 77,7 +79,10 @@ class RPTreeMaxSplit
/**
* Perform the split process according to the information about the split and
 * return the list of changed indices.
+ * return the list of changed indices. This will order the dataset such that
+ * points that belong to the left subtree are on the left of the split column,
+ * and points from the right subtree are on the right side of the split
+ * column.
*
* @param bound The bound used for this node.
* @param data The dataset used by the binary space tree.
diff git a/src/mlpack/core/tree/binary_space_tree/rp_tree_mean_split.hpp b/src/mlpack/core/tree/binary_space_tree/rp_tree_mean_split.hpp
index 64bb10b..718b1de 100644
 a/src/mlpack/core/tree/binary_space_tree/rp_tree_mean_split.hpp
+++ b/src/mlpack/core/tree/binary_space_tree/rp_tree_mean_split.hpp
@@ 63,7 +63,9 @@ class RPTreeMeanSplit
/**
* Perform the split process according to the information about the
 * split.
+ * split. This will order the dataset such that points that belong to the left
+ * subtree are on the left of the split column, and points from the right
+ * subtree are on the right side of the split column.
*
* @param bound The bound used for this node.
* @param data The dataset used by the binary space tree.
@@ 83,7 +85,10 @@ class RPTreeMeanSplit
/**
* Perform the split process according to the information about the split and
 * return the list of changed indices.
+ * return the list of changed indices. This will order the dataset such that
+ * points that belong to the left subtree are on the left of the split column,
+ * and points from the right subtree are on the right side of the split
+ * column.
*
* @param bound The bound used for this node.
* @param data The dataset used by the binary space tree.
diff git a/src/mlpack/core/tree/binary_space_tree/typedef.hpp b/src/mlpack/core/tree/binary_space_tree/typedef.hpp
index f0ca667..a707ffc 100644
 a/src/mlpack/core/tree/binary_space_tree/typedef.hpp
+++ b/src/mlpack/core/tree/binary_space_tree/typedef.hpp
@@ 263,7 +263,7 @@ using RPTree = BinarySpaceTree<MetricType,
/**
* The Universal Btree. When recursively splitting nodes, the class
* calculates addresses of all points and splits each node according to the
 * median address. Children nodes may overlap since the implementation
+ * median address. Children may overlap since the implementation
* of a tighter bound requires a lot of arithmetic operations. In order to get
* a tighter bound increase the CellBound::maxNumBounds constant.
*
diff git a/src/mlpack/core/tree/binary_space_tree/ub_tree_split.hpp b/src/mlpack/core/tree/binary_space_tree/ub_tree_split.hpp
index c0f71b7..f704c90 100644
 a/src/mlpack/core/tree/binary_space_tree/ub_tree_split.hpp
+++ b/src/mlpack/core/tree/binary_space_tree/ub_tree_split.hpp
@@ 14,11 +14,17 @@
namespace mlpack {
namespace tree /** Trees and treebuilding procedures. */ {
+/**
+ * Split a node into two parts according to the median address of points
+ * contained in the node. The class reorders the dataset such that points
+ * with lower addresses belong to the left subtree and points with high
+ * addresses belong to the right subtree.
+ */
template<typename BoundType, typename MatType = arma::mat>
class UBTreeSplit
{
public:
 //! The type of a onedimensional address.
+ //! The type of an address element.
typedef typename std::conditional<sizeof(typename MatType::elem_type) * CHAR_BIT <= 32,
uint32_t,
uint64_t>::type AddressElemType;
diff git a/src/mlpack/core/tree/binary_space_tree/vantage_point_split.hpp b/src/mlpack/core/tree/binary_space_tree/vantage_point_split.hpp
index ef85ec7..c9a3006 100644
 a/src/mlpack/core/tree/binary_space_tree/vantage_point_split.hpp
+++ b/src/mlpack/core/tree/binary_space_tree/vantage_point_split.hpp
@@ 14,6 +14,12 @@
namespace mlpack {
namespace tree /** Trees and treebuilding procedures. */ {
+/**
+ * The class splits a binary space partitioning tree node according to the
+ * median distance to the vantage point. Thus points that are closer to the
+ * vantage point belong to the left subtree and points that are farther from
+ * the vantage point belong to the right subtree.
+ */
template<typename BoundType,
typename MatType = arma::mat,
size_t MaxNumSamples = 100>
@@ 67,7 +73,9 @@ class VantagePointSplit
/**
* Perform the split process according to the information about the
 * split.
+ * split. This will order the dataset such that points that belong to the left
+ * subtree are on the left of the split column, and points from the right
+ * subtree are on the right side of the split column.
*
* @param bound The bound used for this node.
* @param data The dataset used by the binary space tree.
@@ 87,7 +95,10 @@ class VantagePointSplit
/**
* Perform the split process according to the information about the split and
 * return the list of changed indices.
+ * return the list of changed indices. This will order the dataset such that
+ * points that belong to the left subtree are on the left of the split column,
+ * and points from the right subtree are on the right side of the split
+ * column.
*
* @param bound The bound used for this node.
* @param data The dataset used by the binary space tree.
diff git a/src/mlpack/core/tree/cellbound_impl.hpp b/src/mlpack/core/tree/cellbound_impl.hpp
index ba18379..ce6de2a 100644
 a/src/mlpack/core/tree/cellbound_impl.hpp
+++ b/src/mlpack/core/tree/cellbound_impl.hpp
@@ 865,8 +865,8 @@ inline CellBound<MetricType, ElemType>& CellBound<MetricType, ElemType>::operato
{
Log::Assert(data.n_rows == dim);
 arma::Col<ElemType> mins(min(data, 1));
 arma::Col<ElemType> maxs(max(data, 1));
+ arma::Col<ElemType> mins(arma::min(data, 1));
+ arma::Col<ElemType> maxs(arma::max(data, 1));
minWidth = std::numeric_limits<ElemType>::max();
for (size_t i = 0; i < dim; i++)
More information about the mlpackgit
mailing list