[mlpack] 32/207: Fix style and add some comments.
Barak A. Pearlmutter
barak+git at pearlmutter.net
Thu Mar 23 17:53:38 UTC 2017
This is an automated email from the git hooks/post-receive script.
bap pushed a commit to branch master
in repository mlpack.
commit 4d3daa3ca51104e168f29325b663ccb5122d71bb
Author: Ryan Curtin <ryan at ratml.org>
Date: Fri Feb 10 11:06:08 2017 -0500
Fix style and add some comments.
---
src/mlpack/methods/range_search/rs_model.hpp | 104 ++++++++++++----------
src/mlpack/methods/range_search/rs_model_impl.hpp | 95 ++++++++++----------
2 files changed, 106 insertions(+), 93 deletions(-)
diff --git a/src/mlpack/methods/range_search/rs_model.hpp b/src/mlpack/methods/range_search/rs_model.hpp
index c6245f8..e2795aa 100644
--- a/src/mlpack/methods/range_search/rs_model.hpp
+++ b/src/mlpack/methods/range_search/rs_model.hpp
@@ -33,7 +33,6 @@ template<template<typename TreeMetricType,
typename TreeMatType> class TreeType>
using RSType = RangeSearch<metric::EuclideanDistance, arma::mat, TreeType>;
-
struct RSModelName
{
static const std::string Name() { return "range_search_model"; }
@@ -45,23 +44,27 @@ struct RSModelName
*/
class MonoSearchVisitor : public boost::static_visitor<void>
{
- private:
- const math::Range& range;
- std::vector<std::vector<size_t>>& neighbors;
- std::vector<std::vector<double>>& distances;
-
- public:
- template<typename RSType>
- void operator()(RSType* rs) const;
-
- MonoSearchVisitor(const math::Range& range,
- std::vector<std::vector<size_t>>& neighbors,
- std::vector<std::vector<double>>& distances):
- range(range),
- neighbors(neighbors),
- distances(distances)
- {};
+ private:
+ //! The range to search for.
+ const math::Range& range;
+ //! Output neighbors.
+ std::vector<std::vector<size_t>>& neighbors;
+ //! Output distances.
+ std::vector<std::vector<double>>& distances;
+
+ public:
+ //! Perform monochromatic search with the given RangeSearch object.
+ template<typename RSType>
+ void operator()(RSType* rs) const;
+ //! Construct the MonoSearchVisitor with the given parameters.
+ MonoSearchVisitor(const math::Range& range,
+ std::vector<std::vector<size_t>>& neighbors,
+ std::vector<std::vector<double>>& distances):
+ range(range),
+ neighbors(neighbors),
+ distances(distances)
+ {};
};
/**
@@ -185,41 +188,52 @@ class DeleteVisitor : public boost::static_visitor<void>
};
/**
- * Exposes the seralize method of the given RSType
+ * Exposes the seralize method of the given RSType.
*/
template<typename Archive>
- class SerializeVisitor : public boost::static_visitor<void>
- {
- private:
- Archive& ar;
- const std::string& name;
-
- public:
- template<typename RSType>
- void operator()(RSType* rs) const;
-
- SerializeVisitor(Archive& ar, const std::string& name);
- };
+class SerializeVisitor : public boost::static_visitor<void>
+{
+ private:
+ //! Archive to serialize to.
+ Archive& ar;
+ //! Name of the model to serialize.
+ const std::string& name;
+
+ public:
+ //! Serialize the given model.
+ template<typename RSType>
+ void operator()(RSType* rs) const;
+
+ //! Construct the SerializeVisitor with the given archive and name.
+ SerializeVisitor(Archive& ar, const std::string& name);
+};
/**
- * SearchModeVisitor exposes the SearchMode() method of the given RSType.
+ * SingleModeVisitor exposes the SingleMode() method of the given RSType.
*/
- class SingleModeVisitor : public boost::static_visitor<bool&>
- {
- public:
- template<typename RSType>
- bool& operator()(RSType* rs) const;
- };
+class SingleModeVisitor : public boost::static_visitor<bool&>
+{
+ public:
+ /**
+ * Get a reference to the singleMode parameter of the given RangeSeach
+ * object.
+ */
+ template<typename RSType>
+ bool& operator()(RSType* rs) const;
+};
/**
* NaiveVisitor exposes the Naive() method of the given RSType.
*/
- class NaiveVisitor : public boost::static_visitor<bool&>
- {
- public:
- template<typename RSType>
- bool& operator()(RSType* rs) const;
- };
+class NaiveVisitor : public boost::static_visitor<bool&>
+{
+ public:
+ /**
+ * Get a reference to the naive parameter of the given RangeSearch object.
+ */
+ template<typename RSType>
+ bool& operator()(RSType* rs) const;
+};
class RSModel
{
@@ -251,7 +265,7 @@ class RSModel
//! Random projection matrix.
arma::mat q;
- /**
+ /**
* rSearch holds an instance of the RangeSearch class for the current
* treeType. It is initialized every time BuildModel is executed.
* We access to the contained value through the visitor classes defined above.
@@ -270,7 +284,7 @@ class RSModel
RSType<tree::MaxRPTree>*,
RSType<tree::UBTree>*,
RSType<tree::Octree>*> rSearch;
-
+
public:
/**
* Initialize the RSModel with the given type and whether or not a random
diff --git a/src/mlpack/methods/range_search/rs_model_impl.hpp b/src/mlpack/methods/range_search/rs_model_impl.hpp
index bfe6a5e..4a44a56 100644
--- a/src/mlpack/methods/range_search/rs_model_impl.hpp
+++ b/src/mlpack/methods/range_search/rs_model_impl.hpp
@@ -79,32 +79,32 @@ void BiSearchVisitor::operator()(RSTypeT<tree::Octree>* rs) const
template<typename RSType>
void BiSearchVisitor::SearchLeaf(RSType* rs) const
{
- if (!rs->Naive() && !rs->SingleMode())
- {
- // Build a second tree and search.
- Timer::Start("tree_building");
- Log::Info << "Building query tree..." << std::endl;
- std::vector<size_t> oldFromNewQueries;
- typename RSType::Tree queryTree(std::move(querySet), oldFromNewQueries,
- leafSize);
- Log::Info << "Tree built." << std::endl;
- Timer::Stop("tree_building");
-
- std::vector<std::vector<size_t>> neighborsOut;
- std::vector<std::vector<double>> distancesOut;
- rs->Search(&queryTree, range, neighborsOut, distancesOut);
-
- // Remap the query points.
- neighbors.resize(queryTree.Dataset().n_cols);
- distances.resize(queryTree.Dataset().n_cols);
- for (size_t i = 0; i < queryTree.Dataset().n_cols; ++i)
- {
- neighbors[oldFromNewQueries[i]] = neighborsOut[i];
- distances[oldFromNewQueries[i]] = distancesOut[i];
- }
+ if (!rs->Naive() && !rs->SingleMode())
+ {
+ // Build a second tree and search.
+ Timer::Start("tree_building");
+ Log::Info << "Building query tree..." << std::endl;
+ std::vector<size_t> oldFromNewQueries;
+ typename RSType::Tree queryTree(std::move(querySet), oldFromNewQueries,
+ leafSize);
+ Log::Info << "Tree built." << std::endl;
+ Timer::Stop("tree_building");
+
+ std::vector<std::vector<size_t>> neighborsOut;
+ std::vector<std::vector<double>> distancesOut;
+ rs->Search(&queryTree, range, neighborsOut, distancesOut);
+
+ // Remap the query points.
+ neighbors.resize(queryTree.Dataset().n_cols);
+ distances.resize(queryTree.Dataset().n_cols);
+ for (size_t i = 0; i < queryTree.Dataset().n_cols; ++i)
+ {
+ neighbors[oldFromNewQueries[i]] = neighborsOut[i];
+ distances[oldFromNewQueries[i]] = distancesOut[i];
}
- else
- rs->Search(querySet, range, neighbors, distances);
+ }
+ else
+ rs->Search(querySet, range, neighbors, distances);
}
//! Save parameters for Train.
@@ -153,23 +153,22 @@ void TrainVisitor::operator()(RSTypeT<tree::Octree>* rs) const
template<typename RSType>
void TrainVisitor::TrainLeaf(RSType* rs) const
{
- if (rs->Naive())
- rs->Train(std::move(referenceSet));
- else
- {
- std::vector<size_t> oldFromNewReferences;
- typename RSType::Tree* tree =
- new typename RSType::Tree(std::move(referenceSet),
- oldFromNewReferences, leafSize);
- rs->Train(tree);
-
- // Give the model ownership of the tree and the mappings.
- rs->treeOwner = true;
- rs->oldFromNewReferences = std::move(oldFromNewReferences);
+ if (rs->Naive())
+ rs->Train(std::move(referenceSet));
+ else
+ {
+ std::vector<size_t> oldFromNewReferences;
+ typename RSType::Tree* tree =
+ new typename RSType::Tree(std::move(referenceSet), oldFromNewReferences,
+ leafSize);
+ rs->Train(tree);
+
+ // Give the model ownership of the tree and the mappings.
+ rs->treeOwner = true;
+ rs->oldFromNewReferences = std::move(oldFromNewReferences);
}
}
-
//! Expose the referenceSet of the given RSType.
template<typename RSType>
const arma::mat& ReferenceSetVisitor::operator()(RSType* rs) const
@@ -194,14 +193,14 @@ SerializeVisitor<Archive>::SerializeVisitor(Archive& ar,
ar(ar),
name(name)
{}
-
- //! Serializes the given RSType instance
- template<typename Archive>
- template<typename RSType>
- void SerializeVisitor<Archive>::operator()(RSType* rs) const
- {
- ar & data::CreateNVP(rs, name);
- }
+
+//! Serializes the given RSType instance.
+template<typename Archive>
+template<typename RSType>
+void SerializeVisitor<Archive>::operator()(RSType* rs) const
+{
+ ar & data::CreateNVP(rs, name);
+}
//! Return whether single mode enabled
template<typename RSType>
@@ -220,7 +219,7 @@ bool& NaiveVisitor::operator()(RSType* rs) const
return rs->Naive();
throw std::runtime_error("no range search model initialized");
}
-
+
// Serialize the model.
template<typename Archive>
void RSModel::Serialize(Archive& ar, const unsigned int /* version */)
--
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/debian-science/packages/mlpack.git
More information about the debian-science-commits
mailing list