[mlpack-git] master: Minor code cleanups and style fixes. (d3e3c54)
gitdub at mlpack.org
gitdub at mlpack.org
Thu Jun 2 09:47:31 EDT 2016
Repository : https://github.com/mlpack/mlpack
On branch : master
Link : https://github.com/mlpack/mlpack/compare/eba4f9924694bc10daec74ff5059dbb8af001416...e3a23c256f017ebb8185b15847c82f51d359cdfd
>---------------------------------------------------------------
commit d3e3c5470e38f781592d6344321f930df81a54d2
Author: Ryan Curtin <ryan at ratml.org>
Date: Thu Jun 2 09:47:31 2016 -0400
Minor code cleanups and style fixes.
>---------------------------------------------------------------
d3e3c5470e38f781592d6344321f930df81a54d2
src/mlpack/methods/lsh/lsh_search.hpp | 19 ++++++-------------
src/mlpack/methods/lsh/lsh_search_impl.hpp | 21 ++++++++-------------
2 files changed, 14 insertions(+), 26 deletions(-)
diff --git a/src/mlpack/methods/lsh/lsh_search.hpp b/src/mlpack/methods/lsh/lsh_search.hpp
index 7dd3212..1f54873 100644
--- a/src/mlpack/methods/lsh/lsh_search.hpp
+++ b/src/mlpack/methods/lsh/lsh_search.hpp
@@ -202,20 +202,13 @@ class LSHSearch
//! Get the projection tables.
const arma::cube& Projections() { return projections; }
- //! Change the projection tables (Retrains object)
- void Projections(const arma::cube &projTables)
+ //! Change the projection tables (this retrains the LSH model).
+ void Projections(const arma::cube& projTables)
{
- // Simply call Train() with given projection tables
- Train(
- *referenceSet,
- numProj,
- numTables,
- hashWidth,
- secondHashSize,
- bucketSize,
- projTables
- );
- };
+ // Simply call Train() with the given projection tables.
+ Train(*referenceSet, numProj, numTables, hashWidth, secondHashSize,
+ bucketSize, projTables);
+ }
private:
/**
diff --git a/src/mlpack/methods/lsh/lsh_search_impl.hpp b/src/mlpack/methods/lsh/lsh_search_impl.hpp
index 74ac4cc..9ab2067 100644
--- a/src/mlpack/methods/lsh/lsh_search_impl.hpp
+++ b/src/mlpack/methods/lsh/lsh_search_impl.hpp
@@ -165,27 +165,22 @@ void LSHSearch<SortPolicy>::Train(const arma::mat& referenceSet,
// Step III: Obtain the 'numProj' projections for each table.
projections.clear(); // Reset projections vector.
- if (projection.n_slices == 0) //random generation of tables
+ if (projection.n_slices == 0) // Randomly generate the tables.
{
// For L2 metric, 2-stable distributions are used, and the normal Z ~ N(0,
// 1) is a 2-stable distribution.
- // numTables random tables arranged in a cube.
- projections.randn(
- referenceSet.n_rows,
- numProj,
- numTables
- );
+ // Build numTables random tables arranged in a cube.
+ projections.randn(referenceSet.n_rows, numProj, numTables);
}
- else if (projection.n_slices == numTables) //user defined tables
+ else if (projection.n_slices == numTables) // Take user-defined tables.
{
projections = projection;
}
- else //invalid argument
+ else // The user gave something wrong.
{
- throw std::invalid_argument(
- "number of projection tables provided must be equal to numProj"
- );
+ throw std::invalid_argument("LSHSearch::Train(): number of projection "
+ "tables provided must be equal to numProj");
}
for (size_t i = 0; i < numTables; i++)
@@ -213,7 +208,7 @@ void LSHSearch<SortPolicy>::Train(const arma::mat& referenceSet,
// This gives us the bucket for the corresponding point ID.
for (size_t j = 0; j < secondHashVec.n_elem; j++)
- secondHashVec[j] = (double)((size_t) secondHashVec[j] % secondHashSize);
+ secondHashVec[j] = (double) ((size_t) secondHashVec[j] % secondHashSize);
Log::Assert(secondHashVec.n_elem == referenceSet.n_cols);
More information about the mlpack-git
mailing list