[mlpack-svn] r17258 - mlpack/trunk/src/mlpack/methods/neighbor_search
fastlab-svn at coffeetalk-1.cc.gatech.edu
fastlab-svn at coffeetalk-1.cc.gatech.edu
Mon Oct 13 17:20:00 EDT 2014
Author: rcurtin
Date: Mon Oct 13 17:19:59 2014
New Revision: 17258
Log:
Yet another instance of me failing to commit all my changes. Add a BaseCases()
and Scores() function to NeighborSearch, so that a user (or DTNNKMeans) can
obtain how much work was done after the search.
Modified:
mlpack/trunk/src/mlpack/methods/neighbor_search/neighbor_search.hpp
mlpack/trunk/src/mlpack/methods/neighbor_search/neighbor_search_impl.hpp
Modified: mlpack/trunk/src/mlpack/methods/neighbor_search/neighbor_search.hpp
==============================================================================
--- mlpack/trunk/src/mlpack/methods/neighbor_search/neighbor_search.hpp (original)
+++ mlpack/trunk/src/mlpack/methods/neighbor_search/neighbor_search.hpp Mon Oct 13 17:19:59 2014
@@ -192,9 +192,20 @@
arma::Mat<size_t>& resultingNeighbors,
arma::mat& distances);
- // Returns a string representation of this object.
+ //! Returns a string representation of this object.
std::string ToString() const;
+ //! Return the total number of base case evaluations performed during
+ //! searches.
+ size_t BaseCases() const { return baseCases; }
+ //! Modify the total number of base case evaluations.
+ size_t& BaseCases() { return baseCases; }
+
+ //! Return the number of node combination scores during the search.
+ size_t Scores() const { return scores; }
+ //! Modify the number of node combination scores.
+ size_t& Scores() { return scores; }
+
private:
//! Copy of reference dataset (if we need it, because tree building modifies
//! it).
@@ -229,6 +240,12 @@
std::vector<size_t> oldFromNewReferences;
//! Permutations of query points during tree building.
std::vector<size_t> oldFromNewQueries;
+
+ //! The total number of base cases.
+ size_t baseCases;
+ //! The total number of scores (applicable for non-naive search).
+ size_t scores;
+
}; // class NeighborSearch
}; // namespace neighbor
Modified: mlpack/trunk/src/mlpack/methods/neighbor_search/neighbor_search_impl.hpp
==============================================================================
--- mlpack/trunk/src/mlpack/methods/neighbor_search/neighbor_search_impl.hpp (original)
+++ mlpack/trunk/src/mlpack/methods/neighbor_search/neighbor_search_impl.hpp Mon Oct 13 17:19:59 2014
@@ -57,8 +57,13 @@
hasQuerySet(true),
naive(naive),
singleMode(!naive && singleMode), // No single mode if naive.
- metric(metric)
+ metric(metric),
+ baseCases(0),
+ scores(0)
{
+ // C++11 will allow us to call out to other constructors so we can avoid this
+ // copypasta problem.
+
// We'll time tree building, but only if we are building trees.
Timer::Start("tree_building");
@@ -105,7 +110,9 @@
hasQuerySet(false),
naive(naive),
singleMode(!naive && singleMode), // No single mode if naive.
- metric(metric)
+ metric(metric),
+ baseCases(0),
+ scores(0)
{
// We'll time tree building, but only if we are building trees.
Timer::Start("tree_building");
@@ -149,7 +156,9 @@
hasQuerySet(true),
naive(false),
singleMode(singleMode),
- metric(metric)
+ metric(metric),
+ baseCases(0),
+ scores(0)
{
// Nothing else to initialize.
}
@@ -169,7 +178,9 @@
hasQuerySet(false), // In this case we will own a tree, if singleMode.
naive(false),
singleMode(singleMode),
- metric(metric)
+ metric(metric),
+ baseCases(0),
+ scores(0)
{
Timer::Start("tree_building");
@@ -246,12 +257,14 @@
for (size_t i = 0; i < querySet.n_cols; ++i)
for (size_t j = 0; j < referenceSet.n_cols; ++j)
rules.BaseCase(i, j);
+
+ baseCases += querySet.n_cols * referenceSet.n_cols;
}
else if (singleMode)
{
// The search doesn't work if the root node is also a leaf node.
- // if this is the case, it is suggested that you use the naive method.
- assert(!(referenceTree->IsLeaf()));
+ // If this is the case, it is suggested that you use the naive method.
+ Log::Assert(!(referenceTree->IsLeaf()));
// Create the traverser.
typename TreeType::template SingleTreeTraverser<RuleType> traverser(rules);
@@ -260,6 +273,9 @@
for (size_t i = 0; i < querySet.n_cols; ++i)
traverser.Traverse(i, *referenceTree);
+ scores += rules.Scores();
+ baseCases += rules.BaseCases();
+
Log::Info << rules.Scores() << " node combinations were scored.\n";
Log::Info << rules.BaseCases() << " base cases were calculated.\n";
}
@@ -270,6 +286,9 @@
traverser.Traverse(*queryTree, *referenceTree);
+ scores += rules.Scores();
+ baseCases += rules.BaseCases();
+
Log::Info << rules.Scores() << " node combinations were scored.\n";
Log::Info << rules.BaseCases() << " base cases were calculated.\n";
}
More information about the mlpack-svn
mailing list