From 50794b783bd86cd03c60708bbd734943d3284d86 Mon Sep 17 00:00:00 2001 From: Omar Shrit Date: Fri, 29 May 2020 01:29:58 +0200 Subject: [PATCH 01/16] Replace i++ to ++i Why? Pre-increment is faster than post-increment I know that gcc generated the same code, but it is easier to keep a good practice Signed-off-by: Omar Shrit --- .../detail/bernoulli_details.hpp | 4 +- src/mlpack/core/data/load_image_impl.hpp | 2 +- src/mlpack/core/data/save_impl.hpp | 2 +- src/mlpack/core/data/string_encoding_impl.hpp | 6 +- .../core/dists/discrete_distribution.cpp | 6 +- .../core/dists/discrete_distribution.hpp | 8 +- src/mlpack/core/dists/gamma_distribution.cpp | 2 +- .../core/dists/gaussian_distribution.cpp | 8 +- .../core/dists/gaussian_distribution.hpp | 4 +- .../core/dists/laplace_distribution.cpp | 2 +- .../core/dists/laplace_distribution.hpp | 2 +- src/mlpack/core/math/lin_alg.cpp | 8 +- src/mlpack/core/math/random.hpp | 4 +- src/mlpack/core/metrics/lmetric_impl.hpp | 4 +- src/mlpack/core/tree/address.hpp | 10 +- .../binary_space_tree_impl.hpp | 14 +- .../rp_tree_mean_split_impl.hpp | 2 +- .../binary_space_tree/ub_tree_split_impl.hpp | 10 +- .../vantage_point_split_impl.hpp | 2 +- src/mlpack/core/tree/cellbound_impl.hpp | 34 ++-- .../core/tree/cosine_tree/cosine_tree.cpp | 22 +- src/mlpack/core/tree/hrectbound_impl.hpp | 16 +- src/mlpack/core/tree/octree/octree_impl.hpp | 4 +- .../discrete_hilbert_value_impl.hpp | 20 +- .../dual_tree_traverser_impl.hpp | 8 +- ...bert_r_tree_auxiliary_information_impl.hpp | 4 +- .../hilbert_r_tree_split_impl.hpp | 12 +- .../minimal_coverage_sweep_impl.hpp | 16 +- .../minimal_splits_number_sweep_impl.hpp | 4 +- .../rectangle_tree/r_plus_tree_split_impl.hpp | 10 +- .../r_star_tree_descent_heuristic_impl.hpp | 12 +- .../rectangle_tree/r_star_tree_split_impl.hpp | 20 +- .../r_tree_descent_heuristic_impl.hpp | 4 +- .../tree/rectangle_tree/r_tree_split_impl.hpp | 38 ++-- .../rectangle_tree/rectangle_tree_impl.hpp | 50 ++--- .../single_tree_traverser_impl.hpp | 6 +- .../x_tree_auxiliary_information.hpp | 2 +- .../tree/rectangle_tree/x_tree_split_impl.hpp | 62 +++--- .../space_split/mean_space_split_impl.hpp | 2 +- .../tree/space_split/space_split_impl.hpp | 4 +- .../core/tree/spill_tree/spill_tree_impl.hpp | 8 +- src/mlpack/core/util/backtrace.cpp | 4 +- src/mlpack/methods/adaboost/adaboost_impl.hpp | 6 +- .../simple_tolerance_termination.hpp | 2 +- .../validation_rmse_termination.hpp | 4 +- .../methods/amf/update_rules/nmf_als.hpp | 4 +- .../methods/amf/update_rules/nmf_mult_div.hpp | 2 +- .../amf/update_rules/svd_batch_learning.hpp | 4 +- .../hard_sigmoid_function.hpp | 4 +- .../rectifier_function.hpp | 2 +- .../softplus_function.hpp | 4 +- .../softsign_function.hpp | 4 +- .../activation_functions/swish_function.hpp | 2 +- .../methods/ann/ann_low_resource_main.cpp | 176 ++++++++++++++++ .../ann/augmented/tasks/score_impl.hpp | 2 +- .../ann/callbacks/early_stop_at_min_loss.hpp | 126 ++++++++++++ .../ann/convolution_rules/fft_convolution.hpp | 6 +- .../convolution_rules/naive_convolution.hpp | 10 +- .../ann/convolution_rules/svd_convolution.hpp | 6 +- .../ann/dists/bernoulli_distribution_impl.hpp | 2 +- src/mlpack/methods/ann/ffn_impl.hpp | 2 +- .../ann/gan/metrics/inception_score_impl.hpp | 2 +- .../methods/ann/init_rules/gaussian_init.hpp | 2 +- .../methods/ann/init_rules/glorot_init.hpp | 2 +- src/mlpack/methods/ann/init_rules/he_init.hpp | 2 +- .../kathirvalavakumar_subavathi_init.hpp | 2 +- .../ann/init_rules/lecun_normal_init.hpp | 2 +- .../ann/init_rules/nguyen_widrow_init.hpp | 2 +- .../methods/ann/init_rules/oivs_init.hpp | 2 +- .../ann/init_rules/orthogonal_init.hpp | 2 +- .../methods/ann/init_rules/random_init.hpp | 2 +- .../ann/layer/atrous_convolution_impl.hpp | 4 +- .../methods/ann/layer/batch_norm_impl.hpp | 2 +- .../ann/layer/bilinear_interpolation_impl.hpp | 4 +- src/mlpack/methods/ann/layer/celu_impl.hpp | 4 +- src/mlpack/methods/ann/layer/elu_impl.hpp | 4 +- src/mlpack/methods/ann/layer/glimpse.hpp | 4 +- src/mlpack/methods/ann/layer/glimpse_impl.hpp | 2 +- .../methods/ann/layer/hard_tanh_impl.hpp | 4 +- .../methods/ann/layer/leaky_relu_impl.hpp | 2 +- .../layer/minibatch_discrimination_impl.hpp | 4 +- .../ann/layer/parametric_relu_impl.hpp | 2 +- src/mlpack/methods/ann/layer/subview.hpp | 2 +- .../ann/layer/vr_class_reward_impl.hpp | 2 +- src/mlpack/methods/ann/rbm/rbm_impl.hpp | 6 +- .../methods/ann/rbm/spike_slab_rbm_impl.hpp | 16 +- .../orthogonal_regularizer_impl.hpp | 2 +- .../bias_svd/bias_svd_function_impl.hpp | 6 +- src/mlpack/methods/cf/cf_impl.hpp | 4 +- .../batch_svd_method.hpp | 2 +- .../bias_svd_method.hpp | 2 +- .../cf/decomposition_policies/nmf_method.hpp | 2 +- .../randomized_svd_method.hpp | 2 +- .../regularized_svd_method.hpp | 2 +- .../svd_complete_method.hpp | 2 +- .../svd_incomplete_method.hpp | 2 +- .../svdplusplus_method.hpp | 2 +- .../regression_interpolation.hpp | 2 +- .../normalization/item_mean_normalization.hpp | 6 +- .../normalization/user_mean_normalization.hpp | 6 +- src/mlpack/methods/cf/svd_wrapper_impl.hpp | 4 +- .../decision_stump/decision_stump_impl.hpp | 18 +- src/mlpack/methods/det/det_main.cpp | 8 +- src/mlpack/methods/det/dt_utils_impl.hpp | 8 +- src/mlpack/methods/emst/dtb_impl.hpp | 8 +- .../methods/fastmks/fastmks_rules_impl.hpp | 4 +- src/mlpack/methods/gmm/diagonal_gmm.cpp | 4 +- src/mlpack/methods/gmm/em_fit_impl.hpp | 12 +- src/mlpack/methods/gmm/gmm.cpp | 4 +- src/mlpack/methods/gmm/gmm_train_main.cpp | 8 +- src/mlpack/methods/hmm/hmm_impl.hpp | 10 +- .../methods/hmm/hmm_regression_impl.hpp | 6 +- src/mlpack/methods/kmeans/kmeans_impl.hpp | 2 +- src/mlpack/methods/kmeans/kmeans_main.cpp | 4 +- src/mlpack/methods/lars/lars.cpp | 16 +- .../linear_svm/linear_svm_function_impl.hpp | 2 +- .../methods/linear_svm/linear_svm_impl.hpp | 2 +- src/mlpack/methods/lmnn/constraints_impl.hpp | 20 +- .../methods/lmnn/lmnn_function_impl.hpp | 30 +-- src/mlpack/methods/lmnn/lmnn_main.cpp | 6 +- .../methods/local_coordinate_coding/lcc.cpp | 4 +- .../logistic_regression_impl.hpp | 2 +- src/mlpack/methods/lsh/lsh_search_impl.hpp | 8 +- .../matrix_completion/matrix_completion.cpp | 4 +- .../methods/mean_shift/mean_shift_main.cpp | 4 +- .../naive_bayes_classifier_impl.hpp | 2 +- src/mlpack/methods/nca/nca_main.cpp | 2 +- .../nca/nca_softmax_error_function_impl.hpp | 10 +- .../neighbor_search/knn_low_resource_main.cpp | 189 ++++++++++++++++++ .../neighbor_search/neighbor_search_impl.hpp | 8 +- .../neighbor_search_rules_impl.hpp | 4 +- .../methods/perceptron/perceptron_impl.hpp | 4 +- src/mlpack/methods/radical/radical.cpp | 6 +- src/mlpack/methods/radical/radical_main.cpp | 2 +- .../range_search/range_search_impl.hpp | 8 +- src/mlpack/methods/rann/ra_search_impl.hpp | 8 +- .../methods/rann/ra_search_rules_impl.hpp | 38 ++-- src/mlpack/methods/rann/ra_util.cpp | 2 +- .../regularized_svd_function_impl.hpp | 6 +- .../replay/prioritized_replay.hpp | 2 +- .../reinforcement_learning/replay/sumtree.hpp | 2 +- .../softmax_regression/softmax_regression.cpp | 6 +- .../softmax_regression_function.cpp | 2 +- .../methods/sparse_coding/sparse_coding.cpp | 2 +- .../svdplusplus/svdplusplus_function_impl.hpp | 6 +- .../tests/activation_functions_test.cpp | 44 ++-- src/mlpack/tests/adaboost_test.cpp | 6 +- src/mlpack/tests/akfn_test.cpp | 6 +- src/mlpack/tests/aknn_test.cpp | 6 +- src/mlpack/tests/ann_dist_test.cpp | 4 +- src/mlpack/tests/ann_layer_test.cpp | 20 +- src/mlpack/tests/bias_svd_test.cpp | 14 +- src/mlpack/tests/callback_test.cpp | 4 +- src/mlpack/tests/cf_test.cpp | 2 +- src/mlpack/tests/convolution_test.cpp | 6 +- .../tests/convolutional_network_test.cpp | 4 +- src/mlpack/tests/cosine_tree_test.cpp | 16 +- src/mlpack/tests/dcgan_test.cpp | 6 +- src/mlpack/tests/decision_stump_test.cpp | 2 +- src/mlpack/tests/distribution_test.cpp | 42 ++-- src/mlpack/tests/emst_test.cpp | 6 +- src/mlpack/tests/gan_test.cpp | 4 +- src/mlpack/tests/gmm_test.cpp | 56 +++--- src/mlpack/tests/hmm_test.cpp | 64 +++--- src/mlpack/tests/hoeffding_tree_test.cpp | 4 +- src/mlpack/tests/hyperplane_test.cpp | 2 +- src/mlpack/tests/init_rules_test.cpp | 6 +- src/mlpack/tests/kfn_test.cpp | 8 +- src/mlpack/tests/kmeans_test.cpp | 16 +- src/mlpack/tests/knn_test.cpp | 8 +- src/mlpack/tests/krann_search_test.cpp | 28 +-- src/mlpack/tests/lars_test.cpp | 2 +- src/mlpack/tests/lin_alg_test.cpp | 4 +- src/mlpack/tests/linear_svm_test.cpp | 96 ++++----- src/mlpack/tests/lmnn_test.cpp | 6 +- src/mlpack/tests/load_save_test.cpp | 26 +-- .../tests/local_coordinate_coding_test.cpp | 10 +- src/mlpack/tests/loss_functions_test.cpp | 8 +- src/mlpack/tests/main_tests/adaboost_test.cpp | 2 +- src/mlpack/tests/main_tests/emst_test.cpp | 2 +- src/mlpack/tests/main_tests/fastmks_test.cpp | 2 +- .../tests/main_tests/gmm_train_test.cpp | 2 +- .../tests/main_tests/hmm_train_test.cpp | 10 +- src/mlpack/tests/main_tests/kfn_test.cpp | 4 +- src/mlpack/tests/main_tests/knn_test.cpp | 4 +- .../main_tests/preprocess_imputer_test.cpp | 2 +- .../tests/main_tests/range_search_test.cpp | 4 +- .../tests/main_tests/range_search_utils.hpp | 4 +- src/mlpack/tests/mean_shift_test.cpp | 6 +- src/mlpack/tests/mlpack_test.cpp | 2 +- src/mlpack/tests/nbc_test.cpp | 18 +- src/mlpack/tests/pca_test.cpp | 4 +- src/mlpack/tests/perceptron_test.cpp | 2 +- src/mlpack/tests/radical_test.cpp | 4 +- src/mlpack/tests/range_search_test.cpp | 10 +- src/mlpack/tests/rbm_network_test.cpp | 14 +- src/mlpack/tests/rectangle_tree_test.cpp | 78 ++++---- src/mlpack/tests/recurrent_network_test.cpp | 20 +- src/mlpack/tests/regularized_svd_test.cpp | 14 +- src/mlpack/tests/scaling_test.cpp | 4 +- src/mlpack/tests/serialization_test.cpp | 2 +- src/mlpack/tests/softmax_regression_test.cpp | 100 ++++----- src/mlpack/tests/sparse_autoencoder_test.cpp | 8 +- src/mlpack/tests/spill_tree_test.cpp | 8 +- src/mlpack/tests/string_encoding_test.cpp | 10 +- src/mlpack/tests/svdplusplus_test.cpp | 18 +- src/mlpack/tests/tree_test.cpp | 26 +-- src/mlpack/tests/ub_tree_test.cpp | 18 +- src/mlpack/tests/union_find_test.cpp | 2 +- src/mlpack/tests/vantage_point_tree_test.cpp | 10 +- src/mlpack/tests/wgan_test.cpp | 4 +- 211 files changed, 1453 insertions(+), 962 deletions(-) create mode 100644 src/mlpack/methods/ann/ann_low_resource_main.cpp create mode 100644 src/mlpack/methods/ann/callbacks/early_stop_at_min_loss.hpp create mode 100644 src/mlpack/methods/neighbor_search/knn_low_resource_main.cpp diff --git a/src/mlpack/core/boost_backport/detail/bernoulli_details.hpp b/src/mlpack/core/boost_backport/detail/bernoulli_details.hpp index d07d796b1f..f4bb51896d 100644 --- a/src/mlpack/core/boost_backport/detail/bernoulli_details.hpp +++ b/src/mlpack/core/boost_backport/detail/bernoulli_details.hpp @@ -308,7 +308,7 @@ public: BOOST_MATH_INSTRUMENT_VARIABLE(tn[1]); } - for(std::size_t i = std::max(2, prev_size); i < m; i++) + for(std::size_t i = std::max(2, prev_size); i < m; ++i) { bool overflow_check = false; if(i >= min_overflow_index && (boost::math::tools::max_value() / (i-1) < m_intermediates[1]) ) @@ -360,7 +360,7 @@ public: T power_two(ldexp(T(1), static_cast(2 * old_size))); - for(std::size_t i = old_size; i < m; i++) + for(std::size_t i = old_size; i < m; ++i) { T b(static_cast(i * 2)); // diff --git a/src/mlpack/core/data/load_image_impl.hpp b/src/mlpack/core/data/load_image_impl.hpp index b5be00861b..8063ee4642 100644 --- a/src/mlpack/core/data/load_image_impl.hpp +++ b/src/mlpack/core/data/load_image_impl.hpp @@ -76,7 +76,7 @@ bool Load(const std::vector& files, info.Width() * info.Height() * info.Channels(), files.size()); tmpMatrix.col(0) = img; - for (size_t i = 1; i < files.size() ; i++) + for (size_t i = 1; i < files.size() ; ++i) { arma::Mat colImg(tmpMatrix.colptr(i), tmpMatrix.n_rows, 1, false, true); diff --git a/src/mlpack/core/data/save_impl.hpp b/src/mlpack/core/data/save_impl.hpp index 516e0aaf93..b90315ca63 100644 --- a/src/mlpack/core/data/save_impl.hpp +++ b/src/mlpack/core/data/save_impl.hpp @@ -330,7 +330,7 @@ bool Save(const std::vector& files, arma::Mat img; bool status = true; - for (size_t i = 0; i < files.size() ; i++) + for (size_t i = 0; i < files.size() ; ++i) { arma::Mat colImg(matrix.colptr(i), matrix.n_rows, 1, false, true); diff --git a/src/mlpack/core/data/string_encoding_impl.hpp b/src/mlpack/core/data/string_encoding_impl.hpp index 0e50f6c1d8..abe96b2f33 100644 --- a/src/mlpack/core/data/string_encoding_impl.hpp +++ b/src/mlpack/core/data/string_encoding_impl.hpp @@ -110,7 +110,7 @@ EncodeHelper(const std::vector& input, policy.Reset(); // The first pass adds the extracted tokens to the dictionary. - for (size_t i = 0; i < input.size(); i++) + for (size_t i = 0; i < input.size(); ++i) { boost::string_view strView(input[i]); auto token = tokenizer(strView); @@ -141,7 +141,7 @@ EncodeHelper(const std::vector& input, policy.InitMatrix(output, input.size(), numColumns, dictionary.Size()); // The second pass writes the encoded values to the output. - for (size_t i = 0; i < input.size(); i++) + for (size_t i = 0; i < input.size(); ++i) { boost::string_view strView(input[i]); auto token = tokenizer(strView); @@ -170,7 +170,7 @@ EncodeHelper(const std::vector& input, // The loop below extracts the tokens and writes the encoded values // at once. - for (size_t i = 0; i < input.size(); i++) + for (size_t i = 0; i < input.size(); ++i) { boost::string_view strView(input[i]); auto token = tokenizer(strView); diff --git a/src/mlpack/core/dists/discrete_distribution.cpp b/src/mlpack/core/dists/discrete_distribution.cpp index 3e17443cdd..69c6b63e8c 100644 --- a/src/mlpack/core/dists/discrete_distribution.cpp +++ b/src/mlpack/core/dists/discrete_distribution.cpp @@ -66,7 +66,7 @@ void DiscreteDistribution::Train(const arma::mat& observations) const size_t dimensions = probabilities.size(); // Clear the old probabilities. - for (size_t i = 0; i < dimensions; i++) + for (size_t i = 0; i < dimensions; ++i) probabilities[i].zeros(); // Iterate over all the probabilities in each dimension. @@ -121,13 +121,13 @@ void DiscreteDistribution::Train(const arma::mat& observations, size_t dimensions = probabilities.size(); // Clear the old probabilities. - for (size_t i = 0; i < dimensions; i++) + for (size_t i = 0; i < dimensions; ++i) probabilities[i].zeros(); // Ensure that the observation is within the bounds. for (size_t r = 0; r < observations.n_cols; r++) { - for (size_t i = 0; i < dimensions; i++) + for (size_t i = 0; i < dimensions; ++i) { // Add the probability of each observation. The addition of 0.5 // to the observation is to turn the default flooring operation diff --git a/src/mlpack/core/dists/discrete_distribution.hpp b/src/mlpack/core/dists/discrete_distribution.hpp index c2c020570c..bf9370945a 100644 --- a/src/mlpack/core/dists/discrete_distribution.hpp +++ b/src/mlpack/core/dists/discrete_distribution.hpp @@ -76,7 +76,7 @@ class DiscreteDistribution */ DiscreteDistribution(const arma::Col& numObservations) { - for (size_t i = 0; i < numObservations.n_elem; i++) + for (size_t i = 0; i < numObservations.n_elem; ++i) { const size_t numObs = size_t(numObservations[i]); if (numObs <= 0) @@ -98,7 +98,7 @@ class DiscreteDistribution */ DiscreteDistribution(const std::vector& probabilities) { - for (size_t i = 0; i < probabilities.size(); i++) + for (size_t i = 0; i < probabilities.size(); ++i) { arma::vec temp = probabilities[i]; double sum = accu(temp); @@ -180,7 +180,7 @@ class DiscreteDistribution void Probability(const arma::mat& x, arma::vec& probabilities) const { probabilities.set_size(x.n_cols); - for (size_t i = 0; i < x.n_cols; i++) + for (size_t i = 0; i < x.n_cols; ++i) probabilities(i) = Probability(x.unsafe_col(i)); } @@ -195,7 +195,7 @@ class DiscreteDistribution void LogProbability(const arma::mat& x, arma::vec& logProbabilities) const { logProbabilities.set_size(x.n_cols); - for (size_t i = 0; i < x.n_cols; i++) + for (size_t i = 0; i < x.n_cols; ++i) logProbabilities(i) = log(Probability(x.unsafe_col(i))); } diff --git a/src/mlpack/core/dists/gamma_distribution.cpp b/src/mlpack/core/dists/gamma_distribution.cpp index 63f7d7e29c..c79eb10879 100644 --- a/src/mlpack/core/dists/gamma_distribution.cpp +++ b/src/mlpack/core/dists/gamma_distribution.cpp @@ -78,7 +78,7 @@ void GammaDistribution::Train(const arma::mat& rdata, arma::vec meanxVec(rdata.n_rows, arma::fill::zeros); arma::vec logMeanxVec(rdata.n_rows, arma::fill::zeros); - for (size_t i = 0; i < rdata.n_cols; i++) + for (size_t i = 0; i < rdata.n_cols; ++i) { meanLogxVec += probabilities(i) * arma::log(rdata.col(i)); meanxVec += probabilities(i) * rdata.col(i); diff --git a/src/mlpack/core/dists/gaussian_distribution.cpp b/src/mlpack/core/dists/gaussian_distribution.cpp index 812b9d6dd7..37009e7c91 100644 --- a/src/mlpack/core/dists/gaussian_distribution.cpp +++ b/src/mlpack/core/dists/gaussian_distribution.cpp @@ -102,14 +102,14 @@ void GaussianDistribution::Train(const arma::mat& observations) } // Calculate the mean. - for (size_t i = 0; i < observations.n_cols; i++) + for (size_t i = 0; i < observations.n_cols; ++i) mean += observations.col(i); // Normalize the mean. mean /= observations.n_cols; // Now calculate the covariance. - for (size_t i = 0; i < observations.n_cols; i++) + for (size_t i = 0; i < observations.n_cols; ++i) { arma::vec obsNoMean = observations.col(i) - mean; covariance += obsNoMean * trans(obsNoMean); @@ -150,7 +150,7 @@ void GaussianDistribution::Train(const arma::mat& observations, // First calculate the mean, and save the sum of all the probabilities for // later normalization. - for (size_t i = 0; i < observations.n_cols; i++) + for (size_t i = 0; i < observations.n_cols; ++i) { mean += probabilities[i] * observations.col(i); sumProb += probabilities[i]; @@ -170,7 +170,7 @@ void GaussianDistribution::Train(const arma::mat& observations, mean /= sumProb; // Now find the covariance. - for (size_t i = 0; i < observations.n_cols; i++) + for (size_t i = 0; i < observations.n_cols; ++i) { arma::vec obsNoMean = observations.col(i) - mean; covariance += probabilities[i] * (obsNoMean * trans(obsNoMean)); diff --git a/src/mlpack/core/dists/gaussian_distribution.hpp b/src/mlpack/core/dists/gaussian_distribution.hpp index 76bbd0e68e..ea3789f9ea 100644 --- a/src/mlpack/core/dists/gaussian_distribution.hpp +++ b/src/mlpack/core/dists/gaussian_distribution.hpp @@ -91,7 +91,7 @@ class GaussianDistribution void Probability(const arma::mat& x, arma::vec& probabilities) const { probabilities.set_size(x.n_cols); - for (size_t i = 0; i < x.n_cols; i++) + for (size_t i = 0; i < x.n_cols; ++i) { probabilities(i) = Probability(x.unsafe_col(i)); } @@ -116,7 +116,7 @@ class GaussianDistribution // so that later we are referencing columns, not rows -- that is faster. const arma::mat rhs = -0.5 * invCov * diffs; arma::vec logExponents(diffs.n_cols); // We will now fill this. - for (size_t i = 0; i < diffs.n_cols; i++) + for (size_t i = 0; i < diffs.n_cols; ++i) logExponents(i) = accu(diffs.unsafe_col(i) % rhs.unsafe_col(i)); logProbabilities = -0.5 * x.n_rows * log2pi - 0.5 * logDetCov + diff --git a/src/mlpack/core/dists/laplace_distribution.cpp b/src/mlpack/core/dists/laplace_distribution.cpp index aeaf88f347..91b32ed4b3 100644 --- a/src/mlpack/core/dists/laplace_distribution.cpp +++ b/src/mlpack/core/dists/laplace_distribution.cpp @@ -37,7 +37,7 @@ void LaplaceDistribution::Probability(const arma::mat& x, arma::vec& probabilities) const { probabilities.set_size(x.n_cols); - for (size_t i = 0; i < x.n_cols; i++) + for (size_t i = 0; i < x.n_cols; ++i) { probabilities(i) = Probability(x.unsafe_col(i)); } diff --git a/src/mlpack/core/dists/laplace_distribution.hpp b/src/mlpack/core/dists/laplace_distribution.hpp index af39f19345..bc24ca31be 100644 --- a/src/mlpack/core/dists/laplace_distribution.hpp +++ b/src/mlpack/core/dists/laplace_distribution.hpp @@ -113,7 +113,7 @@ class LaplaceDistribution void LogProbability(const arma::mat& x, arma::vec& logProbabilities) const { logProbabilities.set_size(x.n_cols); - for (size_t i = 0; i < x.n_cols; i++) + for (size_t i = 0; i < x.n_cols; ++i) { logProbabilities(i) = LogProbability(x.unsafe_col(i)); } diff --git a/src/mlpack/core/math/lin_alg.cpp b/src/mlpack/core/math/lin_alg.cpp index 48919ce56f..660a1d7c43 100644 --- a/src/mlpack/core/math/lin_alg.cpp +++ b/src/mlpack/core/math/lin_alg.cpp @@ -23,7 +23,7 @@ using namespace math; */ void mlpack::math::VectorPower(arma::vec& vec, const double power) { - for (size_t i = 0; i < vec.n_elem; i++) + for (size_t i = 0; i < vec.n_elem; ++i) { if (std::abs(vec(i)) > 1e-12) vec(i) = (vec(i) > 0) ? std::pow(vec(i), (double) power) : @@ -197,7 +197,7 @@ void mlpack::math::Svec(const arma::mat& input, arma::vec& output) output.zeros(n2bar); size_t idx = 0; - for (size_t i = 0; i < n; i++) + for (size_t i = 0; i < n; ++i) { for (size_t j = i; j < n; j++) { @@ -238,7 +238,7 @@ void mlpack::math::Smat(const arma::vec& input, arma::mat& output) output.zeros(n, n); size_t idx = 0; - for (size_t i = 0; i < n; i++) + for (size_t i = 0; i < n; ++i) { for (size_t j = i; j < n; j++) { @@ -259,7 +259,7 @@ void mlpack::math::SymKronId(const arma::mat& A, arma::mat& op) op.zeros(n2bar, n2bar); size_t idx = 0; - for (size_t i = 0; i < n; i++) + for (size_t i = 0; i < n; ++i) { for (size_t j = i; j < n; j++) { diff --git a/src/mlpack/core/math/random.hpp b/src/mlpack/core/math/random.hpp index 0464652f97..349822718a 100644 --- a/src/mlpack/core/math/random.hpp +++ b/src/mlpack/core/math/random.hpp @@ -158,7 +158,7 @@ inline void ObtainDistinctSamples(const size_t loInclusive, samples.zeros(samplesRangeSize); - for (size_t i = 0; i < maxNumSamples; i++) + for (size_t i = 0; i < maxNumSamples; ++i) samples [ (size_t) math::RandInt(samplesRangeSize) ]++; distinctSamples = arma::find(samples > 0); @@ -169,7 +169,7 @@ inline void ObtainDistinctSamples(const size_t loInclusive, else { distinctSamples.set_size(samplesRangeSize); - for (size_t i = 0; i < samplesRangeSize; i++) + for (size_t i = 0; i < samplesRangeSize; ++i) distinctSamples[i] = loInclusive + i; } } diff --git a/src/mlpack/core/metrics/lmetric_impl.hpp b/src/mlpack/core/metrics/lmetric_impl.hpp index 8e07a4ea38..c13ab851c7 100644 --- a/src/mlpack/core/metrics/lmetric_impl.hpp +++ b/src/mlpack/core/metrics/lmetric_impl.hpp @@ -26,7 +26,7 @@ typename VecTypeA::elem_type LMetric::Evaluate( const VecTypeB& b) { typename VecTypeA::elem_type sum = 0; - for (size_t i = 0; i < a.n_elem; i++) + for (size_t i = 0; i < a.n_elem; ++i) sum += std::pow(fabs(a[i] - b[i]), Power); if (!TakeRoot) // The compiler should optimize this correctly at compile-time. @@ -81,7 +81,7 @@ typename VecTypeA::elem_type LMetric<3, true>::Evaluate( const VecTypeB& b) { typename VecTypeA::elem_type sum = 0; - for (size_t i = 0; i < a.n_elem; i++) + for (size_t i = 0; i < a.n_elem; ++i) sum += std::pow(fabs(a[i] - b[i]), 3.0); return std::pow(arma::accu(arma::pow(arma::abs(a - b), 3.0)), 1.0 / 3.0); diff --git a/src/mlpack/core/tree/address.hpp b/src/mlpack/core/tree/address.hpp index 03c8cb4f9c..bbb9c860c6 100644 --- a/src/mlpack/core/tree/address.hpp +++ b/src/mlpack/core/tree/address.hpp @@ -79,7 +79,7 @@ void PointToAddress(AddressType& address, const VecType& point) assert(point.n_elem == address.n_elem); assert(address.n_elem > 0); - for (size_t i = 0; i < point.n_elem; i++) + for (size_t i = 0; i < point.n_elem; ++i) { int e; VecElemType normalizedVal = std::frexp(point(i), &e); @@ -128,7 +128,7 @@ void PointToAddress(AddressType& address, const VecType& point) // 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 i = 0; i < order; ++i) for (size_t j = 0; j < point.n_elem; j++) { size_t bit = (i * point.n_elem + j) % order; @@ -176,7 +176,7 @@ void AddressToPoint(VecType& point, const AddressType& address) // Calculate the number of bits for the mantissa. const int numMantBits = order - numExpBits - 1; - for (size_t i = 0; i < order; i++) + for (size_t i = 0; i < order; ++i) for (size_t j = 0; j < address.n_elem; j++) { size_t bit = (i * address.n_elem + j) % order; @@ -186,7 +186,7 @@ void AddressToPoint(VecType& point, const AddressType& address) (order - 1 - i)); } - for (size_t i = 0; i < rearrangedAddress.n_elem; i++) + for (size_t i = 0; i < rearrangedAddress.n_elem; ++i) { bool sgn = rearrangedAddress(i) & ((AddressElemType) 1 << (order - 1)); @@ -238,7 +238,7 @@ int CompareAddresses(const AddressType1& addr1, const AddressType2& addr2) assert(addr1.n_elem == addr2.n_elem); - for (size_t i = 0; i < addr1.n_elem; i++) + for (size_t i = 0; i < addr1.n_elem; ++i) { if (addr1[i] < addr2[i]) return -1; diff --git a/src/mlpack/core/tree/binary_space_tree/binary_space_tree_impl.hpp b/src/mlpack/core/tree/binary_space_tree/binary_space_tree_impl.hpp index 7c2f4c08b9..a269cefe1b 100644 --- a/src/mlpack/core/tree/binary_space_tree/binary_space_tree_impl.hpp +++ b/src/mlpack/core/tree/binary_space_tree/binary_space_tree_impl.hpp @@ -72,7 +72,7 @@ BinarySpaceTree( { // Initialize oldFromNew correctly. oldFromNew.resize(data.n_cols); - for (size_t i = 0; i < data.n_cols; i++) + for (size_t i = 0; i < data.n_cols; ++i) oldFromNew[i] = i; // Fill with unharmed indices. // Now do the actual splitting. @@ -106,7 +106,7 @@ BinarySpaceTree( { // Initialize the oldFromNew vector correctly. oldFromNew.resize(data.n_cols); - for (size_t i = 0; i < data.n_cols; i++) + for (size_t i = 0; i < data.n_cols; ++i) oldFromNew[i] = i; // Fill with unharmed indices. // Now do the actual splitting. @@ -118,7 +118,7 @@ BinarySpaceTree( // Map the newFromOld indices correctly. newFromOld.resize(data.n_cols); - for (size_t i = 0; i < data.n_cols; i++) + for (size_t i = 0; i < data.n_cols; ++i) newFromOld[oldFromNew[i]] = i; } @@ -169,7 +169,7 @@ BinarySpaceTree( { // Initialize oldFromNew correctly. oldFromNew.resize(dataset->n_cols); - for (size_t i = 0; i < dataset->n_cols; i++) + for (size_t i = 0; i < dataset->n_cols; ++i) oldFromNew[i] = i; // Fill with unharmed indices. // Now do the actual splitting. @@ -203,7 +203,7 @@ BinarySpaceTree( { // Initialize the oldFromNew vector correctly. oldFromNew.resize(dataset->n_cols); - for (size_t i = 0; i < dataset->n_cols; i++) + for (size_t i = 0; i < dataset->n_cols; ++i) oldFromNew[i] = i; // Fill with unharmed indices. // Now do the actual splitting. @@ -215,7 +215,7 @@ BinarySpaceTree( // Map the newFromOld indices correctly. newFromOld.resize(dataset->n_cols); - for (size_t i = 0; i < dataset->n_cols; i++) + for (size_t i = 0; i < dataset->n_cols; ++i) newFromOld[oldFromNew[i]] = i; } @@ -315,7 +315,7 @@ BinarySpaceTree( // Map the newFromOld indices correctly. newFromOld.resize(dataset->n_cols); - for (size_t i = 0; i < dataset->n_cols; i++) + for (size_t i = 0; i < dataset->n_cols; ++i) newFromOld[oldFromNew[i]] = i; } diff --git a/src/mlpack/core/tree/binary_space_tree/rp_tree_mean_split_impl.hpp b/src/mlpack/core/tree/binary_space_tree/rp_tree_mean_split_impl.hpp index 6c55008adc..8f7bcbc918 100644 --- a/src/mlpack/core/tree/binary_space_tree/rp_tree_mean_split_impl.hpp +++ b/src/mlpack/core/tree/binary_space_tree/rp_tree_mean_split_impl.hpp @@ -70,7 +70,7 @@ GetAveragePointDistance( { ElemType dist = 0; - for (size_t i = 0; i < samples.n_elem; i++) + for (size_t i = 0; i < samples.n_elem; ++i) for (size_t j = i + 1; j < samples.n_elem; j++) dist += metric::SquaredEuclideanDistance::Evaluate(data.col(samples[i]), data.col(samples[j])); diff --git a/src/mlpack/core/tree/binary_space_tree/ub_tree_split_impl.hpp b/src/mlpack/core/tree/binary_space_tree/ub_tree_split_impl.hpp index 46f784b60c..aa4ddcb266 100644 --- a/src/mlpack/core/tree/binary_space_tree/ub_tree_split_impl.hpp +++ b/src/mlpack/core/tree/binary_space_tree/ub_tree_split_impl.hpp @@ -148,7 +148,7 @@ void UBTreeSplit::InitializeAddresses(const MatType& data) addresses.resize(data.n_cols); // Calculate all addresses. - for (size_t i = 0; i < data.n_cols; i++) + for (size_t i = 0; i < data.n_cols; ++i) { addresses[i].first.zeros(data.n_rows); bound::addr::PointToAddress(addresses[i].first, data.col(i)); @@ -169,13 +169,13 @@ size_t UBTreeSplit::PerformSplit( std::vector newFromOld(data.n_cols); std::vector oldFromNew(data.n_cols); - for (size_t i = 0; i < splitInfo.addresses->size(); i++) + for (size_t i = 0; i < splitInfo.addresses->size(); ++i) { newFromOld[i] = i; oldFromNew[i] = i; } - for (size_t i = 0; i < splitInfo.addresses->size(); i++) + for (size_t i = 0; i < splitInfo.addresses->size(); ++i) { size_t index = (*splitInfo.addresses)[i].second; size_t oldI = oldFromNew[i]; @@ -210,10 +210,10 @@ size_t UBTreeSplit::PerformSplit( { std::vector newFromOld(data.n_cols); - for (size_t i = 0; i < splitInfo.addresses->size(); i++) + for (size_t i = 0; i < splitInfo.addresses->size(); ++i) newFromOld[i] = i; - for (size_t i = 0; i < splitInfo.addresses->size(); i++) + for (size_t i = 0; i < splitInfo.addresses->size(); ++i) { size_t index = (*splitInfo.addresses)[i].second; size_t oldI = oldFromNew[i]; diff --git a/src/mlpack/core/tree/binary_space_tree/vantage_point_split_impl.hpp b/src/mlpack/core/tree/binary_space_tree/vantage_point_split_impl.hpp index b1714b7c7d..1d04659655 100644 --- a/src/mlpack/core/tree/binary_space_tree/vantage_point_split_impl.hpp +++ b/src/mlpack/core/tree/binary_space_tree/vantage_point_split_impl.hpp @@ -55,7 +55,7 @@ SelectVantagePoint(const MetricType& metric, const MatType& data, arma::uvec samples; // Evaluate each candidate - for (size_t i = 0; i < vantagePointCandidates.n_elem; i++) + 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); diff --git a/src/mlpack/core/tree/cellbound_impl.hpp b/src/mlpack/core/tree/cellbound_impl.hpp index d986251ffd..165701d46b 100644 --- a/src/mlpack/core/tree/cellbound_impl.hpp +++ b/src/mlpack/core/tree/cellbound_impl.hpp @@ -74,7 +74,7 @@ inline CellBound::CellBound( minWidth(other.MinWidth()) { // Copy other bounds over. - for (size_t i = 0; i < dim; i++) + for (size_t i = 0; i < dim; ++i) bounds[i] = other.bounds[i]; } @@ -102,7 +102,7 @@ inline CellBound< hiAddress = other.hiAddress; // Now copy each of the bound values. - for (size_t i = 0; i < dim; i++) + for (size_t i = 0; i < dim; ++i) bounds[i] = other.bounds[i]; minWidth = other.MinWidth(); @@ -171,7 +171,7 @@ inline void CellBound::Center( if (!(center.n_elem == dim)) center.set_size(dim); - for (size_t i = 0; i < dim; i++) + for (size_t i = 0; i < dim; ++i) center(i) = bounds[i].Mid(); } @@ -193,7 +193,7 @@ void CellBound::AddBound( hiBound(k, numBounds) = std::numeric_limits::lowest(); } - for (size_t i = 0; i < data.n_cols; i++) + for (size_t i = 0; i < data.n_cols; ++i) { size_t k = 0; // Check if the point is contained in the hyperrectangle. @@ -415,7 +415,7 @@ void CellBound::UpdateAddressBounds(const MatType& data) // If the high address is equal to the lower address. if (row == hiAddress.n_elem) { - for (size_t i = 0; i < dim; i++) + for (size_t i = 0; i < dim; ++i) { loBound(i, 0) = bounds[i].Lo(); hiBound(i, 0) = bounds[i].Hi(); @@ -434,7 +434,7 @@ void CellBound::UpdateAddressBounds(const MatType& data) if ((row == hiAddress.n_elem - 1) && (bit == order - 1)) { // If the addresses differ in the last bit. - for (size_t i = 0; i < dim; i++) + for (size_t i = 0; i < dim; ++i) { loBound(i, 0) = bounds[i].Lo(); hiBound(i, 0) = bounds[i].Hi(); @@ -454,7 +454,7 @@ void CellBound::UpdateAddressBounds(const MatType& data) if (numBounds == 0) { // I think this should never happen. - for (size_t i = 0; i < dim; i++) + for (size_t i = 0; i < dim; ++i) { loBound(i, 0) = bounds[i].Lo(); hiBound(i, 0) = bounds[i].Hi(); @@ -479,7 +479,7 @@ inline ElemType CellBound::MinDistance( ElemType lower, higher; - for (size_t i = 0; i < numBounds; i++) + for (size_t i = 0; i < numBounds; ++i) { ElemType sum = 0; @@ -549,7 +549,7 @@ ElemType CellBound::MinDistance(const CellBound& other) ElemType lower, higher; - for (size_t i = 0; i < numBounds; i++) + for (size_t i = 0; i < numBounds; ++i) for (size_t j = 0; j < other.numBounds; j++) { ElemType sum = 0; @@ -616,7 +616,7 @@ inline ElemType CellBound::MaxDistance( Log::Assert(point.n_elem == dim); - for (size_t i = 0; i < numBounds; i++) + for (size_t i = 0; i < numBounds; ++i) { ElemType sum = 0; for (size_t d = 0; d < dim; d++) @@ -663,7 +663,7 @@ inline ElemType CellBound::MaxDistance( Log::Assert(dim == other.dim); ElemType v; - for (size_t i = 0; i < numBounds; i++) + for (size_t i = 0; i < numBounds; ++i) for (size_t j = 0; j < other.numBounds; j++) { ElemType sum = 0; @@ -714,7 +714,7 @@ CellBound::RangeDistance( ElemType v1, v2, vLo, vHi; - for (size_t i = 0; i < numBounds; i++) + for (size_t i = 0; i < numBounds; ++i) for (size_t j = 0; j < other.numBounds; j++) { ElemType loSum = 0; @@ -793,7 +793,7 @@ CellBound::RangeDistance( Log::Assert(point.n_elem == dim); ElemType v1, v2, vLo, vHi; - for (size_t i = 0; i < numBounds; i++) + for (size_t i = 0; i < numBounds; ++i) { ElemType loSum = 0; ElemType hiSum = 0; @@ -876,7 +876,7 @@ CellBound::operator|=(const MatType& data) arma::Col maxs(arma::max(data, 1)); minWidth = std::numeric_limits::max(); - for (size_t i = 0; i < dim; i++) + for (size_t i = 0; i < dim; ++i) { bounds[i] |= math::RangeType(mins[i], maxs[i]); const ElemType width = bounds[i].Width(); @@ -902,7 +902,7 @@ CellBound::operator|=(const CellBound& other) assert(other.dim == dim); minWidth = std::numeric_limits::max(); - for (size_t i = 0; i < dim; i++) + for (size_t i = 0; i < dim; ++i) { bounds[i] |= other.bounds[i]; const ElemType width = bounds[i].Width(); @@ -918,7 +918,7 @@ CellBound::operator|=(const CellBound& other) if (loAddress[0] > hiAddress[0]) { - for (size_t i = 0; i < dim; i++) + for (size_t i = 0; i < dim; ++i) { loBound(i, 0) = bounds[i].Lo(); hiBound(i, 0) = bounds[i].Hi(); @@ -936,7 +936,7 @@ template inline bool CellBound::Contains( const VecType& point) const { - for (size_t i = 0; i < point.n_elem; i++) + for (size_t i = 0; i < point.n_elem; ++i) { if (!bounds[i].Contains(point(i))) return false; diff --git a/src/mlpack/core/tree/cosine_tree/cosine_tree.cpp b/src/mlpack/core/tree/cosine_tree/cosine_tree.cpp index c7947e14ed..39f6a1e958 100644 --- a/src/mlpack/core/tree/cosine_tree/cosine_tree.cpp +++ b/src/mlpack/core/tree/cosine_tree/cosine_tree.cpp @@ -30,7 +30,7 @@ CosineTree::CosineTree(const arma::mat& dataset) : l2NormsSquared.zeros(numColumns); // Set indices and calculate squared norms of the columns. - for (size_t i = 0; i < numColumns; i++) + for (size_t i = 0; i < numColumns; ++i) { indices[i] = i; double l2Norm = arma::norm(dataset.col(i), 2); @@ -60,7 +60,7 @@ CosineTree::CosineTree(CosineTree& parentNode, l2NormsSquared.zeros(numColumns); // Set indices and squared norms of the columns. - for (size_t i = 0; i < numColumns; i++) + for (size_t i = 0; i < numColumns; ++i) { indices[i] = parentNode.indices[subIndices[i]]; l2NormsSquared(i) = parentNode.l2NormsSquared(subIndices[i]); @@ -381,7 +381,7 @@ void CosineTree::ModifiedGramSchmidt(CosineNodeQueue& treeQueue, // For every vector in the current basis, remove its projection from the // centroid. - for ( ; i != treeQueue.end(); i++) + for ( ; i != treeQueue.end(); ++i) { currentNode = *i; @@ -430,7 +430,7 @@ double CosineTree::MonteCarloError(CosineTree* node, projectionSize = treeQueue.size(); // For each sample, calculate the weighted projection onto the current basis. - for (size_t i = 0; i < numSamples; i++) + for (size_t i = 0; i < numSamples; ++i) { // Initialize projection as a vector of zeros. arma::vec projection; @@ -497,7 +497,7 @@ void CosineTree::ConstructBasis(CosineNodeQueue& treeQueue) // Transfer basis vectors from the queue to the basis matrix. size_t j = 0; - for ( ; i != treeQueue.end(); i++, j++) + for ( ; i != treeQueue.end(); ++i, j++) { currentNode = *i; basis.col(j) = currentNode->BasisVector(); @@ -528,7 +528,7 @@ void CosineTree::CosineNodeSplit() // We deviate from the paper here and use < instead of <= in order to handle // the edge case where cosineMax == cosineMin, and force there to be at least // one point in the right node. - for (size_t i = 0; i < numColumns; i++) + for (size_t i = 0; i < numColumns; ++i) { if (cosineMax - cosines(i) < cosines(i) - cosineMin) leftIndices.push_back(i); @@ -550,7 +550,7 @@ void CosineTree::ColumnSamplesLS(std::vector& sampledIndices, cDistribution.zeros(numColumns + 1); // Calculate cumulative length-squared distribution for the node. - for (size_t i = 0; i < numColumns; i++) + for (size_t i = 0; i < numColumns; ++i) { cDistribution(i + 1) = cDistribution(i) + (l2NormsSquared(i) / frobNormSquared); @@ -560,7 +560,7 @@ void CosineTree::ColumnSamplesLS(std::vector& sampledIndices, sampledIndices.resize(numSamples); probabilities.zeros(numSamples); - for (size_t i = 0; i < numSamples; i++) + for (size_t i = 0; i < numSamples; ++i) { // Generate a random value for sampling. double randValue = arma::randu(); @@ -586,7 +586,7 @@ size_t CosineTree::ColumnSampleLS() cDistribution.zeros(numColumns + 1); // Calculate cumulative length-squared distribution for the node. - for (size_t i = 0; i < numColumns; i++) + for (size_t i = 0; i < numColumns; ++i) { cDistribution(i + 1) = cDistribution(i) + (l2NormsSquared(i) / frobNormSquared); @@ -633,7 +633,7 @@ void CosineTree::CalculateCosines(arma::vec& cosines) // Initialize cosine vector as a vector of zeros. cosines.zeros(numColumns); - for (size_t i = 0; i < numColumns; i++) + for (size_t i = 0; i < numColumns; ++i) { // If norm is zero, store cosine value as zero. Else, calculate cosine value // between two vectors. @@ -656,7 +656,7 @@ void CosineTree::CalculateCentroid() centroid.zeros(dataset->n_rows); // Calculate centroid of columns in the node. - for (size_t i = 0; i < numColumns; i++) + for (size_t i = 0; i < numColumns; ++i) { centroid += dataset->col(indices[i]); } diff --git a/src/mlpack/core/tree/hrectbound_impl.hpp b/src/mlpack/core/tree/hrectbound_impl.hpp index cf9cb7aa0a..adcdb4a384 100644 --- a/src/mlpack/core/tree/hrectbound_impl.hpp +++ b/src/mlpack/core/tree/hrectbound_impl.hpp @@ -52,7 +52,7 @@ inline HRectBound::HRectBound( minWidth(other.MinWidth()) { // Copy other bounds over. - for (size_t i = 0; i < dim; i++) + for (size_t i = 0; i < dim; ++i) bounds[i] = other[i]; } @@ -76,7 +76,7 @@ inline HRectBound< } // Now copy each of the bound values. - for (size_t i = 0; i < dim; i++) + for (size_t i = 0; i < dim; ++i) bounds[i] = other[i]; minWidth = other.MinWidth(); @@ -116,7 +116,7 @@ inline HRectBound::~HRectBound() template inline void HRectBound::Clear() { - for (size_t i = 0; i < dim; i++) + for (size_t i = 0; i < dim; ++i) bounds[i] = math::RangeType(); minWidth = 0; } @@ -134,7 +134,7 @@ inline void HRectBound::Center( if (!(center.n_elem == dim)) center.set_size(dim); - for (size_t i = 0; i < dim; i++) + for (size_t i = 0; i < dim; ++i) center(i) = bounds[i].Mid(); } @@ -516,7 +516,7 @@ HRectBound::operator|=(const MatType& data) arma::Col maxs(max(data, 1)); minWidth = std::numeric_limits::max(); - for (size_t i = 0; i < dim; i++) + for (size_t i = 0; i < dim; ++i) { bounds[i] |= math::RangeType(mins[i], maxs[i]); const ElemType width = bounds[i].Width(); @@ -537,7 +537,7 @@ HRectBound::operator|=(const HRectBound& other) assert(other.dim == dim); minWidth = std::numeric_limits::max(); - for (size_t i = 0; i < dim; i++) + for (size_t i = 0; i < dim; ++i) { bounds[i] |= other.bounds[i]; const ElemType width = bounds[i].Width(); @@ -556,7 +556,7 @@ template inline bool HRectBound::Contains( const VecType& point) const { - for (size_t i = 0; i < point.n_elem; i++) + for (size_t i = 0; i < point.n_elem; ++i) { if (!bounds[i].Contains(point(i))) return false; @@ -572,7 +572,7 @@ template inline bool HRectBound::Contains( const HRectBound& bound) const { - for (size_t i = 0; i < dim; i++) + for (size_t i = 0; i < dim; ++i) { const math::RangeType& r_a = bounds[i]; const math::RangeType& r_b = bound.bounds[i]; diff --git a/src/mlpack/core/tree/octree/octree_impl.hpp b/src/mlpack/core/tree/octree/octree_impl.hpp index 017034c54e..ae7bbc8adb 100644 --- a/src/mlpack/core/tree/octree/octree_impl.hpp +++ b/src/mlpack/core/tree/octree/octree_impl.hpp @@ -141,7 +141,7 @@ Octree::Octree( // Map the newFromOld indices correctly. newFromOld.resize(this->dataset->n_cols); - for (size_t i = 0; i < this->dataset->n_cols; i++) + for (size_t i = 0; i < this->dataset->n_cols; ++i) newFromOld[oldFromNew[i]] = i; } @@ -267,7 +267,7 @@ Octree::Octree( // Map the newFromOld indices correctly. newFromOld.resize(this->dataset->n_cols); - for (size_t i = 0; i < this->dataset->n_cols; i++) + for (size_t i = 0; i < this->dataset->n_cols; ++i) newFromOld[oldFromNew[i]] = i; } diff --git a/src/mlpack/core/tree/rectangle_tree/discrete_hilbert_value_impl.hpp b/src/mlpack/core/tree/rectangle_tree/discrete_hilbert_value_impl.hpp index c3af2d79ac..c261746faa 100644 --- a/src/mlpack/core/tree/rectangle_tree/discrete_hilbert_value_impl.hpp +++ b/src/mlpack/core/tree/rectangle_tree/discrete_hilbert_value_impl.hpp @@ -163,7 +163,7 @@ CalculateValue(const VecType& pt, // Calculate the number of bits for the mantissa. const int numMantBits = order - numExpBits - 1; - for (size_t i = 0; i < pt.n_rows; i++) + for (size_t i = 0; i < pt.n_rows; ++i) { int e; VecElemType normalizedVal = std::frexp(pt(i), &e); @@ -216,7 +216,7 @@ CalculateValue(const VecType& pt, { HilbertElemType P = Q - 1; - for (size_t i = 0; i < pt.n_rows; i++) + for (size_t i = 0; i < pt.n_rows; ++i) { if (res(i) & Q) // Invert. res(0) ^= P; @@ -230,7 +230,7 @@ CalculateValue(const VecType& pt, } // Gray encode. - for (size_t i = 1; i < pt.n_rows; i++) + for (size_t i = 1; i < pt.n_rows; ++i) res(i) ^= res(i - 1); HilbertElemType t = 0; @@ -240,13 +240,13 @@ CalculateValue(const VecType& pt, if (res(pt.n_rows - 1) & Q) t ^= Q - 1; - for (size_t i = 0; i < pt.n_rows; i++) + for (size_t i = 0; i < pt.n_rows; ++i) res(i) ^= t; // We should rearrange bits in order to compare two Hilbert values faster. arma::Col rearrangedResult(pt.n_rows, arma::fill::zeros); - for (size_t i = 0; i < order; i++) + for (size_t i = 0; i < order; ++i) for (size_t j = 0; j < pt.n_rows; j++) { size_t bit = (i * pt.n_rows + j) % order; @@ -264,7 +264,7 @@ int DiscreteHilbertValue:: CompareValues(const arma::Col& value1, const arma::Col& value2) { - for (size_t i = 0; i < value1.n_rows; i++) + for (size_t i = 0; i < value1.n_rows; ++i) { if (value1(i) > value2(i)) return 1; @@ -355,7 +355,7 @@ InsertPoint(TreeType *node, if (node->IsLeaf()) { // Find an appropriate place. - for (i = 0; i < numValues; i++) + for (i = 0; i < numValues; ++i) if (CompareValues(localHilbertValues->col(i), *valueToInsert) > 0) break; @@ -473,14 +473,14 @@ void DiscreteHilbertValue::RedistributeHilbertValues( { // We need to update the local dataset if points were redistributed. size_t numPoints = 0; - for (size_t i = firstSibling; i <= lastSibling; i++) + for (size_t i = firstSibling; i <= lastSibling; ++i) numPoints += parent->Child(i).NumPoints(); // Copy the local Hilbert values. arma::Mat tmp(localHilbertValues->n_rows, numPoints); size_t iPoint = 0; - for (size_t i = firstSibling; i<= lastSibling; i++) + for (size_t i = firstSibling; i<= lastSibling; ++i) { DiscreteHilbertValue &value = parent->Child(i).AuxiliaryInfo().HilbertValue(); @@ -496,7 +496,7 @@ void DiscreteHilbertValue::RedistributeHilbertValues( iPoint = 0; // Redistribute the Hilbert values. - for (size_t i = firstSibling; i <= lastSibling; i++) + for (size_t i = firstSibling; i <= lastSibling; ++i) { DiscreteHilbertValue &value = parent->Child(i).AuxiliaryInfo().HilbertValue(); diff --git a/src/mlpack/core/tree/rectangle_tree/dual_tree_traverser_impl.hpp b/src/mlpack/core/tree/rectangle_tree/dual_tree_traverser_impl.hpp index be0e8ea3dd..f6569890d6 100644 --- a/src/mlpack/core/tree/rectangle_tree/dual_tree_traverser_impl.hpp +++ b/src/mlpack/core/tree/rectangle_tree/dual_tree_traverser_impl.hpp @@ -105,7 +105,7 @@ DualTreeTraverser::Traverse(RectangleTree& queryNode, // We sort the children of the reference node by their scores. std::vector nodesAndScores(referenceNode.NumChildren()); - for (size_t i = 0; i < referenceNode.NumChildren(); i++) + for (size_t i = 0; i < referenceNode.NumChildren(); ++i) { rule.TraversalInfo() = traversalInfo; nodesAndScores[i].node = &(referenceNode.Child(i)); @@ -116,7 +116,7 @@ DualTreeTraverser::Traverse(RectangleTree& queryNode, std::sort(nodesAndScores.begin(), nodesAndScores.end(), nodeComparator); numScores += nodesAndScores.size(); - for (size_t i = 0; i < nodesAndScores.size(); i++) + for (size_t i = 0; i < nodesAndScores.size(); ++i) { rule.TraversalInfo() = nodesAndScores[i].travInfo; if (rule.Rescore(queryNode, *(nodesAndScores[i].node), @@ -140,7 +140,7 @@ DualTreeTraverser::Traverse(RectangleTree& queryNode, { // We sort the children of the reference node by their scores. std::vector nodesAndScores(referenceNode.NumChildren()); - for (size_t i = 0; i < referenceNode.NumChildren(); i++) + for (size_t i = 0; i < referenceNode.NumChildren(); ++i) { rule.TraversalInfo() = traversalInfo; nodesAndScores[i].node = &(referenceNode.Child(i)); @@ -151,7 +151,7 @@ DualTreeTraverser::Traverse(RectangleTree& queryNode, std::sort(nodesAndScores.begin(), nodesAndScores.end(), nodeComparator); numScores += nodesAndScores.size(); - for (size_t i = 0; i < nodesAndScores.size(); i++) + for (size_t i = 0; i < nodesAndScores.size(); ++i) { rule.TraversalInfo() = nodesAndScores[i].travInfo; if (rule.Rescore(queryNode.Child(j), *(nodesAndScores[i].node), diff --git a/src/mlpack/core/tree/rectangle_tree/hilbert_r_tree_auxiliary_information_impl.hpp b/src/mlpack/core/tree/rectangle_tree/hilbert_r_tree_auxiliary_information_impl.hpp index d7eea05431..156ab56dac 100644 --- a/src/mlpack/core/tree/rectangle_tree/hilbert_r_tree_auxiliary_information_impl.hpp +++ b/src/mlpack/core/tree/rectangle_tree/hilbert_r_tree_auxiliary_information_impl.hpp @@ -128,7 +128,7 @@ HandlePointDeletion(TreeType* node, const size_t localIndex) // Update the largest Hilbert value. hilbertValue.DeletePoint(node, localIndex); - for (size_t i = localIndex + 1; localIndex < node->NumPoints(); i++) + for (size_t i = localIndex + 1; localIndex < node->NumPoints(); ++i) node->Point(i - 1) = node->Point(i); node->NumPoints()--; @@ -143,7 +143,7 @@ HandleNodeRemoval(TreeType* node, const size_t nodeIndex) // Update the largest Hilbert value. hilbertValue.RemoveNode(node, nodeIndex); - for (size_t i = nodeIndex + 1; nodeIndex < node->NumChildren(); i++) + for (size_t i = nodeIndex + 1; nodeIndex < node->NumChildren(); ++i) node->children[i - 1] = node->children[i]; node->NumChildren()--; diff --git a/src/mlpack/core/tree/rectangle_tree/hilbert_r_tree_split_impl.hpp b/src/mlpack/core/tree/rectangle_tree/hilbert_r_tree_split_impl.hpp index 600665c7bb..5ad4c666ed 100644 --- a/src/mlpack/core/tree/rectangle_tree/hilbert_r_tree_split_impl.hpp +++ b/src/mlpack/core/tree/rectangle_tree/hilbert_r_tree_split_impl.hpp @@ -218,7 +218,7 @@ RedistributeNodesEvenly(const TreeType *parent, size_t numChildren = 0; size_t numChildrenPerNode, numRestChildren; - for (size_t i = firstSibling; i <= lastSibling; i++) + for (size_t i = firstSibling; i <= lastSibling; ++i) numChildren += parent->Child(i).NumChildren(); numChildrenPerNode = numChildren / (lastSibling - firstSibling + 1); @@ -228,7 +228,7 @@ RedistributeNodesEvenly(const TreeType *parent, // Copy children's children in order to redistribute them. size_t iChild = 0; - for (size_t i = firstSibling; i <= lastSibling; i++) + for (size_t i = firstSibling; i <= lastSibling; ++i) { for (size_t j = 0; j < parent->Child(i).NumChildren(); j++) { @@ -238,7 +238,7 @@ RedistributeNodesEvenly(const TreeType *parent, } iChild = 0; - for (size_t i = firstSibling; i <= lastSibling; i++) + for (size_t i = firstSibling; i <= lastSibling; ++i) { // Since we redistribute children of a sibling we should recalculate the // bound. @@ -286,7 +286,7 @@ RedistributePointsEvenly(TreeType* parent, size_t numPoints = 0; size_t numPointsPerNode, numRestPoints; - for (size_t i = firstSibling; i <= lastSibling; i++) + for (size_t i = firstSibling; i <= lastSibling; ++i) numPoints += parent->Child(i).NumPoints(); numPointsPerNode = numPoints / (lastSibling - firstSibling + 1); @@ -296,14 +296,14 @@ RedistributePointsEvenly(TreeType* parent, // Copy children's points in order to redistribute them. size_t iPoint = 0; - for (size_t i = firstSibling; i <= lastSibling; i++) + for (size_t i = firstSibling; i <= lastSibling; ++i) { for (size_t j = 0; j < parent->Child(i).NumPoints(); j++) points[iPoint++] = parent->Child(i).Point(j); } iPoint = 0; - for (size_t i = firstSibling; i <= lastSibling; i++) + for (size_t i = firstSibling; i <= lastSibling; ++i) { // Since we redistribute points of a sibling we should recalculate the // bound. diff --git a/src/mlpack/core/tree/rectangle_tree/minimal_coverage_sweep_impl.hpp b/src/mlpack/core/tree/rectangle_tree/minimal_coverage_sweep_impl.hpp index a9efbcecd6..4f08e929fb 100644 --- a/src/mlpack/core/tree/rectangle_tree/minimal_coverage_sweep_impl.hpp +++ b/src/mlpack/core/tree/rectangle_tree/minimal_coverage_sweep_impl.hpp @@ -30,7 +30,7 @@ SweepNonLeafNode(const size_t axis, std::vector> sorted(node->NumChildren()); - for (size_t i = 0; i < node->NumChildren(); i++) + for (size_t i = 0; i < node->NumChildren(); ++i) { sorted[i].first = SplitPolicy::Bound(node->Child(i))[axis].Hi(); sorted[i].second = i; @@ -66,10 +66,10 @@ SweepNonLeafNode(const size_t axis, BoundType bound2(node->Bound().Dim()); // Find bounds of two resulting nodes. - for (size_t i = 0; i < splitPointer; i++) + for (size_t i = 0; i < splitPointer; ++i) bound1 |= node->Child(sorted[i].second).Bound(); - for (size_t i = splitPointer; i < node->NumChildren(); i++) + for (size_t i = splitPointer; i < node->NumChildren(); ++i) bound2 |= node->Child(sorted[i].second).Bound(); @@ -96,7 +96,7 @@ SweepLeafNode(const size_t axis, sorted.resize(node->Count()); - for (size_t i = 0; i < node->NumPoints(); i++) + for (size_t i = 0; i < node->NumPoints(); ++i) { sorted[i].first = node->Dataset().col(node->Point(i))[axis]; sorted[i].second = i; @@ -122,10 +122,10 @@ SweepLeafNode(const size_t axis, BoundType bound2(node->Bound().Dim()); // Find bounds of two resulting nodes. - for (size_t i = 0; i < splitPointer; i++) + for (size_t i = 0; i < splitPointer; ++i) bound1 |= node->Dataset().col(node->Point(sorted[i].second)); - for (size_t i = splitPointer; i < node->NumChildren(); i++) + for (size_t i = splitPointer; i < node->NumChildren(); ++i) bound2 |= node->Dataset().col(node->Point(sorted[i].second)); // Evaluate the cost of the split i.e. calculate the total coverage @@ -145,7 +145,7 @@ CheckNonLeafSweep(const TreeType* node, size_t numTreeTwoChildren = 0; // Calculate the number of children in the resulting nodes. - for (size_t i = 0; i < node->NumChildren(); i++) + for (size_t i = 0; i < node->NumChildren(); ++i) { const TreeType& child = node->Child(i); int policy = SplitPolicy::GetSplitPolicy(child, cutAxis, cut); @@ -178,7 +178,7 @@ CheckLeafSweep(const TreeType* node, size_t numTreeTwoPoints = 0; // Calculate the number of points in the resulting nodes. - for (size_t i = 0; i < node->NumPoints(); i++) + for (size_t i = 0; i < node->NumPoints(); ++i) { if (node->Dataset().col(node->Point(i))[cutAxis] <= cut) numTreeOnePoints++; diff --git a/src/mlpack/core/tree/rectangle_tree/minimal_splits_number_sweep_impl.hpp b/src/mlpack/core/tree/rectangle_tree/minimal_splits_number_sweep_impl.hpp index 9d3e8c28f6..1d628699dc 100644 --- a/src/mlpack/core/tree/rectangle_tree/minimal_splits_number_sweep_impl.hpp +++ b/src/mlpack/core/tree/rectangle_tree/minimal_splits_number_sweep_impl.hpp @@ -29,7 +29,7 @@ size_t MinimalSplitsNumberSweep::SweepNonLeafNode( std::vector> sorted(node->NumChildren()); - for (size_t i = 0; i < node->NumChildren(); i++) + for (size_t i = 0; i < node->NumChildren(); ++i) { sorted[i].first = SplitPolicy::Bound(node->Child(i))[axis].Hi(); sorted[i].second = i; @@ -46,7 +46,7 @@ size_t MinimalSplitsNumberSweep::SweepNonLeafNode( size_t minCost = SIZE_MAX; // Find a split with the minimal cost. - for (size_t i = 0; i < sorted.size(); i++) + for (size_t i = 0; i < sorted.size(); ++i) { size_t numTreeOneChildren = 0; size_t numTreeTwoChildren = 0; diff --git a/src/mlpack/core/tree/rectangle_tree/r_plus_tree_split_impl.hpp b/src/mlpack/core/tree/rectangle_tree/r_plus_tree_split_impl.hpp index 0293f341e0..e8f6119c3c 100644 --- a/src/mlpack/core/tree/rectangle_tree/r_plus_tree_split_impl.hpp +++ b/src/mlpack/core/tree/rectangle_tree/r_plus_tree_split_impl.hpp @@ -100,7 +100,7 @@ SplitLeafNode(TreeType* tree, std::vector& relevels) TreeType* parent = tree->Parent(); size_t i = 0; while (parent->children[i] != tree) - i++; + ++i; assert(i < parent->NumChildren()); @@ -170,7 +170,7 @@ SplitNonLeafNode(TreeType* tree, std::vector& relevels) TreeType* parent = tree->Parent(); size_t i = 0; while (parent->children[i] != tree) - i++; + ++i; assert(i < parent->NumChildren()); @@ -216,7 +216,7 @@ void RPlusTreeSplit::SplitLeafNodeAlongPartition( } // Insert points into the corresponding subtree. - for (size_t i = 0; i < tree->NumPoints(); i++) + for (size_t i = 0; i < tree->NumPoints(); ++i) { if (tree->Dataset().col(tree->Point(i))[cutAxis] <= cut) { @@ -254,7 +254,7 @@ void RPlusTreeSplit::SplitNonLeafNodeAlongPartition( tree->AuxiliaryInfo().SplitAuxiliaryInfo(treeOne, treeTwo, cutAxis, cut); // Insert children into the corresponding subtree. - for (size_t i = 0; i < tree->NumChildren(); i++) + for (size_t i = 0; i < tree->NumChildren(); ++i) { TreeType* child = tree->children[i]; int policy = SplitPolicyType::GetSplitPolicy(*child, cutAxis, cut); @@ -313,7 +313,7 @@ AddFakeNodes(const TreeType* tree, TreeType* emptyTree) size_t numDescendantNodes = tree->TreeDepth() - 1; TreeType* node = emptyTree; - for (size_t i = 0; i < numDescendantNodes; i++) + for (size_t i = 0; i < numDescendantNodes; ++i) { TreeType* child = new TreeType(node); node->children[node->NumChildren()++] = child; diff --git a/src/mlpack/core/tree/rectangle_tree/r_star_tree_descent_heuristic_impl.hpp b/src/mlpack/core/tree/rectangle_tree/r_star_tree_descent_heuristic_impl.hpp index 52bde99760..a9725005f0 100644 --- a/src/mlpack/core/tree/rectangle_tree/r_star_tree_descent_heuristic_impl.hpp +++ b/src/mlpack/core/tree/rectangle_tree/r_star_tree_descent_heuristic_impl.hpp @@ -35,7 +35,7 @@ inline size_t RStarTreeDescentHeuristic::ChooseDescentNode( // If its children are leaf nodes, use minimum overlap to choose. size_t bestIndex = 0; - for (size_t i = 0; i < node->NumChildren(); i++) + for (size_t i = 0; i < node->NumChildren(); ++i) { ElemType sc = 0; for (size_t j = 0; j < node->NumChildren(); j++) @@ -89,7 +89,7 @@ inline size_t RStarTreeDescentHeuristic::ChooseDescentNode( if (tiedOne) { // If the first heuristic was tied, we need to eliminate garbage values. - for (size_t i = 0; i < scores.size(); i++) + for (size_t i = 0; i < scores.size(); ++i) scores[i] = std::numeric_limits::max(); } @@ -98,7 +98,7 @@ inline size_t RStarTreeDescentHeuristic::ChooseDescentNode( size_t bestIndex = 0; bool tied = false; - for (size_t i = 0; i < node->NumChildren(); i++) + for (size_t i = 0; i < node->NumChildren(); ++i) { if (!tiedOne || originalScores[i] == origMinScore) { @@ -136,7 +136,7 @@ inline size_t RStarTreeDescentHeuristic::ChooseDescentNode( // We break ties by choosing the smallest bound. ElemType minVol = std::numeric_limits::max(); bestIndex = 0; - for (size_t i = 0; i < scores.size(); i++) + for (size_t i = 0; i < scores.size(); ++i) { if (scores[i] == minScore) { @@ -173,7 +173,7 @@ inline size_t RStarTreeDescentHeuristic::ChooseDescentNode( size_t bestIndex = 0; bool tied = false; - for (size_t i = 0; i < node->NumChildren(); i++) + for (size_t i = 0; i < node->NumChildren(); ++i) { ElemType v1 = 1.0; ElemType v2 = 1.0; @@ -209,7 +209,7 @@ inline size_t RStarTreeDescentHeuristic::ChooseDescentNode( // We break ties by choosing the smallest bound. ElemType minVol = std::numeric_limits::max(); bestIndex = 0; - for (size_t i = 0; i < scores.size(); i++) + for (size_t i = 0; i < scores.size(); ++i) { if (scores[i] == minScore) { diff --git a/src/mlpack/core/tree/rectangle_tree/r_star_tree_split_impl.hpp b/src/mlpack/core/tree/rectangle_tree/r_star_tree_split_impl.hpp index 6452cb92b2..0a196dad09 100644 --- a/src/mlpack/core/tree/rectangle_tree/r_star_tree_split_impl.hpp +++ b/src/mlpack/core/tree/rectangle_tree/r_star_tree_split_impl.hpp @@ -50,7 +50,7 @@ size_t RStarTreeSplit::ReinsertPoints(TreeType* tree, std::vector> sorted(tree->Count()); arma::Col center; tree->Bound().Center(center); - for (size_t i = 0; i < sorted.size(); i++) + for (size_t i = 0; i < sorted.size(); ++i) { sorted[i].first = tree->Metric().Evaluate(center, tree->Dataset().col(tree->Point(i))); @@ -60,7 +60,7 @@ size_t RStarTreeSplit::ReinsertPoints(TreeType* tree, std::sort(sorted.begin(), sorted.end(), PairComp); // Remove the points furthest from the center of the node. - for (size_t i = 0; i < p; i++) + for (size_t i = 0; i < p; ++i) root->DeletePoint(sorted[sorted.size() - 1 - i].second, relevels); // Now reinsert the points, but reverse the order---insert the closest to @@ -111,7 +111,7 @@ void RStarTreeSplit::PickLeafSplit(TreeType* tree, arma::Col margins(numPossibleSplits, arma::fill::zeros); arma::Col overlaps(numPossibleSplits, arma::fill::zeros); - for (size_t i = 0; i < numPossibleSplits; i++) + for (size_t i = 0; i < numPossibleSplits; ++i) { // The ith arrangement is obtained by placing the first // tree->MinLeafSize() + i points in one rectangle and the rest in @@ -145,7 +145,7 @@ void RStarTreeSplit::PickLeafSplit(TreeType* tree, size_t areaIndex = 0; bool tiedOnOverlap = false; - for (size_t i = 1; i < areas.n_elem; i++) + for (size_t i = 1; i < areas.n_elem; ++i) { if (overlaps[i] < overlaps[overlapIndex]) { @@ -198,7 +198,7 @@ void RStarTreeSplit::SplitLeafNode(TreeType *tree, std::vector& relevels) * dimension to prepare for reinsertion of points into the new nodes. */ std::vector> sorted(tree->Count()); - for (size_t i = 0; i < sorted.size(); i++) + for (size_t i = 0; i < sorted.size(); ++i) { sorted[i].first = tree->Dataset().col(tree->Point(i))[bestAxis]; sorted[i].second = tree->Point(i); @@ -232,7 +232,7 @@ void RStarTreeSplit::SplitLeafNode(TreeType *tree, std::vector& relevels) tree->bound.Clear(); // Insert the points into the appropriate tree. - for (size_t i = 0; i < numPoints; i++) + for (size_t i = 0; i < numPoints; ++i) { if (i < bestIndex + tree->MinLeafSize()) treeOne->InsertPoint(sorted[i].second); @@ -298,7 +298,7 @@ bool RStarTreeSplit::SplitNonLeafNode( // bound. arma::Col loDimValues(tree->NumChildren()); arma::Col hiDimValues(tree->NumChildren()); - for (size_t i = 0; i < tree->NumChildren(); i++) + for (size_t i = 0; i < tree->NumChildren(); ++i) { loDimValues[i] = tree->Child(i).Bound()[j].Lo(); hiDimValues[i] = tree->Child(i).Bound()[j].Hi(); @@ -381,7 +381,7 @@ bool RStarTreeSplit::SplitNonLeafNode( // Find the best possible split (and whether it is on the low values or // high values of the bounds). - for (size_t i = 1; i < numPossibleSplits; i++) + for (size_t i = 1; i < numPossibleSplits; ++i) { // Check bounds. if (overlaps[2 * i + indexOffset] < overlaps[overlapIndex]) @@ -458,12 +458,12 @@ bool RStarTreeSplit::SplitNonLeafNode( // We have to update the children of treeOne so that they record the correct // parent. - for (size_t i = 0; i < treeOne->NumChildren(); i++) + for (size_t i = 0; i < treeOne->NumChildren(); ++i) treeOne->children[i]->Parent() = treeOne; } // Update the children of treeTwo to have the correct parent. - for (size_t i = 0; i < treeTwo->NumChildren(); i++) + for (size_t i = 0; i < treeTwo->NumChildren(); ++i) treeTwo->children[i]->Parent() = treeTwo; // If we have overflowed hte parent's children, then we need to split that diff --git a/src/mlpack/core/tree/rectangle_tree/r_tree_descent_heuristic_impl.hpp b/src/mlpack/core/tree/rectangle_tree/r_tree_descent_heuristic_impl.hpp index abb04566d6..47029f6716 100644 --- a/src/mlpack/core/tree/rectangle_tree/r_tree_descent_heuristic_impl.hpp +++ b/src/mlpack/core/tree/rectangle_tree/r_tree_descent_heuristic_impl.hpp @@ -29,7 +29,7 @@ inline size_t RTreeDescentHeuristic::ChooseDescentNode(const TreeType* node, int bestIndex = 0; ElemType bestVol = 0.0; - for (size_t i = 0; i < node->NumChildren(); i++) + for (size_t i = 0; i < node->NumChildren(); ++i) { ElemType v1 = 1.0; ElemType v2 = 1.0; @@ -73,7 +73,7 @@ inline size_t RTreeDescentHeuristic::ChooseDescentNode( int bestIndex = 0; ElemType bestVol = 0.0; - for (size_t i = 0; i < node->NumChildren(); i++) + for (size_t i = 0; i < node->NumChildren(); ++i) { ElemType v1 = 1.0; ElemType v2 = 1.0; diff --git a/src/mlpack/core/tree/rectangle_tree/r_tree_split_impl.hpp b/src/mlpack/core/tree/rectangle_tree/r_tree_split_impl.hpp index 02b1427c85..8eda6ae1b0 100644 --- a/src/mlpack/core/tree/rectangle_tree/r_tree_split_impl.hpp +++ b/src/mlpack/core/tree/rectangle_tree/r_tree_split_impl.hpp @@ -130,7 +130,7 @@ bool RTreeSplit::SplitNonLeafNode(TreeType *tree, std::vector& relevels) par->children[index] = treeOne; par->children[par->NumChildren()++] = treeTwo; - for (size_t i = 0; i < par->NumChildren(); i++) + for (size_t i = 0; i < par->NumChildren(); ++i) assert(par->children[i] != tree); // We only add one at a time, so should only need to test for equality just in @@ -142,10 +142,10 @@ bool RTreeSplit::SplitNonLeafNode(TreeType *tree, std::vector& relevels) // We have to update the children of each of these new nodes so that they // record the correct parent. - for (size_t i = 0; i < treeOne->NumChildren(); i++) + for (size_t i = 0; i < treeOne->NumChildren(); ++i) treeOne->children[i]->Parent() = treeOne; - for (size_t i = 0; i < treeTwo->NumChildren(); i++) + for (size_t i = 0; i < treeTwo->NumChildren(); ++i) treeTwo->children[i]->Parent() = treeTwo; assert(treeOne->NumChildren() <= treeOne->MaxNumChildren()); @@ -170,7 +170,7 @@ void RTreeSplit::GetPointSeeds(const TreeType *tree, int& iRet, int& jRet) // same node. Because we are just using points, we will simply choose the two // that would create the most voluminous hyperrectangle. typename TreeType::ElemType worstPairScore = -1.0; - for (size_t i = 0; i < tree->Count(); i++) + for (size_t i = 0; i < tree->Count(); ++i) { for (size_t j = i + 1; j < tree->Count(); j++) { @@ -199,7 +199,7 @@ void RTreeSplit::GetBoundSeeds(const TreeType *tree, int& iRet, int& jRet) typedef typename TreeType::ElemType ElemType; ElemType worstPairScore = -1.0; - for (size_t i = 0; i < tree->NumChildren(); i++) + for (size_t i = 0; i < tree->NumChildren(); ++i) { for (size_t j = i + 1; j < tree->NumChildren(); j++) { @@ -283,7 +283,7 @@ void RTreeSplit::AssignPointDestNode(TreeType* oldTree, // First, calculate the starting volume. ElemType volOne = 1.0; ElemType volTwo = 1.0; - for (size_t i = 0; i < oldTree->Bound().Dim(); i++) + for (size_t i = 0; i < oldTree->Bound().Dim(); ++i) { volOne *= treeOne->Bound()[i].Width(); volTwo *= treeTwo->Bound()[i].Width(); @@ -295,7 +295,7 @@ void RTreeSplit::AssignPointDestNode(TreeType* oldTree, { ElemType newVolOne = 1.0; ElemType newVolTwo = 1.0; - for (size_t i = 0; i < oldTree->Bound().Dim(); i++) + for (size_t i = 0; i < oldTree->Bound().Dim(); ++i) { ElemType c = oldTree->Dataset().col(oldTree->Point(index))[i]; newVolOne *= treeOne->Bound()[i].Contains(c) ? @@ -348,12 +348,12 @@ void RTreeSplit::AssignPointDestNode(TreeType* oldTree, { if (numAssignedOne < numAssignedTwo) { - for (size_t i = 0; i < end; i++) + for (size_t i = 0; i < end; ++i) treeOne->InsertPoint(oldTree->Point(i)); } else { - for (size_t i = 0; i < end; i++) + for (size_t i = 0; i < end; ++i) treeTwo->InsertPoint(oldTree->Point(i)); } } @@ -374,7 +374,7 @@ void RTreeSplit::AssignNodeDestNode(TreeType* oldTree, assert(intI != intJ); - for (size_t i = 0; i < oldTree->NumChildren(); i++) + for (size_t i = 0; i < oldTree->NumChildren(); ++i) for (size_t j = i + 1; j < oldTree->NumChildren(); j++) assert(oldTree->children[i] != oldTree->children[j]); @@ -397,14 +397,14 @@ void RTreeSplit::AssignNodeDestNode(TreeType* oldTree, assert(treeOne->NumChildren() == 1); assert(treeTwo->NumChildren() == 1); - for (size_t i = 0; i < end; i++) + for (size_t i = 0; i < end; ++i) for (size_t j = i + 1; j < end; j++) assert(oldTree->children[i] != oldTree->children[j]); - for (size_t i = 0; i < end; i++) + for (size_t i = 0; i < end; ++i) assert(oldTree->children[i] != treeOne->children[0]); - for (size_t i = 0; i < end; i++) + for (size_t i = 0; i < end; ++i) assert(oldTree->children[i] != treeTwo->children[0]); size_t numAssignTreeOne = 1; @@ -424,7 +424,7 @@ void RTreeSplit::AssignNodeDestNode(TreeType* oldTree, // new rectangles. ElemType volOne = 1.0; ElemType volTwo = 1.0; - for (size_t i = 0; i < oldTree->Bound().Dim(); i++) + for (size_t i = 0; i < oldTree->Bound().Dim(); ++i) { volOne *= treeOne->Bound()[i].Width(); volTwo *= treeTwo->Bound()[i].Width(); @@ -434,7 +434,7 @@ void RTreeSplit::AssignNodeDestNode(TreeType* oldTree, { ElemType newVolOne = 1.0; ElemType newVolTwo = 1.0; - for (size_t i = 0; i < oldTree->Bound().Dim(); i++) + for (size_t i = 0; i < oldTree->Bound().Dim(); ++i) { // For each of the new rectangles, find the width in this dimension if // we add the rectangle at index to the new rectangle. @@ -495,7 +495,7 @@ void RTreeSplit::AssignNodeDestNode(TreeType* oldTree, { if (numAssignTreeOne < numAssignTreeTwo) { - for (size_t i = 0; i < end; i++) + for (size_t i = 0; i < end; ++i) { InsertNodeIntoTree(treeOne, oldTree->children[i]); numAssignTreeOne++; @@ -503,7 +503,7 @@ void RTreeSplit::AssignNodeDestNode(TreeType* oldTree, } else { - for (size_t i = 0; i < end; i++) + for (size_t i = 0; i < end; ++i) { InsertNodeIntoTree(treeTwo, oldTree->children[i]); numAssignTreeTwo++; @@ -511,11 +511,11 @@ void RTreeSplit::AssignNodeDestNode(TreeType* oldTree, } } - for (size_t i = 0; i < treeOne->NumChildren(); i++) + for (size_t i = 0; i < treeOne->NumChildren(); ++i) for (size_t j = i + 1; j < treeOne->NumChildren(); j++) assert(treeOne->children[i] != treeOne->children[j]); - for (size_t i = 0; i < treeTwo->NumChildren(); i++) + for (size_t i = 0; i < treeTwo->NumChildren(); ++i) for (size_t j = i + 1; j < treeTwo->NumChildren(); j++) assert(treeTwo->children[i] != treeTwo->children[j]); } diff --git a/src/mlpack/core/tree/rectangle_tree/rectangle_tree_impl.hpp b/src/mlpack/core/tree/rectangle_tree/rectangle_tree_impl.hpp index 9d56dc69a0..e0705a387c 100644 --- a/src/mlpack/core/tree/rectangle_tree/rectangle_tree_impl.hpp +++ b/src/mlpack/core/tree/rectangle_tree/rectangle_tree_impl.hpp @@ -74,7 +74,7 @@ RectangleTree(const MatType& data, // For now, just insert the points in order. RectangleTree* root = this; - for (size_t i = firstDataIndex; i < data.n_cols; i++) + for (size_t i = firstDataIndex; i < data.n_cols; ++i) root->InsertPoint(i); // Initialize statistic recursively after tree construction is complete. @@ -115,7 +115,7 @@ RectangleTree(MatType&& data, // For now, just insert the points in order. RectangleTree* root = this; - for (size_t i = firstDataIndex; i < dataset->n_cols; i++) + for (size_t i = firstDataIndex; i < dataset->n_cols; ++i) root->InsertPoint(i); // Initialize statistic recursively after tree construction is complete. @@ -196,7 +196,7 @@ RectangleTree( { if (numChildren > 0) { - for (size_t i = 0; i < numChildren; i++) + for (size_t i = 0; i < numChildren; ++i) children[i] = new RectangleTree(other.Child(i), true, this); } } @@ -244,7 +244,7 @@ RectangleTree(RectangleTree&& other) : } if (!IsLeaf()) { - for (size_t i = 0; i < numChildren; i++) + for (size_t i = 0; i < numChildren; ++i) children[i]->parent = this; } // Now we are a clone of the other tree. But we must also clear the other @@ -283,7 +283,7 @@ operator=(const RectangleTree& other) return *this; // Freeing memory that will not be used anymore. - for (size_t i = 0; i < numChildren; i++) + for (size_t i = 0; i < numChildren; ++i) delete children[i]; if (ownsDataset) @@ -309,7 +309,7 @@ operator=(const RectangleTree& other) if (numChildren > 0) { - for (size_t i = 0; i < numChildren; i++) + for (size_t i = 0; i < numChildren; ++i) children[i] = new RectangleTree(other.Child(i), true, this); } @@ -336,7 +336,7 @@ operator=(RectangleTree&& other) return *this; // Freeing memory that will not be used anymore. - for (size_t i = 0; i < numChildren; i++) + for (size_t i = 0; i < numChildren; ++i) delete children[i]; if (ownsDataset) @@ -414,7 +414,7 @@ RectangleTree:: ~RectangleTree() { - for (size_t i = 0; i < numChildren; i++) + for (size_t i = 0; i < numChildren; ++i) delete children[i]; if (ownsDataset) @@ -437,7 +437,7 @@ void RectangleTreeBound().Contains(dataset->col(point))) if (children[i]->DeletePoint(point, lvls)) return true; @@ -641,7 +641,7 @@ bool RectangleTreeBound().Contains(dataset->col(point))) if (children[i]->DeletePoint(point, relevels)) return true; @@ -684,7 +684,7 @@ bool RectangleTree:: RemoveNode(const RectangleTree* node, std::vector& relevels) { - for (size_t i = 0; i < numChildren; i++) + for (size_t i = 0; i < numChildren; ++i) { if (children[i] == node) { @@ -724,7 +724,7 @@ size_t RectangleTree::TreeSize() const { int n = 0; - for (int i = 0; i < numChildren; i++) + for (int i = 0; i < numChildren; ++i) n += children[i]->TreeSize(); return n + 1; // Add one for this node. @@ -1084,7 +1084,7 @@ void RectangleTreeNumChildren(); i++) + for (size_t i = 0; i < parent->NumChildren(); ++i) { if (parent->children[i] == this) { @@ -1186,7 +1186,7 @@ void RectangleTreeAuxiliaryInfo().UpdateAuxiliaryInfo(root); // Reinsert the nodes at the root node. - for (size_t i = 0; i < numChildren; i++) + for (size_t i = 0; i < numChildren; ++i) root->InsertNode(children[i], level, relevels); // This will check the minFill of the point. @@ -1210,7 +1210,7 @@ void RectangleTreeNumChildren(); i++) + for (size_t i = 0; i < child->NumChildren(); ++i) { children[i] = child->children[i]; children[i]->Parent() = this; @@ -1220,7 +1220,7 @@ void RectangleTreeNumChildren(); child->NumChildren() = 0; - for (size_t i = 0; i < child->Count(); i++) + for (size_t i = 0; i < child->Count(); ++i) { // In case the tree has a height of two. points[i] = child->Point(i); @@ -1264,7 +1264,7 @@ bool RectangleTree::max(); bound[i].Hi() = std::numeric_limits::lowest(); } - for (size_t i = 0; i < numChildren; i++) + for (size_t i = 0; i < numChildren; ++i) { bound |= children[i]->Bound(); } ElemType sum2 = 0; - for (size_t i = 0; i < bound.Dim(); i++) + for (size_t i = 0; i < bound.Dim(); ++i) sum2 += bound[i].Width(); return sum != sum2; @@ -1400,7 +1400,7 @@ void RectangleTree::Traverse( // If we reach a leaf node, we need to run the base case. if (referenceNode.IsLeaf()) { - for (size_t i = 0; i < referenceNode.Count(); i++) + for (size_t i = 0; i < referenceNode.Count(); ++i) rule.BaseCase(queryIndex, referenceNode.Point(i)); return; @@ -61,7 +61,7 @@ SingleTreeTraverser::Traverse( // This is not a leaf node so we sort the children of this node by their // scores. std::vector nodesAndScores(referenceNode.NumChildren()); - for (size_t i = 0; i < referenceNode.NumChildren(); i++) + for (size_t i = 0; i < referenceNode.NumChildren(); ++i) { nodesAndScores[i].node = &(referenceNode.Child(i)); nodesAndScores[i].score = rule.Score(queryIndex, *nodesAndScores[i].node); @@ -71,7 +71,7 @@ SingleTreeTraverser::Traverse( // Now iterate through them starting with the best and stopping when we reach // one that isn't good enough. - for (size_t i = 0; i < referenceNode.NumChildren(); i++) + for (size_t i = 0; i < referenceNode.NumChildren(); ++i) { if (rule.Rescore(queryIndex, *nodesAndScores[i].node, nodesAndScores[i].score) != DBL_MAX) diff --git a/src/mlpack/core/tree/rectangle_tree/x_tree_auxiliary_information.hpp b/src/mlpack/core/tree/rectangle_tree/x_tree_auxiliary_information.hpp index 522341ca67..9ddfd14e08 100644 --- a/src/mlpack/core/tree/rectangle_tree/x_tree_auxiliary_information.hpp +++ b/src/mlpack/core/tree/rectangle_tree/x_tree_auxiliary_information.hpp @@ -173,7 +173,7 @@ class XTreeAuxiliaryInformation SplitHistoryStruct(int dim) : lastDimension(0), history(dim) { - for (int i = 0; i < dim; i++) + for (int i = 0; i < dim; ++i) history[i] = false; } diff --git a/src/mlpack/core/tree/rectangle_tree/x_tree_split_impl.hpp b/src/mlpack/core/tree/rectangle_tree/x_tree_split_impl.hpp index de27c39135..a4ff61c36b 100644 --- a/src/mlpack/core/tree/rectangle_tree/x_tree_split_impl.hpp +++ b/src/mlpack/core/tree/rectangle_tree/x_tree_split_impl.hpp @@ -49,7 +49,7 @@ void XTreeSplit::SplitLeafNode(TreeType *tree, std::vector& relevels) * dimension to prepare for reinsertion of points into the new nodes. */ std::vector> sorted(tree->Count()); - for (size_t i = 0; i < sorted.size(); i++) + for (size_t i = 0; i < sorted.size(); ++i) { sorted[i].first = tree->Dataset().col(tree->Point(i))[bestAxis]; sorted[i].second = tree->Point(i); @@ -83,7 +83,7 @@ void XTreeSplit::SplitLeafNode(TreeType *tree, std::vector& relevels) tree->bound.Clear(); // Insert the points into the appropriate tree. - for (size_t i = 0; i < numPoints; i++) + for (size_t i = 0; i < numPoints; ++i) { if (i < bestIndex + tree->MinLeafSize()) treeOne->InsertPoint(sorted[i].second); @@ -137,7 +137,7 @@ bool XTreeSplit::SplitNonLeafNode(TreeType *tree, std::vector& relevels) // Find the next split axis. std::vector axes(tree->Bound().Dim(), true); std::vector dimensionsLastUsed(tree->NumChildren()); - for (size_t i = 0; i < tree->NumChildren(); i++) + for (size_t i = 0; i < tree->NumChildren(); ++i) dimensionsLastUsed[i] = tree->Child(i).AuxiliaryInfo().SplitHistory().lastDimension; std::sort(dimensionsLastUsed.begin(), dimensionsLastUsed.end()); @@ -146,7 +146,7 @@ bool XTreeSplit::SplitNonLeafNode(TreeType *tree, std::vector& relevels) size_t minOverlapSplitDimension = tree->Bound().Dim(); // See if we can use a new dimension. - for (size_t i = lastDim + 1; i < axes.size(); i++) + for (size_t i = lastDim + 1; i < axes.size(); ++i) { for (size_t j = 0; j < tree->NumChildren(); j++) axes[i] = axes[i] & @@ -160,7 +160,7 @@ bool XTreeSplit::SplitNonLeafNode(TreeType *tree, std::vector& relevels) if (minOverlapSplitDimension == tree->Bound().Dim()) { - for (size_t i = 0; i < lastDim + 1; i++) + for (size_t i = 0; i < lastDim + 1; ++i) { axes[i] = true; for (size_t j = 0; j < tree->NumChildren(); j++) @@ -196,7 +196,7 @@ bool XTreeSplit::SplitNonLeafNode(TreeType *tree, std::vector& relevels) // We'll do Bound().Lo() now and use Bound().Hi() later. std::vector> sorted(tree->NumChildren()); - for (size_t i = 0; i < sorted.size(); i++) + for (size_t i = 0; i < sorted.size(); ++i) { sorted[i].first = tree->Child(i).Bound()[j].Lo(); sorted[i].second = &tree->Child(i); @@ -211,14 +211,14 @@ bool XTreeSplit::SplitNonLeafNode(TreeType *tree, std::vector& relevels) 2 * tree->MinNumChildren() + 2); std::vector overlapedAreas(tree->MaxNumChildren() - 2 * tree->MinNumChildren() + 2); - for (size_t i = 0; i < areas.size(); i++) + for (size_t i = 0; i < areas.size(); ++i) { areas[i] = 0.0; margins[i] = 0.0; overlapedAreas[i] = 0.0; } - for (size_t i = 0; i < areas.size(); i++) + for (size_t i = 0; i < areas.size(); ++i) { // The ith arrangement is obtained by placing the first // tree->MinNumChildren() + i points in one rectangle and the rest in @@ -255,7 +255,7 @@ bool XTreeSplit::SplitNonLeafNode(TreeType *tree, std::vector& relevels) bestAreaIndexOnBestAxis = 0; overlapBestOverlapAxis = overlapedAreas[bestOverlapIndexOnBestAxis]; areaBestOverlapAxis = areas[bestAreaIndexOnBestAxis]; - for (size_t i = 1; i < areas.size(); i++) + for (size_t i = 1; i < areas.size(); ++i) { if (overlapedAreas[i] < overlapedAreas[bestOverlapIndexOnBestAxis]) { @@ -283,7 +283,7 @@ bool XTreeSplit::SplitNonLeafNode(TreeType *tree, std::vector& relevels) if (minOverlapSplitDimension != tree->Bound().Dim() && j == minOverlapSplitDimension) { - for (size_t i = 0; i < overlapedAreas.size(); i++) + for (size_t i = 0; i < overlapedAreas.size(); ++i) { if (overlapedAreas[i] < bestScoreMinOverlapSplit) { @@ -301,7 +301,7 @@ bool XTreeSplit::SplitNonLeafNode(TreeType *tree, std::vector& relevels) ElemType axisScore = 0.0; std::vector> sorted(tree->NumChildren()); - for (size_t i = 0; i < sorted.size(); i++) + for (size_t i = 0; i < sorted.size(); ++i) { sorted[i].first = tree->Child(i).Bound()[j].Hi(); sorted[i].second = &tree->Child(i); @@ -316,14 +316,14 @@ bool XTreeSplit::SplitNonLeafNode(TreeType *tree, std::vector& relevels) 2 * tree->MinNumChildren() + 2); std::vector overlapedAreas(tree->MaxNumChildren() - 2 * tree->MinNumChildren() + 2); - for (size_t i = 0; i < areas.size(); i++) + for (size_t i = 0; i < areas.size(); ++i) { areas[i] = 0.0; margins[i] = 0.0; overlapedAreas[i] = 0.0; } - for (size_t i = 0; i < areas.size(); i++) + for (size_t i = 0; i < areas.size(); ++i) { // The ith arrangement is obtained by placing the first // tree->MinNumChildren() + i points in one rectangle and the rest in @@ -362,7 +362,7 @@ bool XTreeSplit::SplitNonLeafNode(TreeType *tree, std::vector& relevels) bestAreaIndexOnBestAxis = 0; overlapBestOverlapAxis = overlapedAreas[bestOverlapIndexOnBestAxis]; areaBestOverlapAxis = areas[bestAreaIndexOnBestAxis]; - for (size_t i = 1; i < areas.size(); i++) + for (size_t i = 1; i < areas.size(); ++i) { if (overlapedAreas[i] < overlapedAreas[bestOverlapIndexOnBestAxis]) { @@ -390,7 +390,7 @@ bool XTreeSplit::SplitNonLeafNode(TreeType *tree, std::vector& relevels) if (minOverlapSplitDimension != tree->Bound().Dim() && j == minOverlapSplitDimension) { - for (size_t i = 0; i < overlapedAreas.size(); i++) + for (size_t i = 0; i < overlapedAreas.size(); ++i) { if (overlapedAreas[i] < bestScoreMinOverlapSplit) { @@ -406,7 +406,7 @@ bool XTreeSplit::SplitNonLeafNode(TreeType *tree, std::vector& relevels) std::vector> sorted(tree->NumChildren()); if (lowIsBest) { - for (size_t i = 0; i < sorted.size(); i++) + for (size_t i = 0; i < sorted.size(); ++i) { sorted[i].first = tree->Child(i).Bound()[bestAxis].Lo(); sorted[i].second = &tree->Child(i); @@ -414,7 +414,7 @@ bool XTreeSplit::SplitNonLeafNode(TreeType *tree, std::vector& relevels) } else { - for (size_t i = 0; i < sorted.size(); i++) + for (size_t i = 0; i < sorted.size(); ++i) { sorted[i].first = tree->Child(i).Bound()[bestAxis].Hi(); sorted[i].second = &tree->Child(i); @@ -439,7 +439,7 @@ bool XTreeSplit::SplitNonLeafNode(TreeType *tree, std::vector& relevels) { tree->numDescendants = 0; tree->bound.Clear(); - for (size_t i = 0; i < numChildren; i++) + for (size_t i = 0; i < numChildren; ++i) { if (i < bestAreaIndexOnBestAxis + tree->MinNumChildren()) InsertNodeIntoTree(tree, sorted[i].second); @@ -456,7 +456,7 @@ bool XTreeSplit::SplitNonLeafNode(TreeType *tree, std::vector& relevels) { tree->numDescendants = 0; tree->bound.Clear(); - for (size_t i = 0; i < numChildren; i++) + for (size_t i = 0; i < numChildren; ++i) { if (i < bestOverlapIndexOnBestAxis + tree->MinNumChildren()) InsertNodeIntoTree(tree, sorted[i].second); @@ -480,7 +480,7 @@ bool XTreeSplit::SplitNonLeafNode(TreeType *tree, std::vector& relevels) std::vector> sorted2(numChildren); if (minOverlapSplitUsesHi) { - for (size_t i = 0; i < sorted2.size(); i++) + for (size_t i = 0; i < sorted2.size(); ++i) { sorted2[i].first = sorted[i].second->Bound()[bestAxis].Hi(); sorted2[i].second = sorted[i].second; @@ -488,7 +488,7 @@ bool XTreeSplit::SplitNonLeafNode(TreeType *tree, std::vector& relevels) } else { - for (size_t i = 0; i < sorted2.size(); i++) + for (size_t i = 0; i < sorted2.size(); ++i) { sorted2[i].first = sorted[i].second->Bound()[bestAxis].Lo(); sorted2[i].second = sorted[i].second; @@ -499,7 +499,7 @@ bool XTreeSplit::SplitNonLeafNode(TreeType *tree, std::vector& relevels) tree->numDescendants = 0; tree->bound.Clear(); - for (size_t i = 0; i < numChildren; i++) + for (size_t i = 0; i < numChildren; ++i) { if (i < bestIndexMinOverlapSplit + tree->MinNumChildren()) InsertNodeIntoTree(tree, sorted2[i].second); @@ -544,7 +544,7 @@ bool XTreeSplit::SplitNonLeafNode(TreeType *tree, std::vector& relevels) tree->AuxiliaryInfo().NormalNodeMaxNumChildren(); tree->children.resize(tree->MaxNumChildren() + 1); tree->numChildren = numChildren; - for (size_t i = 0; i < numChildren; i++) + for (size_t i = 0; i < numChildren; ++i) tree->Child(i).Parent() = tree; delete treeTwo; @@ -574,7 +574,7 @@ bool XTreeSplit::SplitNonLeafNode(TreeType *tree, std::vector& relevels) // We have to update the children of each of these new nodes so that they // record the correct parent. - for (size_t i = 0; i < treeTwo->NumChildren(); i++) + for (size_t i = 0; i < treeTwo->NumChildren(); ++i) treeTwo->Child(i).Parent() = treeTwo; assert(tree->Parent()->NumChildren() <= @@ -602,7 +602,7 @@ bool XTreeSplit::SplitNonLeafNode(TreeType *tree, std::vector& relevels) { if (overlapBestAreaAxis/areaBestAreaAxis < MAX_OVERLAP) { - for (size_t i = 0; i < numChildren; i++) + for (size_t i = 0; i < numChildren; ++i) { if (i < bestAreaIndexOnBestAxis + tree->MinNumChildren()) InsertNodeIntoTree(treeOne, sorted[i].second); @@ -617,7 +617,7 @@ bool XTreeSplit::SplitNonLeafNode(TreeType *tree, std::vector& relevels) { if (overlapBestOverlapAxis/areaBestOverlapAxis < MAX_OVERLAP) { - for (size_t i = 0; i < numChildren; i++) + for (size_t i = 0; i < numChildren; ++i) { if (i < bestOverlapIndexOnBestAxis + tree->MinNumChildren()) InsertNodeIntoTree(treeOne, sorted[i].second); @@ -641,7 +641,7 @@ bool XTreeSplit::SplitNonLeafNode(TreeType *tree, std::vector& relevels) std::vector> sorted2(numChildren); if (minOverlapSplitUsesHi) { - for (size_t i = 0; i < sorted2.size(); i++) + for (size_t i = 0; i < sorted2.size(); ++i) { sorted2[i].first = sorted[i].second->Bound()[bestAxis].Hi(); sorted2[i].second = sorted[i].second; @@ -649,7 +649,7 @@ bool XTreeSplit::SplitNonLeafNode(TreeType *tree, std::vector& relevels) } else { - for (size_t i = 0; i < sorted2.size(); i++) + for (size_t i = 0; i < sorted2.size(); ++i) { sorted2[i].first = sorted[i].second->Bound()[bestAxis].Lo(); sorted2[i].second = sorted[i].second; @@ -658,7 +658,7 @@ bool XTreeSplit::SplitNonLeafNode(TreeType *tree, std::vector& relevels) std::sort(sorted2.begin(), sorted2.end(), PairComp); - for (size_t i = 0; i < numChildren; i++) + for (size_t i = 0; i < numChildren; ++i) { if (i < bestIndexMinOverlapSplit + tree->MinNumChildren()) InsertNodeIntoTree(treeOne, sorted2[i].second); @@ -673,7 +673,7 @@ bool XTreeSplit::SplitNonLeafNode(TreeType *tree, std::vector& relevels) tree->AuxiliaryInfo().NormalNodeMaxNumChildren(); tree->children.resize(tree->MaxNumChildren() + 1); tree->numChildren = numChildren; - for (size_t i = 0; i < numChildren; i++) + for (size_t i = 0; i < numChildren; ++i) tree->Child(i).Parent() = tree; delete treeOne; @@ -698,7 +698,7 @@ bool XTreeSplit::SplitNonLeafNode(TreeType *tree, std::vector& relevels) // record the correct parent. for (size_t i = 0; i < treeOne->NumChildren(); ++i) treeOne->Child(i).Parent() = treeOne; - for (size_t i = 0; i < treeTwo->NumChildren(); i++) + for (size_t i = 0; i < treeTwo->NumChildren(); ++i) treeTwo->Child(i).Parent() = treeTwo; return false; diff --git a/src/mlpack/core/tree/space_split/mean_space_split_impl.hpp b/src/mlpack/core/tree/space_split/mean_space_split_impl.hpp index 158ed5bb84..86fae10f30 100644 --- a/src/mlpack/core/tree/space_split/mean_space_split_impl.hpp +++ b/src/mlpack/core/tree/space_split/mean_space_split_impl.hpp @@ -35,7 +35,7 @@ bool MeanSpaceSplit::SplitSpace( return false; double splitVal = 0.0; - for (size_t i = 0; i < points.n_elem; i++) + for (size_t i = 0; i < points.n_elem; ++i) splitVal += projVector.Project(data.col(points[i])); splitVal /= points.n_elem; diff --git a/src/mlpack/core/tree/space_split/space_split_impl.hpp b/src/mlpack/core/tree/space_split/space_split_impl.hpp index 98f4ee0e41..1f6c82996d 100644 --- a/src/mlpack/core/tree/space_split/space_split_impl.hpp +++ b/src/mlpack/core/tree/space_split/space_split_impl.hpp @@ -67,7 +67,7 @@ bool SpaceSplit::GetProjVector( size_t snd = points[0]; double max = metric.Evaluate(data.col(fst), data.col(snd)); - for (size_t i = 1; i < points.n_elem; i++) + for (size_t i = 1; i < points.n_elem; ++i) { double dist = metric.Evaluate(data.col(fst), data.col(points[i])); if (dist > max) @@ -79,7 +79,7 @@ bool SpaceSplit::GetProjVector( std::swap(fst, snd); - for (size_t i = 0; i < points.n_elem; i++) + for (size_t i = 0; i < points.n_elem; ++i) { double dist = metric.Evaluate(data.col(fst), data.col(points[i])); if (dist > max) diff --git a/src/mlpack/core/tree/spill_tree/spill_tree_impl.hpp b/src/mlpack/core/tree/spill_tree/spill_tree_impl.hpp index b7d6c928d1..d3f6033c71 100644 --- a/src/mlpack/core/tree/spill_tree/spill_tree_impl.hpp +++ b/src/mlpack/core/tree/spill_tree/spill_tree_impl.hpp @@ -722,7 +722,7 @@ void SpillTree:: const double rho) { // We need to expand the bounds of this node properly. - for (size_t i = 0; i < points.n_elem; i++) + for (size_t i = 0; i < points.n_elem; ++i) bound |= dataset->col(points[i]); // Calculate the furthest descendant distance. @@ -795,7 +795,7 @@ bool SpillTree:: size_t left = 0, right = 0, leftFrontier = 0, rightFrontier = 0; // Count the number of points to the left/right of the splitting hyperplane. - for (size_t i = 0; i < points.n_elem; i++) + for (size_t i = 0; i < points.n_elem; ++i) { // Store projection value for future use. projections[i] = hyperplane.Project(dataset->col(points[i])); @@ -824,7 +824,7 @@ bool SpillTree:: // leftPoints and rightPoints. leftPoints.resize(left + rightFrontier); rightPoints.resize(right + leftFrontier); - for (size_t i = 0, rc = 0, lc = 0; i < points.n_elem; i++) + for (size_t i = 0, rc = 0, lc = 0; i < points.n_elem; ++i) { if (projections[i] < tau || projections[i] <= 0) leftPoints[lc++] = points[i]; @@ -841,7 +841,7 @@ bool SpillTree:: // rightPoints. leftPoints.resize(left); rightPoints.resize(right); - for (size_t i = 0, rc = 0, lc = 0; i < points.n_elem; i++) + for (size_t i = 0, rc = 0, lc = 0; i < points.n_elem; ++i) { if (projections[i] <= 0) leftPoints[lc++] = points[i]; diff --git a/src/mlpack/core/util/backtrace.cpp b/src/mlpack/core/util/backtrace.cpp index 696c2cc8ba..fea690ebc4 100644 --- a/src/mlpack/core/util/backtrace.cpp +++ b/src/mlpack/core/util/backtrace.cpp @@ -84,7 +84,7 @@ void Backtrace::GetAddress(int maxDepth) int stackDepth = backtrace(trace, maxDepth); // Skip first stack frame (points to Backtrace::Backtrace). - for (int i = 1; i < stackDepth; i++) + for (int i = 1; i < stackDepth; ++i) { Dl_info addressHandler; @@ -182,7 +182,7 @@ std::string Backtrace::ToString() return stackStr; } - for (size_t i = 0; i < stack.size(); i++) + for (size_t i = 0; i < stack.size(); ++i) { frame = stack[i]; diff --git a/src/mlpack/methods/adaboost/adaboost_impl.hpp b/src/mlpack/methods/adaboost/adaboost_impl.hpp index b2c6d55998..14941fc523 100644 --- a/src/mlpack/methods/adaboost/adaboost_impl.hpp +++ b/src/mlpack/methods/adaboost/adaboost_impl.hpp @@ -106,7 +106,7 @@ double AdaBoost::Train( arma::Row finalH(predictedLabels.n_cols); // Now, start the boosting rounds. - for (size_t i = 0; i < iterations; i++) + for (size_t i = 0; i < iterations; ++i) { // Initialized to zero in every round. rt is used for calculation of // alphat; it is the weighted error. @@ -230,7 +230,7 @@ void AdaBoost::Classify( probabilities.zeros(numClasses, test.n_cols); predictedLabels.set_size(test.n_cols); - for (size_t i = 0; i < wl.size(); i++) + for (size_t i = 0; i < wl.size(); ++i) { wl[i].Classify(test, tempPredictedLabels); @@ -241,7 +241,7 @@ void AdaBoost::Classify( arma::colvec pRow; arma::uword maxIndex = 0; - for (size_t i = 0; i < predictedLabels.n_cols; i++) + for (size_t i = 0; i < predictedLabels.n_cols; ++i) { probabilities.col(i) /= arma::accu(probabilities.col(i)); pRow = probabilities.unsafe_col(i); diff --git a/src/mlpack/methods/amf/termination_policies/simple_tolerance_termination.hpp b/src/mlpack/methods/amf/termination_policies/simple_tolerance_termination.hpp index f645494c31..e19fece5b5 100644 --- a/src/mlpack/methods/amf/termination_policies/simple_tolerance_termination.hpp +++ b/src/mlpack/methods/amf/termination_policies/simple_tolerance_termination.hpp @@ -78,7 +78,7 @@ class SimpleToleranceTermination size_t m = V->n_cols; double sum = 0; size_t count = 0; - for (size_t i = 0; i < n; i++) + for (size_t i = 0; i < n; ++i) { for (size_t j = 0; j < m; j++) { diff --git a/src/mlpack/methods/amf/termination_policies/validation_rmse_termination.hpp b/src/mlpack/methods/amf/termination_policies/validation_rmse_termination.hpp index 9171aa0ae3..e228632935 100644 --- a/src/mlpack/methods/amf/termination_policies/validation_rmse_termination.hpp +++ b/src/mlpack/methods/amf/termination_policies/validation_rmse_termination.hpp @@ -63,7 +63,7 @@ class ValidationRMSETermination test_points.zeros(num_test_points, 3); // fill validation set matrix with random chosen entries - for (size_t i = 0; i < num_test_points; i++) + for (size_t i = 0; i < num_test_points; ++i) { double t_val; size_t t_row; @@ -122,7 +122,7 @@ class ValidationRMSETermination { rmseOld = rmse; rmse = 0; - for (size_t i = 0; i < num_test_points; i++) + for (size_t i = 0; i < num_test_points; ++i) { size_t t_row = test_points(i, 0); size_t t_col = test_points(i, 1); diff --git a/src/mlpack/methods/amf/update_rules/nmf_als.hpp b/src/mlpack/methods/amf/update_rules/nmf_als.hpp index 8d860cc50b..3f3b7d3566 100644 --- a/src/mlpack/methods/amf/update_rules/nmf_als.hpp +++ b/src/mlpack/methods/amf/update_rules/nmf_als.hpp @@ -78,7 +78,7 @@ class NMFALSUpdate W = V * H.t() * pinv(H * H.t()); // Set all negative numbers to machine epsilon. - for (size_t i = 0; i < W.n_elem; i++) + for (size_t i = 0; i < W.n_elem; ++i) { if (W(i) < 0.0) { @@ -109,7 +109,7 @@ class NMFALSUpdate H = pinv(W.t() * W) * W.t() * V; // Set all negative numbers to 0. - for (size_t i = 0; i < H.n_elem; i++) + for (size_t i = 0; i < H.n_elem; ++i) { if (H(i) < 0.0) { diff --git a/src/mlpack/methods/amf/update_rules/nmf_mult_div.hpp b/src/mlpack/methods/amf/update_rules/nmf_mult_div.hpp index 60310a8ec2..ec40feda44 100644 --- a/src/mlpack/methods/amf/update_rules/nmf_mult_div.hpp +++ b/src/mlpack/methods/amf/update_rules/nmf_mult_div.hpp @@ -130,7 +130,7 @@ class NMFMultiplicativeDivergenceUpdate arma::colvec t2; t1 = W * H; - for (size_t i = 0; i < H.n_rows; i++) + for (size_t i = 0; i < H.n_rows; ++i) { for (size_t j = 0; j < H.n_cols; j++) { diff --git a/src/mlpack/methods/amf/update_rules/svd_batch_learning.hpp b/src/mlpack/methods/amf/update_rules/svd_batch_learning.hpp index 63e8d9d03f..5e1180c01d 100644 --- a/src/mlpack/methods/amf/update_rules/svd_batch_learning.hpp +++ b/src/mlpack/methods/amf/update_rules/svd_batch_learning.hpp @@ -100,7 +100,7 @@ class SVDBatchLearning // Compute the step. arma::mat deltaW; deltaW.zeros(n, r); - for (size_t i = 0; i < n; i++) + for (size_t i = 0; i < n; ++i) { for (size_t j = 0; j < m; j++) { @@ -147,7 +147,7 @@ class SVDBatchLearning deltaH.zeros(r, m); for (size_t j = 0; j < m; j++) { - for (size_t i = 0; i < n; i++) + for (size_t i = 0; i < n; ++i) { const double val = V(i, j); if (val != 0) diff --git a/src/mlpack/methods/ann/activation_functions/hard_sigmoid_function.hpp b/src/mlpack/methods/ann/activation_functions/hard_sigmoid_function.hpp index 1aaf8a60ed..60739cfb00 100644 --- a/src/mlpack/methods/ann/activation_functions/hard_sigmoid_function.hpp +++ b/src/mlpack/methods/ann/activation_functions/hard_sigmoid_function.hpp @@ -56,7 +56,7 @@ class HardSigmoidFunction { y.set_size(size(x)); - for (size_t i = 0; i < x.n_elem; i++) + for (size_t i = 0; i < x.n_elem; ++i) y(i) = Fn(x(i)); } @@ -86,7 +86,7 @@ class HardSigmoidFunction { x.set_size(size(y)); - for (size_t i = 0; i < y.n_elem; i++) + for (size_t i = 0; i < y.n_elem; ++i) { x(i) = Deriv(y(i)); } diff --git a/src/mlpack/methods/ann/activation_functions/rectifier_function.hpp b/src/mlpack/methods/ann/activation_functions/rectifier_function.hpp index 214cbb3ffe..6ab7cd3f5f 100644 --- a/src/mlpack/methods/ann/activation_functions/rectifier_function.hpp +++ b/src/mlpack/methods/ann/activation_functions/rectifier_function.hpp @@ -104,7 +104,7 @@ class RectifierFunction { x.set_size(arma::size(y)); - for (size_t i = 0; i < y.n_elem; i++) + for (size_t i = 0; i < y.n_elem; ++i) x(i) = Deriv(y(i)); } }; // class RectifierFunction diff --git a/src/mlpack/methods/ann/activation_functions/softplus_function.hpp b/src/mlpack/methods/ann/activation_functions/softplus_function.hpp index 36e63e8eb7..b785ce3571 100644 --- a/src/mlpack/methods/ann/activation_functions/softplus_function.hpp +++ b/src/mlpack/methods/ann/activation_functions/softplus_function.hpp @@ -67,7 +67,7 @@ class SoftplusFunction { y.set_size(arma::size(x)); - for (size_t i = 0; i < x.n_elem; i++) + for (size_t i = 0; i < x.n_elem; ++i) y(i) = Fn(x(i)); } @@ -116,7 +116,7 @@ class SoftplusFunction { x.set_size(arma::size(y)); - for (size_t i = 0; i < y.n_elem; i++) + for (size_t i = 0; i < y.n_elem; ++i) x(i) = Inv(y(i)); } }; // class SoftplusFunction diff --git a/src/mlpack/methods/ann/activation_functions/softsign_function.hpp b/src/mlpack/methods/ann/activation_functions/softsign_function.hpp index 5900854d45..32030e4dd2 100644 --- a/src/mlpack/methods/ann/activation_functions/softsign_function.hpp +++ b/src/mlpack/methods/ann/activation_functions/softsign_function.hpp @@ -71,7 +71,7 @@ class SoftsignFunction { y.set_size(arma::size(x)); - for (size_t i = 0; i < x.n_elem; i++) + for (size_t i = 0; i < x.n_elem; ++i) y(i) = Fn(x(i)); } @@ -123,7 +123,7 @@ class SoftsignFunction { x.set_size(arma::size(y)); - for (size_t i = 0; i < y.n_elem; i++) + for (size_t i = 0; i < y.n_elem; ++i) x(i) = Inv(y(i)); } }; // class SoftsignFunction diff --git a/src/mlpack/methods/ann/activation_functions/swish_function.hpp b/src/mlpack/methods/ann/activation_functions/swish_function.hpp index 5bfb2ecdeb..758ba98fe0 100644 --- a/src/mlpack/methods/ann/activation_functions/swish_function.hpp +++ b/src/mlpack/methods/ann/activation_functions/swish_function.hpp @@ -64,7 +64,7 @@ class SwishFunction { y.set_size(arma::size(x)); - for (size_t i = 0; i < x.n_elem; i++) + for (size_t i = 0; i < x.n_elem; ++i) y(i) = Fn(x(i)); } diff --git a/src/mlpack/methods/ann/ann_low_resource_main.cpp b/src/mlpack/methods/ann/ann_low_resource_main.cpp new file mode 100644 index 0000000000..ad1770954e --- /dev/null +++ b/src/mlpack/methods/ann/ann_low_resource_main.cpp @@ -0,0 +1,176 @@ +/** + * An example of using Feed Forward Neural Network (FFN) for + * solving Digit Recognizer problem from Kaggle website. + * + * The full description of a problem as well as datasets for training + * and testing are available here https://www.kaggle.com/c/digit-recognizer + * + * mlpack is free software; you may redistribute it and/or modify it under the + * terms of the 3-clause BSD license. You should have received a copy of the + * 3-clause BSD license along with mlpack. If not, see + * http://www.opensource.org/licenses/BSD-3-Clause for more information. + * + * @author Eugene Freyman + * @author Omar Shrit + */ + +#include +#include +#include + +#include +#include + +#include +#include +#include + +#include +#include + +using namespace mlpack::ann; + +using namespace arma; +using namespace mlpack::util; +using namespace ens; + +arma::Row getLabels(arma::mat predOut) +{ + arma::Row predLabels(predOut.n_cols); + for (arma::uword i = 0; i < predOut.n_cols; ++i) + { + predLabels(i) = predOut.col(i).index_max() + 1; + } + return predLabels; +} + +static void +mlpackMain() +{ + // Dataset is randomly split into validation + // and training parts in the following ratio. + constexpr double RATIO = 0.1; + // The number of neurons in the first layer. + constexpr int H1 = 200; + // The number of neurons in the second layer. + constexpr int H2 = 100; + // Step size of the optimizer. + constexpr double STEP_SIZE = 5e-3; + // Number of data points in each iteration of SGD + constexpr size_t BATCH_SIZE = 64; + // Allow infinite number of iterations until we stopped by EarlyStopAtMinLoss. + const int MAX_ITERATIONS = 0; + + // Labeled dataset that contains data for training is loaded from CSV file, + // rows represent features, columns represent data points. + arma::mat dataset; + mlpack::data::Load("../data/train.csv", dataset, true); + + // Originally on Kaggle dataset CSV file has header, so it's necessary to + // get rid of the this row, in Armadillo representation it's the first column. + arma::mat headerLessDataset = + dataset.submat(0, 1, dataset.n_rows - 1, dataset.n_cols - 1); + + // Splitting the training dataset on training and validation parts. + arma::mat train, valid; + mlpack::data::Split(headerLessDataset, train, valid, RATIO); + + // Getting training and validating dataset with features only and then + // normalising + const arma::mat trainX = + train.submat(1, 0, train.n_rows - 1, train.n_cols - 1) / 255.0; + const arma::mat validX = + valid.submat(1, 0, valid.n_rows - 1, valid.n_cols - 1) / 255.0; + + // According to NegativeLogLikelihood output layer of NN, labels should + // specify class of a data point and be in the interval from 1 to + // number of classes (in this case from 1 to 10). + + // Creating labels for training and validating dataset. + const arma::mat trainY = train.row(0) + 1; + const arma::mat validY = valid.row(0) + 1; + + // Specifying the NN model. NegativeLogLikelihood is the output layer that + // is used for classification problem. GlorotInitialization means that + // initial weights in neurons are a uniform gaussian distribution. + FFN, GlorotInitialization> model; + // This is intermediate layer that is needed for connection between input + // data and relu layer. Parameters specify the number of input features + // and number of neurons in the next layer. + model.Add>(trainX.n_rows, H1); + // The first relu layer. + model.Add>(); + // Intermediate layer between relu layers. + model.Add>(H1, H2); + // The second relu layer. + model.Add>(); + // Dropout layer for regularization. First parameter is the probability of + // setting a specific value to 0. + model.Add>(0.2); + // Intermediate layer. + model.Add>(H2, 10); + // LogSoftMax layer is used together with NegativeLogLikelihood for mapping + // output values to log of probabilities of being a specific class. + model.Add>(); + + std::cout << "Start training ..." << std::endl; + + // Set parameters for the Adam optimizer. + ens::Adam optimizer( + STEP_SIZE, // Step size of the optimizer. + BATCH_SIZE, // Batch size. Number of data points that are used in each iteration. + 0.9, // Exponential decay rate for the first moment estimates. + 0.999, // Exponential decay rate for the weighted infinity norm estimates. + 1e-8, // Value used to initialise the mean squared gradient parameter. + MAX_ITERATIONS, // Max number of iterations. + 1e-8, // Tolerance. + true); + + // Train neural network. If this is the first iteration, weights are + // random, using current values as starting point otherwise. + model.Train(trainX, + trainY, + optimizer, + ens::PrintLoss(), + ens::ProgressBar(), + // Stop the training using Early Stop at min loss. + ens::EarlyStopAtMinLoss()); + + mat predOut; + // Getting predictions on training data points. + model.Predict(trainX, predOut); + // Calculating accuracy on training data points. + arma::Row predLabels = getLabels(predOut); + double trainAccuracy = arma::accu(predLabels == trainY) / (double)trainY.n_elem * 100; + // Getting predictions on validating data points. + model.Predict(validX, predOut); + // Calculating accuracy on validating data points. + predLabels = getLabels(predOut); + double validAccuracy = arma::accu(predLabels == validY) / (double)validY.n_elem * 100; + + std::cout << "Accuracy: train = " << trainAccuracy << "%," + << "\t valid = " << validAccuracy << "%" << endl; + + mlpack::data::Save("model.bin", "model", model, false); + + // Loading test dataset (the one whose predicted labels + // should be sent to kaggle website). + arma::mat testingDataset; + mlpack::data::Load("../data/test.csv", testingDataset, true); + + // As before, it's necessary to get rid of header. + arma::mat testX = testingDataset.submat( + 0, 1, testingDataset.n_rows - 1, testingDataset.n_cols - 1); + + std::cout << "Predicting ..." << endl; + mat testPredOut; + // Getting predictions on test data points. + model.Predict(testX, testPredOut); + // Generating labels for the test dataset. + Row testPred = getLabels(testPredOut); + std::cout << "Saving predicted labels to \"results.csv\" ..." << std::endl; + + testPred.save("results.csv", arma::csv_ascii); + std::cout << "Neural network model is saved to \"model.bin\"" << std::endl; + std::cout << "Finished" << std::endl; +} diff --git a/src/mlpack/methods/ann/augmented/tasks/score_impl.hpp b/src/mlpack/methods/ann/augmented/tasks/score_impl.hpp index 528194a0b9..8696113fa9 100644 --- a/src/mlpack/methods/ann/augmented/tasks/score_impl.hpp +++ b/src/mlpack/methods/ann/augmented/tasks/score_impl.hpp @@ -38,7 +38,7 @@ double SequencePrecision(arma::field trueOutputs, throw std::invalid_argument(oss.str()); } - for (size_t i = 0; i < testSize; i++) + for (size_t i = 0; i < testSize; ++i) { arma::vec delta = arma::vectorise(arma::abs( trueOutputs.at(i) - predOutputs.at(i))); diff --git a/src/mlpack/methods/ann/callbacks/early_stop_at_min_loss.hpp b/src/mlpack/methods/ann/callbacks/early_stop_at_min_loss.hpp new file mode 100644 index 0000000000..d6b86d7515 --- /dev/null +++ b/src/mlpack/methods/ann/callbacks/early_stop_at_min_loss.hpp @@ -0,0 +1,126 @@ +/** + * @file early_stop_at_min_loss.hpp + * @author Marcus Edel + * @author Omar Shrit + * + * Implementation of the early stop at minimum loss callback function. + * + * mlpack is free software; you may redistribute it and/or modify it under + * the terms of the 3-clause BSD license. You should have received a copy of + * the 3-clause BSD license along with mlpack. If not, see + * http://www.opensource.org/licenses/BSD-3-Clause for more information. + */ +#ifndef MLPACK_CALLBACKS_EARLY_STOP_AT_MIN_LOSS_HPP +#define MLPACK_CALLBACKS_EARLY_STOP_AT_MIN_LOSS_HPP + +namespace mlpack { +namespace ann /** Artificial Neural Network. */ { + +/** + * Early stopping to terminate the optimization process early if the loss stops + * decreasing. + */ +class EarlyStopAtMinLoss +{ + public: + /** + * Set up the early stop at min loss class, which keeps track of the minimum + * loss and stops the optimization process if the loss stops decreasing. + * + * @param patienceIn The number of epochs to wait after the minimum loss has + * been reached or no improvement has been made (Default: 10). + */ + EarlyStopAtMinLoss(const size_t patienceIn = 10, + std::ostream& output = arma::get_cout_stream()) : + patience(patienceIn), + bestObjective(std::numeric_limits::max()), + steps(0), + output(output) + { /* Nothing to do here */ } + + /** + * Set up the early stop at min class, which keeps track + * of the minimum loss and stops the optimization process if the loss stops + * decreasing on a specific validation set. + * + * @param predictors: data matrix used to predict the responses. + * @param responses: data matrix used to evaluate the predictions. + * @param patienceIn The number of epochs to wait after the minimum loss has + * been reached or no improvement has been made (Default: 10). + */ + EarlyStopAtMinLoss(const arma::mat& predictors, + const arma::mat& responses, + const size_t patienceIn = 10, + std::ostream& output = arma::get_cout_stream()) : + patience(patienceIn), + bestObjective(std::numeric_limits::max()), + steps(0), + output(output) + { + this->predictors = predictors; + this->responses = responses; + } + + /** + * Callback function called at the end of a pass over the data. + * + * @param optimizer The optimizer used to update the function. + * @param function Function to optimize. + * @param coordinates Starting point. + * @param epoch The index of the current epoch. + * @param objective Objective value of the current point. + */ + template + bool EndEpoch(OptimizerType& /* optimizer */, + FunctionType& function, + const MatType& /* coordinates */, + const size_t /* epoch */, + double objective) + { + if ((!predictors.empty()) and (!responses.empty())) + { + objective = function.Evaluate(predictors, responses); + output << "Validation loss: "<< objective << std::endl; + } + + if (objective < bestObjective) + { + steps = 0; + bestObjective = objective; + return false; + } + + steps++; + if (steps >= patience) + { + Log::Info << "Minimum loss reached; terminate optimization." << std::endl; + return true; + } + + return false; + } + + private: + //! The number of epochs to wait before terminating the optimization process. + size_t patience; + + //! Locally-stored best objective. + double bestObjective; + + //! Locally-stored number of steps since the loss improved. + size_t steps; + + //! The output stream that all data is to be sent to; example: std::cout. + std::ostream& output; + + //! The matrix of data points (predictors). + arma::mat predictors; + + //! The matrix of responses to the input data points. + arma::mat responses; +}; + +} +} + +#endif diff --git a/src/mlpack/methods/ann/convolution_rules/fft_convolution.hpp b/src/mlpack/methods/ann/convolution_rules/fft_convolution.hpp index 777fa2632a..d220ace752 100644 --- a/src/mlpack/methods/ann/convolution_rules/fft_convolution.hpp +++ b/src/mlpack/methods/ann/convolution_rules/fft_convolution.hpp @@ -144,7 +144,7 @@ class FFTConvolution input.n_slices); output.slice(0) = convOutput; - for (size_t i = 1; i < input.n_slices; i++) + for (size_t i = 1; i < input.n_slices; ++i) { FFTConvolution::Convolution(input.slice(i), filter.slice(i), output.slice(i)); @@ -175,7 +175,7 @@ class FFTConvolution filter.n_slices); output.slice(0) = convOutput; - for (size_t i = 1; i < filter.n_slices; i++) + for (size_t i = 1; i < filter.n_slices; ++i) { FFTConvolution::Convolution(input, filter.slice(i), output.slice(i)); @@ -203,7 +203,7 @@ class FFTConvolution input.n_slices); output.slice(0) = convOutput; - for (size_t i = 1; i < input.n_slices; i++) + for (size_t i = 1; i < input.n_slices; ++i) { FFTConvolution::Convolution(input.slice(i), filter, output.slice(i)); diff --git a/src/mlpack/methods/ann/convolution_rules/naive_convolution.hpp b/src/mlpack/methods/ann/convolution_rules/naive_convolution.hpp index 1352883c81..7abaa86ee6 100644 --- a/src/mlpack/methods/ann/convolution_rules/naive_convolution.hpp +++ b/src/mlpack/methods/ann/convolution_rules/naive_convolution.hpp @@ -108,7 +108,7 @@ class NaiveConvolution size_t outputCols = (input.n_cols - 1) * dH + 2 * (filter.n_cols - 1) * dilationH + 1; - for (size_t i = 0; i < dW; i++) + for (size_t i = 0; i < dW; ++i) { if (((((i + outputRows - 2 * (filter.n_rows - 1) * dilationW - 1) % dW) + dW) % dW) == i){ @@ -116,7 +116,7 @@ class NaiveConvolution break; } } - for (size_t i = 0; i < dH; i++) + for (size_t i = 0; i < dH; ++i) { if (((((i + outputCols - 2 * (filter.n_cols - 1) * dilationH - 1) % dH) + dH) % dH) == i){ @@ -164,7 +164,7 @@ class NaiveConvolution input.n_slices); output.slice(0) = convOutput; - for (size_t i = 1; i < input.n_slices; i++) + for (size_t i = 1; i < input.n_slices; ++i) { NaiveConvolution::Convolution(input.slice(i), filter.slice(i), output.slice(i), dW, dH, dilationW, dilationH); @@ -200,7 +200,7 @@ class NaiveConvolution filter.n_slices); output.slice(0) = convOutput; - for (size_t i = 1; i < filter.n_slices; i++) + for (size_t i = 1; i < filter.n_slices; ++i) { NaiveConvolution::Convolution(input, filter.slice(i), output.slice(i), dW, dH, dilationW, dilationH); @@ -236,7 +236,7 @@ class NaiveConvolution input.n_slices); output.slice(0) = convOutput; - for (size_t i = 1; i < input.n_slices; i++) + for (size_t i = 1; i < input.n_slices; ++i) { NaiveConvolution::Convolution(input.slice(i), filter, output.slice(i), dW, dH, dilationW, dilationH); diff --git a/src/mlpack/methods/ann/convolution_rules/svd_convolution.hpp b/src/mlpack/methods/ann/convolution_rules/svd_convolution.hpp index 8ed0a9c415..823d40d816 100644 --- a/src/mlpack/methods/ann/convolution_rules/svd_convolution.hpp +++ b/src/mlpack/methods/ann/convolution_rules/svd_convolution.hpp @@ -131,7 +131,7 @@ class SVDConvolution input.n_slices); output.slice(0) = convOutput; - for (size_t i = 1; i < input.n_slices; i++) + for (size_t i = 1; i < input.n_slices; ++i) { SVDConvolution::Convolution(input.slice(i), filter.slice(i), output.slice(i)); @@ -160,7 +160,7 @@ class SVDConvolution filter.n_slices); output.slice(0) = convOutput; - for (size_t i = 1; i < filter.n_slices; i++) + for (size_t i = 1; i < filter.n_slices; ++i) { SVDConvolution::Convolution(input, filter.slice(i), output.slice(i)); @@ -189,7 +189,7 @@ class SVDConvolution input.n_slices); output.slice(0) = convOutput; - for (size_t i = 1; i < input.n_slices; i++) + for (size_t i = 1; i < input.n_slices; ++i) { SVDConvolution::Convolution(input.slice(i), filter, output.slice(i)); diff --git a/src/mlpack/methods/ann/dists/bernoulli_distribution_impl.hpp b/src/mlpack/methods/ann/dists/bernoulli_distribution_impl.hpp index aa751f8f79..df061e26a1 100644 --- a/src/mlpack/methods/ann/dists/bernoulli_distribution_impl.hpp +++ b/src/mlpack/methods/ann/dists/bernoulli_distribution_impl.hpp @@ -52,7 +52,7 @@ DataType BernoulliDistribution::Sample() const DataType sample = arma::randu (probability.n_rows, probability.n_cols); - for (size_t i = 0; i < sample.n_elem; i++) + for (size_t i = 0; i < sample.n_elem; ++i) sample(i) = sample(i) < probability(i); return sample; diff --git a/src/mlpack/methods/ann/ffn_impl.hpp b/src/mlpack/methods/ann/ffn_impl.hpp index d2f71fcdef..e16ccda031 100644 --- a/src/mlpack/methods/ann/ffn_impl.hpp +++ b/src/mlpack/methods/ann/ffn_impl.hpp @@ -242,7 +242,7 @@ void FFN::Predict( results = arma::mat(resultsTemp.n_elem, predictors.n_cols); results.col(0) = resultsTemp.col(0); - for (size_t i = 1; i < predictors.n_cols; i++) + for (size_t i = 1; i < predictors.n_cols; ++i) { Forward(arma::mat(predictors.colptr(i), predictors.n_rows, 1, false, true)); diff --git a/src/mlpack/methods/ann/gan/metrics/inception_score_impl.hpp b/src/mlpack/methods/ann/gan/metrics/inception_score_impl.hpp index 95d4213415..9b77797943 100644 --- a/src/mlpack/methods/ann/gan/metrics/inception_score_impl.hpp +++ b/src/mlpack/methods/ann/gan/metrics/inception_score_impl.hpp @@ -32,7 +32,7 @@ double InceptionScore(ModelType model, size_t index = 0; arma::vec scores = arma::vec(splits); - for (int i = 0; i < splits; i++) + for (int i = 0; i < splits; ++i) { size_t curSize = splitSize; if (remainder) diff --git a/src/mlpack/methods/ann/init_rules/gaussian_init.hpp b/src/mlpack/methods/ann/init_rules/gaussian_init.hpp index 173431b007..9ab120c785 100644 --- a/src/mlpack/methods/ann/init_rules/gaussian_init.hpp +++ b/src/mlpack/methods/ann/init_rules/gaussian_init.hpp @@ -75,7 +75,7 @@ class GaussianInitialization { W = arma::Cube(rows, cols, slices); - for (size_t i = 0; i < slices; i++) + for (size_t i = 0; i < slices; ++i) Initialize(W.slice(i), rows, cols); } diff --git a/src/mlpack/methods/ann/init_rules/glorot_init.hpp b/src/mlpack/methods/ann/init_rules/glorot_init.hpp index a52a496316..09aa4d84d3 100644 --- a/src/mlpack/methods/ann/init_rules/glorot_init.hpp +++ b/src/mlpack/methods/ann/init_rules/glorot_init.hpp @@ -131,7 +131,7 @@ inline void GlorotInitializationType::Initialize(arma::Cube& W, { W = arma::cube(rows, cols, slices); } - for (size_t i = 0; i < slices; i++) + for (size_t i = 0; i < slices; ++i) Initialize(W.slice(i), rows, cols); } diff --git a/src/mlpack/methods/ann/init_rules/he_init.hpp b/src/mlpack/methods/ann/init_rules/he_init.hpp index 421b499dc3..3a5d275566 100644 --- a/src/mlpack/methods/ann/init_rules/he_init.hpp +++ b/src/mlpack/methods/ann/init_rules/he_init.hpp @@ -95,7 +95,7 @@ class HeInitialization if (W.is_empty()) W.set_size(rows, cols, slices); - for (size_t i = 0; i < slices; i++) + for (size_t i = 0; i < slices; ++i) Initialize(W.slice(i), rows, cols); } }; // class HeInitialization diff --git a/src/mlpack/methods/ann/init_rules/kathirvalavakumar_subavathi_init.hpp b/src/mlpack/methods/ann/init_rules/kathirvalavakumar_subavathi_init.hpp index 1fc5f202df..67c14085a7 100644 --- a/src/mlpack/methods/ann/init_rules/kathirvalavakumar_subavathi_init.hpp +++ b/src/mlpack/methods/ann/init_rules/kathirvalavakumar_subavathi_init.hpp @@ -106,7 +106,7 @@ class KathirvalavakumarSubavathiInitialization { W = arma::Cube(rows, cols, slices); - for (size_t i = 0; i < slices; i++) + for (size_t i = 0; i < slices; ++i) Initialize(W.slice(i), rows, cols); } diff --git a/src/mlpack/methods/ann/init_rules/lecun_normal_init.hpp b/src/mlpack/methods/ann/init_rules/lecun_normal_init.hpp index 19bfb46173..ea691f5f74 100644 --- a/src/mlpack/methods/ann/init_rules/lecun_normal_init.hpp +++ b/src/mlpack/methods/ann/init_rules/lecun_normal_init.hpp @@ -101,7 +101,7 @@ class LecunNormalInitialization if (W.is_empty()) W.set_size(rows, cols, slices); - for (size_t i = 0; i < slices; i++) + for (size_t i = 0; i < slices; ++i) Initialize(W.slice(i), rows, cols); } }; // class LecunNormalInitialization diff --git a/src/mlpack/methods/ann/init_rules/nguyen_widrow_init.hpp b/src/mlpack/methods/ann/init_rules/nguyen_widrow_init.hpp index 50d62057e8..35cabdd6be 100644 --- a/src/mlpack/methods/ann/init_rules/nguyen_widrow_init.hpp +++ b/src/mlpack/methods/ann/init_rules/nguyen_widrow_init.hpp @@ -99,7 +99,7 @@ class NguyenWidrowInitialization { W = arma::Cube(rows, cols, slices); - for (size_t i = 0; i < slices; i++) + for (size_t i = 0; i < slices; ++i) Initialize(W.slice(i), rows, cols); } diff --git a/src/mlpack/methods/ann/init_rules/oivs_init.hpp b/src/mlpack/methods/ann/init_rules/oivs_init.hpp index df5c714f20..3b6e1b1174 100644 --- a/src/mlpack/methods/ann/init_rules/oivs_init.hpp +++ b/src/mlpack/methods/ann/init_rules/oivs_init.hpp @@ -108,7 +108,7 @@ class OivsInitialization { W = arma::Cube(rows, cols, slices); - for (size_t i = 0; i < slices; i++) + for (size_t i = 0; i < slices; ++i) Initialize(W.slice(i), rows, cols); } diff --git a/src/mlpack/methods/ann/init_rules/orthogonal_init.hpp b/src/mlpack/methods/ann/init_rules/orthogonal_init.hpp index 23d0245c58..825e21a47b 100644 --- a/src/mlpack/methods/ann/init_rules/orthogonal_init.hpp +++ b/src/mlpack/methods/ann/init_rules/orthogonal_init.hpp @@ -66,7 +66,7 @@ class OrthogonalInitialization { W = arma::Cube(rows, cols, slices); - for (size_t i = 0; i < slices; i++) + for (size_t i = 0; i < slices; ++i) Initialize(W.slice(i), rows, cols); } diff --git a/src/mlpack/methods/ann/init_rules/random_init.hpp b/src/mlpack/methods/ann/init_rules/random_init.hpp index 6b79207c49..b42f986a1e 100644 --- a/src/mlpack/methods/ann/init_rules/random_init.hpp +++ b/src/mlpack/methods/ann/init_rules/random_init.hpp @@ -74,7 +74,7 @@ class RandomInitialization { W = arma::Cube(rows, cols, slices); - for (size_t i = 0; i < slices; i++) + for (size_t i = 0; i < slices; ++i) Initialize(W.slice(i), rows, cols); } diff --git a/src/mlpack/methods/ann/layer/atrous_convolution_impl.hpp b/src/mlpack/methods/ann/layer/atrous_convolution_impl.hpp index 39ddf035e2..0426a30a13 100644 --- a/src/mlpack/methods/ann/layer/atrous_convolution_impl.hpp +++ b/src/mlpack/methods/ann/layer/atrous_convolution_impl.hpp @@ -368,13 +368,13 @@ void AtrousConvolution< if (dilationHeight > 1) { - for (size_t i = 1; i < output.n_cols; i++){ + for (size_t i = 1; i < output.n_cols; ++i){ output.shed_cols(i, i + dilationHeight - 2); } } if (dilationWidth > 1) { - for (size_t i = 1; i < output.n_rows; i++){ + for (size_t i = 1; i < output.n_rows; ++i){ output.shed_rows(i, i + dilationWidth - 2); } } diff --git a/src/mlpack/methods/ann/layer/batch_norm_impl.hpp b/src/mlpack/methods/ann/layer/batch_norm_impl.hpp index 81c75d1997..726787aa29 100644 --- a/src/mlpack/methods/ann/layer/batch_norm_impl.hpp +++ b/src/mlpack/methods/ann/layer/batch_norm_impl.hpp @@ -85,7 +85,7 @@ void BatchNorm::Forward( output.each_col() /= arma::sqrt(variance + eps); // Use Welford method to compute the sample variance and mean. - for (size_t i = 0; i < input.n_cols; i++) + for (size_t i = 0; i < input.n_cols; ++i) { count += 1; diff --git a/src/mlpack/methods/ann/layer/bilinear_interpolation_impl.hpp b/src/mlpack/methods/ann/layer/bilinear_interpolation_impl.hpp index e2e1c005e7..3ee5ae2c39 100644 --- a/src/mlpack/methods/ann/layer/bilinear_interpolation_impl.hpp +++ b/src/mlpack/methods/ann/layer/bilinear_interpolation_impl.hpp @@ -77,7 +77,7 @@ void BilinearInterpolation::Forward( double scaleCol = (double) inColSize / (double) outColSize; arma::mat22 coeffs; - for (size_t i = 0; i < outRowSize; i++) + for (size_t i = 0; i < outRowSize; ++i) { size_t rOrigin = (size_t) std::floor(i * scaleRow); if (rOrigin > inRowSize - 2) @@ -144,7 +144,7 @@ void BilinearInterpolation::Backward( double scaleCol = (double)(outColSize) / inColSize; arma::mat22 coeffs; - for (size_t i = 0; i < inRowSize; i++) + for (size_t i = 0; i < inRowSize; ++i) { size_t rOrigin = (size_t) std::floor(i * scaleRow); if (rOrigin > outRowSize - 2) diff --git a/src/mlpack/methods/ann/layer/celu_impl.hpp b/src/mlpack/methods/ann/layer/celu_impl.hpp index bf92e5da1a..1ed2fb278c 100644 --- a/src/mlpack/methods/ann/layer/celu_impl.hpp +++ b/src/mlpack/methods/ann/layer/celu_impl.hpp @@ -36,7 +36,7 @@ void CELU::Forward( const InputType& input, OutputType& output) { output = arma::ones(arma::size(input)); - for (size_t i = 0; i < input.n_elem; i++) + for (size_t i = 0; i < input.n_elem; ++i) { output(i) = (input(i) >= 0) ? input(i) : alpha * (std::exp(input(i) / alpha) - 1); @@ -45,7 +45,7 @@ void CELU::Forward( if (!deterministic) { derivative.set_size(arma::size(input)); - for (size_t i = 0; i < input.n_elem; i++) + for (size_t i = 0; i < input.n_elem; ++i) { derivative(i) = (input(i) >= 0) ? 1 : (output(i) / alpha) + 1; diff --git a/src/mlpack/methods/ann/layer/elu_impl.hpp b/src/mlpack/methods/ann/layer/elu_impl.hpp index cc2d189995..c02df82ce5 100644 --- a/src/mlpack/methods/ann/layer/elu_impl.hpp +++ b/src/mlpack/methods/ann/layer/elu_impl.hpp @@ -52,7 +52,7 @@ void ELU::Forward( const InputType& input, OutputType& output) { output = arma::ones(arma::size(input)); - for (size_t i = 0; i < input.n_elem; i++) + for (size_t i = 0; i < input.n_elem; ++i) { if (input(i) < DBL_MAX) { @@ -64,7 +64,7 @@ void ELU::Forward( if (!deterministic) { derivative.set_size(arma::size(input)); - for (size_t i = 0; i < input.n_elem; i++) + for (size_t i = 0; i < input.n_elem; ++i) { derivative(i) = (input(i) > 0) ? lambda : output(i) + lambda * alpha; diff --git a/src/mlpack/methods/ann/layer/glimpse.hpp b/src/mlpack/methods/ann/layer/glimpse.hpp index 6e65e5c775..c2700e6c7a 100644 --- a/src/mlpack/methods/ann/layer/glimpse.hpp +++ b/src/mlpack/methods/ann/layer/glimpse.hpp @@ -200,7 +200,7 @@ class Glimpse for (size_t i = 0, k = 0; i < w.n_elem; k++) { - for (size_t j = 0; j < w.n_cols; j++, i++) + for (size_t j = 0; j < w.n_cols; j++, ++i) { w(k, j) = t(i); } @@ -214,7 +214,7 @@ class Glimpse */ void Transform(arma::cube& w) { - for (size_t i = 0; i < w.n_slices; i++) + for (size_t i = 0; i < w.n_slices; ++i) { arma::mat t = w.slice(i); Transform(t); diff --git a/src/mlpack/methods/ann/layer/glimpse_impl.hpp b/src/mlpack/methods/ann/layer/glimpse_impl.hpp index 49f6854301..10ab509f83 100644 --- a/src/mlpack/methods/ann/layer/glimpse_impl.hpp +++ b/src/mlpack/methods/ann/layer/glimpse_impl.hpp @@ -140,7 +140,7 @@ void Glimpse::Backward( for (size_t s = 0, j = 0; s < mappedError.n_slices; s+= gy.n_cols, j++) { - for (size_t i = 0; i < gy.n_cols; i++) + for (size_t i = 0; i < gy.n_cols; ++i) { mappedError.slice(s + i) = arma::Mat(gy.memptr(), outputWidth, outputHeight); diff --git a/src/mlpack/methods/ann/layer/hard_tanh_impl.hpp b/src/mlpack/methods/ann/layer/hard_tanh_impl.hpp index 473330cb07..7449573fde 100644 --- a/src/mlpack/methods/ann/layer/hard_tanh_impl.hpp +++ b/src/mlpack/methods/ann/layer/hard_tanh_impl.hpp @@ -34,7 +34,7 @@ void HardTanH::Forward( const InputType& input, OutputType& output) { output = input; - for (size_t i = 0; i < input.n_elem; i++) + for (size_t i = 0; i < input.n_elem; ++i) { output(i) = (output(i) > maxValue ? maxValue : (output(i) < minValue ? minValue : output(i))); @@ -47,7 +47,7 @@ void HardTanH::Backward( const DataType& input, const DataType& gy, DataType& g) { g = gy; - for (size_t i = 0; i < input.n_elem; i++) + for (size_t i = 0; i < input.n_elem; ++i) { if (input(i) < minValue || input(i) > maxValue) { diff --git a/src/mlpack/methods/ann/layer/leaky_relu_impl.hpp b/src/mlpack/methods/ann/layer/leaky_relu_impl.hpp index 8053cd031a..79baf8dd61 100644 --- a/src/mlpack/methods/ann/layer/leaky_relu_impl.hpp +++ b/src/mlpack/methods/ann/layer/leaky_relu_impl.hpp @@ -42,7 +42,7 @@ void LeakyReLU::Backward( { DataType derivative; derivative.set_size(arma::size(input)); - for (size_t i = 0; i < input.n_elem; i++) + for (size_t i = 0; i < input.n_elem; ++i) derivative(i) = (input(i) >= 0) ? 1 : alpha; g = gy % derivative; diff --git a/src/mlpack/methods/ann/layer/minibatch_discrimination_impl.hpp b/src/mlpack/methods/ann/layer/minibatch_discrimination_impl.hpp index 18f38d5da3..0601abe90b 100644 --- a/src/mlpack/methods/ann/layer/minibatch_discrimination_impl.hpp +++ b/src/mlpack/methods/ann/layer/minibatch_discrimination_impl.hpp @@ -60,7 +60,7 @@ void MiniBatchDiscrimination::Forward( distances.set_size(B, batchSize, batchSize); output.set_size(B, batchSize); - for (size_t i = 0; i < M.n_slices; i++) + for (size_t i = 0; i < M.n_slices; ++i) { output.col(i).ones(); for (size_t j = 0; j < M.n_slices; j++) @@ -94,7 +94,7 @@ void MiniBatchDiscrimination::Backward( arma::Mat gM = gy.tail_rows(B); deltaM.zeros(B, C, batchSize); - for (size_t i = 0; i < M.n_slices; i++) + for (size_t i = 0; i < M.n_slices; ++i) { for (size_t j = 0; j < M.n_slices; j++) { diff --git a/src/mlpack/methods/ann/layer/parametric_relu_impl.hpp b/src/mlpack/methods/ann/layer/parametric_relu_impl.hpp index a794d99eae..6503312ff7 100644 --- a/src/mlpack/methods/ann/layer/parametric_relu_impl.hpp +++ b/src/mlpack/methods/ann/layer/parametric_relu_impl.hpp @@ -53,7 +53,7 @@ void PReLU::Backward( { DataType derivative; derivative.set_size(arma::size(input)); - for (size_t i = 0; i < input.n_elem; i++) + for (size_t i = 0; i < input.n_elem; ++i) { derivative(i) = (input(i) >= 0) ? 1 : alpha(0); } diff --git a/src/mlpack/methods/ann/layer/subview.hpp b/src/mlpack/methods/ann/layer/subview.hpp index ed4200353a..72268ab5ef 100644 --- a/src/mlpack/methods/ann/layer/subview.hpp +++ b/src/mlpack/methods/ann/layer/subview.hpp @@ -86,7 +86,7 @@ class Subview if ((input.n_rows != ((endRow - beginRow + 1) * (endCol - beginCol + 1))) || (input.n_cols != batchSize)) { - for (size_t i = 0; i < batchSize; i++) + for (size_t i = 0; i < batchSize; ++i) { output.col(i) = arma::vectorise( input.submat(beginRow, batchBegin, endRow, batchEnd)); diff --git a/src/mlpack/methods/ann/layer/vr_class_reward_impl.hpp b/src/mlpack/methods/ann/layer/vr_class_reward_impl.hpp index 43a17d83e6..7c452308ff 100644 --- a/src/mlpack/methods/ann/layer/vr_class_reward_impl.hpp +++ b/src/mlpack/methods/ann/layer/vr_class_reward_impl.hpp @@ -49,7 +49,7 @@ double VRClassReward::Forward( reward = 0; arma::uword index = 0; - for (size_t i = 0; i < input.n_cols - 1; i++) + for (size_t i = 0; i < input.n_cols - 1; ++i) { input.unsafe_col(i).max(index); reward = ((index + 1) == target(i)) * scale; diff --git a/src/mlpack/methods/ann/rbm/rbm_impl.hpp b/src/mlpack/methods/ann/rbm/rbm_impl.hpp index 262ac5b4de..d03253a43a 100644 --- a/src/mlpack/methods/ann/rbm/rbm_impl.hpp +++ b/src/mlpack/methods/ann/rbm/rbm_impl.hpp @@ -169,7 +169,7 @@ RBM::SampleHidden( { HiddenMean(std::move(input), std::move(output)); - for (size_t i = 0; i < output.n_elem; i++) + for (size_t i = 0; i < output.n_elem; ++i) { output(i) = math::RandBernoulli(output(i)); } @@ -188,7 +188,7 @@ RBM::SampleVisible( { VisibleMean(std::move(input), std::move(output)); - for (size_t i = 0; i < output.n_elem; i++) + for (size_t i = 0; i < output.n_elem; ++i) { output(i) = math::RandBernoulli(output(i)); } @@ -275,7 +275,7 @@ void RBM::Gradient( Phase(std::move(predictors.cols(i, i + batchSize - 1)), std::move(positiveGradient)); - for (size_t i = 0; i < negSteps; i++) + for (size_t i = 0; i < negSteps; ++i) { Gibbs(std::move(predictors.cols(i, i + batchSize - 1)), std::move(negativeSamples)); diff --git a/src/mlpack/methods/ann/rbm/spike_slab_rbm_impl.hpp b/src/mlpack/methods/ann/rbm/spike_slab_rbm_impl.hpp index 9b282585c5..9e268380c4 100644 --- a/src/mlpack/methods/ann/rbm/spike_slab_rbm_impl.hpp +++ b/src/mlpack/methods/ann/rbm/spike_slab_rbm_impl.hpp @@ -75,7 +75,7 @@ RBM::FreeEnergy( freeEnergy -= 0.5 * hiddenSize * poolSize * std::log((2.0 * M_PI) / slabPenalty); - for (size_t i = 0; i < hiddenSize; i++) + for (size_t i = 0; i < hiddenSize; ++i) { ElemType sum = arma::accu(arma::square(input.t() * weight.slice(i))) / (2.0 * slabPenalty); @@ -109,7 +109,7 @@ RBM::Phase( SampleSpike(std::move(spikeMean), std::move(spikeSamples)); SlabMean(std::move(input), std::move(spikeSamples), std::move(slabMean)); - for (size_t i = 0 ; i < hiddenSize; i++) + for (size_t i = 0 ; i < hiddenSize; ++i) { weightGrad.slice(i) = input * arma::repmat(slabMean.col(i).t(), input.n_cols, 1) * spikeMean(i); @@ -163,7 +163,7 @@ RBM::SampleVisible( for (k = 0; k < numMaxTrials; k++) { - for (size_t i = 0; i < visibleSize; i++) + for (size_t i = 0; i < visibleSize; ++i) { output(i) = math::RandNormal(visibleMean(i), 1.0 / visiblePenalty(0)); } @@ -199,7 +199,7 @@ RBM::VisibleMean( DataType slab(input.memptr() + hiddenSize, poolSize, hiddenSize, false, false); - for (size_t i = 0; i < hiddenSize; i++) + for (size_t i = 0; i < hiddenSize; ++i) { output += weight.slice(i) * slab.col(i) * spike(i); } @@ -240,7 +240,7 @@ RBM::SpikeMean( DataType&& visible, DataType&& spikeMean) { - for (size_t i = 0; i < hiddenSize; i++) + for (size_t i = 0; i < hiddenSize; ++i) { spikeMean(i) = LogisticFunction::Fn(0.5 * (1.0 / slabPenalty) * arma::accu( visible.t() * (weight.slice(i) * weight.slice(i).t()) * visible) @@ -259,7 +259,7 @@ RBM::SampleSpike( DataType&& spikeMean, DataType&& spike) { - for (size_t i = 0; i < hiddenSize; i++) + for (size_t i = 0; i < hiddenSize; ++i) { spike(i) = math::RandBernoulli(spikeMean(i)); } @@ -277,7 +277,7 @@ RBM::SlabMean( DataType&& spike, DataType&& slabMean) { - for (size_t i = 0; i < hiddenSize; i++) + for (size_t i = 0; i < hiddenSize; ++i) { slabMean.col(i) = arma::mean((1.0 / slabPenalty) * spike(i) * weight.slice(i).t() * visible, 1); @@ -295,7 +295,7 @@ RBM::SampleSlab( DataType&& slabMean, DataType&& slab) { - for (size_t i = 0; i < hiddenSize; i++) + for (size_t i = 0; i < hiddenSize; ++i) { for (size_t j = 0; j < poolSize; j++) { diff --git a/src/mlpack/methods/ann/regularizer/orthogonal_regularizer_impl.hpp b/src/mlpack/methods/ann/regularizer/orthogonal_regularizer_impl.hpp index d1f3411e7e..a9ec9a7e97 100644 --- a/src/mlpack/methods/ann/regularizer/orthogonal_regularizer_impl.hpp +++ b/src/mlpack/methods/ann/regularizer/orthogonal_regularizer_impl.hpp @@ -29,7 +29,7 @@ void OrthogonalRegularizer::Evaluate(const MatType& weight, MatType& gradient) { arma::mat grad = arma::zeros(arma::size(weight)); - for (size_t i = 0; i < weight.n_rows; i++) + for (size_t i = 0; i < weight.n_rows; ++i) { for (size_t j = 0; j < weight.n_rows; j++) { diff --git a/src/mlpack/methods/bias_svd/bias_svd_function_impl.hpp b/src/mlpack/methods/bias_svd/bias_svd_function_impl.hpp index f8a16088d5..c752a03c91 100644 --- a/src/mlpack/methods/bias_svd/bias_svd_function_impl.hpp +++ b/src/mlpack/methods/bias_svd/bias_svd_function_impl.hpp @@ -108,7 +108,7 @@ void BiasSVDFunction::Gradient(const arma::mat& parameters, gradient.zeros(rank + 1, numUsers + numItems); - for (size_t i = 0; i < data.n_cols; i++) + for (size_t i = 0; i < data.n_cols; ++i) { // Indices for accessing the the correct parameter columns. const size_t user = data(0, i); @@ -198,7 +198,7 @@ double StandardSGD::Optimize( double overallObjective = 0; // Calculate the first objective function. - for (size_t i = 0; i < numFunctions; i++) + for (size_t i = 0; i < numFunctions; ++i) overallObjective += function.Evaluate(parameters, i); const arma::mat data = function.Dataset(); @@ -207,7 +207,7 @@ double StandardSGD::Optimize( const size_t rank = function.Rank(); // Now iterate! - for (size_t i = 1; i != maxIterations; i++, currentFunction++) + for (size_t i = 1; i != maxIterations; ++i, currentFunction++) { // Is this iteration the start of a sequence? if ((currentFunction % numFunctions) == 0) diff --git a/src/mlpack/methods/cf/cf_impl.hpp b/src/mlpack/methods/cf/cf_impl.hpp index e97d86d0cd..f08867a43a 100644 --- a/src/mlpack/methods/cf/cf_impl.hpp +++ b/src/mlpack/methods/cf/cf_impl.hpp @@ -210,7 +210,7 @@ GetRecommendations(const size_t numRecs, // time and we don't want to repeat the initialization process in each loop. InterpolationPolicy interpolation(cleanedData); - for (size_t i = 0; i < users.n_elem; i++) + for (size_t i = 0; i < users.n_elem; ++i) { // First, calculate the weighted sum of neighborhood values. arma::vec ratings; @@ -355,7 +355,7 @@ Predict(const arma::Mat& combinations, // Calculate interpolation weights. InterpolationPolicy interpolation(cleanedData); - for (size_t i = 0; i < users.n_elem; i++) + for (size_t i = 0; i < users.n_elem; ++i) { interpolation.GetWeights(weights.col(i), decomposition, users[i], neighborhood.col(i), similarities.col(i), cleanedData); diff --git a/src/mlpack/methods/cf/decomposition_policies/batch_svd_method.hpp b/src/mlpack/methods/cf/decomposition_policies/batch_svd_method.hpp index 2d7e38b19b..8d460af0fc 100644 --- a/src/mlpack/methods/cf/decomposition_policies/batch_svd_method.hpp +++ b/src/mlpack/methods/cf/decomposition_policies/batch_svd_method.hpp @@ -138,7 +138,7 @@ class BatchSVDPolicy // Temporarily store feature vector of queried users. arma::mat query(stretchedH.n_rows, users.n_elem); // Select feature vectors of queried users. - for (size_t i = 0; i < users.n_elem; i++) + for (size_t i = 0; i < users.n_elem; ++i) query.col(i) = stretchedH.col(users(i)); NeighborSearchPolicy neighborSearch(stretchedH); diff --git a/src/mlpack/methods/cf/decomposition_policies/bias_svd_method.hpp b/src/mlpack/methods/cf/decomposition_policies/bias_svd_method.hpp index e187712fcc..ce0be288bf 100644 --- a/src/mlpack/methods/cf/decomposition_policies/bias_svd_method.hpp +++ b/src/mlpack/methods/cf/decomposition_policies/bias_svd_method.hpp @@ -128,7 +128,7 @@ class BiasSVDPolicy // Temporarily store feature vector of queried users. arma::mat query(h.n_rows, users.n_elem); // Select feature vectors of queried users. - for (size_t i = 0; i < users.n_elem; i++) + for (size_t i = 0; i < users.n_elem; ++i) query.col(i) = h.col(users(i)); NeighborSearchPolicy neighborSearch(h); diff --git a/src/mlpack/methods/cf/decomposition_policies/nmf_method.hpp b/src/mlpack/methods/cf/decomposition_policies/nmf_method.hpp index f7a9d07c94..173876cd6d 100644 --- a/src/mlpack/methods/cf/decomposition_policies/nmf_method.hpp +++ b/src/mlpack/methods/cf/decomposition_policies/nmf_method.hpp @@ -135,7 +135,7 @@ class NMFPolicy // Temporarily store feature vector of queried users. arma::mat query(stretchedH.n_rows, users.n_elem); // Select feature vectors of queried users. - for (size_t i = 0; i < users.n_elem; i++) + for (size_t i = 0; i < users.n_elem; ++i) query.col(i) = stretchedH.col(users(i)); NeighborSearchPolicy neighborSearch(stretchedH); diff --git a/src/mlpack/methods/cf/decomposition_policies/randomized_svd_method.hpp b/src/mlpack/methods/cf/decomposition_policies/randomized_svd_method.hpp index e190283fbe..088ed5d903 100644 --- a/src/mlpack/methods/cf/decomposition_policies/randomized_svd_method.hpp +++ b/src/mlpack/methods/cf/decomposition_policies/randomized_svd_method.hpp @@ -144,7 +144,7 @@ class RandomizedSVDPolicy // Temporarily store feature vector of queried users. arma::mat query(stretchedH.n_rows, users.n_elem); // Select feature vectors of queried users. - for (size_t i = 0; i < users.n_elem; i++) + for (size_t i = 0; i < users.n_elem; ++i) query.col(i) = stretchedH.col(users(i)); NeighborSearchPolicy neighborSearch(stretchedH); diff --git a/src/mlpack/methods/cf/decomposition_policies/regularized_svd_method.hpp b/src/mlpack/methods/cf/decomposition_policies/regularized_svd_method.hpp index 454666c979..600cf5fae9 100644 --- a/src/mlpack/methods/cf/decomposition_policies/regularized_svd_method.hpp +++ b/src/mlpack/methods/cf/decomposition_policies/regularized_svd_method.hpp @@ -131,7 +131,7 @@ class RegSVDPolicy // Temporarily store feature vector of queried users. arma::mat query(stretchedH.n_rows, users.n_elem); // Select feature vectors of queried users. - for (size_t i = 0; i < users.n_elem; i++) + for (size_t i = 0; i < users.n_elem; ++i) query.col(i) = stretchedH.col(users(i)); NeighborSearchPolicy neighborSearch(stretchedH); diff --git a/src/mlpack/methods/cf/decomposition_policies/svd_complete_method.hpp b/src/mlpack/methods/cf/decomposition_policies/svd_complete_method.hpp index 7d3d44a6ac..d7ecedd538 100644 --- a/src/mlpack/methods/cf/decomposition_policies/svd_complete_method.hpp +++ b/src/mlpack/methods/cf/decomposition_policies/svd_complete_method.hpp @@ -141,7 +141,7 @@ class SVDCompletePolicy // Temporarily store feature vector of queried users. arma::mat query(stretchedH.n_rows, users.n_elem); // Select feature vectors of queried users. - for (size_t i = 0; i < users.n_elem; i++) + for (size_t i = 0; i < users.n_elem; ++i) query.col(i) = stretchedH.col(users(i)); NeighborSearchPolicy neighborSearch(stretchedH); diff --git a/src/mlpack/methods/cf/decomposition_policies/svd_incomplete_method.hpp b/src/mlpack/methods/cf/decomposition_policies/svd_incomplete_method.hpp index 6a1bd27535..a6a7620e5c 100644 --- a/src/mlpack/methods/cf/decomposition_policies/svd_incomplete_method.hpp +++ b/src/mlpack/methods/cf/decomposition_policies/svd_incomplete_method.hpp @@ -140,7 +140,7 @@ class SVDIncompletePolicy // Temporarily store feature vector of queried users. arma::mat query(stretchedH.n_rows, users.n_elem); // Select feature vectors of queried users. - for (size_t i = 0; i < users.n_elem; i++) + for (size_t i = 0; i < users.n_elem; ++i) query.col(i) = stretchedH.col(users(i)); NeighborSearchPolicy neighborSearch(stretchedH); diff --git a/src/mlpack/methods/cf/decomposition_policies/svdplusplus_method.hpp b/src/mlpack/methods/cf/decomposition_policies/svdplusplus_method.hpp index db27705d66..35050008d6 100644 --- a/src/mlpack/methods/cf/decomposition_policies/svdplusplus_method.hpp +++ b/src/mlpack/methods/cf/decomposition_policies/svdplusplus_method.hpp @@ -163,7 +163,7 @@ class SVDPlusPlusPolicy // Temporarily store feature vector of queried users. arma::mat query(h.n_rows, users.n_elem); // Select feature vectors of queried users. - for (size_t i = 0; i < users.n_elem; i++) + for (size_t i = 0; i < users.n_elem; ++i) query.col(i) = h.col(users(i)); NeighborSearchPolicy neighborSearch(h); diff --git a/src/mlpack/methods/cf/interpolation_policies/regression_interpolation.hpp b/src/mlpack/methods/cf/interpolation_policies/regression_interpolation.hpp index ef568d72b1..8096caaf57 100644 --- a/src/mlpack/methods/cf/interpolation_policies/regression_interpolation.hpp +++ b/src/mlpack/methods/cf/interpolation_policies/regression_interpolation.hpp @@ -126,7 +126,7 @@ class RegressionInterpolation return; } - for (size_t i = 0; i < neighborNum; i++) + for (size_t i = 0; i < neighborNum; ++i) { // Calculate coefficient. arma::vec iPrediction; diff --git a/src/mlpack/methods/cf/normalization/item_mean_normalization.hpp b/src/mlpack/methods/cf/normalization/item_mean_normalization.hpp index 98a896e2e8..aaf723c78c 100644 --- a/src/mlpack/methods/cf/normalization/item_mean_normalization.hpp +++ b/src/mlpack/methods/cf/normalization/item_mean_normalization.hpp @@ -65,7 +65,7 @@ class ItemMeanNormalization // Calculate item mean and subtract item mean from ratings. // Set item mean to 0 if the item has no rating. - for (size_t i = 0; i < itemNum; i++) + for (size_t i = 0; i < itemNum; ++i) { if (ratingNum(i) != 0) itemMean(i) /= ratingNum(i); @@ -99,7 +99,7 @@ class ItemMeanNormalization itemMean(it.row()) += *it; ratingNum(it.row()) += 1; } - for (size_t i = 0; i < itemMean.n_elem; i++) + for (size_t i = 0; i < itemMean.n_elem; ++i) { if (ratingNum(i) != 0) itemMean(i) /= ratingNum(i); @@ -143,7 +143,7 @@ class ItemMeanNormalization void Denormalize(const arma::Mat& combinations, arma::vec& predictions) const { - for (size_t i = 0; i < predictions.n_elem; i++) + for (size_t i = 0; i < predictions.n_elem; ++i) { const size_t item = combinations(1, i); predictions(i) += itemMean(item); diff --git a/src/mlpack/methods/cf/normalization/user_mean_normalization.hpp b/src/mlpack/methods/cf/normalization/user_mean_normalization.hpp index c60e1a1df1..0eb48fbf87 100644 --- a/src/mlpack/methods/cf/normalization/user_mean_normalization.hpp +++ b/src/mlpack/methods/cf/normalization/user_mean_normalization.hpp @@ -65,7 +65,7 @@ class UserMeanNormalization // Calculate user mean and subtract user mean from ratings. // Set user mean to 0 if the user has no rating. - for (size_t i = 0; i < userNum; i++) + for (size_t i = 0; i < userNum; ++i) { if (ratingNum(i) != 0) userMean(i) /= ratingNum(i); @@ -99,7 +99,7 @@ class UserMeanNormalization userMean(it.col()) += *it; ratingNum(it.col()) += 1; } - for (size_t i = 0; i < userMean.n_elem; i++) + for (size_t i = 0; i < userMean.n_elem; ++i) { if (ratingNum(i) != 0) userMean(i) /= ratingNum(i); @@ -143,7 +143,7 @@ class UserMeanNormalization void Denormalize(const arma::Mat& combinations, arma::vec& predictions) const { - for (size_t i = 0; i < predictions.n_elem; i++) + for (size_t i = 0; i < predictions.n_elem; ++i) { const size_t user = combinations(0, i); predictions(i) += userMean(user); diff --git a/src/mlpack/methods/cf/svd_wrapper_impl.hpp b/src/mlpack/methods/cf/svd_wrapper_impl.hpp index 2c97eb0ef9..19c5c963ca 100644 --- a/src/mlpack/methods/cf/svd_wrapper_impl.hpp +++ b/src/mlpack/methods/cf/svd_wrapper_impl.hpp @@ -22,7 +22,7 @@ double mlpack::cf::SVDWrapper::Apply(const arma::mat& V, // construct sigma matrix sigma.zeros(V.n_rows, V.n_cols); - for (size_t i = 0; i < sigma.n_rows && i < sigma.n_cols; i++) + for (size_t i = 0; i < sigma.n_rows && i < sigma.n_cols; ++i) sigma(i, i) = E(i, 0); arma::mat V_rec = W * sigma * arma::trans(H); @@ -44,7 +44,7 @@ double mlpack::cf::SVDWrapper::Apply(const arma::mat& V, // construct sigma matrix sigma.zeros(V.n_rows, V.n_cols); - for (size_t i = 0; i < sigma.n_rows && i < sigma.n_cols; i++) + for (size_t i = 0; i < sigma.n_rows && i < sigma.n_cols; ++i) sigma(i, i) = E(i, 0); arma::mat V_rec = W * sigma * arma::trans(H); diff --git a/src/mlpack/methods/decision_stump/decision_stump_impl.hpp b/src/mlpack/methods/decision_stump/decision_stump_impl.hpp index 73e324e2e1..7d471d835b 100644 --- a/src/mlpack/methods/decision_stump/decision_stump_impl.hpp +++ b/src/mlpack/methods/decision_stump/decision_stump_impl.hpp @@ -108,7 +108,7 @@ double DecisionStump::Train(const MatType& data, const double rootEntropy = CalculateEntropy(labels, weights); double gain, bestGain = 0.0; - for (size_t i = 0; i < data.n_rows; i++) + for (size_t i = 0; i < data.n_rows; ++i) { // Go through each dimension of the data. if (IsDistinct(data.row(i))) @@ -150,7 +150,7 @@ void DecisionStump::Classify(const MatType& test, arma::Row& predictedLabels) { predictedLabels.set_size(test.n_cols); - for (size_t i = 0; i < test.n_cols; i++) + for (size_t i = 0; i < test.n_cols; ++i) { // Determine which bin the test point falls into. // Assume first that it falls into the first bin, then proceed through the @@ -236,7 +236,7 @@ double DecisionStump::SetupSplitDimension( arma::Row sortedLabels(dimension.n_elem); arma::rowvec sortedWeights(dimension.n_elem); - for (i = 0; i < dimension.n_elem; i++) + for (i = 0; i < dimension.n_elem; ++i) { sortedLabels(i) = labels(sortedIndexDim(i)); @@ -265,7 +265,7 @@ double DecisionStump::SetupSplitDimension( entropy += ratioEl * CalculateEntropy( sortedLabels.subvec(begin, end), sortedWeights.subvec(begin, end)); - i++; + ++i; } else if (sortedLabels(i) != sortedLabels(i + 1)) { @@ -297,7 +297,7 @@ double DecisionStump::SetupSplitDimension( count = 0; } else - i++; + ++i; } return entropy; } @@ -321,7 +321,7 @@ void DecisionStump::TrainOnDim(const VecType& dimension, arma::Row sortedLabels(dimension.n_elem); sortedLabels.fill(0); - for (i = 0; i < dimension.n_elem; i++) + for (i = 0; i < dimension.n_elem; ++i) sortedLabels(i) = labels(sortedSplitIndexDim(i)); arma::rowvec subCols; @@ -343,7 +343,7 @@ void DecisionStump::TrainOnDim(const VecType& dimension, binLabels.resize(binLabels.n_elem + 1); binLabels(binLabels.n_elem - 1) = mostFreq; - i++; + ++i; } else if (sortedLabels(i) != sortedLabels(i + 1)) { @@ -375,7 +375,7 @@ void DecisionStump::TrainOnDim(const VecType& dimension, count = 0; } else - i++; + ++i; } // Now trim the split matrix so that buckets one after the after which point @@ -390,7 +390,7 @@ void DecisionStump::TrainOnDim(const VecType& dimension, template void DecisionStump::MergeRanges() { - for (size_t i = 1; i < split.n_rows; i++) + for (size_t i = 1; i < split.n_rows; ++i) { if (binLabels(i) == binLabels(i - 1)) { diff --git a/src/mlpack/methods/det/det_main.cpp b/src/mlpack/methods/det/det_main.cpp index df2db81694..2fbe68d10b 100644 --- a/src/mlpack/methods/det/det_main.cpp +++ b/src/mlpack/methods/det/det_main.cpp @@ -173,7 +173,7 @@ static void mlpackMain() // Compute density estimates for each point in the training set. arma::rowvec trainingDensities(trainingData.n_cols); Timer::Start("det_estimation_time"); - for (size_t i = 0; i < trainingData.n_cols; i++) + for (size_t i = 0; i < trainingData.n_cols; ++i) trainingDensities[i] = tree->ComputeValue(trainingData.unsafe_col(i)); Timer::Stop("det_estimation_time"); @@ -197,7 +197,7 @@ static void mlpackMain() Timer::Start("det_test_set_estimation"); arma::rowvec testDensities(testData.n_cols); - for (size_t i = 0; i < testData.n_cols; i++) + for (size_t i = 0; i < testData.n_cols; ++i) testDensities[i] = tree->ComputeValue(testData.unsafe_col(i)); Timer::Stop("det_test_set_estimation"); @@ -252,7 +252,7 @@ static void mlpackMain() PathCacher path(theFormat, tree); counters.zeros(path.NumNodes()); - for (size_t i = 0; i < estimationData.n_cols; i++) + for (size_t i = 0; i < estimationData.n_cols; ++i) { int tag = tree->FindBucket(estimationData.unsafe_col(i)); @@ -281,7 +281,7 @@ static void mlpackMain() int numLeaves = tree->TagTree(); counters.zeros(numLeaves); - for (size_t i = 0; i < estimationData.n_cols; i++) + for (size_t i = 0; i < estimationData.n_cols; ++i) { const int tag = tree->FindBucket(estimationData.unsafe_col(i)); diff --git a/src/mlpack/methods/det/dt_utils_impl.hpp b/src/mlpack/methods/det/dt_utils_impl.hpp index ee24f3c5d4..6e5355b48a 100644 --- a/src/mlpack/methods/det/dt_utils_impl.hpp +++ b/src/mlpack/methods/det/dt_utils_impl.hpp @@ -32,7 +32,7 @@ void PrintLeafMembership(DTree* dtree, arma::Mat table(numLeaves, (numClasses + 1)); table.zeros(); - for (size_t i = 0; i < data.n_cols; i++) + for (size_t i = 0; i < data.n_cols; ++i) { const typename MatType::vec_type testPoint = data.unsafe_col(i); const int leafTag = dtree->FindBucket(testPoint); @@ -120,7 +120,7 @@ DTree* Trainer(MatType& dataset, Timer::Start("tree_growing"); // Prepare to grow the tree... arma::Col oldFromNew(dataset.n_cols); - for (size_t i = 0; i < oldFromNew.n_elem; i++) + for (size_t i = 0; i < oldFromNew.n_elem; ++i) oldFromNew[i] = i; // Save the dataset since it would be modified while growing the tree. @@ -214,7 +214,7 @@ DTree* Trainer(MatType& dataset, // Getting ready to grow the tree... arma::Col cvOldFromNew(train.n_cols); - for (size_t i = 0; i < cvOldFromNew.n_elem; i++) + for (size_t i = 0; i < cvOldFromNew.n_elem; ++i) cvOldFromNew[i] = i; // Grow the tree. @@ -287,7 +287,7 @@ DTree* Trainer(MatType& dataset, dtree = new DTree(dataset); // Getting ready to grow the tree... - for (size_t i = 0; i < oldFromNew.n_elem; i++) + for (size_t i = 0; i < oldFromNew.n_elem; ++i) oldFromNew[i] = i; // Save the dataset since it would be modified while growing the tree. diff --git a/src/mlpack/methods/emst/dtb_impl.hpp b/src/mlpack/methods/emst/dtb_impl.hpp index a5ba58a314..cb4dd4b8a5 100644 --- a/src/mlpack/methods/emst/dtb_impl.hpp +++ b/src/mlpack/methods/emst/dtb_impl.hpp @@ -195,7 +195,7 @@ template< typename TreeMatType> class TreeType> void DualTreeBoruvka::AddAllEdges() { - for (size_t i = 0; i < data.n_cols; i++) + for (size_t i = 0; i < data.n_cols; ++i) { size_t component = connections.Find(i); size_t inEdge = neighborsInComponent[component]; @@ -232,7 +232,7 @@ void DualTreeBoruvka::EmitResults( // Need to unpermute the point labels. if (!naive && ownTree && tree::TreeTraits::RearrangesDataset) { - for (size_t i = 0; i < (data.n_cols - 1); i++) + for (size_t i = 0; i < (data.n_cols - 1); ++i) { // Make sure the edge list stores the smaller index first to // make checking correctness easier @@ -257,7 +257,7 @@ void DualTreeBoruvka::EmitResults( } else { - for (size_t i = 0; i < edges.size(); i++) + for (size_t i = 0; i < edges.size(); ++i) { results(0, i) = edges[i].Lesser(); results(1, i) = edges[i].Greater(); @@ -318,7 +318,7 @@ template< typename TreeMatType> class TreeType> void DualTreeBoruvka::Cleanup() { - for (size_t i = 0; i < data.n_cols; i++) + for (size_t i = 0; i < data.n_cols; ++i) neighborsDistances[i] = DBL_MAX; if (!naive) diff --git a/src/mlpack/methods/fastmks/fastmks_rules_impl.hpp b/src/mlpack/methods/fastmks/fastmks_rules_impl.hpp index 4b98fd6c3d..69b57c3965 100644 --- a/src/mlpack/methods/fastmks/fastmks_rules_impl.hpp +++ b/src/mlpack/methods/fastmks/fastmks_rules_impl.hpp @@ -58,7 +58,7 @@ FastMKSRules::FastMKSRules( CandidateList pqueue; pqueue.reserve(k); - for (size_t i = 0; i < k; i++) + for (size_t i = 0; i < k; ++i) pqueue.push(def); std::vector tmp(querySet.n_cols, pqueue); candidates.swap(tmp); @@ -72,7 +72,7 @@ void FastMKSRules::GetResults( indices.set_size(k, querySet.n_cols); products.set_size(k, querySet.n_cols); - for (size_t i = 0; i < querySet.n_cols; i++) + for (size_t i = 0; i < querySet.n_cols; ++i) { CandidateList& pqueue = candidates[i]; for (size_t j = 1; j <= k; j++) diff --git a/src/mlpack/methods/gmm/diagonal_gmm.cpp b/src/mlpack/methods/gmm/diagonal_gmm.cpp index e5ed0e6001..45f4604560 100644 --- a/src/mlpack/methods/gmm/diagonal_gmm.cpp +++ b/src/mlpack/methods/gmm/diagonal_gmm.cpp @@ -59,7 +59,7 @@ double DiagonalGMM::LogProbability(const arma::vec& observation) const // Sum the probability for each Gaussian in our mixture (and we have to // multiply by the prior for each Gaussian too). double sum = -std::numeric_limits::infinity(); - for (size_t i = 0; i < gaussians; i++) + for (size_t i = 0; i < gaussians; ++i) { sum = math::LogAdd(sum, log(weights[i]) + dists[i].LogProbability(observation)); @@ -163,7 +163,7 @@ double DiagonalGMM::LogLikelihood( arma::vec phis; arma::mat likelihoods(gaussians, observations.n_cols); - for (size_t i = 0; i < gaussians; i++) + for (size_t i = 0; i < gaussians; ++i) { dists[i].Probability(observations, phis); likelihoods.row(i) = weights(i) * trans(phis); diff --git a/src/mlpack/methods/gmm/em_fit_impl.hpp b/src/mlpack/methods/gmm/em_fit_impl.hpp index 93c446b612..298c9b33f6 100644 --- a/src/mlpack/methods/gmm/em_fit_impl.hpp +++ b/src/mlpack/methods/gmm/em_fit_impl.hpp @@ -88,7 +88,7 @@ Estimate(const arma::mat& observations, // Calculate the conditional probabilities of choosing a particular // Gaussian given the observations and the present theta value. - for (size_t i = 0; i < dists.size(); i++) + for (size_t i = 0; i < dists.size(); ++i) { // Store conditional log probabilities into condLogProb vector for each // Gaussian. First we make an alias of the condLogProb vector. @@ -98,7 +98,7 @@ Estimate(const arma::mat& observations, } // Normalize row-wise. - for (size_t i = 0; i < condLogProb.n_rows; i++) + for (size_t i = 0; i < condLogProb.n_rows; ++i) { // Avoid dividing by zero; if the probability for everything is 0, we // don't want to make it NaN. @@ -116,7 +116,7 @@ Estimate(const arma::mat& observations, // Calculate the new value of the means using the updated conditional // probabilities. - for (size_t i = 0; i < dists.size(); i++) + for (size_t i = 0; i < dists.size(); ++i) { // Don't update if there's no probability of the Gaussian having points. if (probRowSums[i] != -std::numeric_limits::infinity()) @@ -193,7 +193,7 @@ Estimate(const arma::mat& observations, { // Calculate the conditional probabilities of choosing a particular // Gaussian given the observations and the present theta value. - for (size_t i = 0; i < dists.size(); i++) + for (size_t i = 0; i < dists.size(); ++i) { // Store conditional log probabilities into condLogProb vector for each // Gaussian. First we make an alias of the condLogProb vector. @@ -203,7 +203,7 @@ Estimate(const arma::mat& observations, } // Normalize row-wise. - for (size_t i = 0; i < condLogProb.n_rows; i++) + for (size_t i = 0; i < condLogProb.n_rows; ++i) { // Avoid dividing by zero; if the probability for everything is 0, we // don't want to make it NaN. @@ -219,7 +219,7 @@ Estimate(const arma::mat& observations, // Calculate the new value of the means using the updated conditional // probabilities. arma::vec logProbabilities = arma::log(probabilities); - for (size_t i = 0; i < dists.size(); i++) + for (size_t i = 0; i < dists.size(); ++i) { // Calculate the sum of probabilities of points, which is the // conditional probability of each point being from Gaussian i diff --git a/src/mlpack/methods/gmm/gmm.cpp b/src/mlpack/methods/gmm/gmm.cpp index 6286b15143..125e7d86c9 100644 --- a/src/mlpack/methods/gmm/gmm.cpp +++ b/src/mlpack/methods/gmm/gmm.cpp @@ -59,7 +59,7 @@ double GMM::LogProbability(const arma::vec& observation) const // Sum the probability for each Gaussian in our mixture (and we have to // multiply by the prior for each Gaussian too). double sum = -std::numeric_limits::infinity(); - for (size_t i = 0; i < gaussians; i++) + for (size_t i = 0; i < gaussians; ++i) sum = math::LogAdd(sum, log(weights[i]) + dists[i].LogProbability(observation)); @@ -169,7 +169,7 @@ double GMM::LogLikelihood( arma::mat logLikelihoods(gaussians, data.n_cols); // It has to be LogProbability() otherwise Probability() would overflow easily - for (size_t i = 0; i < gaussians; i++) + for (size_t i = 0; i < gaussians; ++i) { distsL[i].LogProbability(data, logPhis); logLikelihoods.row(i) = log(weightsL(i)) + trans(logPhis); diff --git a/src/mlpack/methods/gmm/gmm_train_main.cpp b/src/mlpack/methods/gmm/gmm_train_main.cpp index 712c1e957b..d619f98c5d 100644 --- a/src/mlpack/methods/gmm/gmm_train_main.cpp +++ b/src/mlpack/methods/gmm/gmm_train_main.cpp @@ -227,7 +227,7 @@ static void mlpackMain() { // Convert GMMs into DiagonalGMMs. DiagonalGMM dgmm(gmm->Gaussians(), gmm->Dimensionality()); - for (size_t i = 0; i < size_t(gaussians); i++) + for (size_t i = 0; i < size_t(gaussians); ++i) { dgmm.Component(i).Mean() = gmm->Component(i).Mean(); dgmm.Component(i).Covariance( @@ -246,7 +246,7 @@ static void mlpackMain() Timer::Stop("em"); // Convert DiagonalGMMs into GMMs. - for (size_t i = 0; i < size_t(gaussians); i++) + for (size_t i = 0; i < size_t(gaussians); ++i) { gmm->Component(i).Mean() = dgmm.Component(i).Mean(); gmm->Component(i).Covariance( @@ -285,7 +285,7 @@ static void mlpackMain() { // Convert GMMs into DiagonalGMMs. DiagonalGMM dgmm(gmm->Gaussians(), gmm->Dimensionality()); - for (size_t i = 0; i < size_t(gaussians); i++) + for (size_t i = 0; i < size_t(gaussians); ++i) { dgmm.Component(i).Mean() = gmm->Component(i).Mean(); dgmm.Component(i).Covariance( @@ -304,7 +304,7 @@ static void mlpackMain() Timer::Stop("em"); // Convert DiagonalGMMs into GMMs. - for (size_t i = 0; i < size_t(gaussians); i++) + for (size_t i = 0; i < size_t(gaussians); ++i) { gmm->Component(i).Mean() = dgmm.Component(i).Mean(); gmm->Component(i).Covariance( diff --git a/src/mlpack/methods/hmm/hmm_impl.hpp b/src/mlpack/methods/hmm/hmm_impl.hpp index efd049db0e..57fe29f9b7 100644 --- a/src/mlpack/methods/hmm/hmm_impl.hpp +++ b/src/mlpack/methods/hmm/hmm_impl.hpp @@ -166,7 +166,7 @@ double HMM::Train(const std::vector& dataSeq) { // Estimate of T_ij (probability of transition from state j to state // i). We postpone multiplication of the old T_ij until later. - for (size_t i = 0; i < logTransition.n_rows; i++) + for (size_t i = 0; i < logTransition.n_rows; ++i) { newLogTransition(i, j) = math::LogAdd(newLogTransition(i, j), forwardLog(j, t) + backwardLog(i, t + 1) + @@ -204,7 +204,7 @@ double HMM::Train(const std::vector& dataSeq) logTransition += newLogTransition; // Now we normalize the transition matrix. - for (size_t i = 0; i < logTransition.n_cols; i++) + for (size_t i = 0; i < logTransition.n_cols; ++i) { const double sum = math::AccuLog(logTransition.col(i)); if (std::isfinite(sum)) @@ -309,7 +309,7 @@ void HMM::Train(const std::vector& dataSeq, if (emissionList[state].size() > 0) { arma::mat emissions(dimensionality, emissionList[state].size()); - for (size_t i = 0; i < emissions.n_cols; i++) + for (size_t i = 0; i < emissions.n_cols; ++i) { emissions.col(i) = dataSeq[emissionList[state][i].first].col( emissionList[state][i].second); @@ -544,7 +544,7 @@ void HMM::Filter(const arma::mat& dataSeq, // Compute expected emissions. // Will not work for distributions without a Mean() function. filterSeq.zeros(dimensionality, dataSeq.n_cols); - for (size_t i = 0; i < emission.size(); i++) + for (size_t i = 0; i < emission.size(); ++i) filterSeq += emission[i].Mean() * forwardProb.row(i); } @@ -566,7 +566,7 @@ void HMM::Smooth(const arma::mat& dataSeq, // Compute expected emissions. // Will not work for distributions without a Mean() function. smoothSeq.zeros(dimensionality, dataSeq.n_cols); - for (size_t i = 0; i < emission.size(); i++) + for (size_t i = 0; i < emission.size(); ++i) smoothSeq += emission[i].Mean() * exp(stateLogProb.row(i)); } diff --git a/src/mlpack/methods/hmm/hmm_regression_impl.hpp b/src/mlpack/methods/hmm/hmm_regression_impl.hpp index 7d3e82ba69..51e601526c 100644 --- a/src/mlpack/methods/hmm/hmm_regression_impl.hpp +++ b/src/mlpack/methods/hmm/hmm_regression_impl.hpp @@ -116,7 +116,7 @@ void HMMRegression::Filter(const arma::mat& predictors, filterSeq.resize(responses.n_elem - ahead); filterSeq.zeros(); arma::vec nextSeq; - for (size_t i = 0; i < emission.size(); i++) + for (size_t i = 0; i < emission.size(); ++i) { emission[i].Predict(predictors.cols(ahead, predictors.n_cols-1), nextSeq); filterSeq = filterSeq + nextSeq%(forwardProb.row(i).t()); @@ -138,7 +138,7 @@ void HMMRegression::Smooth(const arma::mat& predictors, smoothSeq.resize(responses.n_elem); smoothSeq.zeros(); arma::vec nextSeq; - for (size_t i = 0; i < emission.size(); i++) + for (size_t i = 0; i < emission.size(); ++i) { emission[i].Predict(predictors, nextSeq); smoothSeq = smoothSeq + nextSeq%(stateProb.row(i).t()); @@ -174,7 +174,7 @@ void HMMRegression::StackData(const std::vector& predictors, std::vector& dataSeq) const { arma::mat nextSeq; - for (size_t i = 0; i < predictors.size(); i++) + for (size_t i = 0; i < predictors.size(); ++i) { nextSeq = predictors[i]; nextSeq.insert_rows(0, responses[i].t()); diff --git a/src/mlpack/methods/kmeans/kmeans_impl.hpp b/src/mlpack/methods/kmeans/kmeans_impl.hpp index cdbfccdc4b..4f3564e0b7 100644 --- a/src/mlpack/methods/kmeans/kmeans_impl.hpp +++ b/src/mlpack/methods/kmeans/kmeans_impl.hpp @@ -222,7 +222,7 @@ Cluster(const MatType& data, // If we are not allowing empty clusters, then check that all of our // clusters have points. - for (size_t i = 0; i < counts.n_elem; i++) + for (size_t i = 0; i < counts.n_elem; ++i) { if (counts[i] == 0) { diff --git a/src/mlpack/methods/kmeans/kmeans_main.cpp b/src/mlpack/methods/kmeans/kmeans_main.cpp index bc6934a942..73dc33fb17 100644 --- a/src/mlpack/methods/kmeans/kmeans_main.cpp +++ b/src/mlpack/methods/kmeans/kmeans_main.cpp @@ -303,7 +303,7 @@ void RunKMeans(const InitialPartitionPolicy& ipp) // Add the column of assignments to the dataset; but we have to convert // them to type double first. arma::rowvec converted(assignments.n_elem); - for (size_t i = 0; i < assignments.n_elem; i++) + for (size_t i = 0; i < assignments.n_elem; ++i) converted(i) = (double) assignments(i); dataset.insert_rows(dataset.n_rows, converted); @@ -325,7 +325,7 @@ void RunKMeans(const InitialPartitionPolicy& ipp) { // Convert the assignments to doubles. arma::rowvec converted(assignments.n_elem); - for (size_t i = 0; i < assignments.n_elem; i++) + for (size_t i = 0; i < assignments.n_elem; ++i) converted(i) = (double) assignments(i); dataset.insert_rows(dataset.n_rows, converted); diff --git a/src/mlpack/methods/lars/lars.cpp b/src/mlpack/methods/lars/lars.cpp index 8e9bff983e..083ea6eca5 100644 --- a/src/mlpack/methods/lars/lars.cpp +++ b/src/mlpack/methods/lars/lars.cpp @@ -243,7 +243,7 @@ double LARS::Train(const arma::mat& matX, { // Compute the maximum correlation among inactive dimensions. maxCorr = 0; - for (size_t i = 0; i < dataRef.n_cols; i++) + for (size_t i = 0; i < dataRef.n_cols; ++i) { if ((!isActive[i]) && (!isIgnored[i]) && (fabs(corr(i)) > maxCorr)) { @@ -257,7 +257,7 @@ double LARS::Train(const arma::mat& matX, if (useCholesky) { // vec newGramCol = vec(activeSet.size()); - // for (size_t i = 0; i < activeSet.size(); i++) + // for (size_t i = 0; i < activeSet.size(); ++i) // { // newGramCol[i] = dot(matX.col(activeSet[i]), matX.col(changeInd)); // } @@ -274,7 +274,7 @@ double LARS::Train(const arma::mat& matX, // Compute signs of correlations. arma::vec s = arma::vec(activeSet.size()); - for (size_t i = 0; i < activeSet.size(); i++) + for (size_t i = 0; i < activeSet.size(); ++i) s(i) = corr(activeSet[i]) / fabs(corr(activeSet[i])); // Compute the "equiangular" direction in parameter space (betaDirection). @@ -324,7 +324,7 @@ double LARS::Train(const arma::mat& matX, else { arma::mat matGramActive = arma::mat(activeSet.size(), activeSet.size()); - for (size_t i = 0; i < activeSet.size(); i++) + for (size_t i = 0; i < activeSet.size(); ++i) for (size_t j = 0; j < activeSet.size(); j++) matGramActive(i, j) = (*matGram)(activeSet[i], activeSet[j]); @@ -383,7 +383,7 @@ double LARS::Train(const arma::mat& matX, double lassoboundOnGamma = DBL_MAX; size_t activeIndToKickOut = -1; - for (size_t i = 0; i < activeSet.size(); i++) + for (size_t i = 0; i < activeSet.size(); ++i) { double val = -beta(activeSet[i]) / betaDirection(i); if ((val > 0) && (val < lassoboundOnGamma)) @@ -405,7 +405,7 @@ double LARS::Train(const arma::mat& matX, yHat += gamma * yHatDirection; // Update the estimator. - for (size_t i = 0; i < activeSet.size(); i++) + for (size_t i = 0; i < activeSet.size(); ++i) { beta(activeSet[i]) += gamma * betaDirection(i); } @@ -433,7 +433,7 @@ double LARS::Train(const arma::mat& matX, corr -= lambda2 * beta; double curLambda = 0; - for (size_t i = 0; i < activeSet.size(); i++) + for (size_t i = 0; i < activeSet.size(); ++i) curLambda += fabs(corr(activeSet[i])); curLambda /= ((double) activeSet.size()); @@ -501,7 +501,7 @@ void LARS::ComputeYHatDirection(const arma::mat& matX, arma::vec& yHatDirection) { yHatDirection.fill(0); - for (size_t i = 0; i < activeSet.size(); i++) + for (size_t i = 0; i < activeSet.size(); ++i) yHatDirection += betaDirection(i) * matX.col(activeSet[i]); } diff --git a/src/mlpack/methods/linear_svm/linear_svm_function_impl.hpp b/src/mlpack/methods/linear_svm/linear_svm_function_impl.hpp index 0656631c20..4a736e4e51 100644 --- a/src/mlpack/methods/linear_svm/linear_svm_function_impl.hpp +++ b/src/mlpack/methods/linear_svm/linear_svm_function_impl.hpp @@ -89,7 +89,7 @@ void LinearSVMFunction::GetGroundTruthMatrix( // Row pointers are the labels of the examples, and column pointers are the // number of cumulative entries made uptil that column. - for (size_t i = 0; i < labels.n_elem; i++) + for (size_t i = 0; i < labels.n_elem; ++i) { rowPointers(i) = labels(i); colPointers(i + 1) = i + 1; diff --git a/src/mlpack/methods/linear_svm/linear_svm_impl.hpp b/src/mlpack/methods/linear_svm/linear_svm_impl.hpp index 79f7ac79da..6e1807c355 100644 --- a/src/mlpack/methods/linear_svm/linear_svm_impl.hpp +++ b/src/mlpack/methods/linear_svm/linear_svm_impl.hpp @@ -214,7 +214,7 @@ double LinearSVM::ComputeAccuracy( // Increment count for every correctly predicted label. size_t count = 0; - for (size_t i = 0; i < labels.n_elem ; i++) + for (size_t i = 0; i < labels.n_elem ; ++i) if (testLabels(i) == labels(i)) count++; diff --git a/src/mlpack/methods/lmnn/constraints_impl.hpp b/src/mlpack/methods/lmnn/constraints_impl.hpp index e370bf7256..9cb6d91cdf 100644 --- a/src/mlpack/methods/lmnn/constraints_impl.hpp +++ b/src/mlpack/methods/lmnn/constraints_impl.hpp @@ -49,7 +49,7 @@ inline void Constraints::ReorderResults( // Just a simple loop over the results---we want to make sure that the // largest-norm point with identical distance has the last location. - for (size_t i = 0; i < neighbors.n_cols; i++) + for (size_t i = 0; i < neighbors.n_cols; ++i) { for (size_t start = 0; start < neighbors.n_rows - 1; start++) { @@ -93,7 +93,7 @@ void Constraints::TargetNeighbors(arma::Mat& outputMatrix, arma::Mat neighbors; arma::mat distances; - for (size_t i = 0; i < uniqueLabels.n_cols; i++) + for (size_t i = 0; i < uniqueLabels.n_cols; ++i) { // Perform KNN search with same class points as both reference // set and query set. @@ -138,7 +138,7 @@ void Constraints::TargetNeighbors(arma::Mat& outputMatrix, // Vectors to store indices. arma::uvec subIndexSame; - for (size_t i = 0; i < uniqueLabels.n_cols; i++) + for (size_t i = 0; i < uniqueLabels.n_cols; ++i) { // Calculate Target Neighbors. subIndexSame = arma::find(sublabels == uniqueLabels[i]); @@ -177,7 +177,7 @@ void Constraints::Impostors(arma::Mat& outputMatrix, arma::Mat neighbors; arma::mat distances; - for (size_t i = 0; i < uniqueLabels.n_cols; i++) + for (size_t i = 0; i < uniqueLabels.n_cols; ++i) { // Perform KNN search with differently labeled points as reference // set and same class points as query set. @@ -215,7 +215,7 @@ void Constraints::Impostors(arma::Mat& outputNeighbors, arma::Mat neighbors; arma::mat distances; - for (size_t i = 0; i < uniqueLabels.n_cols; i++) + for (size_t i = 0; i < uniqueLabels.n_cols; ++i) { // Perform KNN search with differently labeled points as reference // set and same class points as query set. @@ -261,7 +261,7 @@ void Constraints::Impostors(arma::Mat& outputMatrix, // Vectors to store indices. arma::uvec subIndexSame; - for (size_t i = 0; i < uniqueLabels.n_cols; i++) + for (size_t i = 0; i < uniqueLabels.n_cols; ++i) { // Calculate impostors. subIndexSame = arma::find(sublabels == uniqueLabels[i]); @@ -310,7 +310,7 @@ void Constraints::Impostors(arma::Mat& outputNeighbors, // Vectors to store indices. arma::uvec subIndexSame; - for (size_t i = 0; i < uniqueLabels.n_cols; i++) + for (size_t i = 0; i < uniqueLabels.n_cols; ++i) { // Calculate impostors. subIndexSame = arma::find(sublabels == uniqueLabels[i]); @@ -357,7 +357,7 @@ void Constraints::Impostors(arma::Mat& outputNeighbors, // Vectors to store indices. arma::uvec subIndexSame; - for (size_t i = 0; i < uniqueLabels.n_cols; i++) + for (size_t i = 0; i < uniqueLabels.n_cols; ++i) { // Calculate impostors. subIndexSame = arma::find(labels.cols(points.head(numPoints)) == @@ -404,7 +404,7 @@ void Constraints::Triplets(arma::Mat& outputMatrix, outputMatrix = arma::Mat(3, k * k * N , arma::fill::zeros); - for (size_t i = 0, r = 0; i < N; i++) + for (size_t i = 0, r = 0; i < N; ++i) { for (size_t j = 0; j < k; j++) { @@ -432,7 +432,7 @@ inline void Constraints::Precalculate( indexSame.resize(uniqueLabels.n_elem); indexDiff.resize(uniqueLabels.n_elem); - for (size_t i = 0; i < uniqueLabels.n_elem; i++) + for (size_t i = 0; i < uniqueLabels.n_elem; ++i) { // Store same and diff indices. indexSame[i] = arma::find(labels == uniqueLabels[i]); diff --git a/src/mlpack/methods/lmnn/lmnn_function_impl.hpp b/src/mlpack/methods/lmnn/lmnn_function_impl.hpp index 32cc9bbf6a..6bfd0ed8ad 100644 --- a/src/mlpack/methods/lmnn/lmnn_function_impl.hpp +++ b/src/mlpack/methods/lmnn/lmnn_function_impl.hpp @@ -44,7 +44,7 @@ LMNNFunction::LMNNFunction(const arma::mat& dataset, // Calculate and store norm of datapoints. norm.set_size(dataset.n_cols); - for (size_t i = 0; i < dataset.n_cols; i++) + for (size_t i = 0; i < dataset.n_cols; ++i) { norm(i) = arma::norm(dataset.col(i)); } @@ -115,7 +115,7 @@ void LMNNFunction::Shuffle() lastTransformationIndices = newlastTransformationIndices.elem(ordering); norm = newNorm.elem(ordering); - for (size_t i = 0; i < ordering.n_elem; i++) + for (size_t i = 0; i < ordering.n_elem; ++i) { evalOld.slice(i) = newEvalOld.slice(ordering(i)); } @@ -231,7 +231,7 @@ double LMNNFunction::Evaluate(const arma::mat& transformation) // Track number of data points to use for impostors calculatiom. size_t numPoints = 0; - for (size_t i = 0; i < dataset.n_cols; i++) + for (size_t i = 0; i < dataset.n_cols; ++i) { if (transformationDiff * (2 * norm(i) + norm(impostors(k - 1, i)) + norm(impostors(k, i))) > distance(k, i) - distance(k - 1, i)) @@ -257,7 +257,7 @@ double LMNNFunction::Evaluate(const arma::mat& transformation) constraint.Impostors(impostors, distance, transformedDataset, labels, norm); } - for (size_t i = 0; i < dataset.n_cols; i++) + for (size_t i = 0; i < dataset.n_cols; ++i) { for (size_t j = 0; j < k ; j++) { @@ -356,7 +356,7 @@ double LMNNFunction::Evaluate(const arma::mat& transformation, // Track number of data points to use for impostors calculatiom. size_t numPoints = 0; - for (size_t i = begin; i < begin + batchSize; i++) + for (size_t i = begin; i < begin + batchSize; ++i) { if (lastTransformationIndices(i)) { @@ -384,7 +384,7 @@ double LMNNFunction::Evaluate(const arma::mat& transformation, norm, begin, batchSize); } - for (size_t i = begin; i < begin + batchSize; i++) + for (size_t i = begin; i < begin + batchSize; ++i) { for (size_t j = 0; j < k ; j++) { @@ -485,7 +485,7 @@ void LMNNFunction::Gradient(const arma::mat& transformation, // Track number of data points to use for impostors calculatiom. size_t numPoints = 0; - for (size_t i = 0; i < dataset.n_cols; i++) + for (size_t i = 0; i < dataset.n_cols; ++i) { if (transformationDiff * (2 * norm(i) + norm(impostors(k - 1, i)) + norm(impostors(k, i))) > distance(k, i) - distance(k - 1, i)) @@ -520,7 +520,7 @@ void LMNNFunction::Gradient(const arma::mat& transformation, // Calculate gradient due to impostors. arma::mat cil = arma::zeros(dataset.n_rows, dataset.n_rows); - for (size_t i = 0; i < dataset.n_cols; i++) + for (size_t i = 0; i < dataset.n_cols; ++i) { for (int j = k - 1; j >= 0; j--) { @@ -616,7 +616,7 @@ void LMNNFunction::Gradient(const arma::mat& transformation, // Track number of data points to use for impostors calculatiom. size_t numPoints = 0; - for (size_t i = begin; i < begin + batchSize; i++) + for (size_t i = begin; i < begin + batchSize; ++i) { if (lastTransformationIndices(i)) { @@ -649,7 +649,7 @@ void LMNNFunction::Gradient(const arma::mat& transformation, arma::mat cij = arma::zeros(dataset.n_rows, dataset.n_rows); arma::mat cil = arma::zeros(dataset.n_rows, dataset.n_rows); - for (size_t i = begin; i < begin + batchSize; i++) + for (size_t i = begin; i < begin + batchSize; ++i) { for (size_t j = 0; j < k ; j++) { @@ -760,7 +760,7 @@ double LMNNFunction::EvaluateWithGradient( // Track number of data points to use for impostors calculatiom. size_t numPoints = 0; - for (size_t i = 0; i < dataset.n_cols; i++) + for (size_t i = 0; i < dataset.n_cols; ++i) { if (transformationDiff * (2 * norm(i) + norm(impostors(k - 1, i)) + norm(impostors(k, i))) > distance(k, i) - distance(k - 1, i)) @@ -795,7 +795,7 @@ double LMNNFunction::EvaluateWithGradient( // Calculate gradient due to impostors. arma::mat cil = arma::zeros(dataset.n_rows, dataset.n_rows); - for (size_t i = 0; i < dataset.n_cols; i++) + for (size_t i = 0; i < dataset.n_cols; ++i) { for (size_t j = 0; j < k ; j++) { @@ -898,7 +898,7 @@ double LMNNFunction::EvaluateWithGradient( // Track number of data points to use for impostors calculatiom. size_t numPoints = 0; - for (size_t i = begin; i < begin + batchSize; i++) + for (size_t i = begin; i < begin + batchSize; ++i) { if (lastTransformationIndices(i)) { @@ -931,7 +931,7 @@ double LMNNFunction::EvaluateWithGradient( arma::mat cij = arma::zeros(dataset.n_rows, dataset.n_rows); arma::mat cil = arma::zeros(dataset.n_rows, dataset.n_rows); - for (size_t i = begin; i < begin + batchSize; i++) + for (size_t i = begin; i < begin + batchSize; ++i) { for (size_t j = 0; j < k ; j++) { @@ -1020,7 +1020,7 @@ inline void LMNNFunction::Precalculate() { pCij.zeros(dataset.n_rows, dataset.n_rows); - for (size_t i = 0; i < dataset.n_cols; i++) + for (size_t i = 0; i < dataset.n_cols; ++i) { for (size_t j = 0; j < k ; j++) { diff --git a/src/mlpack/methods/lmnn/lmnn_main.cpp b/src/mlpack/methods/lmnn/lmnn_main.cpp index 18e6313ba1..faf27f609e 100644 --- a/src/mlpack/methods/lmnn/lmnn_main.cpp +++ b/src/mlpack/methods/lmnn/lmnn_main.cpp @@ -198,7 +198,7 @@ double KNNAccuracy(const arma::mat& dataset, // Keep count. size_t count = 0; - for (size_t i = 0; i < dataset.n_cols; i++) + for (size_t i = 0; i < dataset.n_cols; ++i) { arma::vec Map; Map.zeros(uniqueLabels.n_cols); @@ -295,7 +295,7 @@ static void mlpackMain() // Carry out mean-centering on the dataset, if necessary. if (center) { - for (size_t i = 0; i < data.n_rows; i++) + for (size_t i = 0; i < data.n_rows; ++i) { data.row(i) -= arma::mean(data.row(i)); } @@ -310,7 +310,7 @@ static void mlpackMain() else { Log::Info << "Using last column of input dataset as labels." << endl; - for (size_t i = 0; i < data.n_cols; i++) + for (size_t i = 0; i < data.n_cols; ++i) rawLabels[i] = (size_t) data(data.n_rows - 1, i); data.shed_row(data.n_rows - 1); diff --git a/src/mlpack/methods/local_coordinate_coding/lcc.cpp b/src/mlpack/methods/local_coordinate_coding/lcc.cpp index b066d4c7d5..b5e00e3948 100644 --- a/src/mlpack/methods/local_coordinate_coding/lcc.cpp +++ b/src/mlpack/methods/local_coordinate_coding/lcc.cpp @@ -38,7 +38,7 @@ void LocalCoordinateCoding::Encode(const arma::mat& data, arma::mat& codes) arma::mat dictGramTD(dictGram.n_rows, dictGram.n_cols); codes.set_size(atoms, data.n_cols); - for (size_t i = 0; i < data.n_cols; i++) + for (size_t i = 0; i < data.n_cols; ++i) { // Report progress. if ((i % 100) == 0) @@ -98,7 +98,7 @@ void LocalCoordinateCoding::OptimizeDictionary(const arma::mat& data, dataPrime(arma::span::all, arma::span(0, data.n_cols - 1)) = data; size_t curCol = data.n_cols; - for (size_t i = 0; i < data.n_cols; i++) + for (size_t i = 0; i < data.n_cols; ++i) { if (neighborCounts(i) > 0) { diff --git a/src/mlpack/methods/logistic_regression/logistic_regression_impl.hpp b/src/mlpack/methods/logistic_regression/logistic_regression_impl.hpp index 1f5b81eb33..dcc97ecdc5 100644 --- a/src/mlpack/methods/logistic_regression/logistic_regression_impl.hpp +++ b/src/mlpack/methods/logistic_regression/logistic_regression_impl.hpp @@ -161,7 +161,7 @@ double LogisticRegression::ComputeAccuracy( // Count the number of responses that were correct. size_t count = 0; - for (size_t i = 0; i < responses.n_elem; i++) + for (size_t i = 0; i < responses.n_elem; ++i) { if (responses(i) == tempResponses(i)) count++; diff --git a/src/mlpack/methods/lsh/lsh_search_impl.hpp b/src/mlpack/methods/lsh/lsh_search_impl.hpp index ad1e8b6e81..1d7ff8d9f5 100644 --- a/src/mlpack/methods/lsh/lsh_search_impl.hpp +++ b/src/mlpack/methods/lsh/lsh_search_impl.hpp @@ -193,7 +193,7 @@ void LSHSearch::Train(MatType referenceSet, { const size_t numSamples = 25; // Compute a heuristic hash width from the data. - for (size_t i = 0; i < numSamples; i++) + for (size_t i = 0; i < numSamples; ++i) { size_t p1 = (size_t) math::RandInt(this->referenceSet.n_cols); size_t p2 = (size_t) math::RandInt(this->referenceSet.n_cols); @@ -258,7 +258,7 @@ void LSHSearch::Train(MatType referenceSet, // size_t, otherwise negative numbers are cast to 0. arma::Mat secondHashVectors(numTables, this->referenceSet.n_cols); - for (size_t i = 0; i < numTables; i++) + for (size_t i = 0; i < numTables; ++i) { // Step IV: create the 'numProj'-dimensional key for each point in each // table. @@ -727,7 +727,7 @@ void LSHSearch::ReturnIndicesFromTable( // Compute the projection of the query in each table. arma::mat allProjInTables(numProj, numTablesToSearch); arma::mat queryCodesNotFloored(numProj, numTablesToSearch); - for (size_t i = 0; i < numTablesToSearch; i++) + for (size_t i = 0; i < numTablesToSearch; ++i) queryCodesNotFloored.unsafe_col(i) = projections.slice(i).t() * queryPoint; queryCodesNotFloored += offsets.cols(0, numTablesToSearch - 1); @@ -743,7 +743,7 @@ void LSHSearch::ReturnIndicesFromTable( hashMat.row(0) = arma::conv_to> // Floor by typecasting ::from(secondHashWeights.t() * allProjInTables); // Mod to compute 2nd-level codes. - for (size_t i = 0; i < numTablesToSearch; i++) + for (size_t i = 0; i < numTablesToSearch; ++i) hashMat(0, i) = (hashMat(0, i) % secondHashSize); // Compute hash codes of additional probing bins. diff --git a/src/mlpack/methods/matrix_completion/matrix_completion.cpp b/src/mlpack/methods/matrix_completion/matrix_completion.cpp index a3058094ab..be138668f9 100644 --- a/src/mlpack/methods/matrix_completion/matrix_completion.cpp +++ b/src/mlpack/methods/matrix_completion/matrix_completion.cpp @@ -67,7 +67,7 @@ void MatrixCompletion::CheckValues() << std::endl; } - for (size_t i = 0; i < values.n_elem; i++) + for (size_t i = 0; i < values.n_elem; ++i) { if (indices(0, i) >= m || indices(1, i) >= n) Log::Fatal << "MatrixCompletion::CheckValues(): indices (" @@ -82,7 +82,7 @@ void MatrixCompletion::InitSDP() sdp.SDP().C().eye(m + n, m + n); sdp.SDP().SparseB() = 2. * values; const size_t p = indices.n_cols; - for (size_t i = 0; i < p; i++) + for (size_t i = 0; i < p; ++i) { sdp.SDP().SparseA()[i].zeros(m + n, m + n); sdp.SDP().SparseA()[i](indices(0, i), m + indices(1, i)) = 1.; diff --git a/src/mlpack/methods/mean_shift/mean_shift_main.cpp b/src/mlpack/methods/mean_shift/mean_shift_main.cpp index f3910f0844..71b563900d 100644 --- a/src/mlpack/methods/mean_shift/mean_shift_main.cpp +++ b/src/mlpack/methods/mean_shift/mean_shift_main.cpp @@ -120,7 +120,7 @@ static void mlpackMain() // Add the column of assignments to the dataset; but we have to convert them // to type double first. arma::vec converted(assignments.n_elem); - for (size_t i = 0; i < assignments.n_elem; i++) + for (size_t i = 0; i < assignments.n_elem; ++i) converted(i) = (double) assignments(i); dataset.insert_rows(dataset.n_rows, trans(converted)); @@ -135,7 +135,7 @@ static void mlpackMain() { // Convert the assignments to doubles. arma::vec converted(assignments.n_elem); - for (size_t i = 0; i < assignments.n_elem; i++) + for (size_t i = 0; i < assignments.n_elem; ++i) converted(i) = (double) assignments(i); dataset.insert_rows(dataset.n_rows, trans(converted)); diff --git a/src/mlpack/methods/naive_bayes/naive_bayes_classifier_impl.hpp b/src/mlpack/methods/naive_bayes/naive_bayes_classifier_impl.hpp index 8d571e7b93..a11e720277 100644 --- a/src/mlpack/methods/naive_bayes/naive_bayes_classifier_impl.hpp +++ b/src/mlpack/methods/naive_bayes/naive_bayes_classifier_impl.hpp @@ -217,7 +217,7 @@ void NaiveBayesClassifier::LogLikelihood( // means.n_cols. // Loop over every class. - for (size_t i = 0; i < means.n_cols; i++) + for (size_t i = 0; i < means.n_cols; ++i) { // This is an adaptation of gmm::phi() for the case where the covariance is // a diagonal matrix. diff --git a/src/mlpack/methods/nca/nca_main.cpp b/src/mlpack/methods/nca/nca_main.cpp index 20a159c629..8f823f028c 100644 --- a/src/mlpack/methods/nca/nca_main.cpp +++ b/src/mlpack/methods/nca/nca_main.cpp @@ -200,7 +200,7 @@ static void mlpackMain() else { Log::Info << "Using last column of input dataset as labels." << endl; - for (size_t i = 0; i < data.n_cols; i++) + for (size_t i = 0; i < data.n_cols; ++i) rawLabels[i] = (size_t) data(data.n_rows - 1, i); data.shed_row(data.n_rows - 1); diff --git a/src/mlpack/methods/nca/nca_softmax_error_function_impl.hpp b/src/mlpack/methods/nca/nca_softmax_error_function_impl.hpp index 49ee2eaa13..d0e90bb3ad 100644 --- a/src/mlpack/methods/nca/nca_softmax_error_function_impl.hpp +++ b/src/mlpack/methods/nca/nca_softmax_error_function_impl.hpp @@ -74,7 +74,7 @@ double SoftmaxErrorFunction::Evaluate(const arma::mat& coordinates, // It's quicker to do this now than one point at a time later. stretchedDataset = coordinates * dataset; - for (size_t i = begin; i < begin + batchSize; i++) + for (size_t i = begin; i < begin + batchSize; ++i) { for (size_t k = 0; k < dataset.n_cols; ++k) { @@ -129,7 +129,7 @@ void SoftmaxErrorFunction::Gradient(const arma::mat& coordinates, // (p_i p_ik + p_k p_ki) x_ik x_ik^T arma::mat sum; sum.zeros(stretchedDataset.n_rows, stretchedDataset.n_rows); - for (size_t i = 0; i < stretchedDataset.n_cols; i++) + for (size_t i = 0; i < stretchedDataset.n_cols; ++i) { for (size_t k = (i + 1); k < stretchedDataset.n_cols; k++) { @@ -174,7 +174,7 @@ void SoftmaxErrorFunction::Gradient(const arma::mat& coordinates, // Compute the stretched dataset. stretchedDataset = coordinates * dataset; - for (size_t i = begin; i < begin + batchSize; i++) + for (size_t i = begin; i < begin + batchSize; ++i) { numerator = 0; denominator = 0; @@ -265,7 +265,7 @@ void SoftmaxErrorFunction::Precalculate( // order of O((n * (n + 1)) / 2), which really isn't all that great. p.zeros(stretchedDataset.n_cols); denominators.zeros(stretchedDataset.n_cols); - for (size_t i = 0; i < stretchedDataset.n_cols; i++) + for (size_t i = 0; i < stretchedDataset.n_cols; ++i) { for (size_t j = (i + 1); j < stretchedDataset.n_cols; j++) { @@ -290,7 +290,7 @@ void SoftmaxErrorFunction::Precalculate( p /= denominators; // Clean up any bad values. - for (size_t i = 0; i < stretchedDataset.n_cols; i++) + for (size_t i = 0; i < stretchedDataset.n_cols; ++i) { if (denominators[i] == 0.0) { diff --git a/src/mlpack/methods/neighbor_search/knn_low_resource_main.cpp b/src/mlpack/methods/neighbor_search/knn_low_resource_main.cpp new file mode 100644 index 0000000000..aa7ddfaf17 --- /dev/null +++ b/src/mlpack/methods/neighbor_search/knn_low_resource_main.cpp @@ -0,0 +1,189 @@ +/** + * @file knn_main.cpp + * @author Ryan Curtin + * @author Omar Shrit + * + * Implementation of the kNN executable. Allows some number of standard + * options. + * This implementation is intended to be used on low resource devices + * + * + * mlpack is free software; you may redistribute it and/or modify it under the + * terms of the 3-clause BSD license. You should have received a copy of the + * 3-clause BSD license along with mlpack. If not, see + * http://www.opensource.org/licenses/BSD-3-Clause for more information. + */ +#include +#include +#include +#include +#include + +// #include +// #include +// #include + +#include "neighbor_search.hpp" +#include "ns_model.hpp" +#include "unmap.hpp" + +using namespace std; +using namespace mlpack; +using namespace mlpack::neighbor; +using namespace mlpack::tree; +using namespace mlpack::metric; +using namespace mlpack::util; + +// Convenience typedef. +typedef NSModel KNNModel; + +// Information about the program itself. +PROGRAM_INFO( + "k-Nearest-Neighbors Search", + // Short description. + "An implementation of k-nearest-neighbor search using " + "dual-tree algorithms. Given a set of reference points and query points, " + "this can find the k nearest neighbors in the reference set of each query " + "point using trees; trees that are built can be saved for future use.", + // Long description. + "This program will calculate the k-nearest-neighbors of a set of " + "points using kd-trees or cover trees (cover tree support is experimental " + "and may be slow). You may specify a separate set of " + "reference points and query points, or just a reference set which will be " + "used as both the reference and query set." + "\n\n" + "For example, the following command will calculate the 5 nearest neighbors " + "of each point in " + + PRINT_DATASET("input") + + " and store the distances " + "in " + + PRINT_DATASET("distances") + " and the neighbors in " + + PRINT_DATASET("neighbors") + + ": " + "\n\n" + + PRINT_CALL("knn", + "k", + 5, + "reference", + "input", + "neighbors", + "neighbors", + "distances", + "distances") + + "\n\n" + "The output is organized such that row i and column j in the neighbors " + "output matrix corresponds to the index of the point in the reference set " + "which is the j'th nearest neighbor from the point in the query set with " + "index i. Row j and column i in the distances output matrix corresponds to" + " the distance between those two points.", + SEE_ALSO("NeighborSearch tutorial (k-nearest-neighbors)", + "@doxygen/nstutorial.html"), + SEE_ALSO("Tree-independent dual-tree algorithms (pdf)", + "http://proceedings.mlr.press/v28/curtin13.pdf"), + SEE_ALSO("mlpack::neighbor::NeighborSearch C++ class documentation", + "@doxygen/classmlpack_1_1neighbor_1_1NeighborSearch.html")); + + // Define our input parameters that this program will take. + PARAM_MATRIX_OUT("distances", "Matrix to output distances into.", "d"); + PARAM_UMATRIX_OUT("neighbors", "Matrix to output neighbors into.", "n"); + + // The option exists to load or save models. +// PARAM_MODEL_IN(KNNModel, "input_model", "Pre-trained kNN model.", "m"); + + // The user may specify a query file of query points and a number of nearest + // neighbors to search for. + PARAM_MATRIX_IN("query", "Matrix containing query points (optional).", "q"); + PARAM_INT_IN("k", "Number of nearest neighbors to find.", "k", 0); + +static void +mlpackMain() +{ + // ReportIgnoredParam({ { "input_model", true } }, "tree_type"); + // ReportIgnoredParam({ { "input_model", true } }, "random_basis"); + + // // The user should give something to do... + // RequireAtLeastOnePassed( + // { "k", "output_model" }, false, "no results will be saved"); + + // // If the user specifies k but no output files, they should be warned. + // if (CLI::HasParam("k")) { + // RequireAtLeastOnePassed( + // { "neighbors", "distances" }, + // false, + // "nearest neighbor search results will not be saved"); + // } + + // // If the user specifies output files but no k, they should be warned. + // ReportIgnoredParam({ { "k", false } }, "neighbors"); + // ReportIgnoredParam({ { "k", false } }, "distances"); + // ReportIgnoredParam({ { "k", false } }, "query"); + + KNNModel* knn = new KNNModel(); + + // Load the model from file. + // knn = CLI::GetParam("input_model"); + + // // Adjust search mode. + // // Use the dual tree mode as a default mode + // knn->SearchMode() = DUAL_TREE_MODE; + + // Log::Info << "Loaded kNN model from '" + // << CLI::GetPrintableParam("input_model") + // << "' (trained on " << knn->Dataset().n_rows << "x" + // << knn->Dataset().n_cols << " dataset)." << endl; + + // // Perform search, if desired. + // if (CLI::HasParam("k")) { + // const size_t k = (size_t)CLI::GetParam("k"); + + // arma::mat queryData; + // if (CLI::HasParam("query")) { + // Log::Info << "Using query data from " + // << CLI::GetPrintableParam("query") << "." << endl; + // queryData = std::move(CLI::GetParam("query")); + // if (queryData.n_rows != knn->Dataset().n_rows) { + // // Clean memory if needed before crashing. + // const size_t dimensions = knn->Dataset().n_rows; + // if (CLI::HasParam("reference")) + // delete knn; + // Log::Fatal << "Query has invalid dimensions(" << queryData.n_rows + // << "); should be " << dimensions << "!" << endl; + // } + // } + + // // Sanity check on k value: must be greater than 0, must be less than or + // // equal to the number of reference points. Since it is unsigned, + // // we only test the upper bound. + // if (k > knn->Dataset().n_cols) { + // // Clean memory if needed before crashing. + // const size_t referencePoints = knn->Dataset().n_cols; + + // // Sanity check on k value: must not be equal to the number of reference + // // points when query data has not been provided. + // if (!CLI::HasParam("query") && k == knn->Dataset().n_cols) { + // // Clean memory if needed before crashing. + // const size_t referencePoints = knn->Dataset().n_cols; + // if (CLI::HasParam("reference")) + // delete knn; + // Log::Fatal << "Invalid k: " << k << "; must be less than the number of " + // << "reference points (" << referencePoints + // << ") if query data has " + // << "not been provided." << endl; + // } + + // // Now run the search. + // arma::Mat neighbors; + // arma::mat distances; + + // if (CLI::HasParam("query")) + // knn->Search(std::move(queryData), k, neighbors, distances); + // else + // knn->Search(k, neighbors, distances); + // Log::Info << "Search complete." << endl; + + // // Save output. + // CLI::GetParam>("neighbors") = std::move(neighbors); + // CLI::GetParam("distances") = std::move(distances); + // } + // } +} diff --git a/src/mlpack/methods/neighbor_search/neighbor_search_impl.hpp b/src/mlpack/methods/neighbor_search/neighbor_search_impl.hpp index c679d2393f..9b759cc37c 100644 --- a/src/mlpack/methods/neighbor_search/neighbor_search_impl.hpp +++ b/src/mlpack/methods/neighbor_search/neighbor_search_impl.hpp @@ -542,7 +542,7 @@ DualTreeTraversalType, SingleTreeTraversalType>::Search( neighbors.set_size(k, querySet.n_cols); distances.set_size(k, querySet.n_cols); - for (size_t i = 0; i < distances.n_cols; i++) + for (size_t i = 0; i < distances.n_cols; ++i) { // Map distances (copy a column). distances.col(oldFromNewQueries[i]) = distancePtr->col(i); @@ -583,7 +583,7 @@ DualTreeTraversalType, SingleTreeTraversalType>::Search( neighbors.set_size(k, querySet.n_cols); // Map indices of neighbors. - for (size_t i = 0; i < neighbors.n_cols; i++) + for (size_t i = 0; i < neighbors.n_cols; ++i) for (size_t j = 0; j < neighbors.n_rows; j++) neighbors(j, i) = oldFromNewReferences[(*neighborPtr)(j, i)]; @@ -669,7 +669,7 @@ DualTreeTraversalType, SingleTreeTraversalType>::Search( neighbors.set_size(k, querySet.n_cols); // Map indices of neighbors. - for (size_t i = 0; i < neighbors.n_cols; i++) + for (size_t i = 0; i < neighbors.n_cols; ++i) for (size_t j = 0; j < neighbors.n_rows; j++) neighbors(j, i) = oldFromNewReferences[(*neighborPtr)(j, i)]; @@ -886,7 +886,7 @@ DualTreeTraversalType, SingleTreeTraversalType>::EffectiveError( double effectiveError = 0; size_t numCases = 0; - for (size_t i = 0; i < foundDistances.n_elem; i++) + for (size_t i = 0; i < foundDistances.n_elem; ++i) { if (realDistances(i) != 0 && foundDistances(i) != SortPolicy::WorstDistance()) diff --git a/src/mlpack/methods/neighbor_search/neighbor_search_rules_impl.hpp b/src/mlpack/methods/neighbor_search/neighbor_search_rules_impl.hpp index 835bd50736..212feb719a 100644 --- a/src/mlpack/methods/neighbor_search/neighbor_search_rules_impl.hpp +++ b/src/mlpack/methods/neighbor_search/neighbor_search_rules_impl.hpp @@ -55,7 +55,7 @@ NeighborSearchRules::NeighborSearchRules( CandidateList pqueue(CandidateCmp(), std::move(vect)); candidates.reserve(querySet.n_cols); - for (size_t i = 0; i < querySet.n_cols; i++) + for (size_t i = 0; i < querySet.n_cols; ++i) candidates.push_back(pqueue); } @@ -67,7 +67,7 @@ void NeighborSearchRules::GetResults( neighbors.set_size(k, querySet.n_cols); distances.set_size(k, querySet.n_cols); - for (size_t i = 0; i < querySet.n_cols; i++) + for (size_t i = 0; i < querySet.n_cols; ++i) { CandidateList& pqueue = candidates[i]; for (size_t j = 1; j <= k; j++) diff --git a/src/mlpack/methods/perceptron/perceptron_impl.hpp b/src/mlpack/methods/perceptron/perceptron_impl.hpp index 6e15b53e83..414ba7381f 100644 --- a/src/mlpack/methods/perceptron/perceptron_impl.hpp +++ b/src/mlpack/methods/perceptron/perceptron_impl.hpp @@ -110,7 +110,7 @@ void Perceptron::Classify( arma::uword maxIndex = 0; // Could probably be faster if done in batch. - for (size_t i = 0; i < test.n_cols; i++) + for (size_t i = 0; i < test.n_cols; ++i) { tempLabelMat = weights.t() * test.col(i) + biases; tempLabelMat.max(maxIndex); @@ -159,7 +159,7 @@ void Perceptron::Train( { // This outer loop is for each iteration, and we use the 'converged' // variable for noting whether or not convergence has been reached. - i++; + ++i; converged = true; // Now this inner loop is for going through the dataset in each iteration. diff --git a/src/mlpack/methods/radical/radical.cpp b/src/mlpack/methods/radical/radical.cpp index 5abd842d6a..b38c40f78f 100644 --- a/src/mlpack/methods/radical/radical.cpp +++ b/src/mlpack/methods/radical/radical.cpp @@ -57,7 +57,7 @@ double Radical::Vasicek(vec& z) const // Apparently faster. double sum = 0; uword range = z.n_elem - m; - for (uword i = 0; i < range; i++) + for (uword i = 0; i < range; ++i) { sum += log(max(z(i + m) - z(i), DBL_MIN)); } @@ -74,7 +74,7 @@ double Radical::DoRadical2D(const mat& matX) vec values(angles); - for (size_t i = 0; i < angles; i++) + for (size_t i = 0; i < angles; ++i) { const double theta = (i / (double) angles) * M_PI / 2.0; const double cosTheta = cos(theta); @@ -140,7 +140,7 @@ void Radical::DoRadical(const mat& matXT, mat& matY, mat& matW) { Log::Info << "RADICAL: sweep " << sweepNum << "." << std::endl; - for (size_t i = 0; i < nDims - 1; i++) + for (size_t i = 0; i < nDims - 1; ++i) { for (size_t j = i + 1; j < nDims; j++) { diff --git a/src/mlpack/methods/radical/radical_main.cpp b/src/mlpack/methods/radical/radical_main.cpp index f4fd0734b0..15f847c77d 100644 --- a/src/mlpack/methods/radical/radical_main.cpp +++ b/src/mlpack/methods/radical/radical_main.cpp @@ -126,7 +126,7 @@ static void mlpackMain() // Compute and print objective. mat matYT = trans(matY); double valEst = 0; - for (size_t i = 0; i < matYT.n_cols; i++) + for (size_t i = 0; i < matYT.n_cols; ++i) { vec y = vec(matYT.col(i)); valEst += rad.Vasicek(y); diff --git a/src/mlpack/methods/range_search/range_search_impl.hpp b/src/mlpack/methods/range_search/range_search_impl.hpp index a6e0162528..269cc79859 100644 --- a/src/mlpack/methods/range_search/range_search_impl.hpp +++ b/src/mlpack/methods/range_search/range_search_impl.hpp @@ -390,7 +390,7 @@ void RangeSearch::Search( distances.clear(); distances.resize(querySet.n_cols); - for (size_t i = 0; i < distances.size(); i++) + for (size_t i = 0; i < distances.size(); ++i) { // Map distances (copy a column). const size_t queryMapping = oldFromNewQueries[i]; @@ -433,7 +433,7 @@ void RangeSearch::Search( neighbors.clear(); neighbors.resize(querySet.n_cols); - for (size_t i = 0; i < neighbors.size(); i++) + for (size_t i = 0; i < neighbors.size(); ++i) { neighbors[i].resize((*neighborPtr)[i].size()); for (size_t j = 0; j < neighbors[i].size(); j++) @@ -505,7 +505,7 @@ void RangeSearch::Search( neighbors.clear(); neighbors.resize(querySet.n_cols); - for (size_t i = 0; i < neighbors.size(); i++) + for (size_t i = 0; i < neighbors.size(); ++i) { neighbors[i].resize((*neighborPtr)[i].size()); for (size_t j = 0; j < neighbors[i].size(); j++) @@ -598,7 +598,7 @@ void RangeSearch::Search( distances.clear(); distances.resize(referenceSet->n_cols); - for (size_t i = 0; i < distances.size(); i++) + for (size_t i = 0; i < distances.size(); ++i) { // Map distances (copy a column). const size_t refMapping = oldFromNewReferences[i]; diff --git a/src/mlpack/methods/rann/ra_search_impl.hpp b/src/mlpack/methods/rann/ra_search_impl.hpp index c74032937e..37d095bca8 100644 --- a/src/mlpack/methods/rann/ra_search_impl.hpp +++ b/src/mlpack/methods/rann/ra_search_impl.hpp @@ -379,7 +379,7 @@ Search(const MatType& querySet, neighbors.set_size(k, querySet.n_cols); distances.set_size(k, querySet.n_cols); - for (size_t i = 0; i < distances.n_cols; i++) + for (size_t i = 0; i < distances.n_cols; ++i) { // Map distances (copy a column). distances.col(oldFromNewQueries[i]) = distancePtr->col(i); @@ -420,7 +420,7 @@ Search(const MatType& querySet, neighbors.set_size(k, querySet.n_cols); // Map indices of neighbors. - for (size_t i = 0; i < neighbors.n_cols; i++) + for (size_t i = 0; i < neighbors.n_cols; ++i) for (size_t j = 0; j < neighbors.n_rows; j++) neighbors(j, i) = oldFromNewReferences[(*neighborPtr)(j, i)]; @@ -481,7 +481,7 @@ void RASearch::Search( neighbors.set_size(k, querySet.n_cols); // Map indices of neighbors. - for (size_t i = 0; i < neighbors.n_cols; i++) + for (size_t i = 0; i < neighbors.n_cols; ++i) for (size_t j = 0; j < neighbors.n_rows; j++) neighbors(j, i) = oldFromNewReferences[(*neighborPtr)(j, i)]; @@ -593,7 +593,7 @@ void RASearch::ResetQueryTree( queryNode->Stat().Bound() = SortPolicy::WorstDistance(); queryNode->Stat().NumSamplesMade() = 0; - for (size_t i = 0; i < queryNode->NumChildren(); i++) + for (size_t i = 0; i < queryNode->NumChildren(); ++i) ResetQueryTree(&queryNode->Child(i)); } diff --git a/src/mlpack/methods/rann/ra_search_rules_impl.hpp b/src/mlpack/methods/rann/ra_search_rules_impl.hpp index 2a617871be..0f82f0fe0b 100644 --- a/src/mlpack/methods/rann/ra_search_rules_impl.hpp +++ b/src/mlpack/methods/rann/ra_search_rules_impl.hpp @@ -81,7 +81,7 @@ RASearchRules(const arma::mat& referenceSet, CandidateList pqueue(CandidateCmp(), std::move(vect)); candidates.reserve(querySet.n_cols); - for (size_t i = 0; i < querySet.n_cols; i++) + for (size_t i = 0; i < querySet.n_cols; ++i) candidates.push_back(pqueue); if (naive) // No tree traversal; just do naive sampling here. @@ -105,7 +105,7 @@ void RASearchRules::GetResults( neighbors.set_size(k, querySet.n_cols); distances.set_size(k, querySet.n_cols); - for (size_t i = 0; i < querySet.n_cols; i++) + for (size_t i = 0; i < querySet.n_cols; ++i) { CandidateList& pqueue = candidates[i]; for (size_t j = 1; j <= k; j++) @@ -206,7 +206,7 @@ inline double RASearchRules::Score( arma::uvec distinctSamples; math::ObtainDistinctSamples(0, referenceNode.NumDescendants(), samplesReqd, distinctSamples); - for (size_t i = 0; i < distinctSamples.n_elem; i++) + for (size_t i = 0; i < distinctSamples.n_elem; ++i) // The counting of the samples are done in the 'BaseCase' function // so no book-keeping is required here. BaseCase(queryIndex, referenceNode.Descendant(distinctSamples[i])); @@ -222,7 +222,7 @@ inline double RASearchRules::Score( arma::uvec distinctSamples; math::ObtainDistinctSamples(0, referenceNode.NumDescendants(), samplesReqd, distinctSamples); - for (size_t i = 0; i < distinctSamples.n_elem; i++) + for (size_t i = 0; i < distinctSamples.n_elem; ++i) // The counting of the samples are done in the 'BaseCase' function // so no book-keeping is required here. BaseCase(queryIndex, @@ -310,7 +310,7 @@ Rescore(const size_t queryIndex, arma::uvec distinctSamples; math::ObtainDistinctSamples(0, referenceNode.NumDescendants(), samplesReqd, distinctSamples); - for (size_t i = 0; i < distinctSamples.n_elem; i++) + for (size_t i = 0; i < distinctSamples.n_elem; ++i) // The counting of the samples are done in the 'BaseCase' function so // no book-keeping is required here. BaseCase(queryIndex, referenceNode.Descendant(distinctSamples[i])); @@ -326,7 +326,7 @@ Rescore(const size_t queryIndex, arma::uvec distinctSamples; math::ObtainDistinctSamples(0, referenceNode.NumDescendants(), samplesReqd, distinctSamples); - for (size_t i = 0; i < distinctSamples.n_elem; i++) + for (size_t i = 0; i < distinctSamples.n_elem; ++i) // The counting of the samples are done in the 'BaseCase' function // so no book-keeping is required here. BaseCase(queryIndex, referenceNode.Descendant(distinctSamples[i])); @@ -372,7 +372,7 @@ inline double RASearchRules::Score( double childBound = DBL_MAX; const double maxDescendantDistance = queryNode.FurthestDescendantDistance(); - for (size_t i = 0; i < queryNode.NumPoints(); i++) + for (size_t i = 0; i < queryNode.NumPoints(); ++i) { const double bound = candidates[queryNode.Point(i)].top().first + maxDescendantDistance; @@ -380,7 +380,7 @@ inline double RASearchRules::Score( pointBound = bound; } - for (size_t i = 0; i < queryNode.NumChildren(); i++) + for (size_t i = 0; i < queryNode.NumChildren(); ++i) { const double bound = queryNode.Child(i).Stat().Bound(); if (bound < childBound) @@ -411,7 +411,7 @@ inline double RASearchRules::Score( double childBound = DBL_MAX; const double maxDescendantDistance = queryNode.FurthestDescendantDistance(); - for (size_t i = 0; i < queryNode.NumPoints(); i++) + for (size_t i = 0; i < queryNode.NumPoints(); ++i) { const double bound = candidates[queryNode.Point(i)].top().first + maxDescendantDistance; @@ -419,7 +419,7 @@ inline double RASearchRules::Score( pointBound = bound; } - for (size_t i = 0; i < queryNode.NumChildren(); i++) + for (size_t i = 0; i < queryNode.NumChildren(); ++i) { const double bound = queryNode.Child(i).Stat().Bound(); if (bound < childBound) @@ -451,7 +451,7 @@ inline double RASearchRules::Score( size_t numSamplesMadeInChildNodes = std::numeric_limits::max(); // Find the minimum number of samples made among all children. - for (size_t i = 0; i < queryNode.NumChildren(); i++) + for (size_t i = 0; i < queryNode.NumChildren(); ++i) { const size_t numSamples = queryNode.Child(i).Stat().NumSamplesMade(); if (numSamples < numSamplesMadeInChildNodes) @@ -494,7 +494,7 @@ inline double RASearchRules::Score( // Iterate through all children and propagate the number of samples made // to the children. Only update if the parent node has made samples the // children have not seen. - for (size_t i = 0; i < queryNode.NumChildren(); i++) + for (size_t i = 0; i < queryNode.NumChildren(); ++i) queryNode.Child(i).Stat().NumSamplesMade() = std::max( queryNode.Stat().NumSamplesMade(), queryNode.Child(i).Stat().NumSamplesMade()); @@ -568,7 +568,7 @@ inline double RASearchRules::Score( // Go through all children and propagate the number of // samples made to the children. - for (size_t i = 0; i < queryNode.NumChildren(); i++) + for (size_t i = 0; i < queryNode.NumChildren(); ++i) queryNode.Child(i).Stat().NumSamplesMade() = std::max( queryNode.Stat().NumSamplesMade(), queryNode.Child(i).Stat().NumSamplesMade()); @@ -583,7 +583,7 @@ inline double RASearchRules::Score( // We must first visit the first leaf to boost accuracy. // Go through all children and propagate the number of // samples made to the children. - for (size_t i = 0; i < queryNode.NumChildren(); i++) + for (size_t i = 0; i < queryNode.NumChildren(); ++i) queryNode.Child(i).Stat().NumSamplesMade() = std::max( queryNode.Stat().NumSamplesMade(), queryNode.Child(i).Stat().NumSamplesMade()); @@ -625,7 +625,7 @@ Rescore(TreeType& queryNode, double childBound = DBL_MAX; const double maxDescendantDistance = queryNode.FurthestDescendantDistance(); - for (size_t i = 0; i < queryNode.NumPoints(); i++) + for (size_t i = 0; i < queryNode.NumPoints(); ++i) { const double bound = candidates[queryNode.Point(i)].top().first + maxDescendantDistance; @@ -633,7 +633,7 @@ Rescore(TreeType& queryNode, pointBound = bound; } - for (size_t i = 0; i < queryNode.NumChildren(); i++) + for (size_t i = 0; i < queryNode.NumChildren(); ++i) { const double bound = queryNode.Child(i).Stat().Bound(); if (bound < childBound) @@ -656,7 +656,7 @@ Rescore(TreeType& queryNode, size_t numSamplesMadeInChildNodes = std::numeric_limits::max(); // Find the minimum number of samples made among all children - for (size_t i = 0; i < queryNode.NumChildren(); i++) + for (size_t i = 0; i < queryNode.NumChildren(); ++i) { const size_t numSamples = queryNode.Child(i).Stat().NumSamplesMade(); if (numSamples < numSamplesMadeInChildNodes) @@ -699,7 +699,7 @@ Rescore(TreeType& queryNode, // Go through all children and propagate the number of samples made to the // children. Only update if the parent node has made samples the children // have not seen. - for (size_t i = 0; i < queryNode.NumChildren(); i++) + for (size_t i = 0; i < queryNode.NumChildren(); ++i) queryNode.Child(i).Stat().NumSamplesMade() = std::max( queryNode.Stat().NumSamplesMade(), queryNode.Child(i).Stat().NumSamplesMade()); @@ -769,7 +769,7 @@ Rescore(TreeType& queryNode, { // We cannot sample from leaves, so we cannot prune. // Propagate the number of samples made down to the children. - for (size_t i = 0; i < queryNode.NumChildren(); i++) + for (size_t i = 0; i < queryNode.NumChildren(); ++i) queryNode.Child(i).Stat().NumSamplesMade() = std::max( queryNode.Stat().NumSamplesMade(), queryNode.Child(i).Stat().NumSamplesMade()); diff --git a/src/mlpack/methods/rann/ra_util.cpp b/src/mlpack/methods/rann/ra_util.cpp index 3788917261..92aa2e3b7a 100644 --- a/src/mlpack/methods/rann/ra_util.cpp +++ b/src/mlpack/methods/rann/ra_util.cpp @@ -145,7 +145,7 @@ double mlpack::neighbor::RAUtil::SuccessProbability(const size_t n, else jTrans = m - j; - for (size_t i = 2; i <= jTrans; i++) + for (size_t i = 2; i <= jTrans; ++i) { mCj *= (double) (m - (i - 1)); mCj /= (double) i; diff --git a/src/mlpack/methods/regularized_svd/regularized_svd_function_impl.hpp b/src/mlpack/methods/regularized_svd/regularized_svd_function_impl.hpp index bab98bf287..40f452eecb 100644 --- a/src/mlpack/methods/regularized_svd/regularized_svd_function_impl.hpp +++ b/src/mlpack/methods/regularized_svd/regularized_svd_function_impl.hpp @@ -101,7 +101,7 @@ void RegularizedSVDFunction::Gradient(const arma::mat& parameters, gradient.zeros(rank, numUsers + numItems); - for (size_t i = 0; i < data.n_cols; i++) + for (size_t i = 0; i < data.n_cols; ++i) { // Indices for accessing the the correct parameter columns. const size_t user = data(0, i); @@ -170,13 +170,13 @@ double StandardSGD::Optimize( double overallObjective = 0; // Calculate the first objective function. - for (size_t i = 0; i < numFunctions; i++) + for (size_t i = 0; i < numFunctions; ++i) overallObjective += function.Evaluate(parameters, i); const arma::mat data = function.Dataset(); // Now iterate! - for (size_t i = 1; i != maxIterations; i++, currentFunction++) + for (size_t i = 1; i != maxIterations; ++i, currentFunction++) { // Is this iteration the start of a sequence? if ((currentFunction % numFunctions) == 0) diff --git a/src/mlpack/methods/reinforcement_learning/replay/prioritized_replay.hpp b/src/mlpack/methods/reinforcement_learning/replay/prioritized_replay.hpp index 3086abcc42..377d26037f 100644 --- a/src/mlpack/methods/reinforcement_learning/replay/prioritized_replay.hpp +++ b/src/mlpack/methods/reinforcement_learning/replay/prioritized_replay.hpp @@ -166,7 +166,7 @@ class PrioritizedReplay size_t numSample = full ? capacity : position; weights = arma::rowvec(sampledIndices.n_rows); - for (size_t i = 0; i < sampledIndices.n_rows; i++) + for (size_t i = 0; i < sampledIndices.n_rows; ++i) { double p_sample = idxSum.Get(sampledIndices(i)) / idxSum.Sum(); weights(i) = pow(numSample * p_sample, -beta); diff --git a/src/mlpack/methods/reinforcement_learning/replay/sumtree.hpp b/src/mlpack/methods/reinforcement_learning/replay/sumtree.hpp index 8c577308a7..b13028cb07 100644 --- a/src/mlpack/methods/reinforcement_learning/replay/sumtree.hpp +++ b/src/mlpack/methods/reinforcement_learning/replay/sumtree.hpp @@ -74,7 +74,7 @@ class SumTree */ void BatchUpdate(const arma::ucolvec& indices, const arma::Col& data) { - for (size_t i = 0; i < indices.n_rows; i++) + for (size_t i = 0; i < indices.n_rows; ++i) { element[indices[i] + capacity] = data[i]; } diff --git a/src/mlpack/methods/softmax_regression/softmax_regression.cpp b/src/mlpack/methods/softmax_regression/softmax_regression.cpp index 16e69e6052..f3bc28df8b 100644 --- a/src/mlpack/methods/softmax_regression/softmax_regression.cpp +++ b/src/mlpack/methods/softmax_regression/softmax_regression.cpp @@ -39,7 +39,7 @@ void SoftmaxRegression::Classify(const arma::mat& dataset, double maxProbability = 0; // For each test input. - for (size_t i = 0; i < dataset.n_cols; i++) + for (size_t i = 0; i < dataset.n_cols; ++i) { // For each class. for (size_t j = 0; j < numClasses; j++) @@ -69,7 +69,7 @@ void SoftmaxRegression::Classify(const arma::mat& dataset, double maxProbability = 0; // For each test input. - for (size_t i = 0; i < dataset.n_cols; i++) + for (size_t i = 0; i < dataset.n_cols; ++i) { // For each class. for (size_t j = 0; j < numClasses; j++) @@ -133,7 +133,7 @@ double SoftmaxRegression::ComputeAccuracy( // Increment count for every correctly predicted label. size_t count = 0; - for (size_t i = 0; i < predictions.n_elem; i++) + for (size_t i = 0; i < predictions.n_elem; ++i) if (predictions(i) == labels(i)) count++; diff --git a/src/mlpack/methods/softmax_regression/softmax_regression_function.cpp b/src/mlpack/methods/softmax_regression/softmax_regression_function.cpp index 4752e6107d..7958e89cbc 100644 --- a/src/mlpack/methods/softmax_regression/softmax_regression_function.cpp +++ b/src/mlpack/methods/softmax_regression/softmax_regression_function.cpp @@ -128,7 +128,7 @@ void SoftmaxRegressionFunction::GetGroundTruthMatrix( // Row pointers are the labels of the examples, and column pointers are the // number of cumulative entries made uptil that column. - for (size_t i = 0; i < labels.n_elem; i++) + for (size_t i = 0; i < labels.n_elem; ++i) { rowPointers(i) = labels(i); colPointers(i + 1) = i + 1; diff --git a/src/mlpack/methods/sparse_coding/sparse_coding.cpp b/src/mlpack/methods/sparse_coding/sparse_coding.cpp index a383c37eb2..402c2827b2 100644 --- a/src/mlpack/methods/sparse_coding/sparse_coding.cpp +++ b/src/mlpack/methods/sparse_coding/sparse_coding.cpp @@ -127,7 +127,7 @@ double SparseCoding::OptimizeDictionary(const arma::mat& data, // vec dualVars = diagvec(solve(dictionary, data * trans(codes)) // - codes * trans(codes)); - // for (size_t i = 0; i < dualVars.n_elem; i++) + // for (size_t i = 0; i < dualVars.n_elem; ++i) // if (dualVars(i) < 0) // dualVars(i) = 0; diff --git a/src/mlpack/methods/svdplusplus/svdplusplus_function_impl.hpp b/src/mlpack/methods/svdplusplus/svdplusplus_function_impl.hpp index f9d58d19af..2a556d7773 100644 --- a/src/mlpack/methods/svdplusplus/svdplusplus_function_impl.hpp +++ b/src/mlpack/methods/svdplusplus/svdplusplus_function_impl.hpp @@ -155,7 +155,7 @@ void SVDPlusPlusFunction::Gradient(const arma::mat& parameters, gradient.zeros(rank + 1, numUsers + 2 * numItems); - for (size_t i = 0; i < data.n_cols; i++) + for (size_t i = 0; i < data.n_cols; ++i) { // Indices for accessing the the correct parameter columns. const size_t user = data(0, i); @@ -305,7 +305,7 @@ double StandardSGD::Optimize( double overallObjective = 0; // Calculate the first objective function. - for (size_t i = 0; i < numFunctions; i++) + for (size_t i = 0; i < numFunctions; ++i) overallObjective += function.Evaluate(parameters, i); const arma::mat data = function.Dataset(); @@ -318,7 +318,7 @@ double StandardSGD::Optimize( const size_t rank = function.Rank(); // Now iterate! - for (size_t i = 1; i != maxIterations; i++, currentFunction++) + for (size_t i = 1; i != maxIterations; ++i, currentFunction++) { // Is this iteration the start of a sequence? if ((currentFunction % numFunctions) == 0) diff --git a/src/mlpack/tests/activation_functions_test.cpp b/src/mlpack/tests/activation_functions_test.cpp index 1e92a1cacd..a1f22ca2cc 100644 --- a/src/mlpack/tests/activation_functions_test.cpp +++ b/src/mlpack/tests/activation_functions_test.cpp @@ -51,7 +51,7 @@ void CheckActivationCorrect(const arma::colvec input, const arma::colvec target) { // Test the activation function using a single value as input. - for (size_t i = 0; i < target.n_elem; i++) + for (size_t i = 0; i < target.n_elem; ++i) { BOOST_REQUIRE_CLOSE(ActivationFunction::Fn(input.at(i)), target.at(i), 1e-3); @@ -60,7 +60,7 @@ void CheckActivationCorrect(const arma::colvec input, // Test the activation function using the entire vector as input. arma::colvec activations; ActivationFunction::Fn(input, activations); - for (size_t i = 0; i < activations.n_elem; i++) + for (size_t i = 0; i < activations.n_elem; ++i) { BOOST_REQUIRE_CLOSE(activations.at(i), target.at(i), 1e-3); } @@ -79,7 +79,7 @@ void CheckDerivativeCorrect(const arma::colvec input, const arma::colvec target) { // Test the calculation of the derivatives using a single value as input. - for (size_t i = 0; i < target.n_elem; i++) + for (size_t i = 0; i < target.n_elem; ++i) { BOOST_REQUIRE_CLOSE(ActivationFunction::Deriv(input.at(i)), target.at(i), 1e-3); @@ -88,7 +88,7 @@ void CheckDerivativeCorrect(const arma::colvec input, // Test the calculation of the derivatives using the entire vector as input. arma::colvec derivatives; ActivationFunction::Deriv(input, derivatives); - for (size_t i = 0; i < derivatives.n_elem; i++) + for (size_t i = 0; i < derivatives.n_elem; ++i) { BOOST_REQUIRE_CLOSE(derivatives.at(i), target.at(i), 1e-3); } @@ -106,7 +106,7 @@ template void CheckInverseCorrect(const arma::colvec input) { // Test the calculation of the inverse using a single value as input. - for (size_t i = 0; i < input.n_elem; i++) + for (size_t i = 0; i < input.n_elem; ++i) { BOOST_REQUIRE_CLOSE(ActivationFunction::Inv(ActivationFunction::Fn( input.at(i))), input.at(i), 1e-3); @@ -117,7 +117,7 @@ void CheckInverseCorrect(const arma::colvec input) ActivationFunction::Fn(input, activations); ActivationFunction::Inv(activations, activations); - for (size_t i = 0; i < input.n_elem; i++) + for (size_t i = 0; i < input.n_elem; ++i) { BOOST_REQUIRE_CLOSE(activations.at(i), input.at(i), 1e-3); } @@ -138,7 +138,7 @@ void CheckHardTanHActivationCorrect(const arma::colvec input, // Test the activation function using the entire vector as input. arma::colvec activations; htf.Forward(input, activations); - for (size_t i = 0; i < activations.n_elem; i++) + for (size_t i = 0; i < activations.n_elem; ++i) { BOOST_REQUIRE_CLOSE(activations.at(i), target.at(i), 1e-3); } @@ -164,7 +164,7 @@ void CheckHardTanHDerivativeCorrect(const arma::colvec input, arma::colvec error = arma::ones(input.n_elem); htf.Backward(input, error, derivatives); - for (size_t i = 0; i < derivatives.n_elem; i++) + for (size_t i = 0; i < derivatives.n_elem; ++i) { BOOST_REQUIRE_CLOSE(derivatives.at(i), target.at(i), 1e-3); } @@ -186,7 +186,7 @@ void CheckLeakyReLUActivationCorrect(const arma::colvec input, // Test the activation function using the entire vector as input. arma::colvec activations; lrf.Forward(input, activations); - for (size_t i = 0; i < activations.n_elem; i++) + for (size_t i = 0; i < activations.n_elem; ++i) { BOOST_REQUIRE_CLOSE(activations.at(i), target.at(i), 1e-3); } @@ -212,7 +212,7 @@ void CheckLeakyReLUDerivativeCorrect(const arma::colvec input, // This error vector will be set to 1 to get the derivatives. arma::colvec error = arma::ones(input.n_elem); lrf.Backward(input, error, derivatives); - for (size_t i = 0; i < derivatives.n_elem; i++) + for (size_t i = 0; i < derivatives.n_elem; ++i) { BOOST_REQUIRE_CLOSE(derivatives.at(i), target.at(i), 1e-3); } @@ -234,7 +234,7 @@ void CheckELUActivationCorrect(const arma::colvec input, // Test the activation function using the entire vector as input. arma::colvec activations; lrf.Forward(input, activations); - for (size_t i = 0; i < activations.n_elem; i++) + for (size_t i = 0; i < activations.n_elem; ++i) { BOOST_REQUIRE_CLOSE(activations.at(i), target.at(i), 1e-3); } @@ -260,7 +260,7 @@ void CheckELUDerivativeCorrect(const arma::colvec input, arma::colvec error = arma::ones(input.n_elem); lrf.Forward(input, activations); lrf.Backward(activations, error, derivatives); - for (size_t i = 0; i < derivatives.n_elem; i++) + for (size_t i = 0; i < derivatives.n_elem; ++i) { BOOST_REQUIRE_CLOSE(derivatives.at(i), target.at(i), 1e-3); } @@ -282,7 +282,7 @@ void CheckPReLUActivationCorrect(const arma::colvec input, // Test the activation function using the entire vector as input. arma::colvec activations; prelu.Forward(input, activations); - for (size_t i = 0; i < activations.n_elem; i++) + for (size_t i = 0; i < activations.n_elem; ++i) { BOOST_REQUIRE_CLOSE(activations.at(i), target.at(i), 1e-3); } @@ -308,7 +308,7 @@ void CheckPReLUDerivativeCorrect(const arma::colvec input, // This error vector will be set to 1 to get the derivatives. arma::colvec error = arma::ones(input.n_elem); prelu.Backward(input, error, derivatives); - for (size_t i = 0; i < derivatives.n_elem; i++) + for (size_t i = 0; i < derivatives.n_elem; ++i) { BOOST_REQUIRE_CLOSE(derivatives.at(i), target.at(i), 1e-3); } @@ -354,7 +354,7 @@ void CheckHardShrinkActivationCorrect(const arma::colvec input, // Test the activation function using the entire vector as input. arma::colvec activations; hardshrink.Forward(input, activations); - for (size_t i = 0; i < activations.n_elem; i++) + for (size_t i = 0; i < activations.n_elem; ++i) { BOOST_REQUIRE_CLOSE(activations.at(i), target.at(i), 1e-3); } @@ -380,7 +380,7 @@ void CheckHardShrinkDerivativeCorrect(const arma::colvec input, // This error vector will be set to 1 to get the derivatives. arma::colvec error = arma::ones(input.n_elem); hardshrink.Backward(input, error, derivatives); - for (size_t i = 0; i < derivatives.n_elem; i++) + for (size_t i = 0; i < derivatives.n_elem; ++i) { BOOST_REQUIRE_CLOSE(derivatives.at(i), target.at(i), 1e-3); } @@ -402,7 +402,7 @@ void CheckSoftShrinkActivationCorrect(const arma::colvec input, // Test the activation function using the entire vector as input. arma::colvec activations; softshrink.Forward(input, activations); - for (size_t i = 0; i < activations.n_elem; i++) + for (size_t i = 0; i < activations.n_elem; ++i) { BOOST_REQUIRE_CLOSE(activations.at(i), target.at(i), 1e-3); } @@ -428,7 +428,7 @@ void CheckSoftShrinkDerivativeCorrect(const arma::colvec input, // This error vector will be set to 1 to get the derivatives. arma::colvec error = arma::ones(input.n_elem); softshrink.Backward(input, error, derivatives); - for (size_t i = 0; i < derivatives.n_elem; i++) + for (size_t i = 0; i < derivatives.n_elem; ++i) { BOOST_REQUIRE_CLOSE(derivatives.at(i), target.at(i), 1e-3); } @@ -523,7 +523,7 @@ void CheckCELUActivationCorrect(const arma::colvec input, // Test the activation function using the entire vector as input. arma::colvec activations; lrf.Forward(input, activations); - for (size_t i = 0; i < activations.n_elem; i++) + for (size_t i = 0; i < activations.n_elem; ++i) { BOOST_REQUIRE_CLOSE(activations.at(i), target.at(i), 1e-3); } @@ -549,7 +549,7 @@ void CheckCELUDerivativeCorrect(const arma::colvec input, arma::colvec error = arma::ones(input.n_elem); lrf.Forward(input, activations); lrf.Backward(activations, error, derivatives); - for (size_t i = 0; i < derivatives.n_elem; i++) + for (size_t i = 0; i < derivatives.n_elem; ++i) { BOOST_REQUIRE_CLOSE(derivatives.at(i), target.at(i), 1e-3); } @@ -734,11 +734,11 @@ BOOST_AUTO_TEST_CASE(CReLUFunctionTest) // This error vector will be set to 1 to get the derivatives. arma::colvec error = arma::ones(desiredActivations.n_elem); crelu.Backward(desiredActivations, error, derivatives); - for (size_t i = 0; i < activations.n_elem; i++) + for (size_t i = 0; i < activations.n_elem; ++i) { BOOST_REQUIRE_CLOSE(activations.at(i), desiredActivations.at(i), 1e-3); } - for (size_t i = 0; i < derivatives.n_elem; i++) + for (size_t i = 0; i < derivatives.n_elem; ++i) { BOOST_REQUIRE_CLOSE(derivatives.at(i), desiredDerivatives.at(i), 1e-3); } diff --git a/src/mlpack/tests/adaboost_test.cpp b/src/mlpack/tests/adaboost_test.cpp index 0065877abe..92f20edb9b 100644 --- a/src/mlpack/tests/adaboost_test.cpp +++ b/src/mlpack/tests/adaboost_test.cpp @@ -587,7 +587,7 @@ BOOST_AUTO_TEST_CASE(ClassifyTest_VERTEBRALCOL) arma::colvec pRow; arma::uword maxIndex = 0; - for (size_t i = 0; i < predictedLabels1.n_cols; i++) + for (size_t i = 0; i < predictedLabels1.n_cols; ++i) { pRow = probabilities.unsafe_col(i); pRow.max(maxIndex); @@ -655,7 +655,7 @@ BOOST_AUTO_TEST_CASE(ClassifyTest_NONLINSEP) arma::colvec pRow; arma::uword maxIndex = 0; - for (size_t i = 0; i < predictedLabels1.n_cols; i++) + for (size_t i = 0; i < predictedLabels1.n_cols; ++i) { pRow = probabilities.unsafe_col(i); pRow.max(maxIndex); @@ -722,7 +722,7 @@ BOOST_AUTO_TEST_CASE(ClassifyTest_IRIS) arma::colvec pRow; arma::uword maxIndex = 0; - for (size_t i = 0; i < predictedLabels1.n_cols; i++) + for (size_t i = 0; i < predictedLabels1.n_cols; ++i) { pRow = probabilities.unsafe_col(i); pRow.max(maxIndex); diff --git a/src/mlpack/tests/akfn_test.cpp b/src/mlpack/tests/akfn_test.cpp index 93f4014503..e05aece147 100644 --- a/src/mlpack/tests/akfn_test.cpp +++ b/src/mlpack/tests/akfn_test.cpp @@ -67,7 +67,7 @@ BOOST_AUTO_TEST_CASE(ApproxVsExact1) arma::mat distancesApprox; akfn->Search(dataset, 15, neighborsApprox, distancesApprox); - for (size_t i = 0; i < neighborsApprox.n_elem; i++) + for (size_t i = 0; i < neighborsApprox.n_elem; ++i) REQUIRE_RELATIVE_ERR(distancesApprox(i), distancesExact(i), epsilon); // Clean the memory. @@ -98,7 +98,7 @@ BOOST_AUTO_TEST_CASE(ApproxVsExact2) arma::mat distancesApprox; akfn.Search(15, neighborsApprox, distancesApprox); - for (size_t i = 0; i < neighborsApprox.n_elem; i++) + for (size_t i = 0; i < neighborsApprox.n_elem; ++i) REQUIRE_RELATIVE_ERR(distancesApprox[i], distancesExact[i], 0.05); } @@ -125,7 +125,7 @@ BOOST_AUTO_TEST_CASE(SingleTreeVsExact) arma::mat distancesApprox; akfn.Search(15, neighborsApprox, distancesApprox); - for (size_t i = 0; i < neighborsApprox.n_elem; i++) + for (size_t i = 0; i < neighborsApprox.n_elem; ++i) REQUIRE_RELATIVE_ERR(distancesApprox[i], distancesExact[i], 0.05); } diff --git a/src/mlpack/tests/aknn_test.cpp b/src/mlpack/tests/aknn_test.cpp index 82d1bdf11c..1a1d9018db 100644 --- a/src/mlpack/tests/aknn_test.cpp +++ b/src/mlpack/tests/aknn_test.cpp @@ -70,7 +70,7 @@ BOOST_AUTO_TEST_CASE(ApproxVsExact1) arma::mat distancesApprox; aknn->Search(dataset, 15, neighborsApprox, distancesApprox); - for (size_t i = 0; i < neighborsApprox.n_elem; i++) + for (size_t i = 0; i < neighborsApprox.n_elem; ++i) REQUIRE_RELATIVE_ERR(distancesApprox(i), distancesExact(i), epsilon); // Clean the memory. @@ -101,7 +101,7 @@ BOOST_AUTO_TEST_CASE(ApproxVsExact2) arma::mat distancesApprox; aknn.Search(15, neighborsApprox, distancesApprox); - for (size_t i = 0; i < neighborsApprox.n_elem; i++) + for (size_t i = 0; i < neighborsApprox.n_elem; ++i) REQUIRE_RELATIVE_ERR(distancesApprox(i), distancesExact(i), 0.05); } @@ -128,7 +128,7 @@ BOOST_AUTO_TEST_CASE(SingleTreeApproxVsExact) arma::mat distancesApprox; aknn.Search(15, neighborsApprox, distancesApprox); - for (size_t i = 0; i < neighborsApprox.n_elem; i++) + for (size_t i = 0; i < neighborsApprox.n_elem; ++i) REQUIRE_RELATIVE_ERR(distancesApprox[i], distancesExact[i], 0.05); } diff --git a/src/mlpack/tests/ann_dist_test.cpp b/src/mlpack/tests/ann_dist_test.cpp index 6c6dad1371..d66bf7e9fb 100644 --- a/src/mlpack/tests/ann_dist_test.cpp +++ b/src/mlpack/tests/ann_dist_test.cpp @@ -43,7 +43,7 @@ BOOST_AUTO_TEST_CASE(SimpleBernoulliDistributionTest) */ BOOST_AUTO_TEST_CASE(JacobianBernoulliDistributionTest) { - for (size_t i = 0; i < 5; i++) + for (size_t i = 0; i < 5; ++i) { const size_t targetElements = math::RandInt(2, 1000); @@ -86,7 +86,7 @@ BOOST_AUTO_TEST_CASE(JacobianBernoulliDistributionTest) */ BOOST_AUTO_TEST_CASE(JacobianBernoulliDistributionLogisticTest) { - for (size_t i = 0; i < 5; i++) + for (size_t i = 0; i < 5; ++i) { const size_t targetElements = math::RandInt(2, 1000); diff --git a/src/mlpack/tests/ann_layer_test.cpp b/src/mlpack/tests/ann_layer_test.cpp index a2a8487ef7..cc99852f55 100644 --- a/src/mlpack/tests/ann_layer_test.cpp +++ b/src/mlpack/tests/ann_layer_test.cpp @@ -64,7 +64,7 @@ BOOST_AUTO_TEST_CASE(SimpleAddLayerTest) */ BOOST_AUTO_TEST_CASE(JacobianAddLayerTest) { - for (size_t i = 0; i < 5; i++) + for (size_t i = 0; i < 5; ++i) { const size_t elements = math::RandInt(2, 1000); arma::mat input; @@ -166,7 +166,7 @@ BOOST_AUTO_TEST_CASE(SimpleConstantLayerTest) */ BOOST_AUTO_TEST_CASE(JacobianConstantLayerTest) { - for (size_t i = 0; i < 5; i++) + for (size_t i = 0; i < 5; ++i) { const size_t elements = math::RandInt(2, 1000); arma::mat input; @@ -394,7 +394,7 @@ BOOST_AUTO_TEST_CASE(SimpleLinearLayerTest) */ BOOST_AUTO_TEST_CASE(JacobianLinearLayerTest) { - for (size_t i = 0; i < 5; i++) + for (size_t i = 0; i < 5; ++i) { const size_t inputElements = math::RandInt(2, 1000); const size_t outputElements = math::RandInt(2, 1000); @@ -498,7 +498,7 @@ BOOST_AUTO_TEST_CASE(SimplePaddingLayerTest) */ BOOST_AUTO_TEST_CASE(JacobianLinearNoBiasLayerTest) { - for (size_t i = 0; i < 5; i++) + for (size_t i = 0; i < 5; ++i) { const size_t inputElements = math::RandInt(2, 1000); const size_t outputElements = math::RandInt(2, 1000); @@ -562,7 +562,7 @@ BOOST_AUTO_TEST_CASE(GradientLinearNoBiasLayerTest) */ BOOST_AUTO_TEST_CASE(JacobianNegativeLogLikelihoodLayerTest) { - for (size_t i = 0; i < 5; i++) + for (size_t i = 0; i < 5; ++i) { NegativeLogLikelihood<> module; const size_t inputElements = math::RandInt(5, 100); @@ -583,7 +583,7 @@ BOOST_AUTO_TEST_CASE(JacobianNegativeLogLikelihoodLayerTest) */ BOOST_AUTO_TEST_CASE(JacobianLeakyReLULayerTest) { - for (size_t i = 0; i < 5; i++) + for (size_t i = 0; i < 5; ++i) { const size_t inputElements = math::RandInt(2, 1000); @@ -602,7 +602,7 @@ BOOST_AUTO_TEST_CASE(JacobianLeakyReLULayerTest) */ BOOST_AUTO_TEST_CASE(JacobianFlexibleReLULayerTest) { - for (size_t i = 0; i < 5; i++) + for (size_t i = 0; i < 5; ++i) { const size_t inputElements = math::RandInt(2, 1000); @@ -666,7 +666,7 @@ BOOST_AUTO_TEST_CASE(GradientFlexibleReLULayerTest) */ BOOST_AUTO_TEST_CASE(JacobianMultiplyConstantLayerTest) { - for (size_t i = 0; i < 5; i++) + for (size_t i = 0; i < 5; ++i) { const size_t inputElements = math::RandInt(2, 1000); @@ -685,7 +685,7 @@ BOOST_AUTO_TEST_CASE(JacobianMultiplyConstantLayerTest) */ BOOST_AUTO_TEST_CASE(JacobianHardTanHLayerTest) { - for (size_t i = 0; i < 5; i++) + for (size_t i = 0; i < 5; ++i) { const size_t inputElements = math::RandInt(2, 1000); @@ -2669,7 +2669,7 @@ BOOST_AUTO_TEST_CASE(ReparametrizationLayerIncludeKlTest) */ BOOST_AUTO_TEST_CASE(JacobianReparametrizationLayerTest) { - for (size_t i = 0; i < 5; i++) + for (size_t i = 0; i < 5; ++i) { const size_t inputElementsHalf = math::RandInt(2, 1000); diff --git a/src/mlpack/tests/bias_svd_test.cpp b/src/mlpack/tests/bias_svd_test.cpp index 9aff4e7b2f..74d6504e27 100644 --- a/src/mlpack/tests/bias_svd_test.cpp +++ b/src/mlpack/tests/bias_svd_test.cpp @@ -46,7 +46,7 @@ BOOST_AUTO_TEST_CASE(BiasSVDFunctionRandomEvaluate) // Make a BiasSVDFunction with zero regularization. BiasSVDFunction biasSVDFunc(data, rank, 0); - for (size_t i = 0; i < numTrials; i++) + for (size_t i = 0; i < numTrials; ++i) { arma::mat parameters = arma::randu(rank + 1, numUsers + numItems); @@ -99,7 +99,7 @@ BOOST_AUTO_TEST_CASE(BiasSVDFunctionRegularizationEvaluate) BiasSVDFunction biasSVDFuncSmallReg(data, rank, 0.5); BiasSVDFunction biasSVDFuncBigReg(data, rank, 20); - for (size_t i = 0; i < numTrials; i++) + for (size_t i = 0; i < numTrials; ++i) { arma::mat parameters = arma::randu(rank + 1, numUsers + numItems); @@ -166,7 +166,7 @@ BOOST_AUTO_TEST_CASE(BiasSVDFunctionGradient) double costPlus1, costMinus1, numGradient1; double costPlus2, costMinus2, numGradient2; - for (size_t i = 0; i < rank; i++) + for (size_t i = 0; i < rank; ++i) { for (size_t j = 0; j < numUsers + numItems; j++) { @@ -262,7 +262,7 @@ BOOST_AUTO_TEST_CASE(BiasSVDFunctionOptimize) data(1, numRatings - 1) = numItems - 1; // Make rating entries based on the parameters. - for (size_t i = 0; i < numRatings; i++) + for (size_t i = 0; i < numRatings; ++i) { const size_t user = data(0, i); const size_t item = data(1, i) + numUsers; @@ -283,7 +283,7 @@ BOOST_AUTO_TEST_CASE(BiasSVDFunctionOptimize) // Get predicted ratings from optimized parameters. arma::mat predictedData(1, numRatings); - for (size_t i = 0; i < numRatings; i++) + for (size_t i = 0; i < numRatings; ++i) { const size_t user = data(0, i); const size_t item = data(1, i) + numUsers; @@ -330,7 +330,7 @@ BOOST_AUTO_TEST_CASE(BiasSVDFunctionParallelOptimize) data(1, numRatings - 1) = numItems - 1; // Make rating entries based on the parameters. - for (size_t i = 0; i < numRatings; i++) + for (size_t i = 0; i < numRatings; ++i) { const size_t user = data(0, i); const size_t item = data(1, i) + numUsers; @@ -358,7 +358,7 @@ BOOST_AUTO_TEST_CASE(BiasSVDFunctionParallelOptimize) // Get predicted ratings from optimized parameters. arma::mat predictedData(1, numRatings); - for (size_t i = 0; i < numRatings; i++) + for (size_t i = 0; i < numRatings; ++i) { const size_t user = data(0, i); const size_t item = data(1, i) + numUsers; diff --git a/src/mlpack/tests/callback_test.cpp b/src/mlpack/tests/callback_test.cpp index 2ec9d6a585..68a119c385 100644 --- a/src/mlpack/tests/callback_test.cpp +++ b/src/mlpack/tests/callback_test.cpp @@ -211,12 +211,12 @@ BOOST_AUTO_TEST_CASE(SRWithOptimizerCallback) arma::mat data(inputSize, points); arma::Row labels(points); - for (size_t i = 0; i < points / 2; i++) + for (size_t i = 0; i < points / 2; ++i) { data.col(i) = g1.Random(); labels(i) = 0; } - for (size_t i = points / 2; i < points; i++) + for (size_t i = points / 2; i < points; ++i) { data.col(i) = g2.Random(); labels(i) = 1; diff --git a/src/mlpack/tests/cf_test.cpp b/src/mlpack/tests/cf_test.cpp index df844f0f88..5649b95703 100644 --- a/src/mlpack/tests/cf_test.cpp +++ b/src/mlpack/tests/cf_test.cpp @@ -132,7 +132,7 @@ void GetRecommendationsQueriedUser() // Create dummy query set. arma::Col users = arma::zeros >(numUsers, 1); - for (size_t i = 0; i < numUsers; i++) + for (size_t i = 0; i < numUsers; ++i) users(i) = i; // Matrix to save recommendations into. diff --git a/src/mlpack/tests/convolution_test.cpp b/src/mlpack/tests/convolution_test.cpp index 97ce3bee98..2d40e05c1f 100644 --- a/src/mlpack/tests/convolution_test.cpp +++ b/src/mlpack/tests/convolution_test.cpp @@ -51,7 +51,7 @@ void Convolution2DMethodTest(const arma::mat input, const double* outputPtr = output.memptr(); const double* convOutputPtr = convOutput.memptr(); - for (size_t i = 0; i < output.n_elem; i++, outputPtr++, convOutputPtr++) + for (size_t i = 0; i < output.n_elem; ++i, outputPtr++, convOutputPtr++) BOOST_REQUIRE_CLOSE(*outputPtr, *convOutputPtr, 1e-3); } @@ -82,7 +82,7 @@ void Convolution3DMethodTest(const arma::cube input, const double* outputPtr = output.memptr(); const double* convOutputPtr = convOutput.memptr(); - for (size_t i = 0; i < output.n_elem; i++, outputPtr++, convOutputPtr++) + for (size_t i = 0; i < output.n_elem; ++i, outputPtr++, convOutputPtr++) BOOST_REQUIRE_CLOSE(*outputPtr, *convOutputPtr, 1e-3); } @@ -114,7 +114,7 @@ void ConvolutionMethodBatchTest(const arma::mat input, const double* outputPtr = output.memptr(); const double* convOutputPtr = convOutput.memptr(); - for (size_t i = 0; i < output.n_elem; i++, outputPtr++, convOutputPtr++) + for (size_t i = 0; i < output.n_elem; ++i, outputPtr++, convOutputPtr++) BOOST_REQUIRE_CLOSE(*outputPtr, *convOutputPtr, 1e-3); } diff --git a/src/mlpack/tests/convolutional_network_test.cpp b/src/mlpack/tests/convolutional_network_test.cpp index a7c3e41442..cefab9d0df 100644 --- a/src/mlpack/tests/convolutional_network_test.cpp +++ b/src/mlpack/tests/convolutional_network_test.cpp @@ -36,14 +36,14 @@ BOOST_AUTO_TEST_CASE(VanillaNetworkTest) // Normalize each point since these are images. arma::uword nPoints = X.n_cols; - for (arma::uword i = 0; i < nPoints; i++) + for (arma::uword i = 0; i < nPoints; ++i) { X.col(i) /= norm(X.col(i), 2); } // Build the target matrix. arma::mat Y = arma::zeros(1, nPoints); - for (size_t i = 0; i < nPoints; i++) + for (size_t i = 0; i < nPoints; ++i) { if (i < nPoints / 2) { diff --git a/src/mlpack/tests/cosine_tree_test.cpp b/src/mlpack/tests/cosine_tree_test.cpp index 1c299d6e16..b65d465f60 100644 --- a/src/mlpack/tests/cosine_tree_test.cpp +++ b/src/mlpack/tests/cosine_tree_test.cpp @@ -104,7 +104,7 @@ BOOST_AUTO_TEST_CASE(CosineNodeCosineSplit) cosines.zeros(currentNode->NumColumns()); size_t i, j, k; - for (i = 0; i < leftIndices.size(); i++) + for (i = 0; i < leftIndices.size(); ++i) cosines(i) = arma::norm_dot(data.col(leftIndices[i]), splitPoint); for (j = 0, k = i; j < rightIndices.size(); j++, k++) @@ -124,7 +124,7 @@ BOOST_AUTO_TEST_CASE(CosineNodeCosineSplit) if (std::fabs(cosineMax - cosineMax2) < precision) { // Check with some precision. - for (i = 0; i < leftIndices.size(); i++) + for (i = 0; i < leftIndices.size(); ++i) BOOST_REQUIRE_LT(cosineMax - cosines(i), cosines(i) - cosineMin + precision); @@ -138,7 +138,7 @@ BOOST_AUTO_TEST_CASE(CosineNodeCosineSplit) size_t numMax2Errors = 0; // Find errors for cosineMax. - for (i = 0; i < leftIndices.size(); i++) + for (i = 0; i < leftIndices.size(); ++i) if (cosineMax - cosines(i) >= cosines(i) - cosineMin + precision) numMax1Errors++; @@ -147,7 +147,7 @@ BOOST_AUTO_TEST_CASE(CosineNodeCosineSplit) numMax1Errors++; // Find errors for cosineMax2. - for (i = 0; i < leftIndices.size(); i++) + for (i = 0; i < leftIndices.size(); ++i) if (cosineMax2 - cosines(i) >= cosines(i) - cosineMin + precision) numMax2Errors++; @@ -181,7 +181,7 @@ BOOST_AUTO_TEST_CASE(CosineTreeModifiedGramSchmidt) CosineNodeQueue basisQueue; CosineTree dummyTree(data, epsilon, delta); - for (size_t i = 0; i < numCols; i++) + for (size_t i = 0; i < numCols; ++i) { // Make a new CosineNode object. CosineTree* basisNode; @@ -212,7 +212,7 @@ BOOST_AUTO_TEST_CASE(CosineTreeModifiedGramSchmidt) } // Deallocate memory given to the objects. - for (size_t i = 0; i < numCols; i++) + for (size_t i = 0; i < numCols; ++i) { CosineTree* currentNode; currentNode = basisQueue.top(); @@ -316,7 +316,7 @@ BOOST_AUTO_TEST_CASE(CopyConstructorAndOperatorCosineTreeTest) } } - for (size_t i = 0; i < v1.size(); i++) + for (size_t i = 0; i < v1.size(); ++i) { BOOST_REQUIRE_EQUAL(v1.at(i), v2.at(i)); BOOST_REQUIRE_EQUAL(v1.at(i), v3.at(i)); @@ -429,7 +429,7 @@ BOOST_AUTO_TEST_CASE(MoveConstructorAndOperatorCosineTreeTest) } } - for (size_t i = 0; i < v1.size(); i++) + for (size_t i = 0; i < v1.size(); ++i) { BOOST_REQUIRE_EQUAL(v1.at(i), v2.at(i)); BOOST_REQUIRE_EQUAL(v1.at(i), v3.at(i)); diff --git a/src/mlpack/tests/dcgan_test.cpp b/src/mlpack/tests/dcgan_test.cpp index c843aca60e..36ab7bdabf 100644 --- a/src/mlpack/tests/dcgan_test.cpp +++ b/src/mlpack/tests/dcgan_test.cpp @@ -137,7 +137,7 @@ BOOST_AUTO_TEST_CASE(DCGANMNISTTest) size_t dim = std::sqrt(trainData.n_rows); arma::mat generatedData(2 * dim, dim * numSamples); - for (size_t i = 0; i < numSamples; i++) + for (size_t i = 0; i < numSamples; ++i) { arma::mat samples; noise.imbue( [&]() { return noiseFunction(); } ); @@ -292,7 +292,7 @@ BOOST_AUTO_TEST_CASE(DCGANMNISTTest) size_t dim = std::sqrt(trainData.n_rows); arma::mat generatedData(2 * dim, dim * numSamples); - for (size_t i = 0; i < numSamples; i++) + for (size_t i = 0; i < numSamples; ++i) { arma::mat samples; noise.imbue( [&]() { return noiseFunction(); } ); @@ -448,7 +448,7 @@ BOOST_AUTO_TEST_CASE(DCGANCelebATest) size_t dim = std::sqrt(trainData.n_rows); arma::mat generatedData(2 * dim, dim * numSamples); - for (size_t i = 0; i < numSamples; i++) + for (size_t i = 0; i < numSamples; ++i) { arma::mat samples; noise.imbue( [&]() { return noiseFunction(); } ); diff --git a/src/mlpack/tests/decision_stump_test.cpp b/src/mlpack/tests/decision_stump_test.cpp index 7adb0f2950..17da179974 100644 --- a/src/mlpack/tests/decision_stump_test.cpp +++ b/src/mlpack/tests/decision_stump_test.cpp @@ -49,7 +49,7 @@ BOOST_AUTO_TEST_CASE(OneClass) Row predictedLabels; ds.Classify(testingData, predictedLabels); - for (size_t i = 0; i < predictedLabels.size(); i++) + for (size_t i = 0; i < predictedLabels.size(); ++i) BOOST_CHECK_EQUAL(predictedLabels(i), 1); } diff --git a/src/mlpack/tests/distribution_test.cpp b/src/mlpack/tests/distribution_test.cpp index 83ecda846e..04a5d2c97f 100644 --- a/src/mlpack/tests/distribution_test.cpp +++ b/src/mlpack/tests/distribution_test.cpp @@ -78,7 +78,7 @@ BOOST_AUTO_TEST_CASE(DiscreteDistributionRandomTest) actualProb.zeros(); - for (size_t i = 0; i < 50000; i++) + for (size_t i = 0; i < 50000; ++i) actualProb((size_t) (d.Random()[0] + 0.5))++; // Normalize. @@ -282,10 +282,10 @@ BOOST_AUTO_TEST_CASE(GaussianDistributionDistributionConstructor) GaussianDistribution d(mean, covariance); - for (size_t i = 0; i < 3; i++) + for (size_t i = 0; i < 3; ++i) BOOST_REQUIRE_CLOSE(d.Mean()[i], mean[i], 1e-5); - for (size_t i = 0; i < 3; i++) + for (size_t i = 0; i < 3; ++i) for (size_t j = 0; j < 3; j++) BOOST_REQUIRE_CLOSE(d.Covariance()(i, j), covariance(i, j), 1e-5); } @@ -456,7 +456,7 @@ BOOST_AUTO_TEST_CASE(GaussianDistributionRandomTest) arma::mat obs(2, 5000); - for (size_t i = 0; i < 5000; i++) + for (size_t i = 0; i < 5000; ++i) obs.col(i) = d.Random(); // Now make sure that reflects the actual distribution. @@ -488,7 +488,7 @@ BOOST_AUTO_TEST_CASE(GaussianDistributionTrainTest) arma::mat observations(4, 10000); arma::mat transChol = trans(chol(cov)); - for (size_t i = 0; i < 10000; i++) + for (size_t i = 0; i < 10000; ++i) observations.col(i) = transChol * arma::randn(4) + mean; // Now estimate. @@ -501,10 +501,10 @@ BOOST_AUTO_TEST_CASE(GaussianDistributionTrainTest) d.Train(observations); // Check that everything is estimated right. - for (size_t i = 0; i < 4; i++) + for (size_t i = 0; i < 4; ++i) BOOST_REQUIRE_SMALL(d.Mean()[i] - actualMean[i], 1e-5); - for (size_t i = 0; i < 4; i++) + for (size_t i = 0; i < 4; ++i) for (size_t j = 0; j < 4; j++) BOOST_REQUIRE_SMALL(d.Covariance()(i, j) - actualCov(i, j), 1e-5); } @@ -523,11 +523,11 @@ BOOST_AUTO_TEST_CASE(GaussianDistributionTrainWithProbabilitiesTest) size_t d = 1; arma::mat rdata(d, N); - for (size_t i = 0; i < N; i++) + for (size_t i = 0; i < N; ++i) rdata.col(i) = dist.Random(); arma::vec probabilities(N); - for (size_t i = 0; i < N; i++) + for (size_t i = 0; i < N; ++i) probabilities(i) = Random(); // Fit distribution with probabilities and data. @@ -560,7 +560,7 @@ BOOST_AUTO_TEST_CASE(GaussianDistributionWithProbabilties1Test) arma::mat rdata(d, N); - for (size_t i = 0; i < N; i++) + for (size_t i = 0; i < N; ++i) rdata.col(i) = Random(); arma::vec probabilities(N, arma::fill::ones); @@ -615,7 +615,7 @@ BOOST_AUTO_TEST_CASE(GaussianDistributionTrainWithTwoDistProbabilitiesTest) // Assign high probabilities to points drawn from dist1 and low probabilities // to numbers drawn from dist2. - for (size_t i = 0 ; i < N ; i++) + for (size_t i = 0 ; i < N ; ++i) { if (i % 2 == 0) probabilities(i) = Random(0.98, 1); @@ -697,7 +697,7 @@ BOOST_AUTO_TEST_CASE(GammaDistributionTrainWithProbabilitiesTest) arma::mat rdata(d, N); for (size_t j = 0; j < d; j++) - for (size_t i = 0; i < N; i++) + for (size_t i = 0; i < N; ++i) rdata(j, i) = dist(math::randGen); // Fill the probabilities randomly. @@ -741,7 +741,7 @@ BOOST_AUTO_TEST_CASE(GammaDistributionTrainAllProbabilities1Test) arma::mat rdata(d, N); for (size_t j = 0; j < d; j++) - for (size_t i = 0; i < N; i++) + for (size_t i = 0; i < N; ++i) rdata(j, i) = dist(math::randGen); // Fit results with only data. @@ -787,7 +787,7 @@ BOOST_AUTO_TEST_CASE(GammaDistributionTrainTwoDistProbabilities1Test) // Draw points alternately from the two different distributions. for (size_t j = 0; j < d; j++) { - for (size_t i = 0; i < N; i++) + for (size_t i = 0; i < N; ++i) { if (i % 2 == 0) rdata(j, i) = dist(math::randGen); @@ -796,7 +796,7 @@ BOOST_AUTO_TEST_CASE(GammaDistributionTrainTwoDistProbabilities1Test) } } - for (size_t i = 0; i < N; i++) + for (size_t i = 0; i < N; ++i) { if (i % 2 == 0) probabilities(i) = 0.02 * math::Random(); @@ -1282,7 +1282,7 @@ BOOST_AUTO_TEST_CASE(DiagonalGaussianDistributionConstructor) DiagonalGaussianDistribution d(mean, covariance); // Make sure the mean and covariance is correct. - for (size_t i = 0; i < 3; i++) + for (size_t i = 0; i < 3; ++i) { BOOST_REQUIRE_CLOSE(d.Mean()(i), mean(i), 1e-5); BOOST_REQUIRE_CLOSE(d.Covariance()(i), covariance(i), 1e-5); @@ -1413,7 +1413,7 @@ BOOST_AUTO_TEST_CASE(DiagonalGaussianDistributionRandomTest) arma::mat obs(2, 5000); - for (size_t i = 0; i < 5000; i++) + for (size_t i = 0; i < 5000; ++i) obs.col(i) = d.Random(); // Make sure that reflects the actual distribution. @@ -1439,7 +1439,7 @@ BOOST_AUTO_TEST_CASE(DiagonalGaussianDistributionTrainTest) // Generate the observations. arma::mat observations(4, 10000); - for (size_t i = 0; i < 10000; i++) + for (size_t i = 0; i < 10000; ++i) observations.col(i) = (arma::sqrt(cov) % arma::randn(4)) + mean; DiagonalGaussianDistribution d; @@ -1452,7 +1452,7 @@ BOOST_AUTO_TEST_CASE(DiagonalGaussianDistributionTrainTest) d.Train(observations); // Check that the estimated parameters are right. - for (size_t i = 0; i < 4; i++) + for (size_t i = 0; i < 4; ++i) { BOOST_REQUIRE_SMALL(d.Mean()(i) - actualMean(i), 1e-5); BOOST_REQUIRE_SMALL(d.Covariance()(i) - actualCov(i, i), 1e-5); @@ -1503,7 +1503,7 @@ BOOST_AUTO_TEST_CASE(DiagonalGaussianWeightedParametersReductionTest) arma::mat obs(4, 5); arma::vec probs("0.2 0.2 0.2 0.2 0.2"); - for (size_t i = 0; i < 5; i++) + for (size_t i = 0; i < 5; ++i) obs.col(i) = (arma::sqrt(cov) % arma::randn(4)) + mean; DiagonalGaussianDistribution d1; @@ -1514,7 +1514,7 @@ BOOST_AUTO_TEST_CASE(DiagonalGaussianWeightedParametersReductionTest) d2.Train(obs, probs); // Check if these are equal. - for (size_t i = 0; i < 4; i++) + for (size_t i = 0; i < 4; ++i) { BOOST_REQUIRE_CLOSE(d1.Mean()(i), d2.Mean()(i), 1e-5); BOOST_REQUIRE_CLOSE(d1.Covariance()(i), d2.Covariance()(i), 1e-5); diff --git a/src/mlpack/tests/emst_test.cpp b/src/mlpack/tests/emst_test.cpp index d35cfd757b..5f4154ab9d 100644 --- a/src/mlpack/tests/emst_test.cpp +++ b/src/mlpack/tests/emst_test.cpp @@ -213,7 +213,7 @@ BOOST_AUTO_TEST_CASE(DualTreeVsNaive) BOOST_REQUIRE_EQUAL(dualResults.n_cols, naiveResults.n_cols); BOOST_REQUIRE_EQUAL(dualResults.n_rows, naiveResults.n_rows); - for (size_t i = 0; i < dualResults.n_cols; i++) + for (size_t i = 0; i < dualResults.n_cols; ++i) { BOOST_REQUIRE_EQUAL(dualResults(0, i), naiveResults(0, i)); BOOST_REQUIRE_EQUAL(dualResults(1, i), naiveResults(1, i)); @@ -241,7 +241,7 @@ BOOST_AUTO_TEST_CASE(CoverTreeTest) bst.ComputeMST(bstResults); ct.ComputeMST(coverResults); - for (size_t i = 0; i < bstResults.n_cols; i++) + for (size_t i = 0; i < bstResults.n_cols; ++i) { BOOST_REQUIRE_EQUAL(bstResults(0, i), coverResults(0, i)); BOOST_REQUIRE_EQUAL(bstResults(1, i), coverResults(1, i)); @@ -270,7 +270,7 @@ BOOST_AUTO_TEST_CASE(BallTreeTest) bst.ComputeMST(bstResults); ballt.ComputeMST(ballResults); - for (size_t i = 0; i < bstResults.n_cols; i++) + for (size_t i = 0; i < bstResults.n_cols; ++i) { BOOST_REQUIRE_EQUAL(bstResults(0, i), ballResults(0, i)); BOOST_REQUIRE_EQUAL(bstResults(1, i), ballResults(1, i)); diff --git a/src/mlpack/tests/gan_test.cpp b/src/mlpack/tests/gan_test.cpp index 4b82bfab0b..57d66fa613 100644 --- a/src/mlpack/tests/gan_test.cpp +++ b/src/mlpack/tests/gan_test.cpp @@ -97,7 +97,7 @@ BOOST_AUTO_TEST_CASE(GANTest) size_t dim = std::sqrt(trainData.n_rows); arma::mat generatedData(2 * dim, dim * numSamples); - for (size_t i = 0; i < numSamples; i++) + for (size_t i = 0; i < numSamples; ++i) { arma::mat samples; noise.imbue( [&]() { return noiseFunction(); } ); @@ -226,7 +226,7 @@ BOOST_AUTO_TEST_CASE(GANMNISTTest) size_t dim = std::sqrt(trainData.n_rows); arma::mat generatedData(2 * dim, dim * numSamples); - for (size_t i = 0; i < numSamples; i++) + for (size_t i = 0; i < numSamples; ++i) { arma::mat samples; noise.imbue( [&]() { return noiseFunction(); } ); diff --git a/src/mlpack/tests/gmm_test.cpp b/src/mlpack/tests/gmm_test.cpp index deb0faed6d..f9e913e303 100644 --- a/src/mlpack/tests/gmm_test.cpp +++ b/src/mlpack/tests/gmm_test.cpp @@ -167,7 +167,7 @@ BOOST_AUTO_TEST_CASE(GMMTrainEMMultipleGaussians) minDiff = std::abs(weights[i] - weights[j]); } while (minDiff < 0.02); - for (size_t i = 0; i < gaussians; i++) + for (size_t i = 0; i < gaussians; ++i) counts[i] = round(weights[i] * (data.n_cols - gaussians)); // Ensure one point minimum in each. counts += 1; @@ -177,7 +177,7 @@ BOOST_AUTO_TEST_CASE(GMMTrainEMMultipleGaussians) // Build each Gaussian individually. size_t point = 0; - for (size_t i = 0; i < gaussians; i++) + for (size_t i = 0; i < gaussians; ++i) { arma::mat gaussian; gaussian.randn(dims, counts[i]); @@ -206,7 +206,7 @@ BOOST_AUTO_TEST_CASE(GMMTrainEMMultipleGaussians) } // Calculate actual weights. - for (size_t i = 0; i < gaussians; i++) + for (size_t i = 0; i < gaussians; ++i) weights[i] = (double) counts[i] / data.n_cols; // Now train the model. @@ -228,7 +228,7 @@ BOOST_AUTO_TEST_CASE(GMMTrainEMMultipleGaussians) continue; // Check the model to see that it is correct. - for (size_t i = 0; i < gaussians; i++) + for (size_t i = 0; i < gaussians; ++i) { // Check the mean. BOOST_REQUIRE_LT( @@ -261,7 +261,7 @@ BOOST_AUTO_TEST_CASE(GMMTrainEMSingleGaussianWithProbability) // 10000 observations, each with random probability. arma::mat observations(2, 20000); - for (size_t i = 0; i < 20000; i++) + for (size_t i = 0; i < 20000; ++i) observations.col(i) = d.Random(); arma::vec probabilities; probabilities.randu(20000); // Random probabilities. @@ -310,7 +310,7 @@ BOOST_AUTO_TEST_CASE(GMMTrainEMMultipleGaussiansWithProbability) arma::mat points(3, 2000); arma::vec probabilities(2000); - for (size_t i = 0; i < 2000; i++) + for (size_t i = 0; i < 2000; ++i) { double randValue = math::Random(); @@ -354,7 +354,7 @@ BOOST_AUTO_TEST_CASE(GMMTrainEMMultipleGaussiansWithProbability) // First Gaussian (d1). BOOST_REQUIRE_SMALL(g.Weights()[sortedIndices[0]] - 0.2, 0.1); - for (size_t i = 0; i < 3; i++) + for (size_t i = 0; i < 3; ++i) BOOST_REQUIRE_SMALL((g.Component(sortedIndices[0]).Mean()[i] - d1.Mean()[i]), 0.4); @@ -366,7 +366,7 @@ BOOST_AUTO_TEST_CASE(GMMTrainEMMultipleGaussiansWithProbability) // Second Gaussian (d2). BOOST_REQUIRE_SMALL(g.Weights()[sortedIndices[1]] - 0.3, 0.1); - for (size_t i = 0; i < 3; i++) + for (size_t i = 0; i < 3; ++i) BOOST_REQUIRE_SMALL((g.Component(sortedIndices[1]).Mean()[i] - d2.Mean()[i]), 0.4); @@ -410,7 +410,7 @@ BOOST_AUTO_TEST_CASE(GMMRandomTest) // Now generate a bunch of observations. arma::mat observations(2, 4000); - for (size_t i = 0; i < 4000; i++) + for (size_t i = 0; i < 4000; ++i) observations.col(i) = gmm.Random(); // A new one which we'll train. @@ -664,7 +664,7 @@ BOOST_AUTO_TEST_CASE(UseExistingModelTest) weights /= accu(weights); } - for (size_t i = 0; i < gaussians; i++) + for (size_t i = 0; i < gaussians; ++i) counts[i] = round(weights[i] * (data.n_cols - gaussians)); // Ensure one point minimum in each. counts += 1; @@ -674,7 +674,7 @@ BOOST_AUTO_TEST_CASE(UseExistingModelTest) // Build each Gaussian individually. size_t point = 0; - for (size_t i = 0; i < gaussians; i++) + for (size_t i = 0; i < gaussians; ++i) { arma::mat gaussian; gaussian.randn(dims, counts[i]); @@ -703,7 +703,7 @@ BOOST_AUTO_TEST_CASE(UseExistingModelTest) } // Calculate actual weights. - for (size_t i = 0; i < gaussians; i++) + for (size_t i = 0; i < gaussians; ++i) weights[i] = (double) counts[i] / data.n_cols; // Now train the model. @@ -881,7 +881,7 @@ BOOST_AUTO_TEST_CASE(DiagonalGMMTrainEMOneGaussianWithProbability) // Generate 20000 observations, each with random probabilities. arma::mat observations(2, 20000); - for (size_t i = 0; i < 20000; i++) + for (size_t i = 0; i < 20000; ++i) observations.col(i) = d.Random(); // Random probabilities. @@ -925,7 +925,7 @@ BOOST_AUTO_TEST_CASE(DiagonalGMMTrainEMMultipleGaussians) // Now we'll generate points and probabilities. arma::mat observations(3, 5000); - for (size_t i = 0; i < 5000; i++) + for (size_t i = 0; i < 5000; ++i) { double randValue = math::Random(); @@ -949,11 +949,11 @@ BOOST_AUTO_TEST_CASE(DiagonalGMMTrainEMMultipleGaussians) // First Gaussian (d1). BOOST_REQUIRE_SMALL(g.Weights()[sortedIndices[0]] - 0.2, 0.1); - for (size_t i = 0; i < 3; i++) + for (size_t i = 0; i < 3; ++i) BOOST_REQUIRE_SMALL((g.Component(sortedIndices[0]).Mean()[i] - d1.Mean()[i]), 0.4); - for (size_t i = 0; i < 3; i++) + for (size_t i = 0; i < 3; ++i) { const double v = g.Component(sortedIndices[0]).Covariance()(i); BOOST_REQUIRE_SMALL(v - d1.Covariance()(i), 0.5); @@ -962,11 +962,11 @@ BOOST_AUTO_TEST_CASE(DiagonalGMMTrainEMMultipleGaussians) // Second Gaussian (d2). BOOST_REQUIRE_SMALL(g.Weights()[sortedIndices[1]] - 0.3, 0.1); - for (size_t i = 0; i < 3; i++) + for (size_t i = 0; i < 3; ++i) BOOST_REQUIRE_SMALL((g.Component(sortedIndices[1]).Mean()[i] - d2.Mean()[i]), 0.4); - for (size_t i = 0; i < 3; i++) + for (size_t i = 0; i < 3; ++i) { const double v = g.Component(sortedIndices[1]).Covariance()(i); BOOST_REQUIRE_SMALL(v - d2.Covariance()(i), 0.5); @@ -979,7 +979,7 @@ BOOST_AUTO_TEST_CASE(DiagonalGMMTrainEMMultipleGaussians) BOOST_REQUIRE_SMALL((g.Component(sortedIndices[2]).Mean()[i] - d3.Mean()[i]), 0.4); - for (size_t i = 0; i < 3; i++) + for (size_t i = 0; i < 3; ++i) { const double v = g.Component(sortedIndices[2]).Covariance()(i); BOOST_REQUIRE_SMALL(v - d3.Covariance()(i), 0.5); @@ -1005,7 +1005,7 @@ BOOST_AUTO_TEST_CASE(DiagonalGMMTrainEMMultipleGaussiansWithProbability) // Now we'll generate observations and probabilities. arma::mat observations(3, 10000); - for (size_t i = 0; i < 10000; i++) + for (size_t i = 0; i < 10000; ++i) { double randValue = math::Random(); @@ -1032,11 +1032,11 @@ BOOST_AUTO_TEST_CASE(DiagonalGMMTrainEMMultipleGaussiansWithProbability) // First Gaussian (d1). BOOST_REQUIRE_CLOSE(g.Weights()[sortedIndices[0]], 0.2, 10.0); - for (size_t i = 0; i < 3; i++) + for (size_t i = 0; i < 3; ++i) BOOST_REQUIRE_CLOSE(g.Component(sortedIndices[0]).Mean()[i], d1.Mean()[i], 13.0); - for (size_t i = 0; i < 3; i++) + for (size_t i = 0; i < 3; ++i) { const double v = g.Component(sortedIndices[0]).Covariance()(i); BOOST_REQUIRE_CLOSE(v, d1.Covariance()(i), 17.0); @@ -1045,11 +1045,11 @@ BOOST_AUTO_TEST_CASE(DiagonalGMMTrainEMMultipleGaussiansWithProbability) // Second Gaussian (d2). BOOST_REQUIRE_CLOSE(g.Weights()[sortedIndices[1]], 0.3, 10.0); - for (size_t i = 0; i < 3; i++) + for (size_t i = 0; i < 3; ++i) BOOST_REQUIRE_CLOSE(g.Component(sortedIndices[1]).Mean()[i], d2.Mean()[i], 13.0); - for (size_t i = 0; i < 3; i++) + for (size_t i = 0; i < 3; ++i) { const double v = g.Component(sortedIndices[1]).Covariance()(i); BOOST_REQUIRE_CLOSE(v, d2.Covariance()(i), 17.0); @@ -1062,7 +1062,7 @@ BOOST_AUTO_TEST_CASE(DiagonalGMMTrainEMMultipleGaussiansWithProbability) BOOST_REQUIRE_CLOSE(g.Component(sortedIndices[2]).Mean()[i], d3.Mean()[i], 13.0); - for (size_t i = 0; i < 3; i++) + for (size_t i = 0; i < 3; ++i) { const double v = g.Component(sortedIndices[2]).Covariance()(i); BOOST_REQUIRE_CLOSE(v, d3.Covariance()(i), 17.0); @@ -1088,7 +1088,7 @@ BOOST_AUTO_TEST_CASE(DiagonalGMMRandomTest) // Now generate a bunch of observations. arma::mat observations(2, 4000); - for (size_t i = 0; i < 4000; i++) + for (size_t i = 0; i < 4000; ++i) observations.col(i) = gmm.Random(); // A new one which we'll train. @@ -1165,10 +1165,10 @@ BOOST_AUTO_TEST_CASE(DiagonalGMMLoadSaveTest) BOOST_REQUIRE_EQUAL(gmm.Gaussians(), gmm2.Gaussians()); BOOST_REQUIRE_EQUAL(gmm.Dimensionality(), gmm2.Dimensionality()); - for (size_t i = 0; i < gmm.Dimensionality(); i++) + for (size_t i = 0; i < gmm.Dimensionality(); ++i) BOOST_REQUIRE_CLOSE(gmm.Weights()[i], gmm2.Weights()[i], 1e-3); - for (size_t i = 0; i < gmm.Gaussians(); i++) + for (size_t i = 0; i < gmm.Gaussians(); ++i) { for (size_t j = 0; j < gmm.Dimensionality(); j++) { diff --git a/src/mlpack/tests/hmm_test.cpp b/src/mlpack/tests/hmm_test.cpp index fd1c1946fc..de37811f5c 100644 --- a/src/mlpack/tests/hmm_test.cpp +++ b/src/mlpack/tests/hmm_test.cpp @@ -246,7 +246,7 @@ BOOST_AUTO_TEST_CASE(SimpleBaumWelchDiscreteHMM_2) size_t obsNum = 250; // Number of observations. size_t obsLen = 500; // Number of elements in each observation. size_t stateZeroStarts = 0; // Number of times we start in state 0. - for (size_t i = 0; i < obsNum; i++) + for (size_t i = 0; i < obsNum; ++i) { arma::mat observation(1, obsLen); @@ -428,7 +428,7 @@ BOOST_AUTO_TEST_CASE(DiscreteHMMSimpleGenerateTest) arma::vec stateProb(2); emissionProb.zeros(); stateProb.zeros(); - for (size_t i = 0; i < 100000; i++) + for (size_t i = 0; i < 100000; ++i) { emissionProb[(size_t) dataSeq.col(i)[0] + 0.5]++; stateProb[stateSeq[i]]++; @@ -480,7 +480,7 @@ BOOST_AUTO_TEST_CASE(DiscreteHMMGenerateTest) int numObs = 3000; std::vector sequences(numSeq); std::vector > states(numSeq); - for (int i = 0; i < numSeq; i++) + for (int i = 0; i < numSeq; ++i) { // Random starting state. size_t startState = math::RandInt(4); @@ -561,7 +561,7 @@ BOOST_AUTO_TEST_CASE(GaussianHMMSimpleTest) // 1000-observations sequence. classes[0] = 0; observations.col(0) = g1.Random(); - for (size_t i = 1; i < 1000; i++) + for (size_t i = 1; i < 1000; ++i) { double randValue = math::Random(); @@ -584,7 +584,7 @@ BOOST_AUTO_TEST_CASE(GaussianHMMSimpleTest) hmm.Estimate(observations, stateProb); // Check that each prediction is right. - for (size_t i = 0; i < 1000; i++) + for (size_t i = 0; i < 1000; ++i) { BOOST_REQUIRE_EQUAL(predictedClasses[i], classes[i]); @@ -906,7 +906,7 @@ BOOST_AUTO_TEST_CASE(GMMHMMPredictTest) states[0] = 0; observations.col(0) = gmms[0].Random(); - for (size_t i = 1; i < 1000; i++) + for (size_t i = 1; i < 1000; ++i) { double randValue = math::Random(); @@ -924,7 +924,7 @@ BOOST_AUTO_TEST_CASE(GMMHMMPredictTest) // Check that the predictions were correct. success = true; - for (size_t i = 0; i < 1000; i++) + for (size_t i = 0; i < 1000; ++i) { if (predictions[i] != states[i]) { @@ -978,7 +978,7 @@ BOOST_AUTO_TEST_CASE(GMMHMMLabeledTrainingTest) states[obs][0] = 0; observations[obs].col(0) = gmms[0].Random(); - for (size_t i = 1; i < 2500; i++) + for (size_t i = 1; i < 2500; ++i) { double randValue = (double) rand() / (double) RAND_MAX; @@ -1304,7 +1304,7 @@ BOOST_AUTO_TEST_CASE(DiagonalGMMHMMPredictTest) states[0] = 0; observations.col(0) = gmms[0].Random(); - for (size_t i = 1; i < 1000; i++) + for (size_t i = 1; i < 1000; ++i) { double randValue = math::Random(); @@ -1322,7 +1322,7 @@ BOOST_AUTO_TEST_CASE(DiagonalGMMHMMPredictTest) // Check them. success = true; - for (size_t i = 0; i < 1000; i++) + for (size_t i = 0; i < 1000; ++i) { if (predictions[i] != states[i]) { @@ -1395,7 +1395,7 @@ BOOST_AUTO_TEST_CASE(DiagonalGMMHMMOneGaussianOneStateTrainingTest) { observations[obs].col(0) = d.Random(); - for (size_t i = 1; i < 5000; i++) + for (size_t i = 1; i < 5000; ++i) { observations[obs].col(i) = d.Random(); } @@ -1446,7 +1446,7 @@ BOOST_AUTO_TEST_CASE(DiagonalGMMHMMOneGaussianUnlabeledTrainingTest) states[obs][0] = 0; observations[obs].col(0) = gmms[0].Random(); - for (size_t i = 1; i < 500; i++) + for (size_t i = 1; i < 500; ++i) { double randValue = math::Random(); @@ -1471,22 +1471,22 @@ BOOST_AUTO_TEST_CASE(DiagonalGMMHMMOneGaussianUnlabeledTrainingTest) BOOST_REQUIRE_SMALL(hmm.Initial()[1], 0.01); // Check the transition probability matrix. - for (size_t i = 0; i < 2; i++) + for (size_t i = 0; i < 2; ++i) for (size_t j = 0; j < 2; j++) BOOST_REQUIRE_SMALL(hmm.Transition()(i, j) - transProbs(i, j), 0.08); // Check the estimated weights of the each emission distribution. - for (size_t i = 0; i < 2; i++) + for (size_t i = 0; i < 2; ++i) BOOST_REQUIRE_SMALL(hmm.Emission()[i].Weights()[0] - gmms[i].Weights()[0], 0.08); // Check the estimated means of the each emission distribution. - for (size_t i = 0; i < 2; i++) + for (size_t i = 0; i < 2; ++i) BOOST_REQUIRE_LT(arma::norm(hmm.Emission()[i].Component(0).Mean() - gmms[i].Component(0).Mean()), 0.2); // Check the estimated covariances of the each emission distribution. - for (size_t i = 0; i < 2; i++) + for (size_t i = 0; i < 2; ++i) BOOST_REQUIRE_LT(arma::norm(hmm.Emission()[i].Component(0).Covariance() - gmms[i].Component(0).Covariance()), 0.5); } @@ -1523,7 +1523,7 @@ BOOST_AUTO_TEST_CASE(DiagonalGMMHMMOneGaussianLabeledTrainingTest) states[obs][0] = 0; observations[obs].col(0) = gmms[0].Random(); - for (size_t i = 1; i < 5000; i++) + for (size_t i = 1; i < 5000; ++i) { double randValue = math::Random(); double probSum = 0; @@ -1553,22 +1553,22 @@ BOOST_AUTO_TEST_CASE(DiagonalGMMHMMOneGaussianLabeledTrainingTest) BOOST_REQUIRE_SMALL(hmm.Initial()[2], 0.01); // Check the transition probability matrix. - for (size_t i = 0; i < 3; i++) + for (size_t i = 0; i < 3; ++i) for (size_t j = 0; j < 3; j++) BOOST_REQUIRE_SMALL(hmm.Transition()(i, j) - transProbs(i, j), 0.03); // Check the estimated weights of the each emission distribution. - for (size_t i = 0; i < 3; i++) + for (size_t i = 0; i < 3; ++i) BOOST_REQUIRE_SMALL(hmm.Emission()[i].Weights()[0] - gmms[i].Weights()[0], 0.08); // Check the estimated means of the each emission distribution. - for (size_t i = 0; i < 3; i++) + for (size_t i = 0; i < 3; ++i) BOOST_REQUIRE_LT(arma::norm(hmm.Emission()[i].Component(0).Mean() - gmms[i].Component(0).Mean()), 0.2); // Check the estimated covariances of the each emission distribution. - for (size_t i = 0; i < 3; i++) + for (size_t i = 0; i < 3; ++i) BOOST_REQUIRE_LT(arma::norm(hmm.Emission()[i].Component(0).Covariance() - gmms[i].Component(0).Covariance()), 0.5); } @@ -1607,7 +1607,7 @@ BOOST_AUTO_TEST_CASE(DiagonalGMMHMMMultipleGaussiansUnlabeledTrainingTest) states[obs][0] = 0; observations[obs].col(0) = gmms[0].Random(); - for (size_t i = 1; i < 1000; i++) + for (size_t i = 1; i < 1000; ++i) { double randValue = math::Random(); @@ -1632,7 +1632,7 @@ BOOST_AUTO_TEST_CASE(DiagonalGMMHMMMultipleGaussiansUnlabeledTrainingTest) BOOST_REQUIRE_SMALL(hmm.Initial()[1], 0.01); // Check the transition probability matrix. - for (size_t i = 0; i < 2; i++) + for (size_t i = 0; i < 2; ++i) for (size_t j = 0; j < 2; j++) BOOST_REQUIRE_SMALL(hmm.Transition()(i, j) - transProbs(i, j), 0.08); @@ -1640,7 +1640,7 @@ BOOST_AUTO_TEST_CASE(DiagonalGMMHMMMultipleGaussiansUnlabeledTrainingTest) arma::uvec sortedIndices = sort_index(hmm.Emission()[0].Weights()); // Check the first emission distribution. - for (size_t i = 0; i < 2; i++) + for (size_t i = 0; i < 2; ++i) { // Check the estimated weights using the first DiagonalGMM. BOOST_REQUIRE_SMALL(hmm.Emission()[0].Weights()[sortedIndices[i]] - @@ -1661,7 +1661,7 @@ BOOST_AUTO_TEST_CASE(DiagonalGMMHMMMultipleGaussiansUnlabeledTrainingTest) sortedIndices = sort_index(hmm.Emission()[1].Weights()); // Check the second emission distribution. - for (size_t i = 0; i < 2; i++) + for (size_t i = 0; i < 2; ++i) { // Check the estimated weights using the second DiagonalGMM. BOOST_REQUIRE_SMALL(hmm.Emission()[1].Weights()[sortedIndices[i]] - @@ -1712,7 +1712,7 @@ BOOST_AUTO_TEST_CASE(DiagonalGMMHMMMultipleGaussiansLabeledTrainingTest) states[obs][0] = 0; observations[obs].col(0) = gmms[0].Random(); - for (size_t i = 1; i < 2500; i++) + for (size_t i = 1; i < 2500; ++i) { double randValue = math::Random(); @@ -1736,7 +1736,7 @@ BOOST_AUTO_TEST_CASE(DiagonalGMMHMMMultipleGaussiansLabeledTrainingTest) BOOST_REQUIRE_SMALL(hmm.Initial()[1], 0.01); // Check the transition probability matrix. - for (size_t i = 0; i < 2; i++) + for (size_t i = 0; i < 2; ++i) for (size_t j = 0; j < 2; j++) BOOST_REQUIRE_SMALL(hmm.Transition()(i, j) - transProbs(i, j), 0.03); @@ -1744,7 +1744,7 @@ BOOST_AUTO_TEST_CASE(DiagonalGMMHMMMultipleGaussiansLabeledTrainingTest) arma::uvec sortedIndices = sort_index(hmm.Emission()[0].Weights()); // Check the first emission distribution. - for (size_t i = 0; i < 2; i++) + for (size_t i = 0; i < 2; ++i) { // Check the estimated weights using the first DiagonalGMM. BOOST_REQUIRE_SMALL(hmm.Emission()[0].Weights()[sortedIndices[i]] - @@ -1765,7 +1765,7 @@ BOOST_AUTO_TEST_CASE(DiagonalGMMHMMMultipleGaussiansLabeledTrainingTest) sortedIndices = sort_index(hmm.Emission()[1].Weights()); // Check the second emission distribution. - for (size_t i = 0; i < 2; i++) + for (size_t i = 0; i < 2; ++i) { // Check the estimated weights using the second DiagonalGMM. BOOST_REQUIRE_SMALL(hmm.Emission()[1].Weights()[sortedIndices[i]] - @@ -1795,7 +1795,7 @@ BOOST_AUTO_TEST_CASE(DiagonalGMMHMMLoadSaveTest) for (size_t j = 0; j < hmm.Emission().size(); j++) { hmm.Emission()[j].Weights().randu(); - for (size_t i = 0; i < hmm.Emission()[j].Gaussians(); i++) + for (size_t i = 0; i < hmm.Emission()[j].Gaussians(); ++i) { hmm.Emission()[j].Component(i).Mean().randu(); arma::vec covariance = arma::randu( @@ -1834,12 +1834,12 @@ BOOST_AUTO_TEST_CASE(DiagonalGMMHMMLoadSaveTest) BOOST_REQUIRE_EQUAL(hmm.Emission()[j].Dimensionality(), hmm2.Emission()[j].Dimensionality()); - for (size_t i = 0; i < hmm.Emission()[j].Dimensionality(); i++) + for (size_t i = 0; i < hmm.Emission()[j].Dimensionality(); ++i) // Check the weights. BOOST_REQUIRE_CLOSE(hmm.Emission()[j].Weights()[i], hmm2.Emission()[j].Weights()[i], 1e-3); - for (size_t i = 0; i < hmm.Emission()[j].Gaussians(); i++) + for (size_t i = 0; i < hmm.Emission()[j].Gaussians(); ++i) { for (size_t l = 0; l < hmm.Emission()[j].Dimensionality(); l++) { diff --git a/src/mlpack/tests/hoeffding_tree_test.cpp b/src/mlpack/tests/hoeffding_tree_test.cpp index 46967279a4..26e628d333 100644 --- a/src/mlpack/tests/hoeffding_tree_test.cpp +++ b/src/mlpack/tests/hoeffding_tree_test.cpp @@ -1087,7 +1087,7 @@ BOOST_AUTO_TEST_CASE(ConfidenceChangeTest) while ((tree.NumChildren() == 0) && (i < 9000)) { tree.Train(dataset.col(i), labels[i]); - i++; + ++i; } BOOST_REQUIRE_LT(i, 9000); @@ -1102,7 +1102,7 @@ BOOST_AUTO_TEST_CASE(ConfidenceChangeTest) while ((tree.NumChildren() == 0) && (i < 90000)) { tree.Train(dataset.col(i % 9000), labels[i % 9000]); - i++; + ++i; } for (size_t c = 0; c < tree.NumChildren(); ++c) diff --git a/src/mlpack/tests/hyperplane_test.cpp b/src/mlpack/tests/hyperplane_test.cpp index 8c150446a6..2cfb74d787 100644 --- a/src/mlpack/tests/hyperplane_test.cpp +++ b/src/mlpack/tests/hyperplane_test.cpp @@ -33,7 +33,7 @@ BOOST_AUTO_TEST_CASE(HyperplaneEmptyConstructor) arma::mat dataset; dataset.randu(3, 20); // 20 points in 3 dimensions. - for (size_t i = 0; i < dataset.n_cols; i++) + for (size_t i = 0; i < dataset.n_cols; ++i) { BOOST_REQUIRE(h1.Left(dataset.col(i))); BOOST_REQUIRE(h2.Left(dataset.col(i))); diff --git a/src/mlpack/tests/init_rules_test.cpp b/src/mlpack/tests/init_rules_test.cpp index 692bf57302..e8114c3d33 100644 --- a/src/mlpack/tests/init_rules_test.cpp +++ b/src/mlpack/tests/init_rules_test.cpp @@ -61,14 +61,14 @@ BOOST_AUTO_TEST_CASE(OrthogonalInitTest) arma::mat orthogonalWeights = arma::eye(100, 100); weights *= weights.t(); - for (size_t i = 0; i < weights.n_rows; i++) + for (size_t i = 0; i < weights.n_rows; ++i) for (size_t j = 0; j < weights.n_cols; j++) BOOST_REQUIRE_SMALL(weights.at(i, j) - orthogonalWeights.at(i, j), 1e-3); orthogonalInit.Initialize(weights, 200, 100); weights = weights.t() * weights; - for (size_t i = 0; i < weights.n_rows; i++) + for (size_t i = 0; i < weights.n_rows; ++i) for (size_t j = 0; j < weights.n_cols; j++) BOOST_REQUIRE_SMALL(weights.at(i, j) - orthogonalWeights.at(i, j), 1e-3); } @@ -88,7 +88,7 @@ BOOST_AUTO_TEST_CASE(OrthogonalInitGainTest) orthogonalWeights *= (gain * gain); weights *= weights.t(); - for (size_t i = 0; i < weights.n_rows; i++) + for (size_t i = 0; i < weights.n_rows; ++i) for (size_t j = 0; j < weights.n_cols; j++) BOOST_REQUIRE_SMALL(weights.at(i, j) - orthogonalWeights.at(i, j), 1e-3); } diff --git a/src/mlpack/tests/kfn_test.cpp b/src/mlpack/tests/kfn_test.cpp index 2f7c5b372c..2142dbc2dd 100644 --- a/src/mlpack/tests/kfn_test.cpp +++ b/src/mlpack/tests/kfn_test.cpp @@ -56,7 +56,7 @@ BOOST_AUTO_TEST_CASE(ExhaustiveSyntheticTest) TreeType tree(data, oldFromNew, newFromOld, 1); KFN kfn(std::move(tree)); - for (int i = 0; i < 3; i++) + for (int i = 0; i < 3; ++i) { switch (i) { @@ -351,7 +351,7 @@ BOOST_AUTO_TEST_CASE(DualTreeVsNaive1) arma::mat distancesNaive; naive.Search(dataset, 15, neighborsNaive, distancesNaive); - for (size_t i = 0; i < neighborsTree.n_elem; i++) + for (size_t i = 0; i < neighborsTree.n_elem; ++i) { BOOST_REQUIRE(neighborsTree[i] == neighborsNaive[i]); BOOST_REQUIRE_CLOSE(distancesTree[i], distancesNaive[i], 1e-5); @@ -385,7 +385,7 @@ BOOST_AUTO_TEST_CASE(DualTreeVsNaive2) arma::mat distancesNaive; naive.Search(15, neighborsNaive, distancesNaive); - for (size_t i = 0; i < neighborsTree.n_elem; i++) + for (size_t i = 0; i < neighborsTree.n_elem; ++i) { BOOST_REQUIRE_EQUAL(neighborsTree[i], neighborsNaive[i]); BOOST_REQUIRE_CLOSE(distancesTree[i], distancesNaive[i], 1e-5); @@ -419,7 +419,7 @@ BOOST_AUTO_TEST_CASE(SingleTreeVsNaive) arma::mat distancesNaive; naive.Search(15, neighborsNaive, distancesNaive); - for (size_t i = 0; i < neighborsTree.n_elem; i++) + for (size_t i = 0; i < neighborsTree.n_elem; ++i) { BOOST_REQUIRE_EQUAL(neighborsTree[i], neighborsNaive[i]); BOOST_REQUIRE_CLOSE(distancesTree[i], distancesNaive[i], 1e-5); diff --git a/src/mlpack/tests/kmeans_test.cpp b/src/mlpack/tests/kmeans_test.cpp index 2a1f1fce37..53f7feb11d 100644 --- a/src/mlpack/tests/kmeans_test.cpp +++ b/src/mlpack/tests/kmeans_test.cpp @@ -82,7 +82,7 @@ BOOST_AUTO_TEST_CASE(KMeansSimpleTest) // clusters are ordered, so we have to be careful about that. size_t firstClass = assignments(0); - for (size_t i = 1; i < 13; i++) + for (size_t i = 1; i < 13; ++i) BOOST_REQUIRE_EQUAL(assignments(i), firstClass); size_t secondClass = assignments(13); @@ -90,7 +90,7 @@ BOOST_AUTO_TEST_CASE(KMeansSimpleTest) // To ensure that class 1 != class 2. BOOST_REQUIRE_NE(firstClass, secondClass); - for (size_t i = 13; i < 20; i++) + for (size_t i = 13; i < 20; ++i) BOOST_REQUIRE_EQUAL(assignments(i), secondClass); size_t thirdClass = assignments(20); @@ -99,7 +99,7 @@ BOOST_AUTO_TEST_CASE(KMeansSimpleTest) BOOST_REQUIRE_NE(firstClass, thirdClass); BOOST_REQUIRE_NE(secondClass, thirdClass); - for (size_t i = 20; i < 30; i++) + for (size_t i = 20; i < 30; ++i) BOOST_REQUIRE_EQUAL(assignments(i), thirdClass); } @@ -128,11 +128,11 @@ BOOST_AUTO_TEST_CASE(AllowEmptyClusterTest) metric, 0); // Make sure no assignments were changed. - for (size_t i = 0; i < assignments.n_elem; i++) + for (size_t i = 0; i < assignments.n_elem; ++i) BOOST_REQUIRE_EQUAL(assignments[i], assignmentsOld[i]); // Make sure no counts were changed. - for (size_t i = 0; i < 3; i++) + for (size_t i = 0; i < 3; ++i) BOOST_REQUIRE_EQUAL(counts[i], countsOld[i]); } @@ -161,11 +161,11 @@ BOOST_AUTO_TEST_CASE(KillEmptyClusterTest) metric, 0); // Make sure no assignments were changed. - for (size_t i = 0; i < assignments.n_elem; i++) + for (size_t i = 0; i < assignments.n_elem; ++i) BOOST_REQUIRE_EQUAL(assignments[i], assignmentsOld[i]); // Make sure no counts were changed for clusters that are not empty. - for (size_t i = 0; i < 2; i++) + for (size_t i = 0; i < 2; ++i) BOOST_REQUIRE_EQUAL(counts[i], countsOld[i]); // Make sure that counts contain one less element than old counts. @@ -249,7 +249,7 @@ BOOST_AUTO_TEST_CASE(RandomPartitionTest) BOOST_REQUIRE_EQUAL(assignments.n_elem, 1000); // Ensure that no value is greater than 17 (the maximum valid cluster). - for (size_t i = 0; i < 1000; i++) + for (size_t i = 0; i < 1000; ++i) BOOST_REQUIRE_LT(assignments[i], 18); } diff --git a/src/mlpack/tests/knn_test.cpp b/src/mlpack/tests/knn_test.cpp index 92d921d5c8..ea5723505c 100644 --- a/src/mlpack/tests/knn_test.cpp +++ b/src/mlpack/tests/knn_test.cpp @@ -383,7 +383,7 @@ BOOST_AUTO_TEST_CASE(ExhaustiveSyntheticTest) KNN knn(std::move(tree)); - for (int i = 0; i < 3; i++) + for (int i = 0; i < 3; ++i) { switch (i) { @@ -678,7 +678,7 @@ BOOST_AUTO_TEST_CASE(DualTreeVsNaive1) arma::mat distancesNaive; naive.Search(dataset, 15, neighborsNaive, distancesNaive); - for (size_t i = 0; i < neighborsTree.n_elem; i++) + for (size_t i = 0; i < neighborsTree.n_elem; ++i) { BOOST_REQUIRE_EQUAL(neighborsTree(i), neighborsNaive(i)); BOOST_REQUIRE_CLOSE(distancesTree(i), distancesNaive(i), 1e-5); @@ -713,7 +713,7 @@ BOOST_AUTO_TEST_CASE(DualTreeVsNaive2) arma::mat distancesNaive; naive.Search(15, neighborsNaive, distancesNaive); - for (size_t i = 0; i < neighborsTree.n_elem; i++) + for (size_t i = 0; i < neighborsTree.n_elem; ++i) { BOOST_REQUIRE_EQUAL(neighborsTree[i], neighborsNaive[i]); BOOST_REQUIRE_CLOSE(distancesTree[i], distancesNaive[i], 1e-5); @@ -748,7 +748,7 @@ BOOST_AUTO_TEST_CASE(SingleTreeVsNaive) arma::mat distancesNaive; naive.Search(15, neighborsNaive, distancesNaive); - for (size_t i = 0; i < neighborsTree.n_elem; i++) + for (size_t i = 0; i < neighborsTree.n_elem; ++i) { BOOST_REQUIRE_EQUAL(neighborsTree[i], neighborsNaive[i]); BOOST_REQUIRE_CLOSE(distancesTree[i], distancesNaive[i], 1e-5); diff --git a/src/mlpack/tests/krann_search_test.cpp b/src/mlpack/tests/krann_search_test.cpp index dc92c62606..db8da43172 100644 --- a/src/mlpack/tests/krann_search_test.cpp +++ b/src/mlpack/tests/krann_search_test.cpp @@ -57,7 +57,7 @@ BOOST_AUTO_TEST_CASE(NaiveGuaranteeTest) { rsRann.Search(queryData, 1, neighbors, distances); - for (size_t i = 0; i < queryData.n_cols; i++) + for (size_t i = 0; i < queryData.n_cols; ++i) if (qrRanks(i, neighbors(0, i)) < expectedRankErrorUB) numSuccessRounds[i]++; @@ -70,7 +70,7 @@ BOOST_AUTO_TEST_CASE(NaiveGuaranteeTest) size_t threshold = floor(numRounds * (0.95 - (1.96 * sqrt(0.95 * 0.05 / numRounds)))); size_t numQueriesFail = 0; - for (size_t i = 0; i < queryData.n_cols; i++) + for (size_t i = 0; i < queryData.n_cols; ++i) if (numSuccessRounds[i] < threshold) numQueriesFail++; @@ -116,7 +116,7 @@ BOOST_AUTO_TEST_CASE(SingleTreeSearch) { tssRann.Search(queryData, 1, neighbors, distances); - for (size_t i = 0; i < queryData.n_cols; i++) + for (size_t i = 0; i < queryData.n_cols; ++i) if (qrRanks(i, neighbors(0, i)) < expectedRankErrorUB) numSuccessRounds[i]++; @@ -129,7 +129,7 @@ BOOST_AUTO_TEST_CASE(SingleTreeSearch) size_t threshold = floor(numRounds * (0.95 - (1.96 * sqrt(0.95 * 0.05 / numRounds)))); size_t numQueriesFail = 0; - for (size_t i = 0; i < queryData.n_cols; i++) + for (size_t i = 0; i < queryData.n_cols; ++i) if (numSuccessRounds[i] < threshold) numQueriesFail++; @@ -180,7 +180,7 @@ BOOST_AUTO_TEST_CASE(DualTreeSearch) { tsdRann.Search(&queryTree, 1, neighbors, distances); - for (size_t i = 0; i < queryData.n_cols; i++) + for (size_t i = 0; i < queryData.n_cols; ++i) { const size_t oldIndex = oldFromNewQueries[i]; if (qrRanks(oldIndex, neighbors(0, i)) < expectedRankErrorUB) @@ -198,7 +198,7 @@ BOOST_AUTO_TEST_CASE(DualTreeSearch) size_t threshold = floor(numRounds * (0.95 - (1.96 * sqrt(0.95 * 0.05 / numRounds)))); size_t numQueriesFail = 0; - for (size_t i = 0; i < queryData.n_cols; i++) + for (size_t i = 0; i < queryData.n_cols; ++i) if (numSuccessRounds[i] < threshold) numQueriesFail++; @@ -305,7 +305,7 @@ BOOST_AUTO_TEST_CASE(SingleCoverTreeTest) { tssRann.Search(queryData, 1, neighbors, distances); - for (size_t i = 0; i < queryData.n_cols; i++) + for (size_t i = 0; i < queryData.n_cols; ++i) if (qrRanks(i, neighbors(0, i)) < expectedRankErrorUB) numSuccessRounds[i]++; @@ -318,7 +318,7 @@ BOOST_AUTO_TEST_CASE(SingleCoverTreeTest) size_t threshold = floor(numRounds * (0.95 - (1.96 * sqrt(0.95 * 0.05 / numRounds)))); size_t numQueriesFail = 0; - for (size_t i = 0; i < queryData.n_cols; i++) + for (size_t i = 0; i < queryData.n_cols; ++i) if (numSuccessRounds[i] < threshold) numQueriesFail++; @@ -370,7 +370,7 @@ BOOST_AUTO_TEST_CASE(DualCoverTreeTest) { tsdRann.Search(&queryTree, 1, neighbors, distances); - for (size_t i = 0; i < queryData.n_cols; i++) + for (size_t i = 0; i < queryData.n_cols; ++i) if (qrRanks(i, neighbors(0, i)) < expectedRankErrorUB) numSuccessRounds[i]++; @@ -385,7 +385,7 @@ BOOST_AUTO_TEST_CASE(DualCoverTreeTest) size_t threshold = floor(numRounds * (0.95 - (1.96 * sqrt(0.95 * 0.05 / numRounds)))); size_t numQueriesFail = 0; - for (size_t i = 0; i < queryData.n_cols; i++) + for (size_t i = 0; i < queryData.n_cols; ++i) if (numSuccessRounds[i] < threshold) numQueriesFail++; @@ -437,7 +437,7 @@ BOOST_AUTO_TEST_CASE(SingleBallTreeTest) { tssRann.Search(1, neighbors, distances, 1.0, 0.95, false, false, 5); - for (size_t i = 0; i < queryData.n_cols; i++) + for (size_t i = 0; i < queryData.n_cols; ++i) if (qrRanks(i, neighbors(0, i)) < expectedRankErrorUB) numSuccessRounds[i]++; @@ -450,7 +450,7 @@ BOOST_AUTO_TEST_CASE(SingleBallTreeTest) size_t threshold = floor(numRounds * (0.95 - (1.96 * sqrt(0.95 * 0.05 / numRounds)))); size_t numQueriesFail = 0; - for (size_t i = 0; i < queryData.n_cols; i++) + for (size_t i = 0; i < queryData.n_cols; ++i) if (numSuccessRounds[i] < threshold) numQueriesFail++; @@ -502,7 +502,7 @@ BOOST_AUTO_TEST_CASE(DualBallTreeTest) { tsdRann.Search(1, neighbors, distances, 1.0, 0.95, false, false, 5); - for (size_t i = 0; i < queryData.n_cols; i++) + for (size_t i = 0; i < queryData.n_cols; ++i) if (qrRanks(i, neighbors(0, i)) < expectedRankErrorUB) numSuccessRounds[i]++; @@ -517,7 +517,7 @@ BOOST_AUTO_TEST_CASE(DualBallTreeTest) size_t threshold = floor(numRounds * (0.95 - (1.96 * sqrt(0.95 * 0.05 / numRounds)))); size_t numQueriesFail = 0; - for (size_t i = 0; i < queryData.n_cols; i++) + for (size_t i = 0; i < queryData.n_cols; ++i) if (numSuccessRounds[i] < threshold) numQueriesFail++; diff --git a/src/mlpack/tests/lars_test.cpp b/src/mlpack/tests/lars_test.cpp index 50a2f5c6cf..abf0c4258e 100644 --- a/src/mlpack/tests/lars_test.cpp +++ b/src/mlpack/tests/lars_test.cpp @@ -60,7 +60,7 @@ void LassoTest(size_t nPoints, size_t nDims, bool elasticNet, bool useCholesky) arma::mat X; arma::rowvec y; - for (size_t i = 0; i < 100; i++) + for (size_t i = 0; i < 100; ++i) { GenerateProblem(X, y, nPoints, nDims); diff --git a/src/mlpack/tests/lin_alg_test.cpp b/src/mlpack/tests/lin_alg_test.cpp index ecccae50e7..c213066d03 100644 --- a/src/mlpack/tests/lin_alg_test.cpp +++ b/src/mlpack/tests/lin_alg_test.cpp @@ -179,7 +179,7 @@ BOOST_AUTO_TEST_CASE(TestSvecSmat) Smat(sx, Xtest); BOOST_REQUIRE_EQUAL(Xtest.n_rows, 3); BOOST_REQUIRE_EQUAL(Xtest.n_cols, 3); - for (size_t i = 0; i < 3; i++) + for (size_t i = 0; i < 3; ++i) for (size_t j = 0; j < 3; j++) BOOST_REQUIRE_CLOSE(X(i, j), Xtest(i, j), 1e-7); } @@ -240,7 +240,7 @@ BOOST_AUTO_TEST_CASE(TestSymKronId) arma::mat Op; SymKronId(A, Op); - for (size_t i = 0; i < 5; i++) + for (size_t i = 0; i < 5; ++i) { arma::mat X = arma::randu(n, n); X += X.t(); diff --git a/src/mlpack/tests/linear_svm_test.cpp b/src/mlpack/tests/linear_svm_test.cpp index f7991dc542..230d608733 100644 --- a/src/mlpack/tests/linear_svm_test.cpp +++ b/src/mlpack/tests/linear_svm_test.cpp @@ -100,7 +100,7 @@ BOOST_AUTO_TEST_CASE(LinearSVMFunctionRandomBinaryEvaluate) // Create random class labels. arma::Row labels(points); - for (size_t i = 0; i < points; i++) + for (size_t i = 0; i < points; ++i) labels(i) = math::RandInt(0, numClasses); // Create a LinearSVMFunction, Regularization term ignored. @@ -156,7 +156,7 @@ BOOST_AUTO_TEST_CASE(LinearSVMFunctionRandomEvaluate) // Create random class labels. arma::Row labels(points); - for (size_t i = 0; i < points; i++) + for (size_t i = 0; i < points; ++i) labels(i) = math::RandInt(0, numClasses); // Create a LinearSVMFunction, Regularization term ignored. @@ -211,7 +211,7 @@ BOOST_AUTO_TEST_CASE(LinearSVMFunctionRegularizationEvaluate) // Create random class labels. arma::Row labels(points); - for (size_t i = 0; i < points; i++) + for (size_t i = 0; i < points; ++i) labels(i) = math::RandInt(0, numClasses); // 3 objects for comparing regularization costs. @@ -220,7 +220,7 @@ BOOST_AUTO_TEST_CASE(LinearSVMFunctionRegularizationEvaluate) LinearSVMFunction svmfBigReg(data, labels, numClasses, 20); // Run a number of trials. - for (size_t i = 0; i < trials; i++) + for (size_t i = 0; i < trials; ++i) { // Create a random set of parameters. arma::mat parameters; @@ -257,7 +257,7 @@ BOOST_AUTO_TEST_CASE(LinearSVMFunctionSeparableEvaluate) // Create random class labels. arma::Row labels(points); - for (size_t i = 0; i < points; i++) + for (size_t i = 0; i < points; ++i) labels(i) = math::RandInt(0, numClasses); LinearSVMFunction<> svmf(data, labels, numClasses); @@ -297,7 +297,7 @@ BOOST_AUTO_TEST_CASE(LinearSVMFunctionRegularizationSeparableEvaluate) // Create random class labels. arma::Row labels(points); - for (size_t i = 0; i < points; i++) + for (size_t i = 0; i < points; ++i) labels(i) = math::RandInt(0, numClasses); LinearSVMFunction<> svmfNoReg(data, labels, numClasses, 0.0); @@ -351,7 +351,7 @@ BOOST_AUTO_TEST_CASE(LinearSVMFunctionGradient) // Create random class labels. arma::Row labels(points); - for (size_t i = 0; i < points; i++) + for (size_t i = 0; i < points; ++i) labels(i) = math::RandInt(0, numClasses); // Create a LinearSVMFunction, Regularization term ignored. @@ -423,7 +423,7 @@ BOOST_AUTO_TEST_CASE(LinearSVMFunctionSeparableGradient) // Create random class labels. arma::Row labels(points); - for (size_t i = 0; i < points; i++) + for (size_t i = 0; i < points; ++i) labels(i) = math::RandInt(0, numClasses); LinearSVMFunction<> svmfNoReg(data, labels, numClasses, 0.0); @@ -552,12 +552,12 @@ BOOST_AUTO_TEST_CASE(LinearSVMLBFGSTwoClasses) bool success = false; for (size_t trial = 0; trial < 5; ++trial) { - for (size_t i = 0; i < points / 2; i++) + for (size_t i = 0; i < points / 2; ++i) { data.col(i) = g1.Random(); labels(i) = 0; } - for (size_t i = points / 2; i < points; i++) + for (size_t i = points / 2; i < points; ++i) { data.col(i) = g2.Random(); labels(i) = 1; @@ -574,12 +574,12 @@ BOOST_AUTO_TEST_CASE(LinearSVMLBFGSTwoClasses) } // Create test dataset. - for (size_t i = 0; i < points / 2; i++) + for (size_t i = 0; i < points / 2; ++i) { data.col(i) = g1.Random(); labels(i) = 0; } - for (size_t i = points / 2; i < points; i++) + for (size_t i = points / 2; i < points; ++i) { data.col(i) = g2.Random(); labels(i) = 1; @@ -698,12 +698,12 @@ BOOST_AUTO_TEST_CASE(LinearSVMDeltaLBFGSTwoClasses) arma::mat data(inputSize, points); arma::Row labels(points); - for (size_t i = 0; i < points / 2; i++) + for (size_t i = 0; i < points / 2; ++i) { data.col(i) = g1.Random(); labels(i) = 0; } - for (size_t i = points / 2; i < points; i++) + for (size_t i = points / 2; i < points; ++i) { data.col(i) = g2.Random(); labels(i) = 1; @@ -807,12 +807,12 @@ BOOST_AUTO_TEST_CASE(LinearSVMParallelSGDTwoClasses) arma::mat data(inputSize, points); arma::Row labels(points); - for (size_t i = 0; i < points / 2; i++) + for (size_t i = 0; i < points / 2; ++i) { data.col(i) = g1.Random(); labels(i) = 0; } - for (size_t i = points / 2; i < points; i++) + for (size_t i = points / 2; i < points; ++i) { data.col(i) = g2.Random(); labels(i) = 1; @@ -833,12 +833,12 @@ BOOST_AUTO_TEST_CASE(LinearSVMParallelSGDTwoClasses) BOOST_REQUIRE_CLOSE(acc, 1.0, 2.0); // Create test dataset. - for (size_t i = 0; i < points / 2; i++) + for (size_t i = 0; i < points / 2; ++i) { data.col(i) = g1.Random(); labels(i) = 0; } - for (size_t i = points / 2; i < points; i++) + for (size_t i = points / 2; i < points; ++i) { data.col(i) = g2.Random(); labels(i) = 1; @@ -905,27 +905,27 @@ BOOST_AUTO_TEST_CASE(LinearSVMLBFGSMultipleClasses) bool success = false; for (size_t trial = 0; trial < 5; ++trial) { - for (size_t i = 0; i < points / 5; i++) + for (size_t i = 0; i < points / 5; ++i) { data.col(i) = g1.Random(); labels(i) = 0; } - for (size_t i = points / 5; i < (2 * points) / 5; i++) + for (size_t i = points / 5; i < (2 * points) / 5; ++i) { data.col(i) = g2.Random(); labels(i) = 1; } - for (size_t i = (2 * points) / 5; i < (3 * points) / 5; i++) + for (size_t i = (2 * points) / 5; i < (3 * points) / 5; ++i) { data.col(i) = g3.Random(); labels(i) = 2; } - for (size_t i = (3 * points) / 5; i < (4 * points) / 5; i++) + for (size_t i = (3 * points) / 5; i < (4 * points) / 5; ++i) { data.col(i) = g4.Random(); labels(i) = 3; } - for (size_t i = (4 * points) / 5; i < points; i++) + for (size_t i = (4 * points) / 5; i < points; ++i) { data.col(i) = g5.Random(); labels(i) = 4; @@ -940,27 +940,27 @@ BOOST_AUTO_TEST_CASE(LinearSVMLBFGSMultipleClasses) continue; // Create test dataset. - for (size_t i = 0; i < points / 5; i++) + for (size_t i = 0; i < points / 5; ++i) { data.col(i) = g1.Random(); labels(i) = 0; } - for (size_t i = points / 5; i < (2 * points) / 5; i++) + for (size_t i = points / 5; i < (2 * points) / 5; ++i) { data.col(i) = g2.Random(); labels(i) = 1; } - for (size_t i = (2 * points) / 5; i < (3 * points) / 5; i++) + for (size_t i = (2 * points) / 5; i < (3 * points) / 5; ++i) { data.col(i) = g3.Random(); labels(i) = 2; } - for (size_t i = (3 * points) / 5; i < (4 * points) / 5; i++) + for (size_t i = (3 * points) / 5; i < (4 * points) / 5; ++i) { data.col(i) = g4.Random(); labels(i) = 3; } - for (size_t i = (4 * points) / 5; i < points; i++) + for (size_t i = (4 * points) / 5; i < points; ++i) { data.col(i) = g5.Random(); labels(i) = 4; @@ -999,27 +999,27 @@ BOOST_AUTO_TEST_CASE(LinearSVMClassifySinglePointTest) arma::mat data(inputSize, points); arma::Row labels(points); - for (size_t i = 0; i < points / 5; i++) + for (size_t i = 0; i < points / 5; ++i) { data.col(i) = g1.Random(); labels(i) = 0; } - for (size_t i = points / 5; i < (2 * points) / 5; i++) + for (size_t i = points / 5; i < (2 * points) / 5; ++i) { data.col(i) = g2.Random(); labels(i) = 1; } - for (size_t i = (2 * points) / 5; i < (3 * points) / 5; i++) + for (size_t i = (2 * points) / 5; i < (3 * points) / 5; ++i) { data.col(i) = g3.Random(); labels(i) = 2; } - for (size_t i = (3 * points) / 5; i < (4 * points) / 5; i++) + for (size_t i = (3 * points) / 5; i < (4 * points) / 5; ++i) { data.col(i) = g4.Random(); labels(i) = 3; } - for (size_t i = (4 * points) / 5; i < points; i++) + for (size_t i = (4 * points) / 5; i < points; ++i) { data.col(i) = g5.Random(); labels(i) = 4; @@ -1029,27 +1029,27 @@ BOOST_AUTO_TEST_CASE(LinearSVMClassifySinglePointTest) LinearSVM lsvm(data, labels, numClasses, lambda); // Create test dataset. - for (size_t i = 0; i < points / 5; i++) + for (size_t i = 0; i < points / 5; ++i) { data.col(i) = g1.Random(); labels(i) = 0; } - for (size_t i = points / 5; i < (2 * points) / 5; i++) + for (size_t i = points / 5; i < (2 * points) / 5; ++i) { data.col(i) = g2.Random(); labels(i) = 1; } - for (size_t i = (2 * points) / 5; i < (3 * points) / 5; i++) + for (size_t i = (2 * points) / 5; i < (3 * points) / 5; ++i) { data.col(i) = g3.Random(); labels(i) = 2; } - for (size_t i = (3 * points) / 5; i < (4 * points) / 5; i++) + for (size_t i = (3 * points) / 5; i < (4 * points) / 5; ++i) { data.col(i) = g4.Random(); labels(i) = 3; } - for (size_t i = (4 * points) / 5; i < points; i++) + for (size_t i = (4 * points) / 5; i < points; ++i) { data.col(i) = g5.Random(); labels(i) = 4; @@ -1085,27 +1085,27 @@ BOOST_AUTO_TEST_CASE(SinglePointClassifyTest) arma::mat data(inputSize, points); arma::Row labels(points); - for (size_t i = 0; i < points / 5; i++) + for (size_t i = 0; i < points / 5; ++i) { data.col(i) = g1.Random(); labels(i) = 0; } - for (size_t i = points / 5; i < (2 * points) / 5; i++) + for (size_t i = points / 5; i < (2 * points) / 5; ++i) { data.col(i) = g2.Random(); labels(i) = 1; } - for (size_t i = (2 * points) / 5; i < (3 * points) / 5; i++) + for (size_t i = (2 * points) / 5; i < (3 * points) / 5; ++i) { data.col(i) = g3.Random(); labels(i) = 2; } - for (size_t i = (3 * points) / 5; i < (4 * points) / 5; i++) + for (size_t i = (3 * points) / 5; i < (4 * points) / 5; ++i) { data.col(i) = g4.Random(); labels(i) = 3; } - for (size_t i = (4 * points) / 5; i < points; i++) + for (size_t i = (4 * points) / 5; i < points; ++i) { data.col(i) = g5.Random(); labels(i) = 4; @@ -1115,27 +1115,27 @@ BOOST_AUTO_TEST_CASE(SinglePointClassifyTest) LinearSVM lsvm(data, labels, numClasses, lambda); // Create test dataset. - for (size_t i = 0; i < points / 5; i++) + for (size_t i = 0; i < points / 5; ++i) { data.col(i) = g1.Random(); labels(i) = 0; } - for (size_t i = points / 5; i < (2 * points) / 5; i++) + for (size_t i = points / 5; i < (2 * points) / 5; ++i) { data.col(i) = g2.Random(); labels(i) = 1; } - for (size_t i = (2 * points) / 5; i < (3 * points) / 5; i++) + for (size_t i = (2 * points) / 5; i < (3 * points) / 5; ++i) { data.col(i) = g3.Random(); labels(i) = 2; } - for (size_t i = (3 * points) / 5; i < (4 * points) / 5; i++) + for (size_t i = (3 * points) / 5; i < (4 * points) / 5; ++i) { data.col(i) = g4.Random(); labels(i) = 3; } - for (size_t i = (4 * points) / 5; i < points; i++) + for (size_t i = (4 * points) / 5; i < points; ++i) { data.col(i) = g5.Random(); labels(i) = 4; diff --git a/src/mlpack/tests/lmnn_test.cpp b/src/mlpack/tests/lmnn_test.cpp index 43e772691b..c4e6187b22 100644 --- a/src/mlpack/tests/lmnn_test.cpp +++ b/src/mlpack/tests/lmnn_test.cpp @@ -48,7 +48,7 @@ BOOST_AUTO_TEST_CASE(LMNNTargetNeighborsTest) // Calculate norm of datapoints. arma::vec norm(dataset.n_cols); - for (size_t i = 0; i < dataset.n_cols; i++) + for (size_t i = 0; i < dataset.n_cols; ++i) { norm(i) = arma::norm(dataset.col(i)); } @@ -81,7 +81,7 @@ BOOST_AUTO_TEST_CASE(LMNNImpostorsTest) // Calculate norm of datapoints. arma::vec norm(dataset.n_cols); - for (size_t i = 0; i < dataset.n_cols; i++) + for (size_t i = 0; i < dataset.n_cols; ++i) { norm(i) = arma::norm(dataset.col(i)); } @@ -409,7 +409,7 @@ double KnnAccuracy(const arma::mat& dataset, // Keep count. size_t count = 0.0; - for (size_t i = 0; i < dataset.n_cols; i++) + for (size_t i = 0; i < dataset.n_cols; ++i) { arma::vec Map; Map.zeros(uniqueLabels.n_cols); diff --git a/src/mlpack/tests/load_save_test.cpp b/src/mlpack/tests/load_save_test.cpp index 783e0065b0..fd48743da3 100644 --- a/src/mlpack/tests/load_save_test.cpp +++ b/src/mlpack/tests/load_save_test.cpp @@ -69,7 +69,7 @@ BOOST_AUTO_TEST_CASE(LoadCSVTest) BOOST_REQUIRE_EQUAL(test.n_rows, 4); BOOST_REQUIRE_EQUAL(test.n_cols, 2); - for (size_t i = 0; i < 8; i++) + for (size_t i = 0; i < 8; ++i) BOOST_REQUIRE_CLOSE(test[i], (double) (i + 1), 1e-5); // Remove the file. @@ -95,7 +95,7 @@ BOOST_AUTO_TEST_CASE(LoadTSVTest) BOOST_REQUIRE_EQUAL(test.n_rows, 4); BOOST_REQUIRE_EQUAL(test.n_cols, 2); - for (size_t i = 0; i < 8; i++) + for (size_t i = 0; i < 8; ++i) BOOST_REQUIRE_CLOSE(test[i], (double) (i + 1), 1e-5); // Remove the file. @@ -121,7 +121,7 @@ BOOST_AUTO_TEST_CASE(LoadTSVExtensionTest) BOOST_REQUIRE_EQUAL(test.n_rows, 4); BOOST_REQUIRE_EQUAL(test.n_cols, 2); - for (size_t i = 0; i < 8; i++) + for (size_t i = 0; i < 8; ++i) BOOST_REQUIRE_CLOSE(test[i], (double) (i + 1), 1e-5); // Remove the file. @@ -147,7 +147,7 @@ BOOST_AUTO_TEST_CASE(SaveCSVTest) BOOST_REQUIRE_EQUAL(test2.n_rows, 4); BOOST_REQUIRE_EQUAL(test2.n_cols, 2); - for (size_t i = 0; i < 8; i++) + for (size_t i = 0; i < 8; ++i) BOOST_REQUIRE_CLOSE(test2[i], (double) (i + 1), 1e-5); // Remove the file. @@ -575,7 +575,7 @@ BOOST_AUTO_TEST_CASE(LoadArmaASCIITest) BOOST_REQUIRE_EQUAL(test.n_rows, 4); BOOST_REQUIRE_EQUAL(test.n_cols, 2); - for (size_t i = 0; i < 8; i++) + for (size_t i = 0; i < 8; ++i) BOOST_REQUIRE_CLOSE(test[i], (double) (i + 1), 1e-5); // Remove the file. @@ -600,7 +600,7 @@ BOOST_AUTO_TEST_CASE(SaveArmaASCIITest) BOOST_REQUIRE_EQUAL(test.n_rows, 4); BOOST_REQUIRE_EQUAL(test.n_cols, 2); - for (size_t i = 0; i < 8; i++) + for (size_t i = 0; i < 8; ++i) BOOST_REQUIRE_CLOSE(test[i], (double) (i + 1), 1e-5); // Remove the file. @@ -626,7 +626,7 @@ BOOST_AUTO_TEST_CASE(LoadRawASCIITest) BOOST_REQUIRE_EQUAL(test.n_rows, 4); BOOST_REQUIRE_EQUAL(test.n_cols, 2); - for (size_t i = 0; i < 8; i++) + for (size_t i = 0; i < 8; ++i) BOOST_REQUIRE_CLOSE(test[i], (double) (i + 1), 1e-5); // Remove the file. @@ -652,7 +652,7 @@ BOOST_AUTO_TEST_CASE(LoadCSVTxtTest) BOOST_REQUIRE_EQUAL(test.n_rows, 4); BOOST_REQUIRE_EQUAL(test.n_cols, 2); - for (size_t i = 0; i < 8; i++) + for (size_t i = 0; i < 8; ++i) BOOST_REQUIRE_CLOSE(test[i], (double) (i + 1), 1e-5); // Remove the file. @@ -679,7 +679,7 @@ BOOST_AUTO_TEST_CASE(LoadArmaBinaryTest) BOOST_REQUIRE_EQUAL(test.n_rows, 4); BOOST_REQUIRE_EQUAL(test.n_cols, 2); - for (size_t i = 0; i < 8; i++) + for (size_t i = 0; i < 8; ++i) BOOST_REQUIRE_CLOSE(test[i], (double) (i + 1), 1e-5); // Remove the file. @@ -703,7 +703,7 @@ BOOST_AUTO_TEST_CASE(SaveArmaBinaryTest) BOOST_REQUIRE_EQUAL(test.n_rows, 4); BOOST_REQUIRE_EQUAL(test.n_cols, 2); - for (size_t i = 0; i < 8; i++) + for (size_t i = 0; i < 8; ++i) BOOST_REQUIRE_CLOSE(test[i], (double) (i + 1), 1e-5); // Remove the file. @@ -730,7 +730,7 @@ BOOST_AUTO_TEST_CASE(LoadRawBinaryTest) BOOST_REQUIRE_EQUAL(test.n_rows, 1); BOOST_REQUIRE_EQUAL(test.n_cols, 8); - for (size_t i = 0; i < 8; i++) + for (size_t i = 0; i < 8; ++i) BOOST_REQUIRE_CLOSE(test[i], (double) (i + 1), 1e-5); // Remove the file. @@ -757,7 +757,7 @@ BOOST_AUTO_TEST_CASE(LoadPGMBinaryTest) BOOST_REQUIRE_EQUAL(test.n_rows, 4); BOOST_REQUIRE_EQUAL(test.n_cols, 2); - for (size_t i = 0; i < 8; i++) + for (size_t i = 0; i < 8; ++i) BOOST_REQUIRE_CLOSE(test[i], (double) (i + 1), 1e-5); // Remove the file. @@ -782,7 +782,7 @@ BOOST_AUTO_TEST_CASE(SavePGMBinaryTest) BOOST_REQUIRE_EQUAL(test.n_rows, 4); BOOST_REQUIRE_EQUAL(test.n_cols, 2); - for (size_t i = 0; i < 8; i++) + for (size_t i = 0; i < 8; ++i) BOOST_REQUIRE_CLOSE(test[i], (double) (i + 1), 1e-5); // Remove the file. diff --git a/src/mlpack/tests/local_coordinate_coding_test.cpp b/src/mlpack/tests/local_coordinate_coding_test.cpp index c809a9399e..f9ba49414f 100644 --- a/src/mlpack/tests/local_coordinate_coding_test.cpp +++ b/src/mlpack/tests/local_coordinate_coding_test.cpp @@ -60,7 +60,7 @@ BOOST_AUTO_TEST_CASE(LocalCoordinateCodingTestCodingStep) uword nPoints = X.n_cols; // normalize each point since these are images - for (uword i = 0; i < nPoints; i++) + for (uword i = 0; i < nPoints; ++i) { X.col(i) /= norm(X.col(i), 2); } @@ -71,7 +71,7 @@ BOOST_AUTO_TEST_CASE(LocalCoordinateCodingTestCodingStep) mat D = lcc.Dictionary(); - for (uword i = 0; i < nPoints; i++) + for (uword i = 0; i < nPoints; ++i) { vec sqDists = vec(nAtoms); for (uword j = 0; j < nAtoms; j++) @@ -98,7 +98,7 @@ BOOST_AUTO_TEST_CASE(LocalCoordinateCodingTestDictionaryStep) uword nPoints = X.n_cols; // normalize each point since these are images - for (uword i = 0; i < nPoints; i++) + for (uword i = 0; i < nPoints; ++i) { X.col(i) /= norm(X.col(i), 2); } @@ -112,7 +112,7 @@ BOOST_AUTO_TEST_CASE(LocalCoordinateCodingTestDictionaryStep) mat D = lcc.Dictionary(); mat grad = zeros(D.n_rows, D.n_cols); - for (uword i = 0; i < nPoints; i++) + for (uword i = 0; i < nPoints; ++i) { grad += (D - repmat(X.unsafe_col(i), 1, nAtoms)) * diagmat(abs(Z.unsafe_col(i))); @@ -179,7 +179,7 @@ BOOST_AUTO_TEST_CASE(LocalCoordinateCodingTrainReturnObjective) uword nPoints = X.n_cols; // Normalize each point since these are images. - for (uword i = 0; i < nPoints; i++) + for (uword i = 0; i < nPoints; ++i) { X.col(i) /= norm(X.col(i), 2); } diff --git a/src/mlpack/tests/loss_functions_test.cpp b/src/mlpack/tests/loss_functions_test.cpp index ff3035d376..4f031ea6ed 100644 --- a/src/mlpack/tests/loss_functions_test.cpp +++ b/src/mlpack/tests/loss_functions_test.cpp @@ -274,7 +274,7 @@ BOOST_AUTO_TEST_CASE(SimpleSigmoidCrossEntropyErrorTest) // Test the Backward function. module.Backward(input1, target1, output); expected = 0.62245929; - for (size_t i = 0; i < output.n_elem; i++) + for (size_t i = 0; i < output.n_elem; ++i) BOOST_REQUIRE_SMALL(output(i) - expected, 1e-5); BOOST_REQUIRE_EQUAL(output.n_rows, input1.n_rows); BOOST_REQUIRE_EQUAL(output.n_cols, input1.n_cols); @@ -282,7 +282,7 @@ BOOST_AUTO_TEST_CASE(SimpleSigmoidCrossEntropyErrorTest) expectedOutput = arma::mat( "0.7310586 0.88079709 -0.04742587 0.98201376 -0.00669285"); module.Backward(input2, target2, output); - for (size_t i = 0; i < output.n_elem; i++) + for (size_t i = 0; i < output.n_elem; ++i) BOOST_REQUIRE_SMALL(output(i) - expectedOutput(i), 1e-5); BOOST_REQUIRE_EQUAL(output.n_rows, input2.n_rows); BOOST_REQUIRE_EQUAL(output.n_cols, input2.n_cols); @@ -326,14 +326,14 @@ BOOST_AUTO_TEST_CASE(SimpleEarthMoverDistanceLayerTest) // Test the Backward function. module.Backward(input1, target1, output); expected = 0.0; - for (size_t i = 0; i < output.n_elem; i++) + for (size_t i = 0; i < output.n_elem; ++i) BOOST_REQUIRE_SMALL(output(i) - expected, 1e-5); BOOST_REQUIRE_EQUAL(output.n_rows, input1.n_rows); BOOST_REQUIRE_EQUAL(output.n_cols, input1.n_cols); expectedOutput = arma::mat("-1 0 -1 0 -1"); module.Backward(input2, target2, output); - for (size_t i = 0; i < output.n_elem; i++) + for (size_t i = 0; i < output.n_elem; ++i) BOOST_REQUIRE_SMALL(output(i) - expectedOutput(i), 1e-5); BOOST_REQUIRE_EQUAL(output.n_rows, input2.n_rows); BOOST_REQUIRE_EQUAL(output.n_cols, input2.n_cols); diff --git a/src/mlpack/tests/main_tests/adaboost_test.cpp b/src/mlpack/tests/main_tests/adaboost_test.cpp index f90815aac2..427be79d7d 100644 --- a/src/mlpack/tests/main_tests/adaboost_test.cpp +++ b/src/mlpack/tests/main_tests/adaboost_test.cpp @@ -109,7 +109,7 @@ BOOST_AUTO_TEST_CASE(AdaBoostProbabilitiesTest) BOOST_REQUIRE_EQUAL(probabilities.n_cols, testSize); - for (size_t i = 0; i < testSize; i++) + for (size_t i = 0; i < testSize; ++i) BOOST_REQUIRE_CLOSE(arma::accu(probabilities.col(i)), 1, 1e-5); } diff --git a/src/mlpack/tests/main_tests/emst_test.cpp b/src/mlpack/tests/main_tests/emst_test.cpp index 87ca2cd3a9..afb4c7a9ee 100644 --- a/src/mlpack/tests/main_tests/emst_test.cpp +++ b/src/mlpack/tests/main_tests/emst_test.cpp @@ -120,7 +120,7 @@ BOOST_AUTO_TEST_CASE(EMSTFirstTwoOutputRowsIntegerTest) SetInputParam("input", std::move(x)); SetInputParam("leaf_size", (int) 2); - for (size_t i = 0; i < CLI::GetParam("output").n_cols; i++) + for (size_t i = 0; i < CLI::GetParam("output").n_cols; ++i) { BOOST_REQUIRE_CLOSE(CLI::GetParam("output")(0, i), boost::math::iround(CLI::GetParam("output")(0, i)), 1e-5); diff --git a/src/mlpack/tests/main_tests/fastmks_test.cpp b/src/mlpack/tests/main_tests/fastmks_test.cpp index 1d81551038..db812377ed 100644 --- a/src/mlpack/tests/main_tests/fastmks_test.cpp +++ b/src/mlpack/tests/main_tests/fastmks_test.cpp @@ -427,7 +427,7 @@ BOOST_AUTO_TEST_CASE(FastMKSKernelTest) arma::mat kernels; // Looping over all the kernels - for (size_t i = 0; i < nofkerneltypes; i++) + for (size_t i = 0; i < nofkerneltypes; ++i) { if (kerneltypes[i] == "hyptan") { diff --git a/src/mlpack/tests/main_tests/gmm_train_test.cpp b/src/mlpack/tests/main_tests/gmm_train_test.cpp index c0b8026aed..b385c21755 100644 --- a/src/mlpack/tests/main_tests/gmm_train_test.cpp +++ b/src/mlpack/tests/main_tests/gmm_train_test.cpp @@ -557,7 +557,7 @@ BOOST_AUTO_TEST_CASE(GmmTrainDiagCovariance) for (size_t k = 0; k < sortedIndices.n_elem; k++) { arma::mat diagCov(gmm->Component(sortedIndices[k]).Covariance()); - for (size_t i = 0; i < diagCov.n_rows; i++) + for (size_t i = 0; i < diagCov.n_rows; ++i) for (size_t j = 0; j < diagCov.n_cols; j++) if (i != j && diagCov(i, j) != (double) 0) BOOST_FAIL("Covariance is not diagonal"); diff --git a/src/mlpack/tests/main_tests/hmm_train_test.cpp b/src/mlpack/tests/main_tests/hmm_train_test.cpp index f3b377be48..93aac8b005 100644 --- a/src/mlpack/tests/main_tests/hmm_train_test.cpp +++ b/src/mlpack/tests/main_tests/hmm_train_test.cpp @@ -64,7 +64,7 @@ inline void CheckMatricesDiffer(arma::mat& a, arma::mat& b, double tolerance) bool valsEqual = true; if (dimsEqual) { - for (size_t i=0; i(neighborsFile); distances = ReadData(distanceFile); - for (size_t i = 1; i < leafSizes.size(); i++) + for (size_t i = 1; i < leafSizes.size(); ++i) { SetInputParam("leaf_size", leafSizes[i]); SetInputParam("reference", inputData); @@ -400,7 +400,7 @@ BOOST_AUTO_TEST_CASE(TreeTypeTesting) distances = ReadData(distanceFile); RSModel* outputModel1 = CLI::GetParam("output_model"); - for (size_t i = 1; i < trees.size(); i++) + for (size_t i = 1; i < trees.size(); ++i) { if (!data::Load("iris.csv", inputData)) BOOST_FAIL("Unable to load dataset iris.csv!"); diff --git a/src/mlpack/tests/main_tests/range_search_utils.hpp b/src/mlpack/tests/main_tests/range_search_utils.hpp index 7b8007b4e4..4d77e11682 100644 --- a/src/mlpack/tests/main_tests/range_search_utils.hpp +++ b/src/mlpack/tests/main_tests/range_search_utils.hpp @@ -43,7 +43,7 @@ inline void CheckMatrices(std::vector>& vec1, const double tolerance = 1e-3) { BOOST_REQUIRE_EQUAL(vec1.size() , vec2.size()); - for (size_t i = 0; i < vec1.size(); i++) + for (size_t i = 0; i < vec1.size(); ++i) { BOOST_REQUIRE_EQUAL(vec1[i].size(), vec2[i].size()); std::sort(vec1[i].begin(), vec1[i].end()); @@ -65,7 +65,7 @@ inline void CheckMatrices(std::vector>& vec1, std::vector>& vec2) { BOOST_REQUIRE_EQUAL(vec1.size() , vec2.size()); - for (size_t i = 0; i < vec1.size(); i++) + for (size_t i = 0; i < vec1.size(); ++i) { BOOST_REQUIRE_EQUAL(vec1[i].size(), vec2[i].size()); std::sort(vec1[i].begin(), vec1[i].end()); diff --git a/src/mlpack/tests/mean_shift_test.cpp b/src/mlpack/tests/mean_shift_test.cpp index 55c0a1232c..bd666a3d43 100644 --- a/src/mlpack/tests/mean_shift_test.cpp +++ b/src/mlpack/tests/mean_shift_test.cpp @@ -69,7 +69,7 @@ BOOST_AUTO_TEST_CASE(MeanShiftSimpleTest) // clusters are ordered, so we have to be careful about that. size_t firstClass = assignments(0); - for (size_t i = 1; i < 13; i++) + for (size_t i = 1; i < 13; ++i) BOOST_REQUIRE_EQUAL(assignments(i), firstClass); size_t secondClass = assignments(13); @@ -77,7 +77,7 @@ BOOST_AUTO_TEST_CASE(MeanShiftSimpleTest) // To ensure that class 1 != class 2. BOOST_REQUIRE_NE(firstClass, secondClass); - for (size_t i = 13; i < 20; i++) + for (size_t i = 13; i < 20; ++i) BOOST_REQUIRE_EQUAL(assignments(i), secondClass); size_t thirdClass = assignments(20); @@ -86,7 +86,7 @@ BOOST_AUTO_TEST_CASE(MeanShiftSimpleTest) BOOST_REQUIRE_NE(firstClass, thirdClass); BOOST_REQUIRE_NE(secondClass, thirdClass); - for (size_t i = 20; i < 30; i++) + for (size_t i = 20; i < 30; ++i) BOOST_REQUIRE_EQUAL(assignments(i), thirdClass); } diff --git a/src/mlpack/tests/mlpack_test.cpp b/src/mlpack/tests/mlpack_test.cpp index 0d7cdae5b7..459fbaa176 100644 --- a/src/mlpack/tests/mlpack_test.cpp +++ b/src/mlpack/tests/mlpack_test.cpp @@ -107,7 +107,7 @@ struct GlobalFixture #endif for (int i = 0; i < boost::unit_test::framework::master_test_suite().argc; - i++) + ++i) { std::string argument( boost::unit_test::framework::master_test_suite().argv[i]); diff --git a/src/mlpack/tests/nbc_test.cpp b/src/mlpack/tests/nbc_test.cpp index 0ead0c605e..192d76a738 100644 --- a/src/mlpack/tests/nbc_test.cpp +++ b/src/mlpack/tests/nbc_test.cpp @@ -43,7 +43,7 @@ BOOST_AUTO_TEST_CASE(NaiveBayesClassifierTest) size_t dimension = nbcTest.Means().n_rows; calcMat.zeros(2 * dimension + 1, classes); - for (size_t i = 0; i < dimension; i++) + for (size_t i = 0; i < dimension; ++i) { for (size_t j = 0; j < classes; j++) { @@ -52,10 +52,10 @@ BOOST_AUTO_TEST_CASE(NaiveBayesClassifierTest) } } - for (size_t i = 0; i < classes; i++) + for (size_t i = 0; i < classes; ++i) calcMat(2 * dimension, i) = nbcTest.Probabilities()(i); - for (size_t i = 0; i < calcMat.n_rows; i++) + for (size_t i = 0; i < calcMat.n_rows; ++i) for (size_t j = 0; j < classes; j++) BOOST_REQUIRE_CLOSE(trainRes(i, j) + .00001, calcMat(i, j), 0.01); @@ -72,7 +72,7 @@ BOOST_AUTO_TEST_CASE(NaiveBayesClassifierTest) nbcTest.Classify(testData, calcVec, calcProbs); - for (size_t i = 0; i < testData.n_cols; i++) + for (size_t i = 0; i < testData.n_cols; ++i) BOOST_REQUIRE_EQUAL(testRes(i), calcVec(i)); for (size_t i = 0; i < testResProbs.n_cols; ++i) @@ -111,7 +111,7 @@ BOOST_AUTO_TEST_CASE(NaiveBayesClassifierIncrementalTest) size_t dimension = nbcTest.Means().n_rows; calcMat.zeros(2 * dimension + 1, classes); - for (size_t i = 0; i < dimension; i++) + for (size_t i = 0; i < dimension; ++i) { for (size_t j = 0; j < classes; j++) { @@ -120,10 +120,10 @@ BOOST_AUTO_TEST_CASE(NaiveBayesClassifierIncrementalTest) } } - for (size_t i = 0; i < classes; i++) + for (size_t i = 0; i < classes; ++i) calcMat(2 * dimension, i) = nbcTest.Probabilities()(i); - for (size_t i = 0; i < calcMat.n_cols; i++) + for (size_t i = 0; i < calcMat.n_cols; ++i) for (size_t j = 0; j < classes; j++) BOOST_REQUIRE_CLOSE(trainRes(j, i) + .00001, calcMat(j, i), 0.01); @@ -140,7 +140,7 @@ BOOST_AUTO_TEST_CASE(NaiveBayesClassifierIncrementalTest) nbcTest.Classify(testData, calcVec, calcProbs); - for (size_t i = 0; i < testData.n_cols; i++) + for (size_t i = 0; i < testData.n_cols; ++i) BOOST_REQUIRE_EQUAL(testRes(i), calcVec(i)); for (size_t i = 0; i < testResProba.n_cols; ++i) @@ -351,7 +351,7 @@ BOOST_AUTO_TEST_CASE(NaiveBayesClassifierHighDimensionsTest) nbcTest.Classify(testData, calcVec, calcProbs); // Check the results. - for (size_t i = 0; i < calcVec.n_cols; i++) + for (size_t i = 0; i < calcVec.n_cols; ++i) BOOST_REQUIRE_EQUAL(calcVec(i), testLabels(i)); } diff --git a/src/mlpack/tests/pca_test.cpp b/src/mlpack/tests/pca_test.cpp index 0a5bd8f6e3..2dd15aa3a5 100644 --- a/src/mlpack/tests/pca_test.cpp +++ b/src/mlpack/tests/pca_test.cpp @@ -47,7 +47,7 @@ void ArmaComparisonPCA( princomp(coeff, score, eigVal, trans(data)); // Verify the PCA results based on the eigenvalues. - for (size_t i = 0; i < eigVal.n_elem; i++) + for (size_t i = 0; i < eigVal.n_elem; ++i) { if (eigVal[i] == 0.0) BOOST_REQUIRE_SMALL(eigVal1[i], 1e-15); @@ -99,7 +99,7 @@ void PCADimensionalityReduction( // If the eigenvectors are pointed opposite directions, they will cancel // each other out in this summation. - for (size_t i = 0; i < data.n_rows; i++) + for (size_t i = 0; i < data.n_rows; ++i) { if (accu(abs(correct.row(i) + data.row(i))) < 0.001 /* arbitrary */) { diff --git a/src/mlpack/tests/perceptron_test.cpp b/src/mlpack/tests/perceptron_test.cpp index ab8adabd60..67a506ad0f 100644 --- a/src/mlpack/tests/perceptron_test.cpp +++ b/src/mlpack/tests/perceptron_test.cpp @@ -179,7 +179,7 @@ BOOST_AUTO_TEST_CASE(Random3) Row predictedLabels(testData.n_cols); p.Classify(testData, predictedLabels); - for (size_t i = 0; i < predictedLabels.n_cols; i++) + for (size_t i = 0; i < predictedLabels.n_cols; ++i) BOOST_CHECK_EQUAL(predictedLabels(0, i), 0); } diff --git a/src/mlpack/tests/radical_test.cpp b/src/mlpack/tests/radical_test.cpp index df8bf95394..a30346a627 100644 --- a/src/mlpack/tests/radical_test.cpp +++ b/src/mlpack/tests/radical_test.cpp @@ -35,7 +35,7 @@ BOOST_AUTO_TEST_CASE(Radical_Test_Radical3D) mat matYT = trans(matY); double valEst = 0; - for (uword i = 0; i < matYT.n_cols; i++) + for (uword i = 0; i < matYT.n_cols; ++i) { vec y = vec(matYT.col(i)); valEst += rad.Vasicek(y); @@ -48,7 +48,7 @@ BOOST_AUTO_TEST_CASE(Radical_Test_Radical3D) matYT = trans(matY); double valBest = 0; - for (uword i = 0; i < matYT.n_cols; i++) + for (uword i = 0; i < matYT.n_cols; ++i) { vec y = vec(matYT.col(i)); valBest += rad.Vasicek(y); diff --git a/src/mlpack/tests/range_search_test.cpp b/src/mlpack/tests/range_search_test.cpp index 714dde9d0e..923004cf12 100644 --- a/src/mlpack/tests/range_search_test.cpp +++ b/src/mlpack/tests/range_search_test.cpp @@ -33,7 +33,7 @@ void SortResults(const vector>& neighbors, vector>>& output) { output.resize(neighbors.size()); - for (size_t i = 0; i < neighbors.size(); i++) + for (size_t i = 0; i < neighbors.size(); ++i) { output[i].resize(neighbors[i].size()); for (size_t j = 0; j < neighbors[i].size(); j++) @@ -85,7 +85,7 @@ BOOST_AUTO_TEST_CASE(ExhaustiveSyntheticTest) std::vector oldFromNew; std::vector newFromOld; TreeType* tree = new TreeType(data, oldFromNew, newFromOld, 1); - for (int i = 0; i < 3; i++) + for (int i = 0; i < 3; ++i) { RangeSearch<>* rs; @@ -485,7 +485,7 @@ BOOST_AUTO_TEST_CASE(DualTreeVsNaive1) vector>> sortedNaive; SortResults(neighborsNaive, distancesNaive, sortedNaive); - for (size_t i = 0; i < sortedTree.size(); i++) + for (size_t i = 0; i < sortedTree.size(); ++i) { BOOST_REQUIRE(sortedTree[i].size() == sortedNaive[i].size()); @@ -534,7 +534,7 @@ BOOST_AUTO_TEST_CASE(DualTreeVsNaive2) vector>> sortedNaive; SortResults(neighborsNaive, distancesNaive, sortedNaive); - for (size_t i = 0; i < sortedTree.size(); i++) + for (size_t i = 0; i < sortedTree.size(); ++i) { BOOST_REQUIRE(sortedTree[i].size() == sortedNaive[i].size()); @@ -583,7 +583,7 @@ BOOST_AUTO_TEST_CASE(SingleTreeVsNaive) vector>> sortedNaive; SortResults(neighborsNaive, distancesNaive, sortedNaive); - for (size_t i = 0; i < sortedTree.size(); i++) + for (size_t i = 0; i < sortedTree.size(); ++i) { BOOST_REQUIRE(sortedTree[i].size() == sortedNaive[i].size()); diff --git a/src/mlpack/tests/rbm_network_test.cpp b/src/mlpack/tests/rbm_network_test.cpp index 5afe92e619..6b9fa3748c 100644 --- a/src/mlpack/tests/rbm_network_test.cpp +++ b/src/mlpack/tests/rbm_network_test.cpp @@ -86,13 +86,13 @@ BOOST_AUTO_TEST_CASE(BinaryRBMClassificationTest) // Test that objective value returned by RBM::Train() is finite. BOOST_REQUIRE_EQUAL(std::isfinite(objVal), true); - for (size_t i = 0; i < trainData.n_cols; i++) + for (size_t i = 0; i < trainData.n_cols; ++i) { model.HiddenMean(std::move(trainData.col(i)), std::move(output)); XRbm.col(i) = output; } - for (size_t i = 0; i < testData.n_cols; i++) + for (size_t i = 0; i < testData.n_cols; ++i) { model.HiddenMean(std::move(testData.col(i)), std::move(output)); @@ -150,7 +150,7 @@ BOOST_AUTO_TEST_CASE(ssRBMClassificationTest) for (size_t i = 0; i < testLabelsTemp.n_cols; ++i) testLabels(i) = arma::as_scalar(testLabelsTemp.col(i)); - for (size_t i = 0; i < trainData.n_cols; i++) + for (size_t i = 0; i < trainData.n_cols; ++i) { tempRadius = arma::norm(trainData.col(i)); if (radius < tempRadius) @@ -187,14 +187,14 @@ BOOST_AUTO_TEST_CASE(ssRBMClassificationTest) // Test that objective value returned by RBM::Train() is finite. BOOST_REQUIRE_EQUAL(std::isfinite(objVal), true); - for (size_t i = 0; i < trainData.n_cols; i++) + for (size_t i = 0; i < trainData.n_cols; ++i) { modelssRBM.HiddenMean(std::move(trainData.col(i)), std::move(output)); XRbm.col(i) = output; } - for (size_t i = 0; i < testData.n_cols; i++) + for (size_t i = 0; i < testData.n_cols; ++i) { modelssRBM.HiddenMean(std::move(testData.col(i)), std::move(output)); @@ -236,12 +236,12 @@ void BuildVanillaNetwork(MatType& trainData, arma::Mat freeEnergy = MatType( "-0.87523715, 0.50615066, 0.46923476, 1.21509084;"); arma::vec calculatedFreeEnergy(4, arma::fill::zeros); - for (size_t i = 0; i < trainData.n_cols; i++) + for (size_t i = 0; i < trainData.n_cols; ++i) { calculatedFreeEnergy(i) = model.FreeEnergy(std::move(trainData.col(i))); } - for (size_t i = 0; i < freeEnergy.n_elem; i++) + for (size_t i = 0; i < freeEnergy.n_elem; ++i) BOOST_REQUIRE_CLOSE(calculatedFreeEnergy(i), freeEnergy(i), 1e-3); } diff --git a/src/mlpack/tests/rectangle_tree_test.cpp b/src/mlpack/tests/rectangle_tree_test.cpp index a880595987..9828815cdc 100644 --- a/src/mlpack/tests/rectangle_tree_test.cpp +++ b/src/mlpack/tests/rectangle_tree_test.cpp @@ -72,7 +72,7 @@ std::vector GetAllPointsInTree(const TreeType& tree) std::vector vec; if (tree.NumChildren() > 0) { - for (size_t i = 0; i < tree.NumChildren(); i++) + for (size_t i = 0; i < tree.NumChildren(); ++i) { std::vector tmp = GetAllPointsInTree(tree.Child(i)); vec.insert(vec.begin(), tmp.begin(), tmp.end()); @@ -80,7 +80,7 @@ std::vector GetAllPointsInTree(const TreeType& tree) } else { - for (size_t i = 0; i < tree.Count(); i++) + for (size_t i = 0; i < tree.Count(); ++i) { arma::vec* c = new arma::vec(tree.Dataset().col(tree.Point(i))); vec.push_back(c); @@ -103,7 +103,7 @@ BOOST_AUTO_TEST_CASE(RectangleTreeConstructionRepeatTest) TreeType tree(dataset, 20, 6, 5, 2, 0); std::vector allPoints = GetAllPointsInTree(tree); - for (size_t i = 0; i < allPoints.size(); i++) + for (size_t i = 0; i < allPoints.size(); ++i) { for (size_t j = i + 1; j < allPoints.size(); j++) { @@ -117,7 +117,7 @@ BOOST_AUTO_TEST_CASE(RectangleTreeConstructionRepeatTest) } } - for (size_t i = 0; i < allPoints.size(); i++) + for (size_t i = 0; i < allPoints.size(); ++i) delete allPoints[i]; } @@ -133,13 +133,13 @@ void CheckContainment(const TreeType& tree) { if (tree.NumChildren() == 0) { - for (size_t i = 0; i < tree.Count(); i++) + for (size_t i = 0; i < tree.Count(); ++i) BOOST_REQUIRE(tree.Bound().Contains( tree.Dataset().unsafe_col(tree.Point(i)))); } else { - for (size_t i = 0; i < tree.NumChildren(); i++) + for (size_t i = 0; i < tree.NumChildren(); ++i) { for (size_t j = 0; j < tree.Bound().Dim(); j++) { @@ -167,7 +167,7 @@ void CheckExactContainment(const TreeType& tree) { if (tree.NumChildren() == 0) { - for (size_t i = 0; i < tree.Bound().Dim(); i++) + for (size_t i = 0; i < tree.Bound().Dim(); ++i) { double min = DBL_MAX; double max = -1.0 * DBL_MAX; @@ -184,7 +184,7 @@ void CheckExactContainment(const TreeType& tree) } else { - for (size_t i = 0; i < tree.Bound().Dim(); i++) + for (size_t i = 0; i < tree.Bound().Dim(); ++i) { double min = DBL_MAX; double max = -1.0 * DBL_MAX; @@ -200,7 +200,7 @@ void CheckExactContainment(const TreeType& tree) BOOST_REQUIRE_EQUAL(min, tree.Bound()[i].Lo()); } - for (size_t i = 0; i < tree.NumChildren(); i++) + for (size_t i = 0; i < tree.NumChildren(); ++i) CheckExactContainment(tree.Child(i)); } } @@ -211,7 +211,7 @@ void CheckExactContainment(const TreeType& tree) template void CheckHierarchy(const TreeType& tree) { - for (size_t i = 0; i < tree.NumChildren(); i++) + for (size_t i = 0; i < tree.NumChildren(); ++i) { BOOST_REQUIRE_EQUAL(&tree, tree.Child(i).Parent()); CheckHierarchy(tree.Child(i)); @@ -254,7 +254,7 @@ void CheckFills(const TreeType& tree) } else { - for (size_t i = 0; i < tree.NumChildren(); i++) + for (size_t i = 0; i < tree.NumChildren(); ++i) { BOOST_REQUIRE(tree.NumChildren() >= tree.MinNumChildren() || tree.Parent() == NULL); @@ -292,7 +292,7 @@ int GetMaxLevel(const TreeType& tree) if (!tree.IsLeaf()) { int m = 0; - for (size_t i = 0; i < tree.NumChildren(); i++) + for (size_t i = 0; i < tree.NumChildren(); ++i) { int n = GetMaxLevel(tree.Child(i)); if (n > m) @@ -319,7 +319,7 @@ int GetMinLevel(const TreeType& tree) if (!tree.IsLeaf()) { int m = INT_MAX; - for (size_t i = 0; i < tree.NumChildren(); i++) + for (size_t i = 0; i < tree.NumChildren(); ++i) { int n = GetMinLevel(tree.Child(i)); if (n < m) @@ -345,7 +345,7 @@ size_t CheckNumDescendants(const TreeType& tree) size_t numDescendants = 0; - for (size_t i = 0; i < tree.NumChildren(); i++) + for (size_t i = 0; i < tree.NumChildren(); ++i) numDescendants += CheckNumDescendants(tree.Child(i)); BOOST_REQUIRE_EQUAL(tree.NumDescendants(), numDescendants); @@ -387,14 +387,14 @@ BOOST_AUTO_TEST_CASE(PointDeletion) arma::mat> TreeType; TreeType tree(dataset, 20, 6, 5, 2, 0); - for (int i = 0; i < numIter; i++) + for (int i = 0; i < numIter; ++i) tree.DeletePoint(999 - i); // Do a few sanity checks. Ensure each point is unique, the tree has the // correct number of points, the tree has legal containment, and the tree's // data is in sync. std::vector allPoints = GetAllPointsInTree(tree); - for (size_t i = 0; i < allPoints.size(); i++) + for (size_t i = 0; i < allPoints.size(); ++i) { for (size_t j = i + 1; j < allPoints.size(); j++) { @@ -408,7 +408,7 @@ BOOST_AUTO_TEST_CASE(PointDeletion) } } - for (size_t i = 0; i < allPoints.size(); i++) + for (size_t i = 0; i < allPoints.size(); ++i) delete allPoints[i]; BOOST_REQUIRE_EQUAL(tree.NumDescendants(), 1000 - numIter); @@ -437,7 +437,7 @@ BOOST_AUTO_TEST_CASE(PointDeletion) knn2.Search(querySet, 5, neighbors2, distances2); - for (size_t i = 0; i < neighbors1.size(); i++) + for (size_t i = 0; i < neighbors1.size(); ++i) { BOOST_REQUIRE_EQUAL(distances1[i], distances2[i]); BOOST_REQUIRE_EQUAL(neighbors1[i], neighbors2[i]); @@ -467,7 +467,7 @@ BOOST_AUTO_TEST_CASE(PointDynamicAdd) dataset.reshape(8, 1000 + numIter); arma::mat tmpData; tmpData.randu(8, numIter); - for (int i = 0; i < numIter; i++) + for (int i = 0; i < numIter; ++i) { tree.Dataset().col(1000 + i) = tmpData.col(i); dataset.col(1000 + i) = tmpData.col(i); @@ -478,7 +478,7 @@ BOOST_AUTO_TEST_CASE(PointDynamicAdd) // correct number of points, the tree has legal containment, and the tree's // data is in sync. std::vector allPoints = GetAllPointsInTree(tree); - for (size_t i = 0; i < allPoints.size(); i++) + for (size_t i = 0; i < allPoints.size(); ++i) { for (size_t j = i + 1; j < allPoints.size(); j++) { @@ -492,7 +492,7 @@ BOOST_AUTO_TEST_CASE(PointDynamicAdd) } } - for (size_t i = 0; i < allPoints.size(); i++) + for (size_t i = 0; i < allPoints.size(); ++i) delete allPoints[i]; BOOST_REQUIRE_EQUAL(tree.NumDescendants(), 1000 + numIter); @@ -518,7 +518,7 @@ BOOST_AUTO_TEST_CASE(PointDynamicAdd) knn2.Search(5, neighbors2, distances2); - for (size_t i = 0; i < neighbors1.size(); i++) + for (size_t i = 0; i < neighbors1.size(); ++i) { BOOST_REQUIRE_EQUAL(distances1[i], distances2[i]); BOOST_REQUIRE_EQUAL(neighbors1[i], neighbors2[i]); @@ -558,7 +558,7 @@ BOOST_AUTO_TEST_CASE(SingleTreeTraverserTest) knn2.Search(5, neighbors2, distances2); - for (size_t i = 0; i < neighbors1.size(); i++) + for (size_t i = 0; i < neighbors1.size(); ++i) { BOOST_REQUIRE_EQUAL(neighbors1[i], neighbors2[i]); BOOST_REQUIRE_EQUAL(distances1[i], distances2[i]); @@ -601,7 +601,7 @@ BOOST_AUTO_TEST_CASE(XTreeTraverserTest) knn2.Search(5, neighbors2, distances2); - for (size_t i = 0; i < neighbors1.size(); i++) + for (size_t i = 0; i < neighbors1.size(); ++i) { BOOST_REQUIRE_EQUAL(neighbors1[i], neighbors2[i]); BOOST_REQUIRE_EQUAL(distances1[i], distances2[i]); @@ -642,7 +642,7 @@ BOOST_AUTO_TEST_CASE(HilbertRTreeTraverserTest) knn2.Search(5, neighbors2, distances2); - for (size_t i = 0; i < neighbors1.size(); i++) + for (size_t i = 0; i < neighbors1.size(); ++i) { BOOST_REQUIRE_EQUAL(neighbors1[i], neighbors2[i]); BOOST_REQUIRE_EQUAL(distances1[i], distances2[i]); @@ -654,7 +654,7 @@ void CheckHilbertOrdering(const TreeType& tree) { if (tree.IsLeaf()) { - for (size_t i = 0; i < tree.NumPoints() - 1; i++) + for (size_t i = 0; i < tree.NumPoints() - 1; ++i) BOOST_REQUIRE_LE(tree.AuxiliaryInfo().HilbertValue().ComparePoints( tree.Dataset().col(tree.Point(i)), tree.Dataset().col(tree.Point(i + 1))), @@ -666,7 +666,7 @@ void CheckHilbertOrdering(const TreeType& tree) } else { - for (size_t i = 0; i < tree.NumChildren() - 1; i++) + for (size_t i = 0; i < tree.NumChildren() - 1; ++i) BOOST_REQUIRE_LE(tree.AuxiliaryInfo().HilbertValue().CompareValues( tree.Child(i).AuxiliaryInfo().HilbertValue(), tree.Child(i + 1).AuxiliaryInfo().HilbertValue()), @@ -676,7 +676,7 @@ void CheckHilbertOrdering(const TreeType& tree) tree.Child(tree.NumChildren() - 1).AuxiliaryInfo().HilbertValue()), 0); - for (size_t i = 0; i < tree.NumChildren(); i++) + for (size_t i = 0; i < tree.NumChildren(); ++i) CheckHilbertOrdering(tree.Child(i)); } } @@ -704,7 +704,7 @@ void CheckDiscreteHilbertValueSync(const TreeType& tree) { const HilbertValue& value = tree.AuxiliaryInfo().HilbertValue(); - for (size_t i = 0; i < tree.NumPoints(); i++) + for (size_t i = 0; i < tree.NumPoints(); ++i) { arma::Col pointValue = HilbertValue::CalculateValue(tree.Dataset().col(tree.Point(i))); @@ -717,7 +717,7 @@ void CheckDiscreteHilbertValueSync(const TreeType& tree) } else { - for (size_t i = 0; i < tree.NumChildren(); i++) + for (size_t i = 0; i < tree.NumChildren(); ++i) CheckDiscreteHilbertValueSync(tree.Child(i)); } } @@ -885,7 +885,7 @@ void CheckHilbertValue(const TreeType& tree) return; } - for (size_t i = 0; i < tree.NumChildren(); i++) + for (size_t i = 0; i < tree.NumChildren(); ++i) { const HilbertValue& childValue = tree.Child(i).AuxiliaryInfo().HilbertValue(); @@ -904,7 +904,7 @@ void CheckHilbertValue(const TreeType& tree) BOOST_REQUIRE_EQUAL(value.OwnsLocalHilbertValues(), false); - for (size_t i = 0; i < tree.NumChildren(); i++) + for (size_t i = 0; i < tree.NumChildren(); ++i) CheckHilbertValue(tree.Child(i)); } @@ -954,7 +954,7 @@ void CheckOverlap(const TreeType& tree) bool success = true; // Check if two nodes overlap each other. - for (size_t i = 0; i < tree.NumChildren(); i++) + for (size_t i = 0; i < tree.NumChildren(); ++i) { success = true; @@ -973,7 +973,7 @@ void CheckOverlap(const TreeType& tree) } BOOST_REQUIRE_EQUAL(success, true); - for (size_t i = 0; i < tree.NumChildren(); i++) + for (size_t i = 0; i < tree.NumChildren(); ++i) CheckOverlap(tree.Child(i)); } @@ -1034,7 +1034,7 @@ BOOST_AUTO_TEST_CASE(RPlusTreeTraverserTest) knn2.Search(5, neighbors2, distances2); - for (size_t i = 0; i < neighbors1.size(); i++) + for (size_t i = 0; i < neighbors1.size(); ++i) { BOOST_REQUIRE_EQUAL(neighbors1[i], neighbors2[i]); BOOST_REQUIRE_EQUAL(distances1[i], distances2[i]); @@ -1061,7 +1061,7 @@ void CheckRPlusPlusTreeBound(const TreeType& tree) if (tree.IsLeaf()) { // Ensure that the maximum bounding rectangle contains all points. - for (size_t i = 0; i < tree.Count(); i++) + for (size_t i = 0; i < tree.Count(); ++i) BOOST_REQUIRE_EQUAL(true, tree.Bound().Contains(tree.Dataset().col(tree.Point(i)))); @@ -1070,7 +1070,7 @@ void CheckRPlusPlusTreeBound(const TreeType& tree) // Ensure that two children's maximum bounding rectangles do not overlap // each other. - for (size_t i = 0; i < tree.NumChildren(); i++) + for (size_t i = 0; i < tree.NumChildren(); ++i) { const Bound& bound1 = tree.Child(i).AuxiliaryInfo().OuterBound(); success = true; @@ -1091,7 +1091,7 @@ void CheckRPlusPlusTreeBound(const TreeType& tree) } BOOST_REQUIRE_EQUAL(success, true); - for (size_t i = 0; i < tree.NumChildren(); i++) + for (size_t i = 0; i < tree.NumChildren(); ++i) CheckRPlusPlusTreeBound(tree.Child(i)); } @@ -1165,7 +1165,7 @@ BOOST_AUTO_TEST_CASE(RPlusPlusTreeTraverserTest) knn2.Search(5, neighbors2, distances2); - for (size_t i = 0; i < neighbors1.size(); i++) + for (size_t i = 0; i < neighbors1.size(); ++i) { BOOST_REQUIRE_EQUAL(neighbors1[i], neighbors2[i]); BOOST_REQUIRE_EQUAL(distances1[i], distances2[i]); diff --git a/src/mlpack/tests/recurrent_network_test.cpp b/src/mlpack/tests/recurrent_network_test.cpp index 9d178f12e0..3c8e62b91d 100644 --- a/src/mlpack/tests/recurrent_network_test.cpp +++ b/src/mlpack/tests/recurrent_network_test.cpp @@ -480,7 +480,7 @@ arma::Mat GenerateReberGrammarData( arma::colvec translation; // Generate the training data. - for (size_t i = 0; i < trainReberGrammarCount; i++) + for (size_t i = 0; i < trainReberGrammarCount; ++i) { if (recursive) GenerateRecursiveReber(transitions, 3, 5, trainReber); @@ -498,7 +498,7 @@ arma::Mat GenerateReberGrammarData( } // Generate the test data. - for (size_t i = 0; i < testReberGrammarCount; i++) + for (size_t i = 0; i < testReberGrammarCount; ++i) { if (recursive) GenerateRecursiveReber(transitions, averageRecursion, maxRecursion, @@ -595,7 +595,7 @@ void ReberGrammarTestNetwork(ModelType& model, double error = 0; // Ask the network to predict the next Reber grammar in the given sequence. - for (size_t i = 0; i < testReberGrammarCount; i++) + for (size_t i = 0; i < testReberGrammarCount; ++i) { arma::cube prediction; arma::cube input(testInput.at(0, i).memptr(), inputSize, 1, @@ -736,14 +736,14 @@ void GenerateDistractedSequence(arma::mat& input, arma::mat& output) // Set the target in the input sequence and the corresponding targets in the // output sequence by following the correct order. - for (size_t i = 0; i < 2; i++) + for (size_t i = 0; i < 2; ++i) { size_t idx = rand() % 2; input(idx, index(i)) = 1; output(idx, index(i) > index(i == 0) ? 9 : 8) = 1; } - for (size_t i = 2; i < 8; i++) + for (size_t i = 2; i < 8; ++i) input(2 + rand() % 6, index(i)) = 1; // Set the prompts which direct the network to give an answer. @@ -771,11 +771,11 @@ void DistractedSequenceRecallTestNetwork( arma::field testLabels(1, testDistractedSequenceCount); // Generate the training data. - for (size_t i = 0; i < trainDistractedSequenceCount; i++) + for (size_t i = 0; i < trainDistractedSequenceCount; ++i) GenerateDistractedSequence(trainInput(0, i), trainLabels(0, i)); // Generate the test data. - for (size_t i = 0; i < testDistractedSequenceCount; i++) + for (size_t i = 0; i < testDistractedSequenceCount; ++i) GenerateDistractedSequence(testInput(0, i), testLabels(0, i)); /* @@ -835,7 +835,7 @@ void DistractedSequenceRecallTestNetwork( // Ask the network to predict the targets in the given sequence at the // prompts. - for (size_t i = 0; i < testDistractedSequenceCount; i++) + for (size_t i = 0; i < testDistractedSequenceCount; ++i) { arma::cube output; arma::cube input(testInput.at(0, i).memptr(), inputSize, 1, @@ -1122,7 +1122,7 @@ void ReberGrammarTestCustomNetwork(const size_t hiddenSize = 4, double error = 0; // Ask the network to predict the next Reber grammar in the given sequence. - for (size_t i = 0; i < testReberGrammarCount; i++) + for (size_t i = 0; i < testReberGrammarCount; ++i) { arma::cube prediction; arma::cube input(testInput.at(0, i).memptr(), inputSize, 1, @@ -1233,7 +1233,7 @@ void GenerateNoisySinRNN(arma::cube& data, x.for_each([&i, gain, freq, phase, noisePercent, interval] (arma::colvec::elem_type& val) { - double t = interval * (i++); + double t = interval * (++i); val = gain * ::sin(2 * M_PI * freq * t + phase) + (noisePercent * gain / 100 * Random(0.0, 0.1)); }); diff --git a/src/mlpack/tests/regularized_svd_test.cpp b/src/mlpack/tests/regularized_svd_test.cpp index 51a152cb1b..4c7e38ab6b 100644 --- a/src/mlpack/tests/regularized_svd_test.cpp +++ b/src/mlpack/tests/regularized_svd_test.cpp @@ -46,7 +46,7 @@ BOOST_AUTO_TEST_CASE(RegularizedSVDFunctionRandomEvaluate) // Make a RegularizedSVDFunction with zero regularization. RegularizedSVDFunction rSVDFunc(data, rank, 0); - for (size_t i = 0; i < numTrials; i++) + for (size_t i = 0; i < numTrials; ++i) { arma::mat parameters = arma::randu(rank, numUsers + numItems); @@ -96,7 +96,7 @@ BOOST_AUTO_TEST_CASE(RegularizedSVDFunctionRegularizationEvaluate) RegularizedSVDFunction rSVDFuncSmallReg(data, rank, 0.5); RegularizedSVDFunction rSVDFuncBigReg(data, rank, 20); - for (size_t i = 0; i < numTrials; i++) + for (size_t i = 0; i < numTrials; ++i) { arma::mat parameters = arma::randu(rank, numUsers + numItems); @@ -162,7 +162,7 @@ BOOST_AUTO_TEST_CASE(RegularizedSVDFunctionGradient) double costPlus1, costMinus1, numGradient1; double costPlus2, costMinus2, numGradient2; - for (size_t i = 0; i < rank; i++) + for (size_t i = 0; i < rank; ++i) { for (size_t j = 0; j < numUsers + numItems; j++) { @@ -221,7 +221,7 @@ BOOST_AUTO_TEST_CASE(RegularizedSVDFunctionOptimize) data(1, numRatings - 1) = numItems - 1; // Make rating entries based on the parameters. - for (size_t i = 0; i < numRatings; i++) + for (size_t i = 0; i < numRatings; ++i) { data(2, i) = arma::dot(parameters.col(data(0, i)), parameters.col(numUsers + data(1, i))); @@ -237,7 +237,7 @@ BOOST_AUTO_TEST_CASE(RegularizedSVDFunctionOptimize) // Get predicted ratings from optimized parameters. arma::mat predictedData(1, numRatings); - for (size_t i = 0; i < numRatings; i++) + for (size_t i = 0; i < numRatings; ++i) { predictedData(0, i) = arma::dot(optParameters.col(data(0, i)), optParameters.col(numUsers + data(1, i))); @@ -279,7 +279,7 @@ BOOST_AUTO_TEST_CASE(RegularizedSVDFunctionOptimizeHOGWILD) data(1, numRatings - 1) = numItems - 1; // Make rating entries based on the parameters. - for (size_t i = 0; i < numRatings; i++) + for (size_t i = 0; i < numRatings; ++i) { data(2, i) = arma::dot(parameters.col(data(0, i)), parameters.col(numUsers + data(1, i))); @@ -302,7 +302,7 @@ BOOST_AUTO_TEST_CASE(RegularizedSVDFunctionOptimizeHOGWILD) // Get predicted ratings from optimized parameters. arma::mat predictedData(1, numRatings); - for (size_t i = 0; i < numRatings; i++) + for (size_t i = 0; i < numRatings; ++i) { predictedData(0, i) = arma::dot(optParameters.col(data(0, i)), optParameters.col(numUsers + data(1, i))); diff --git a/src/mlpack/tests/scaling_test.cpp b/src/mlpack/tests/scaling_test.cpp index 280fce85d2..c676c73a64 100644 --- a/src/mlpack/tests/scaling_test.cpp +++ b/src/mlpack/tests/scaling_test.cpp @@ -149,7 +149,7 @@ BOOST_AUTO_TEST_CASE(PCAWhiteningTest) arma::vec diagonals = (mlpack::math::ColumnCovariance(output)).diag(); // Checking covarience is close to 1.0 double ccovsum = 0.0; - for (size_t i = 0; i < diagonals.n_elem; i++) + for (size_t i = 0; i < diagonals.n_elem; ++i) ccovsum += diagonals(i); BOOST_REQUIRE_CLOSE(ccovsum, 1.0, 1e-3); scale.InverseTransform(output, temp); @@ -168,7 +168,7 @@ BOOST_AUTO_TEST_CASE(ZCAWhiteningTest) arma::vec diagonals = (mlpack::math::ColumnCovariance(output)).diag(); // Check that the covariance is close to 1.0. double ccovsum = 0.0; - for (size_t i = 0; i < diagonals.n_elem; i++) + for (size_t i = 0; i < diagonals.n_elem; ++i) ccovsum += diagonals(i); BOOST_REQUIRE_CLOSE(ccovsum, 1.0, 1e-3); scale.InverseTransform(output, temp); diff --git a/src/mlpack/tests/serialization_test.cpp b/src/mlpack/tests/serialization_test.cpp index da819f4ee4..41a4faccb6 100644 --- a/src/mlpack/tests/serialization_test.cpp +++ b/src/mlpack/tests/serialization_test.cpp @@ -1559,7 +1559,7 @@ BOOST_AUTO_TEST_CASE(ssRBMTest) data.randu(3, 100); double slabPenalty = 1; double tempRadius, radius = arma::norm(data.col(0)); - for (size_t i = 1; i < data.n_cols; i++) + for (size_t i = 1; i < data.n_cols; ++i) { tempRadius = arma::norm(data.col(i)); if (radius < tempRadius) diff --git a/src/mlpack/tests/softmax_regression_test.cpp b/src/mlpack/tests/softmax_regression_test.cpp index 5d7833bdbf..a56d3bf22b 100644 --- a/src/mlpack/tests/softmax_regression_test.cpp +++ b/src/mlpack/tests/softmax_regression_test.cpp @@ -34,14 +34,14 @@ BOOST_AUTO_TEST_CASE(SoftmaxRegressionFunctionEvaluate) // Create random class labels. arma::Row labels(points); - for (size_t i = 0; i < points; i++) + for (size_t i = 0; i < points; ++i) labels(i) = math::RandInt(0, numClasses); // Create a SoftmaxRegressionFunction. Regularization term ignored. SoftmaxRegressionFunction srf(data, labels, numClasses, 0); // Run a number of trials. - for (size_t i = 0; i < trials; i++) + for (size_t i = 0; i < trials; ++i) { // Create a random set of parameters. arma::mat parameters; @@ -79,7 +79,7 @@ BOOST_AUTO_TEST_CASE(SoftmaxRegressionFunctionRegularizationEvaluate) // Create random class labels. arma::Row labels(points); - for (size_t i = 0; i < points; i++) + for (size_t i = 0; i < points; ++i) labels(i) = math::RandInt(0, numClasses); // 3 objects for comparing regularization costs. @@ -88,7 +88,7 @@ BOOST_AUTO_TEST_CASE(SoftmaxRegressionFunctionRegularizationEvaluate) SoftmaxRegressionFunction srfBigReg(data, labels, numClasses, 20); // Run a number of trials. - for (size_t i = 0; i < trials; i++) + for (size_t i = 0; i < trials; ++i) { // Create a random set of parameters. arma::mat parameters; @@ -120,7 +120,7 @@ BOOST_AUTO_TEST_CASE(SoftmaxRegressionFunctionGradient) // Create random class labels. arma::Row labels(points); - for (size_t i = 0; i < points; i++) + for (size_t i = 0; i < points; ++i) labels(i) = math::RandInt(0, numClasses); // 2 objects for 2 terms in the cost function. Each term contributes towards @@ -143,7 +143,7 @@ BOOST_AUTO_TEST_CASE(SoftmaxRegressionFunctionGradient) double costPlus2, costMinus2, numGradient2; // For each parameter. - for (size_t i = 0; i < numClasses; i++) + for (size_t i = 0; i < numClasses; ++i) { for (size_t j = 0; j < inputSize; j++) { @@ -185,12 +185,12 @@ BOOST_AUTO_TEST_CASE(SoftmaxRegressionTwoClasses) arma::mat data(inputSize, points); arma::Row labels(points); - for (size_t i = 0; i < points / 2; i++) + for (size_t i = 0; i < points / 2; ++i) { data.col(i) = g1.Random(); labels(i) = 0; } - for (size_t i = points / 2; i < points; i++) + for (size_t i = points / 2; i < points; ++i) { data.col(i) = g2.Random(); labels(i) = 1; @@ -204,12 +204,12 @@ BOOST_AUTO_TEST_CASE(SoftmaxRegressionTwoClasses) BOOST_REQUIRE_CLOSE(acc, 100.0, 0.5); // Create test dataset. - for (size_t i = 0; i < points / 2; i++) + for (size_t i = 0; i < points / 2; ++i) { data.col(i) = g1.Random(); labels(i) = 0; } - for (size_t i = points / 2; i < points; i++) + for (size_t i = points / 2; i < points; ++i) { data.col(i) = g2.Random(); labels(i) = 1; @@ -282,27 +282,27 @@ BOOST_AUTO_TEST_CASE(SoftmaxRegressionMultipleClasses) arma::mat data(inputSize, points); arma::Row labels(points); - for (size_t i = 0; i < points / 5; i++) + for (size_t i = 0; i < points / 5; ++i) { data.col(i) = g1.Random(); labels(i) = 0; } - for (size_t i = points / 5; i < (2 * points) / 5; i++) + for (size_t i = points / 5; i < (2 * points) / 5; ++i) { data.col(i) = g2.Random(); labels(i) = 1; } - for (size_t i = (2 * points) / 5; i < (3 * points) / 5; i++) + for (size_t i = (2 * points) / 5; i < (3 * points) / 5; ++i) { data.col(i) = g3.Random(); labels(i) = 2; } - for (size_t i = (3 * points) / 5; i < (4 * points) / 5; i++) + for (size_t i = (3 * points) / 5; i < (4 * points) / 5; ++i) { data.col(i) = g4.Random(); labels(i) = 3; } - for (size_t i = (4 * points) / 5; i < points; i++) + for (size_t i = (4 * points) / 5; i < points; ++i) { data.col(i) = g5.Random(); labels(i) = 4; @@ -316,27 +316,27 @@ BOOST_AUTO_TEST_CASE(SoftmaxRegressionMultipleClasses) BOOST_REQUIRE_CLOSE(acc, 100.0, 2.0); // Create test dataset. - for (size_t i = 0; i < points / 5; i++) + for (size_t i = 0; i < points / 5; ++i) { data.col(i) = g1.Random(); labels(i) = 0; } - for (size_t i = points / 5; i < (2 * points) / 5; i++) + for (size_t i = points / 5; i < (2 * points) / 5; ++i) { data.col(i) = g2.Random(); labels(i) = 1; } - for (size_t i = (2 * points) / 5; i < (3 * points) / 5; i++) + for (size_t i = (2 * points) / 5; i < (3 * points) / 5; ++i) { data.col(i) = g3.Random(); labels(i) = 2; } - for (size_t i = (3 * points) / 5; i < (4 * points) / 5; i++) + for (size_t i = (3 * points) / 5; i < (4 * points) / 5; ++i) { data.col(i) = g4.Random(); labels(i) = 3; } - for (size_t i = (4 * points) / 5; i < points; i++) + for (size_t i = (4 * points) / 5; i < points; ++i) { data.col(i) = g5.Random(); labels(i) = 4; @@ -428,27 +428,27 @@ BOOST_AUTO_TEST_CASE(SoftmaxRegressionClassifySinglePointTest) arma::mat data(inputSize, points); arma::Row labels(points); - for (size_t i = 0; i < points / 5; i++) + for (size_t i = 0; i < points / 5; ++i) { data.col(i) = g1.Random(); labels(i) = 0; } - for (size_t i = points / 5; i < (2 * points) / 5; i++) + for (size_t i = points / 5; i < (2 * points) / 5; ++i) { data.col(i) = g2.Random(); labels(i) = 1; } - for (size_t i = (2 * points) / 5; i < (3 * points) / 5; i++) + for (size_t i = (2 * points) / 5; i < (3 * points) / 5; ++i) { data.col(i) = g3.Random(); labels(i) = 2; } - for (size_t i = (3 * points) / 5; i < (4 * points) / 5; i++) + for (size_t i = (3 * points) / 5; i < (4 * points) / 5; ++i) { data.col(i) = g4.Random(); labels(i) = 3; } - for (size_t i = (4 * points) / 5; i < points; i++) + for (size_t i = (4 * points) / 5; i < points; ++i) { data.col(i) = g5.Random(); labels(i) = 4; @@ -458,27 +458,27 @@ BOOST_AUTO_TEST_CASE(SoftmaxRegressionClassifySinglePointTest) SoftmaxRegression sr(data, labels, numClasses, lambda); // Create test dataset. - for (size_t i = 0; i < points / 5; i++) + for (size_t i = 0; i < points / 5; ++i) { data.col(i) = g1.Random(); labels(i) = 0; } - for (size_t i = points / 5; i < (2 * points) / 5; i++) + for (size_t i = points / 5; i < (2 * points) / 5; ++i) { data.col(i) = g2.Random(); labels(i) = 1; } - for (size_t i = (2 * points) / 5; i < (3 * points) / 5; i++) + for (size_t i = (2 * points) / 5; i < (3 * points) / 5; ++i) { data.col(i) = g3.Random(); labels(i) = 2; } - for (size_t i = (3 * points) / 5; i < (4 * points) / 5; i++) + for (size_t i = (3 * points) / 5; i < (4 * points) / 5; ++i) { data.col(i) = g4.Random(); labels(i) = 3; } - for (size_t i = (4 * points) / 5; i < points; i++) + for (size_t i = (4 * points) / 5; i < points; ++i) { data.col(i) = g5.Random(); labels(i) = 4; @@ -510,27 +510,27 @@ BOOST_AUTO_TEST_CASE(SoftmaxRegressionComputeProbabilitiesTest) arma::mat data(inputSize, points); arma::Row labels(points); - for (size_t i = 0; i < points / 5; i++) + for (size_t i = 0; i < points / 5; ++i) { data.col(i) = g1.Random(); labels(i) = 0; } - for (size_t i = points / 5; i < (2 * points) / 5; i++) + for (size_t i = points / 5; i < (2 * points) / 5; ++i) { data.col(i) = g2.Random(); labels(i) = 1; } - for (size_t i = (2 * points) / 5; i < (3 * points) / 5; i++) + for (size_t i = (2 * points) / 5; i < (3 * points) / 5; ++i) { data.col(i) = g3.Random(); labels(i) = 2; } - for (size_t i = (3 * points) / 5; i < (4 * points) / 5; i++) + for (size_t i = (3 * points) / 5; i < (4 * points) / 5; ++i) { data.col(i) = g4.Random(); labels(i) = 3; } - for (size_t i = (4 * points) / 5; i < points; i++) + for (size_t i = (4 * points) / 5; i < points; ++i) { data.col(i) = g5.Random(); labels(i) = 4; @@ -540,27 +540,27 @@ BOOST_AUTO_TEST_CASE(SoftmaxRegressionComputeProbabilitiesTest) SoftmaxRegression sr(data, labels, numClasses, lambda); // Create test dataset. - for (size_t i = 0; i < points / 5; i++) + for (size_t i = 0; i < points / 5; ++i) { data.col(i) = g1.Random(); labels(i) = 0; } - for (size_t i = points / 5; i < (2 * points) / 5; i++) + for (size_t i = points / 5; i < (2 * points) / 5; ++i) { data.col(i) = g2.Random(); labels(i) = 1; } - for (size_t i = (2 * points) / 5; i < (3 * points) / 5; i++) + for (size_t i = (2 * points) / 5; i < (3 * points) / 5; ++i) { data.col(i) = g3.Random(); labels(i) = 2; } - for (size_t i = (3 * points) / 5; i < (4 * points) / 5; i++) + for (size_t i = (3 * points) / 5; i < (4 * points) / 5; ++i) { data.col(i) = g4.Random(); labels(i) = 3; } - for (size_t i = (4 * points) / 5; i < points; i++) + for (size_t i = (4 * points) / 5; i < points; ++i) { data.col(i) = g5.Random(); labels(i) = 4; @@ -596,27 +596,27 @@ BOOST_AUTO_TEST_CASE(SoftmaxRegressionComputeProbabilitiesAndLabelsTest) arma::mat data(inputSize, points); arma::Row labels(points); - for (size_t i = 0; i < points / 5; i++) + for (size_t i = 0; i < points / 5; ++i) { data.col(i) = g1.Random(); labels(i) = 0; } - for (size_t i = points / 5; i < (2 * points) / 5; i++) + for (size_t i = points / 5; i < (2 * points) / 5; ++i) { data.col(i) = g2.Random(); labels(i) = 1; } - for (size_t i = (2 * points) / 5; i < (3 * points) / 5; i++) + for (size_t i = (2 * points) / 5; i < (3 * points) / 5; ++i) { data.col(i) = g3.Random(); labels(i) = 2; } - for (size_t i = (3 * points) / 5; i < (4 * points) / 5; i++) + for (size_t i = (3 * points) / 5; i < (4 * points) / 5; ++i) { data.col(i) = g4.Random(); labels(i) = 3; } - for (size_t i = (4 * points) / 5; i < points; i++) + for (size_t i = (4 * points) / 5; i < points; ++i) { data.col(i) = g5.Random(); labels(i) = 4; @@ -626,27 +626,27 @@ BOOST_AUTO_TEST_CASE(SoftmaxRegressionComputeProbabilitiesAndLabelsTest) SoftmaxRegression sr(data, labels, numClasses, lambda); // Create test dataset. - for (size_t i = 0; i < points / 5; i++) + for (size_t i = 0; i < points / 5; ++i) { data.col(i) = g1.Random(); labels(i) = 0; } - for (size_t i = points / 5; i < (2 * points) / 5; i++) + for (size_t i = points / 5; i < (2 * points) / 5; ++i) { data.col(i) = g2.Random(); labels(i) = 1; } - for (size_t i = (2 * points) / 5; i < (3 * points) / 5; i++) + for (size_t i = (2 * points) / 5; i < (3 * points) / 5; ++i) { data.col(i) = g3.Random(); labels(i) = 2; } - for (size_t i = (3 * points) / 5; i < (4 * points) / 5; i++) + for (size_t i = (3 * points) / 5; i < (4 * points) / 5; ++i) { data.col(i) = g4.Random(); labels(i) = 3; } - for (size_t i = (4 * points) / 5; i < points; i++) + for (size_t i = (4 * points) / 5; i < points; ++i) { data.col(i) = g5.Random(); labels(i) = 4; diff --git a/src/mlpack/tests/sparse_autoencoder_test.cpp b/src/mlpack/tests/sparse_autoencoder_test.cpp index d9e41983cd..3f885310df 100644 --- a/src/mlpack/tests/sparse_autoencoder_test.cpp +++ b/src/mlpack/tests/sparse_autoencoder_test.cpp @@ -74,7 +74,7 @@ BOOST_AUTO_TEST_CASE(SparseAutoencoderFunctionRandomEvaluate) SparseAutoencoderFunction saf(data, vSize, hSize, 0, 0); // Run a number of trials. - for (size_t i = 0; i < trials; i++) + for (size_t i = 0; i < trials; ++i) { // Create a random set of parameters. arma::mat parameters; @@ -123,7 +123,7 @@ BOOST_AUTO_TEST_CASE(SparseAutoencoderFunctionRegularizationEvaluate) SparseAutoencoderFunction safBigReg(data, vSize, hSize, 20, 0); // Run a number of trials. - for (size_t i = 0; i < trials; i++) + for (size_t i = 0; i < trials; ++i) { // Create a random set of parameters. arma::mat parameters; @@ -167,7 +167,7 @@ BOOST_AUTO_TEST_CASE(SparseAutoencoderFunctionKLDivergenceEvaluate) SparseAutoencoderFunction safBigDiv(data, vSize, hSize, 0, 20, rho); // Run a number of trials. - for (size_t i = 0; i < trials; i++) + for (size_t i = 0; i < trials; ++i) { // Create a random set of parameters. arma::mat parameters; @@ -236,7 +236,7 @@ BOOST_AUTO_TEST_CASE(SparseAutoencoderFunctionGradient) double costPlus3, costMinus3, numGradient3; // For each parameter. - for (size_t i = 0; i <= l3; i++) + for (size_t i = 0; i <= l3; ++i) { for (size_t j = 0; j <= l2; j++) { diff --git a/src/mlpack/tests/spill_tree_test.cpp b/src/mlpack/tests/spill_tree_test.cpp index e972c48336..4fc7c20bd0 100644 --- a/src/mlpack/tests/spill_tree_test.cpp +++ b/src/mlpack/tests/spill_tree_test.cpp @@ -143,7 +143,7 @@ void SpillTreeHyperplaneTestAux() // Let's check that points in the left child are projected to values // in the range: (-inf, tau] size_t numDesc = node->Left()->NumDescendants(); - for (size_t i = 0; i < numDesc; i++) + for (size_t i = 0; i < numDesc; ++i) { size_t descIndex = node->Left()->Descendant(i); BOOST_REQUIRE_LE( @@ -156,7 +156,7 @@ void SpillTreeHyperplaneTestAux() // Let's check that points in the right child are projected to values // in the range: (-tau, inf) size_t numDesc = node->Right()->NumDescendants(); - for (size_t i = 0; i < numDesc; i++) + for (size_t i = 0; i < numDesc; ++i) { size_t descIndex = node->Right()->Descendant(i); BOOST_REQUIRE_GT( @@ -173,7 +173,7 @@ void SpillTreeHyperplaneTestAux() // Let's check that points in the left child are considered to the // left by the splitting hyperplane. size_t numDesc = node->Left()->NumDescendants(); - for (size_t i = 0; i < numDesc; i++) + for (size_t i = 0; i < numDesc; ++i) { size_t descIndex = node->Left()->Descendant(i); BOOST_REQUIRE( @@ -185,7 +185,7 @@ void SpillTreeHyperplaneTestAux() // Let's check that points in the right child are considered to the // right by the splitting hyperplane. size_t numDesc = node->Right()->NumDescendants(); - for (size_t i = 0; i < numDesc; i++) + for (size_t i = 0; i < numDesc; ++i) { size_t descIndex = node->Right()->Descendant(i); BOOST_REQUIRE( diff --git a/src/mlpack/tests/string_encoding_test.cpp b/src/mlpack/tests/string_encoding_test.cpp index 31a0f22713..e6ce85f88c 100644 --- a/src/mlpack/tests/string_encoding_test.cpp +++ b/src/mlpack/tests/string_encoding_test.cpp @@ -66,7 +66,7 @@ void CheckVectors(const vector>& a, { BOOST_REQUIRE_EQUAL(a.size(), b.size()); - for (size_t i = 0; i < a.size(); i++) + for (size_t i = 0; i < a.size(); ++i) { BOOST_REQUIRE_EQUAL(a[i].size(), b[i].size()); @@ -206,7 +206,7 @@ BOOST_AUTO_TEST_CASE(SplitByAnyOfTokenizerTest) BOOST_REQUIRE_EQUAL(tokens.size(), expected.size()); - for (size_t i = 0; i < tokens.size(); i++) + for (size_t i = 0; i < tokens.size(); ++i) BOOST_REQUIRE_EQUAL(tokens[i], expected[i]); } @@ -238,7 +238,7 @@ BOOST_AUTO_TEST_CASE(SplitByAnyOfTokenizerUnicodeTest) BOOST_REQUIRE_EQUAL(tokens.size(), expectedUtf8Tokens.size()); - for (size_t i = 0; i < tokens.size(); i++) + for (size_t i = 0; i < tokens.size(); ++i) BOOST_REQUIRE_EQUAL(tokens[i], expectedUtf8Tokens[i]); } @@ -417,7 +417,7 @@ void CheckDictionaries( BOOST_REQUIRE_EQUAL(mapping.size(), expectedMapping.size()); BOOST_REQUIRE_EQUAL(mapping.size(), tokens.size()); - for (size_t i = 0; i < tokens.size(); i++) + for (size_t i = 0; i < tokens.size(); ++i) { BOOST_REQUIRE_EQUAL(tokens[i], expectedTokens[i]); BOOST_REQUIRE_EQUAL(expectedMapping.at(tokens[i]), mapping.at(tokens[i])); @@ -440,7 +440,7 @@ void CheckDictionaries(const StringEncodingDictionary& expected, BOOST_REQUIRE_EQUAL(expected.Size(), obtained.Size()); - for (size_t i = 0; i < mapping.size(); i++) + for (size_t i = 0; i < mapping.size(); ++i) { BOOST_REQUIRE_EQUAL(mapping[i], expectedMapping[i]); } diff --git a/src/mlpack/tests/svdplusplus_test.cpp b/src/mlpack/tests/svdplusplus_test.cpp index ad6bc1c1af..f363a9199a 100644 --- a/src/mlpack/tests/svdplusplus_test.cpp +++ b/src/mlpack/tests/svdplusplus_test.cpp @@ -49,7 +49,7 @@ BOOST_AUTO_TEST_CASE(SVDPlusPlusEvaluate) // Make a SVDPlusPlusFunction with zero regularization. SVDPlusPlusFunction svdPPFunc(data, implicitData, rank, 0); - for (size_t i = 0; i < numTrials; i++) + for (size_t i = 0; i < numTrials; ++i) { arma::mat parameters = arma::randu(rank + 1, numUsers + 2 * numItems); @@ -123,7 +123,7 @@ BOOST_AUTO_TEST_CASE(SVDPlusPlusFunctionRegularizationEvaluate) 0.5); SVDPlusPlusFunction svdPPFuncBigReg(data, implicitData, rank, 20); - for (size_t i = 0; i < numTrials; i++) + for (size_t i = 0; i < numTrials; ++i) { arma::mat parameters = arma::randu(rank + 1, numUsers + 2 * numItems); @@ -219,7 +219,7 @@ BOOST_AUTO_TEST_CASE(SVDPlusPlusFunctionGradient) double costPlus1, costMinus1, numGradient1; double costPlus2, costMinus2, numGradient2; - for (size_t i = 0; i < rank; i++) + for (size_t i = 0; i < rank; ++i) { for (size_t j = 0; j < numUsers + numItems; j++) { @@ -311,7 +311,7 @@ BOOST_AUTO_TEST_CASE(SVDPlusPlusCleanDataTest) } else { - i++; + ++i; } } @@ -327,7 +327,7 @@ BOOST_AUTO_TEST_CASE(SVDPlusPlusCleanDataTest) BOOST_REQUIRE_EQUAL(cleanedData.n_nonzero, implicitData.n_cols); // Make sure all implicitData are in cleanedData. - for (size_t i = 0; i < implicitData.n_cols; i++) + for (size_t i = 0; i < implicitData.n_cols; ++i) { double value = cleanedData(implicitData(1, i), implicitData(0, i)); BOOST_REQUIRE_GT(std::fabs(value), 0); @@ -361,7 +361,7 @@ BOOST_AUTO_TEST_CASE(SVDPlusPlusFunctionOptimize) arma::sp_mat implicitData = arma::sprandu(numItems, numUsers, 0.05); // Make rating entries based on the parameters. - for (size_t i = 0; i < numRatings; i++) + for (size_t i = 0; i < numRatings; ++i) { const size_t user = data(0, i); const size_t item = data(1, i) + numUsers; @@ -399,7 +399,7 @@ BOOST_AUTO_TEST_CASE(SVDPlusPlusFunctionOptimize) // Get predicted ratings from optimized parameters. arma::mat predictedData(1, numRatings); - for (size_t i = 0; i < numRatings; i++) + for (size_t i = 0; i < numRatings; ++i) { const size_t user = data(0, i); const size_t item = data(1, i) + numUsers; @@ -468,7 +468,7 @@ BOOST_AUTO_TEST_CASE(SVDPlusPlusFunctionParallelOptimize) arma::sp_mat implicitData = arma::sprandu(numItems, numUsers, 0.05); // Make rating entries based on the parameters. - for (size_t i = 0; i < numRatings; i++) + for (size_t i = 0; i < numRatings; ++i) { const size_t user = data(0, i); const size_t item = data(1, i) + numUsers; @@ -513,7 +513,7 @@ BOOST_AUTO_TEST_CASE(SVDPlusPlusFunctionParallelOptimize) // Get predicted ratings from optimized parameters. arma::mat predictedData(1, numRatings); - for (size_t i = 0; i < numRatings; i++) + for (size_t i = 0; i < numRatings; ++i) { const size_t user = data(0, i); const size_t item = data(1, i) + numUsers; diff --git a/src/mlpack/tests/tree_test.cpp b/src/mlpack/tests/tree_test.cpp index af8eaeb081..455e280920 100644 --- a/src/mlpack/tests/tree_test.cpp +++ b/src/mlpack/tests/tree_test.cpp @@ -408,7 +408,7 @@ BOOST_AUTO_TEST_CASE(HRectBoundMaxDistanceBound) */ BOOST_AUTO_TEST_CASE(HRectBoundRangeDistanceBound) { - for (int i = 0; i < 50; i++) + for (int i = 0; i < 50; ++i) { size_t dim = math::RandInt(20); @@ -459,7 +459,7 @@ BOOST_AUTO_TEST_CASE(HRectBoundRangeDistanceBound) */ BOOST_AUTO_TEST_CASE(HRectBoundRangeDistancePoint) { - for (int i = 0; i < 20; i++) + for (int i = 0; i < 20; ++i) { size_t dim = math::RandInt(20); @@ -931,7 +931,7 @@ BOOST_AUTO_TEST_CASE(HRectBoundRootMaxDistanceBound) */ BOOST_AUTO_TEST_CASE(HRectBoundRootRangeDistanceBound) { - for (int i = 0; i < 50; i++) + for (int i = 0; i < 50; ++i) { size_t dim = math::RandInt(20); @@ -982,7 +982,7 @@ BOOST_AUTO_TEST_CASE(HRectBoundRootRangeDistanceBound) */ BOOST_AUTO_TEST_CASE(HRectBoundRootRangeDistancePoint) { - for (int i = 0; i < 20; i++) + for (int i = 0; i < 20; ++i) { size_t dim = math::RandInt(20); @@ -1322,7 +1322,7 @@ BOOST_AUTO_TEST_CASE(KdTreeTest) BOOST_REQUIRE_EQUAL(root.Count(), size); // Check the forward and backward mappings for correctness. - for (size_t i = 0; i < size; i++) + for (size_t i = 0; i < size; ++i) { for (size_t j = 0; j < dimensions; j++) { @@ -1343,7 +1343,7 @@ BOOST_AUTO_TEST_CASE(KdTreeTest) // Compare each peer against every other peer. while (depth < v.size()) { - for (size_t i = depth; i < 2 * depth && i < v.size(); i++) + for (size_t i = depth; i < 2 * depth && i < v.size(); ++i) for (size_t j = i + 1; j < 2 * depth && j < v.size(); j++) if (v[i] != NULL && v[j] != NULL) BOOST_REQUIRE(!v[i]->Bound().Contains(v[j]->Bound())); @@ -1391,7 +1391,7 @@ BOOST_AUTO_TEST_CASE(MaxRPTreeTest) BOOST_REQUIRE_EQUAL(root.Count(), size); // Check the forward and backward mappings for correctness. - for (size_t i = 0; i < size; i++) + for (size_t i = 0; i < size; ++i) { for (size_t j = 0; j < dimensions; j++) { @@ -1424,7 +1424,7 @@ bool CheckHyperplaneSplit(const TreeType& tree) // The hyperplane splits the node if the expression takes on opposite // values on node's children. - for (size_t i = 0; i < tree.Left()->NumDescendants(); i++) + for (size_t i = 0; i < tree.Left()->NumDescendants(); ++i) { for (size_t k = 0; k < dataset.n_rows; k++) mat(k, i) = - dataset(k, tree.Left()->Descendant(i)); @@ -1432,7 +1432,7 @@ bool CheckHyperplaneSplit(const TreeType& tree) mat(dataset.n_rows, i) = -1; } - for (size_t i = 0; i < tree.Right()->NumDescendants(); i++) + for (size_t i = 0; i < tree.Right()->NumDescendants(); ++i) { for (size_t k = 0; k < dataset.n_rows; k++) mat(k, i + tree.Left()->NumDescendants()) = @@ -1533,7 +1533,7 @@ BOOST_AUTO_TEST_CASE(RPTreeTest) BOOST_REQUIRE_EQUAL(root.Count(), size); // Check the forward and backward mappings for correctness. - for (size_t i = 0; i < size; i++) + for (size_t i = 0; i < size; ++i) { for (size_t j = 0; j < dimensions; j++) { @@ -1648,7 +1648,7 @@ BOOST_AUTO_TEST_CASE(BallTreeTest) BOOST_REQUIRE_EQUAL(root.NumDescendants(), size); // Check the forward and backward mappings for correctness. - for (size_t i = 0; i < size; i++) + for (size_t i = 0; i < size; ++i) { for (size_t j = 0; j < dimensions; j++) { @@ -1753,7 +1753,7 @@ BOOST_AUTO_TEST_CASE(ExhaustiveSparseKDTreeTest) BOOST_REQUIRE_EQUAL(root.Count(), size); // Check the forward and backward mappings for correctness. - for (size_t i = 0; i < size; i++) + for (size_t i = 0; i < size; ++i) { for (size_t j = 0; j < dimensions; j++) { @@ -1774,7 +1774,7 @@ BOOST_AUTO_TEST_CASE(ExhaustiveSparseKDTreeTest) // Compare each peer against every other peer. while (depth < v.size()) { - for (size_t i = depth; i < 2 * depth && i < v.size(); i++) + for (size_t i = depth; i < 2 * depth && i < v.size(); ++i) for (size_t j = i + 1; j < 2 * depth && j < v.size(); j++) if (v[i] != NULL && v[j] != NULL) BOOST_REQUIRE(!v[i]->Bound().Contains(v[j]->Bound())); diff --git a/src/mlpack/tests/ub_tree_test.cpp b/src/mlpack/tests/ub_tree_test.cpp index f36376b0c2..ddc055f8b0 100644 --- a/src/mlpack/tests/ub_tree_test.cpp +++ b/src/mlpack/tests/ub_tree_test.cpp @@ -39,7 +39,7 @@ BOOST_AUTO_TEST_CASE(AddressTest) arma::Col point(dataset.n_rows); // Ensure that this is one-to-one transform. - for (size_t i = 0; i < dataset.n_cols; i++) + for (size_t i = 0; i < dataset.n_cols; ++i) { addr::PointToAddress(address, dataset.col(i)); addr::AddressToPoint(point, address); @@ -69,7 +69,7 @@ void CheckSplit(const TreeType& tree) arma::Col address(tree.Bound().Dim()); // Find the highest address of the left node. - for (size_t i = 0; i < tree.Left()->NumDescendants(); i++) + for (size_t i = 0; i < tree.Left()->NumDescendants(); ++i) { addr::PointToAddress(address, tree.Dataset().col(tree.Left()->Descendant(i))); @@ -79,7 +79,7 @@ void CheckSplit(const TreeType& tree) } // Find the lowest address of the right node. - for (size_t i = 0; i < tree.Right()->NumDescendants(); i++) + for (size_t i = 0; i < tree.Right()->NumDescendants(); ++i) { addr::PointToAddress(address, tree.Dataset().col(tree.Right()->Descendant(i))); @@ -110,7 +110,7 @@ template void CheckBound(const TreeType& tree) { typedef typename TreeType::ElemType ElemType; - for (size_t i = 0; i < tree.NumDescendants(); i++) + for (size_t i = 0; i < tree.NumDescendants(); ++i) { arma::Col point = tree.Dataset().col(tree.Descendant(i)); @@ -178,7 +178,7 @@ void CheckDistance(TreeType& tree, TreeType* node = NULL) const arma::Col& point = tree. Dataset().col(j); ElemType maxDist = 0; ElemType minDist = std::numeric_limits::max(); - for (size_t i = 0; i < tree.NumDescendants(); i++) + for (size_t i = 0; i < tree.NumDescendants(); ++i) { ElemType dist = MetricType::Evaluate( tree.Dataset().col(tree.Descendant(i)), @@ -215,7 +215,7 @@ void CheckDistance(TreeType& tree, TreeType* node = NULL) { ElemType maxDist = 0; ElemType minDist = std::numeric_limits::max(); - for (size_t i = 0; i < tree.NumDescendants(); i++) + for (size_t i = 0; i < tree.NumDescendants(); ++i) for (size_t j = 0; j < node->NumDescendants(); j++) { ElemType dist = MetricType::Evaluate( @@ -292,7 +292,7 @@ BOOST_AUTO_TEST_CASE(UBTreeTest) BOOST_REQUIRE_EQUAL(root.NumDescendants(), size); // Check the forward and backward mappings for correctness. - for (size_t i = 0; i < size; i++) + for (size_t i = 0; i < size; ++i) { for (size_t j = 0; j < dimensions; j++) { @@ -323,7 +323,7 @@ BOOST_AUTO_TEST_CASE(SingleTreeTraverserTest) knn2.Search(5, neighbors2, distances2); - for (size_t i = 0; i < neighbors1.size(); i++) + for (size_t i = 0; i < neighbors1.size(); ++i) { BOOST_REQUIRE_EQUAL(neighbors1[i], neighbors2[i]); BOOST_REQUIRE_EQUAL(distances1[i], distances2[i]); @@ -350,7 +350,7 @@ BOOST_AUTO_TEST_CASE(DualTreeTraverserTest) knn2.Search(5, neighbors2, distances2); - for (size_t i = 0; i < neighbors1.size(); i++) + for (size_t i = 0; i < neighbors1.size(); ++i) { BOOST_REQUIRE_EQUAL(neighbors1[i], neighbors2[i]); BOOST_REQUIRE_EQUAL(distances1[i], distances2[i]); diff --git a/src/mlpack/tests/union_find_test.cpp b/src/mlpack/tests/union_find_test.cpp index 51815301c1..3544fcb7ce 100644 --- a/src/mlpack/tests/union_find_test.cpp +++ b/src/mlpack/tests/union_find_test.cpp @@ -25,7 +25,7 @@ BOOST_AUTO_TEST_CASE(TestFind) static const size_t testSize = 10; UnionFind testUnionFind(testSize); - for (size_t i = 0; i < testSize; i++) + for (size_t i = 0; i < testSize; ++i) BOOST_REQUIRE(testUnionFind.Find(i) == i); testUnionFind.Union(0, 1); diff --git a/src/mlpack/tests/vantage_point_tree_test.cpp b/src/mlpack/tests/vantage_point_tree_test.cpp index 5ff0abd197..c4f2c6b874 100644 --- a/src/mlpack/tests/vantage_point_tree_test.cpp +++ b/src/mlpack/tests/vantage_point_tree_test.cpp @@ -139,7 +139,7 @@ void CheckBound(TreeType& tree) if (tree.IsLeaf()) { // Ensure that the bound contains all descendant points. - for (size_t i = 0; i < tree.NumPoints(); i++) + for (size_t i = 0; i < tree.NumPoints(); ++i) { ElemType dist = tree.Bound().Metric().Evaluate(tree.Bound().Center(), tree.Dataset().col(tree.Point(i))); @@ -157,7 +157,7 @@ void CheckBound(TreeType& tree) else { // Ensure that the bound contains all descendant points. - for (size_t i = 0; i < tree.NumDescendants(); i++) + for (size_t i = 0; i < tree.NumDescendants(); ++i) { ElemType dist = tree.Bound().Metric().Evaluate(tree.Bound().Center(), tree.Dataset().col(tree.Descendant(i))); @@ -220,7 +220,7 @@ BOOST_AUTO_TEST_CASE(VPTreeTest) BOOST_REQUIRE_EQUAL(root.NumDescendants(), size); // Check the forward and backward mappings for correctness. - for (size_t i = 0; i < size; i++) + for (size_t i = 0; i < size; ++i) { for (size_t j = 0; j < dimensions; j++) { @@ -251,7 +251,7 @@ BOOST_AUTO_TEST_CASE(SingleTreeTraverserTest) knn2.Search(5, neighbors2, distances2); - for (size_t i = 0; i < neighbors1.size(); i++) + for (size_t i = 0; i < neighbors1.size(); ++i) { BOOST_REQUIRE_EQUAL(neighbors1[i], neighbors2[i]); BOOST_REQUIRE_EQUAL(distances1[i], distances2[i]); @@ -278,7 +278,7 @@ BOOST_AUTO_TEST_CASE(DualTreeTraverserTest) knn2.Search(5, neighbors2, distances2); - for (size_t i = 0; i < neighbors1.size(); i++) + for (size_t i = 0; i < neighbors1.size(); ++i) { BOOST_REQUIRE_EQUAL(neighbors1[i], neighbors2[i]); BOOST_REQUIRE_EQUAL(distances1[i], distances2[i]); diff --git a/src/mlpack/tests/wgan_test.cpp b/src/mlpack/tests/wgan_test.cpp index 8ad8611992..70f78dcc71 100644 --- a/src/mlpack/tests/wgan_test.cpp +++ b/src/mlpack/tests/wgan_test.cpp @@ -139,7 +139,7 @@ BOOST_AUTO_TEST_CASE(WGANMNISTTest) size_t dim = std::sqrt(trainData.n_rows); arma::mat generatedData(2 * dim, dim * numSamples); - for (size_t i = 0; i < numSamples; i++) + for (size_t i = 0; i < numSamples; ++i) { arma::mat samples; noise.imbue( [&]() { return noiseFunction(); } ); @@ -301,7 +301,7 @@ BOOST_AUTO_TEST_CASE(WGANGPMNISTTest) size_t dim = std::sqrt(trainData.n_rows); arma::mat generatedData(2 * dim, dim * numSamples); - for (size_t i = 0; i < numSamples; i++) + for (size_t i = 0; i < numSamples; ++i) { arma::mat samples; noise.imbue( [&]() { return noiseFunction(); } ); From d5e6ece336797b66a7170af3157ac82559a41e76 Mon Sep 17 00:00:00 2001 From: Omar Shrit Date: Fri, 29 May 2020 12:53:20 +0200 Subject: [PATCH 02/16] j++ into ++j and k++ into ++k Signed-off-by: Omar Shrit --- .../detail/bernoulli_details.hpp | 2 +- src/mlpack/core/math/columns_to_blocks.cpp | 2 +- src/mlpack/core/math/lin_alg.cpp | 8 ++--- src/mlpack/core/tree/address.hpp | 4 +-- .../rp_tree_max_split_impl.hpp | 2 +- .../rp_tree_mean_split_impl.hpp | 6 ++-- .../binary_space_tree/ub_tree_split_impl.hpp | 2 +- .../vantage_point_split_impl.hpp | 2 +- src/mlpack/core/tree/cellbound_impl.hpp | 18 +++++----- .../core/tree/cosine_tree/cosine_tree.cpp | 6 ++-- src/mlpack/core/tree/hrectbound_impl.hpp | 6 ++-- .../discrete_hilbert_value_impl.hpp | 6 ++-- .../dual_tree_traverser_impl.hpp | 2 +- .../hilbert_r_tree_split_impl.hpp | 8 ++--- .../minimal_splits_number_sweep_impl.hpp | 2 +- ...s_plus_tree_auxiliary_information_impl.hpp | 2 +- .../r_plus_tree_descent_heuristic_impl.hpp | 4 +-- .../rectangle_tree/r_plus_tree_split_impl.hpp | 2 +- .../r_star_tree_descent_heuristic_impl.hpp | 8 ++--- .../rectangle_tree/r_star_tree_split_impl.hpp | 8 ++--- .../r_tree_descent_heuristic_impl.hpp | 4 +-- .../tree/rectangle_tree/r_tree_split_impl.hpp | 14 ++++---- .../rectangle_tree/rectangle_tree_impl.hpp | 14 ++++---- .../tree/rectangle_tree/x_tree_split_impl.hpp | 12 +++---- src/mlpack/methods/adaboost/adaboost_impl.hpp | 10 +++--- .../simple_tolerance_termination.hpp | 2 +- .../methods/amf/update_rules/nmf_mult_div.hpp | 2 +- .../amf/update_rules/svd_batch_learning.hpp | 4 +-- .../ann/layer/bilinear_interpolation_impl.hpp | 8 ++--- .../ann/layer/concat_performance_impl.hpp | 2 +- src/mlpack/methods/ann/layer/glimpse.hpp | 4 +-- src/mlpack/methods/ann/layer/glimpse_impl.hpp | 2 +- .../layer/minibatch_discrimination_impl.hpp | 4 +-- src/mlpack/methods/ann/rbm/rbm_impl.hpp | 2 +- .../methods/ann/rbm/spike_slab_rbm_impl.hpp | 4 +-- .../orthogonal_regularizer_impl.hpp | 2 +- .../regression_interpolation.hpp | 2 +- .../decision_stump/decision_stump_impl.hpp | 8 ++--- src/mlpack/methods/det/dt_utils_impl.hpp | 2 +- src/mlpack/methods/fastmks/fastmks_impl.hpp | 4 +-- .../methods/fastmks/fastmks_rules_impl.hpp | 2 +- src/mlpack/methods/gmm/diagonal_gmm.cpp | 2 +- src/mlpack/methods/gmm/gmm.cpp | 2 +- src/mlpack/methods/hmm/hmm_impl.hpp | 6 ++-- src/mlpack/methods/kmeans/kmeans_impl.hpp | 2 +- .../kmeans/max_variance_new_cluster_impl.hpp | 2 +- .../methods/kmeans/naive_kmeans_impl.hpp | 2 +- src/mlpack/methods/lars/lars.cpp | 4 +-- src/mlpack/methods/lmnn/constraints_impl.hpp | 16 ++++----- .../methods/lmnn/lmnn_function_impl.hpp | 12 +++---- src/mlpack/methods/lmnn/lmnn_main.cpp | 2 +- src/mlpack/methods/lsh/lsh_search_impl.hpp | 6 ++-- .../nca/nca_softmax_error_function_impl.hpp | 4 +-- .../neighbor_search/neighbor_search_impl.hpp | 6 ++-- .../neighbor_search_rules_impl.hpp | 2 +- .../methods/perceptron/perceptron_impl.hpp | 2 +- src/mlpack/methods/radical/radical.cpp | 2 +- .../range_search/range_search_impl.hpp | 8 ++--- src/mlpack/methods/rann/ra_search_impl.hpp | 6 ++-- .../methods/rann/ra_search_rules_impl.hpp | 12 +++---- src/mlpack/methods/rann/ra_util.cpp | 2 +- .../softmax_regression/softmax_regression.cpp | 4 +-- .../methods/sparse_coding/sparse_coding.cpp | 2 +- src/mlpack/tests/bias_svd_test.cpp | 6 ++-- src/mlpack/tests/cosine_tree_test.cpp | 10 +++--- src/mlpack/tests/distribution_test.cpp | 12 +++---- src/mlpack/tests/gmm_test.cpp | 2 +- src/mlpack/tests/hmm_test.cpp | 12 +++---- src/mlpack/tests/init_rules_test.cpp | 6 ++-- src/mlpack/tests/kmeans_test.cpp | 2 +- src/mlpack/tests/krann_search_test.cpp | 4 +-- src/mlpack/tests/lars_test.cpp | 2 +- src/mlpack/tests/lin_alg_test.cpp | 6 ++-- src/mlpack/tests/lmnn_test.cpp | 2 +- .../tests/local_coordinate_coding_test.cpp | 4 +-- .../tests/main_tests/gmm_train_test.cpp | 4 +-- .../tests/main_tests/hmm_train_test.cpp | 6 ++-- .../tests/main_tests/range_search_utils.hpp | 4 +-- src/mlpack/tests/nbc_test.cpp | 8 ++--- src/mlpack/tests/range_search_test.cpp | 8 ++--- src/mlpack/tests/rectangle_tree_test.cpp | 24 ++++++------- src/mlpack/tests/recurrent_network_test.cpp | 14 ++++---- src/mlpack/tests/regularized_svd_test.cpp | 6 ++-- src/mlpack/tests/softmax_regression_test.cpp | 4 +-- src/mlpack/tests/sparse_autoencoder_test.cpp | 6 ++-- src/mlpack/tests/sparse_coding_test.cpp | 2 +- src/mlpack/tests/string_encoding_test.cpp | 2 +- src/mlpack/tests/svdplusplus_test.cpp | 6 ++-- src/mlpack/tests/tree_test.cpp | 36 +++++++++---------- src/mlpack/tests/ub_tree_test.cpp | 12 +++---- src/mlpack/tests/vantage_point_tree_test.cpp | 2 +- 91 files changed, 263 insertions(+), 263 deletions(-) diff --git a/src/mlpack/core/boost_backport/detail/bernoulli_details.hpp b/src/mlpack/core/boost_backport/detail/bernoulli_details.hpp index f4bb51896d..b4838ec4cc 100644 --- a/src/mlpack/core/boost_backport/detail/bernoulli_details.hpp +++ b/src/mlpack/core/boost_backport/detail/bernoulli_details.hpp @@ -317,7 +317,7 @@ public: break; } m_intermediates[1] = m_intermediates[1] * (i-1); - for(std::size_t j = 2; j <= i; j++) + for(std::size_t j = 2; j <= i; ++j) { overflow_check = (i >= min_overflow_index) && ( diff --git a/src/mlpack/core/math/columns_to_blocks.cpp b/src/mlpack/core/math/columns_to_blocks.cpp index 4cdab32668..eeb4469886 100644 --- a/src/mlpack/core/math/columns_to_blocks.cpp +++ b/src/mlpack/core/math/columns_to_blocks.cpp @@ -77,7 +77,7 @@ void ColumnsToBlocks::Transform(const arma::mat& maximalInputs, const size_t maxCol = j * colOffset + blockWidth; output.submat(minRow, minCol, maxRow, maxCol) = - arma::reshape(maximalInputs.col(k++), blockHeight, blockWidth); + arma::reshape(maximalInputs.col(++k), blockHeight, blockWidth); if (k >= maxSize) break; diff --git a/src/mlpack/core/math/lin_alg.cpp b/src/mlpack/core/math/lin_alg.cpp index 660a1d7c43..f92a3c31e4 100644 --- a/src/mlpack/core/math/lin_alg.cpp +++ b/src/mlpack/core/math/lin_alg.cpp @@ -199,7 +199,7 @@ void mlpack::math::Svec(const arma::mat& input, arma::vec& output) size_t idx = 0; for (size_t i = 0; i < n; ++i) { - for (size_t j = i; j < n; j++) + for (size_t j = i; j < n; ++j) { if (i == j) output(idx++) = input(i, j); @@ -240,7 +240,7 @@ void mlpack::math::Smat(const arma::vec& input, arma::mat& output) size_t idx = 0; for (size_t i = 0; i < n; ++i) { - for (size_t j = i; j < n; j++) + for (size_t j = i; j < n; ++j) { if (i == j) output(i, j) = input(idx++); @@ -261,9 +261,9 @@ void mlpack::math::SymKronId(const arma::mat& A, arma::mat& op) size_t idx = 0; for (size_t i = 0; i < n; ++i) { - for (size_t j = i; j < n; j++) + for (size_t j = i; j < n; ++j) { - for (size_t k = 0; k < n; k++) + for (size_t k = 0; k < n; ++k) { op(idx, SvecIndex(k, j, n)) += ((k == j) ? 1. : M_SQRT1_2) * A(i, k); diff --git a/src/mlpack/core/tree/address.hpp b/src/mlpack/core/tree/address.hpp index bbb9c860c6..d5b72ad30e 100644 --- a/src/mlpack/core/tree/address.hpp +++ b/src/mlpack/core/tree/address.hpp @@ -129,7 +129,7 @@ void PointToAddress(AddressType& address, const VecType& point) // 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++) + for (size_t j = 0; j < point.n_elem; ++j) { size_t bit = (i * point.n_elem + j) % order; size_t row = (i * point.n_elem + j) / order; @@ -177,7 +177,7 @@ void AddressToPoint(VecType& point, const AddressType& address) const int numMantBits = order - numExpBits - 1; for (size_t i = 0; i < order; ++i) - for (size_t j = 0; j < address.n_elem; j++) + for (size_t j = 0; j < address.n_elem; ++j) { size_t bit = (i * address.n_elem + j) % order; size_t row = (i * address.n_elem + j) / order; diff --git a/src/mlpack/core/tree/binary_space_tree/rp_tree_max_split_impl.hpp b/src/mlpack/core/tree/binary_space_tree/rp_tree_max_split_impl.hpp index 6ccd932c59..ef24c04bbc 100644 --- a/src/mlpack/core/tree/binary_space_tree/rp_tree_max_split_impl.hpp +++ b/src/mlpack/core/tree/binary_space_tree/rp_tree_max_split_impl.hpp @@ -54,7 +54,7 @@ bool RPTreeMaxSplit::GetSplitVal( arma::Col values(samples.n_elem); // Find the median of scalar products of the samples and the normal vector. - for (size_t k = 0; k < samples.n_elem; k++) + for (size_t k = 0; k < samples.n_elem; ++k) values[k] = arma::dot(data.col(samples[k]), direction); const ElemType maximum = arma::max(values); diff --git a/src/mlpack/core/tree/binary_space_tree/rp_tree_mean_split_impl.hpp b/src/mlpack/core/tree/binary_space_tree/rp_tree_mean_split_impl.hpp index 8f7bcbc918..fbb4c3a06b 100644 --- a/src/mlpack/core/tree/binary_space_tree/rp_tree_mean_split_impl.hpp +++ b/src/mlpack/core/tree/binary_space_tree/rp_tree_mean_split_impl.hpp @@ -71,7 +71,7 @@ GetAveragePointDistance( ElemType dist = 0; for (size_t i = 0; i < samples.n_elem; ++i) - for (size_t j = i + 1; j < samples.n_elem; j++) + for (size_t j = i + 1; j < samples.n_elem; ++j) dist += metric::SquaredEuclideanDistance::Evaluate(data.col(samples[i]), data.col(samples[j])); @@ -89,7 +89,7 @@ bool RPTreeMeanSplit::GetDotMedian( { arma::Col values(samples.n_elem); - for (size_t k = 0; k < samples.n_elem; k++) + for (size_t k = 0; k < samples.n_elem; ++k) values[k] = arma::dot(data.col(samples[k]), direction); const ElemType maximum = arma::max(values); @@ -118,7 +118,7 @@ bool RPTreeMeanSplit::GetMeanMedian( arma::Col tmp(data.n_rows); - for (size_t k = 0; k < samples.n_elem; k++) + for (size_t k = 0; k < samples.n_elem; ++k) { tmp = data.col(samples[k]); tmp -= mean; diff --git a/src/mlpack/core/tree/binary_space_tree/ub_tree_split_impl.hpp b/src/mlpack/core/tree/binary_space_tree/ub_tree_split_impl.hpp index aa4ddcb266..a00d037e3c 100644 --- a/src/mlpack/core/tree/binary_space_tree/ub_tree_split_impl.hpp +++ b/src/mlpack/core/tree/binary_space_tree/ub_tree_split_impl.hpp @@ -132,7 +132,7 @@ bool UBTreeSplit::SplitNode(BoundType& bound, } // Set the minimum and the maximum addresses. - for (size_t k = 0; k < bound.Dim(); k++) + for (size_t k = 0; k < bound.Dim(); ++k) { bound.LoAddress()[k] = addresses[begin].first[k]; bound.HiAddress()[k] = addresses[begin + count - 1].first[k]; diff --git a/src/mlpack/core/tree/binary_space_tree/vantage_point_split_impl.hpp b/src/mlpack/core/tree/binary_space_tree/vantage_point_split_impl.hpp index 1d04659655..e16558879a 100644 --- a/src/mlpack/core/tree/binary_space_tree/vantage_point_split_impl.hpp +++ b/src/mlpack/core/tree/binary_space_tree/vantage_point_split_impl.hpp @@ -64,7 +64,7 @@ SelectVantagePoint(const MetricType& metric, const MatType& data, // candidate using these random samples. distances.set_size(samples.n_elem); - for (size_t j = 0; j < samples.n_elem; j++) + for (size_t j = 0; j < samples.n_elem; ++j) distances[j] = metric.Evaluate(data.col(vantagePointCandidates[i]), data.col(samples[j])); diff --git a/src/mlpack/core/tree/cellbound_impl.hpp b/src/mlpack/core/tree/cellbound_impl.hpp index 165701d46b..9842b3a1a7 100644 --- a/src/mlpack/core/tree/cellbound_impl.hpp +++ b/src/mlpack/core/tree/cellbound_impl.hpp @@ -51,7 +51,7 @@ inline CellBound::CellBound(const size_t dimension) : hiAddress(dim), minWidth(0) { - for (size_t k = 0; k < dim ; k++) + for (size_t k = 0; k < dim ; ++k) { loAddress[k] = std::numeric_limits::max(); hiAddress[k] = 0; @@ -147,7 +147,7 @@ inline CellBound::~CellBound() template inline void CellBound::Clear() { - for (size_t k = 0; k < dim; k++) + for (size_t k = 0; k < dim; ++k) { bounds[k] = math::RangeType(); @@ -187,7 +187,7 @@ void CellBound::AddBound( assert(loCorner.n_elem == dim); assert(hiCorner.n_elem == dim); - for (size_t k = 0; k < dim; k++) + for (size_t k = 0; k < dim; ++k) { loBound(k, numBounds) = std::numeric_limits::max(); hiBound(k, numBounds) = std::numeric_limits::lowest(); @@ -197,7 +197,7 @@ void CellBound::AddBound( { size_t k = 0; // Check if the point is contained in the hyperrectangle. - for (k = 0; k < dim; k++) + for (k = 0; k < dim; ++k) if (data(k, i) < loCorner[k] || data(k, i) > hiCorner[k]) break; @@ -205,14 +205,14 @@ void CellBound::AddBound( continue; // The point is not contained in the hyperrectangle. // Shrink the bound. - for (k = 0; k < dim; k++) + for (k = 0; k < dim; ++k) { loBound(k, numBounds) = std::min(loBound(k, numBounds), data(k, i)); hiBound(k, numBounds) = std::max(hiBound(k, numBounds), data(k, i)); } } - for (size_t k = 0; k < dim; k++) + for (size_t k = 0; k < dim; ++k) if (loBound(k, numBounds) > hiBound(k, numBounds)) return; // The hyperrectangle does not contain points. @@ -550,7 +550,7 @@ ElemType CellBound::MinDistance(const CellBound& other) ElemType lower, higher; for (size_t i = 0; i < numBounds; ++i) - for (size_t j = 0; j < other.numBounds; j++) + for (size_t j = 0; j < other.numBounds; ++j) { ElemType sum = 0; for (size_t d = 0; d < dim; d++) @@ -664,7 +664,7 @@ inline ElemType CellBound::MaxDistance( ElemType v; for (size_t i = 0; i < numBounds; ++i) - for (size_t j = 0; j < other.numBounds; j++) + for (size_t j = 0; j < other.numBounds; ++j) { ElemType sum = 0; for (size_t d = 0; d < dim; d++) @@ -715,7 +715,7 @@ CellBound::RangeDistance( ElemType v1, v2, vLo, vHi; for (size_t i = 0; i < numBounds; ++i) - for (size_t j = 0; j < other.numBounds; j++) + for (size_t j = 0; j < other.numBounds; ++j) { ElemType loSum = 0; ElemType hiSum = 0; diff --git a/src/mlpack/core/tree/cosine_tree/cosine_tree.cpp b/src/mlpack/core/tree/cosine_tree/cosine_tree.cpp index 39f6a1e958..6865eca93a 100644 --- a/src/mlpack/core/tree/cosine_tree/cosine_tree.cpp +++ b/src/mlpack/core/tree/cosine_tree/cosine_tree.cpp @@ -441,7 +441,7 @@ double CosineTree::MonteCarloError(CosineTree* node, size_t k = 0; // Compute the projection of the sampled vector onto the existing subspace. - for ( ; j != treeQueue.end(); j++, k++) + for ( ; j != treeQueue.end(); ++j, ++k) { currentNode = *j; @@ -451,7 +451,7 @@ double CosineTree::MonteCarloError(CosineTree* node, // If two additional vectors are passed, take their projections. if (addBasisVector1 && addBasisVector2) { - projection(k++) = arma::dot(dataset.col(sampledIndices[i]), + projection(++k) = arma::dot(dataset.col(sampledIndices[i]), *addBasisVector1); projection(k) = arma::dot(dataset.col(sampledIndices[i]), *addBasisVector2); @@ -497,7 +497,7 @@ void CosineTree::ConstructBasis(CosineNodeQueue& treeQueue) // Transfer basis vectors from the queue to the basis matrix. size_t j = 0; - for ( ; i != treeQueue.end(); ++i, j++) + for ( ; i != treeQueue.end(); ++i, ++j) { currentNode = *i; basis.col(j) = currentNode->BasisVector(); diff --git a/src/mlpack/core/tree/hrectbound_impl.hpp b/src/mlpack/core/tree/hrectbound_impl.hpp index adcdb4a384..7c10c00159 100644 --- a/src/mlpack/core/tree/hrectbound_impl.hpp +++ b/src/mlpack/core/tree/hrectbound_impl.hpp @@ -594,7 +594,7 @@ HRectBound::operator&(const HRectBound& bound) const { HRectBound result(dim); - for (size_t k = 0; k < dim; k++) + for (size_t k = 0; k < dim; ++k) { result[k].Lo() = std::max(bounds[k].Lo(), bound.bounds[k].Lo()); result[k].Hi() = std::min(bounds[k].Hi(), bound.bounds[k].Hi()); @@ -609,7 +609,7 @@ template inline HRectBound& HRectBound::operator&=(const HRectBound& bound) { - for (size_t k = 0; k < dim; k++) + for (size_t k = 0; k < dim; ++k) { bounds[k].Lo() = std::max(bounds[k].Lo(), bound.bounds[k].Lo()); bounds[k].Hi() = std::min(bounds[k].Hi(), bound.bounds[k].Hi()); @@ -626,7 +626,7 @@ inline ElemType HRectBound::Overlap( { ElemType volume = 1.0; - for (size_t k = 0; k < dim; k++) + for (size_t k = 0; k < dim; ++k) { ElemType lo = std::max(bounds[k].Lo(), bound.bounds[k].Lo()); ElemType hi = std::min(bounds[k].Hi(), bound.bounds[k].Hi()); diff --git a/src/mlpack/core/tree/rectangle_tree/discrete_hilbert_value_impl.hpp b/src/mlpack/core/tree/rectangle_tree/discrete_hilbert_value_impl.hpp index c261746faa..b8b90881d3 100644 --- a/src/mlpack/core/tree/rectangle_tree/discrete_hilbert_value_impl.hpp +++ b/src/mlpack/core/tree/rectangle_tree/discrete_hilbert_value_impl.hpp @@ -247,7 +247,7 @@ CalculateValue(const VecType& pt, arma::Col rearrangedResult(pt.n_rows, arma::fill::zeros); for (size_t i = 0; i < order; ++i) - for (size_t j = 0; j < pt.n_rows; j++) + for (size_t j = 0; j < pt.n_rows; ++j) { size_t bit = (i * pt.n_rows + j) % order; size_t row = (i * pt.n_rows + j) / order; @@ -485,7 +485,7 @@ void DiscreteHilbertValue::RedistributeHilbertValues( DiscreteHilbertValue &value = parent->Child(i).AuxiliaryInfo().HilbertValue(); - for (size_t j = 0; j < value.NumValues(); j++) + for (size_t j = 0; j < value.NumValues(); ++j) { tmp.col(iPoint) = value.LocalHilbertValues()->col(j); iPoint++; @@ -501,7 +501,7 @@ void DiscreteHilbertValue::RedistributeHilbertValues( DiscreteHilbertValue &value = parent->Child(i).AuxiliaryInfo().HilbertValue(); - for (size_t j = 0; j < parent->Child(i).NumPoints(); j++) + for (size_t j = 0; j < parent->Child(i).NumPoints(); ++j) { value.LocalHilbertValues()->col(j) = tmp.col(iPoint); iPoint++; diff --git a/src/mlpack/core/tree/rectangle_tree/dual_tree_traverser_impl.hpp b/src/mlpack/core/tree/rectangle_tree/dual_tree_traverser_impl.hpp index f6569890d6..e625cbcae1 100644 --- a/src/mlpack/core/tree/rectangle_tree/dual_tree_traverser_impl.hpp +++ b/src/mlpack/core/tree/rectangle_tree/dual_tree_traverser_impl.hpp @@ -136,7 +136,7 @@ DualTreeTraverser::Traverse(RectangleTree& queryNode, // We need to traverse down both the reference and the query trees. // We loop through all of the query nodes, and for each of them, we // loop through the reference nodes to see where we need to descend. - for (size_t j = 0; j < queryNode.NumChildren(); j++) + for (size_t j = 0; j < queryNode.NumChildren(); ++j) { // We sort the children of the reference node by their scores. std::vector nodesAndScores(referenceNode.NumChildren()); diff --git a/src/mlpack/core/tree/rectangle_tree/hilbert_r_tree_split_impl.hpp b/src/mlpack/core/tree/rectangle_tree/hilbert_r_tree_split_impl.hpp index 5ad4c666ed..a558fc22c5 100644 --- a/src/mlpack/core/tree/rectangle_tree/hilbert_r_tree_split_impl.hpp +++ b/src/mlpack/core/tree/rectangle_tree/hilbert_r_tree_split_impl.hpp @@ -230,7 +230,7 @@ RedistributeNodesEvenly(const TreeType *parent, size_t iChild = 0; for (size_t i = firstSibling; i <= lastSibling; ++i) { - for (size_t j = 0; j < parent->Child(i).NumChildren(); j++) + for (size_t j = 0; j < parent->Child(i).NumChildren(); ++j) { children[iChild] = parent->Child(i).children[j]; iChild++; @@ -245,7 +245,7 @@ RedistributeNodesEvenly(const TreeType *parent, parent->Child(i).Bound().Clear(); parent->Child(i).numDescendants = 0; - for (size_t j = 0; j < numChildrenPerNode; j++) + for (size_t j = 0; j < numChildrenPerNode; ++j) { parent->Child(i).Bound() |= children[iChild]->Bound(); parent->Child(i).numDescendants += children[iChild]->numDescendants; @@ -298,7 +298,7 @@ RedistributePointsEvenly(TreeType* parent, size_t iPoint = 0; for (size_t i = firstSibling; i <= lastSibling; ++i) { - for (size_t j = 0; j < parent->Child(i).NumPoints(); j++) + for (size_t j = 0; j < parent->Child(i).NumPoints(); ++j) points[iPoint++] = parent->Child(i).Point(j); } @@ -310,7 +310,7 @@ RedistributePointsEvenly(TreeType* parent, parent->Child(i).Bound().Clear(); size_t j; - for (j = 0; j < numPointsPerNode; j++) + for (j = 0; j < numPointsPerNode; ++j) { parent->Child(i).Bound() |= parent->Dataset().col(points[iPoint]); parent->Child(i).Point(j) = points[iPoint]; diff --git a/src/mlpack/core/tree/rectangle_tree/minimal_splits_number_sweep_impl.hpp b/src/mlpack/core/tree/rectangle_tree/minimal_splits_number_sweep_impl.hpp index 1d628699dc..63f96d8b1a 100644 --- a/src/mlpack/core/tree/rectangle_tree/minimal_splits_number_sweep_impl.hpp +++ b/src/mlpack/core/tree/rectangle_tree/minimal_splits_number_sweep_impl.hpp @@ -53,7 +53,7 @@ size_t MinimalSplitsNumberSweep::SweepNonLeafNode( size_t numSplits = 0; // Calculate the number of splits. - for (size_t j = 0; j < node->NumChildren(); j++) + for (size_t j = 0; j < node->NumChildren(); ++j) { const TreeType& child = node->Child(j); int policy = SplitPolicy::GetSplitPolicy(child, axis, sorted[i].first); diff --git a/src/mlpack/core/tree/rectangle_tree/r_plus_plus_tree_auxiliary_information_impl.hpp b/src/mlpack/core/tree/rectangle_tree/r_plus_plus_tree_auxiliary_information_impl.hpp index e1e9659559..214fe9f379 100644 --- a/src/mlpack/core/tree/rectangle_tree/r_plus_plus_tree_auxiliary_information_impl.hpp +++ b/src/mlpack/core/tree/rectangle_tree/r_plus_plus_tree_auxiliary_information_impl.hpp @@ -35,7 +35,7 @@ RPlusPlusTreeAuxiliaryInformation(const TreeType* tree) : // Initialize the maximum bounding rectangle if the node is the root if (!tree->Parent()) { - for (size_t k = 0; k < outerBound.Dim(); k++) + for (size_t k = 0; k < outerBound.Dim(); ++k) { outerBound[k].Lo() = std::numeric_limits::lowest(); outerBound[k].Hi() = std::numeric_limits::max(); diff --git a/src/mlpack/core/tree/rectangle_tree/r_plus_tree_descent_heuristic_impl.hpp b/src/mlpack/core/tree/rectangle_tree/r_plus_tree_descent_heuristic_impl.hpp index fd27a270ca..b88e320023 100644 --- a/src/mlpack/core/tree/rectangle_tree/r_plus_tree_descent_heuristic_impl.hpp +++ b/src/mlpack/core/tree/rectangle_tree/r_plus_tree_descent_heuristic_impl.hpp @@ -45,14 +45,14 @@ size_t RPlusTreeDescentHeuristic::ChooseDescentNode(TreeType* node, success = true; - for (size_t j = 0; j < node->NumChildren(); j++) + for (size_t j = 0; j < node->NumChildren(); ++j) { if (j == bestIndex) continue; success = false; // Two nodes overlap if and only if there are no dimension in which // they do not overlap each other. - for (size_t k = 0; k < node->Bound().Dim(); k++) + for (size_t k = 0; k < node->Bound().Dim(); ++k) { if (bound[k].Lo() >= node->Child(j).Bound()[k].Hi() || node->Child(j).Bound()[k].Lo() >= bound[k].Hi()) diff --git a/src/mlpack/core/tree/rectangle_tree/r_plus_tree_split_impl.hpp b/src/mlpack/core/tree/rectangle_tree/r_plus_tree_split_impl.hpp index e8f6119c3c..0f7bcbf8ab 100644 --- a/src/mlpack/core/tree/rectangle_tree/r_plus_tree_split_impl.hpp +++ b/src/mlpack/core/tree/rectangle_tree/r_plus_tree_split_impl.hpp @@ -342,7 +342,7 @@ PartitionNode(const TreeType* node, size_t& minCutAxis, minCutAxis = node->Bound().Dim(); // Find the sweep with a minimal cost. - for (size_t k = 0; k < node->Bound().Dim(); k++) + for (size_t k = 0; k < node->Bound().Dim(); ++k) { typename TreeType::ElemType cut; SweepCostType cost; diff --git a/src/mlpack/core/tree/rectangle_tree/r_star_tree_descent_heuristic_impl.hpp b/src/mlpack/core/tree/rectangle_tree/r_star_tree_descent_heuristic_impl.hpp index a9725005f0..087c6b1ad2 100644 --- a/src/mlpack/core/tree/rectangle_tree/r_star_tree_descent_heuristic_impl.hpp +++ b/src/mlpack/core/tree/rectangle_tree/r_star_tree_descent_heuristic_impl.hpp @@ -38,13 +38,13 @@ inline size_t RStarTreeDescentHeuristic::ChooseDescentNode( for (size_t i = 0; i < node->NumChildren(); ++i) { ElemType sc = 0; - for (size_t j = 0; j < node->NumChildren(); j++) + for (size_t j = 0; j < node->NumChildren(); ++j) { if (j != i) { ElemType overlap = 1.0; ElemType newOverlap = 1.0; - for (size_t k = 0; k < node->Bound().Dim(); k++) + for (size_t k = 0; k < node->Bound().Dim(); ++k) { ElemType newHigh = std::max(node->Dataset().col(point)[k], node->Child(i).Bound()[k].Hi()); @@ -104,7 +104,7 @@ inline size_t RStarTreeDescentHeuristic::ChooseDescentNode( { ElemType v1 = 1.0; ElemType v2 = 1.0; - for (size_t j = 0; j < node->Bound().Dim(); j++) + for (size_t j = 0; j < node->Bound().Dim(); ++j) { v1 *= node->Child(i).Bound()[j].Width(); v2 *= node->Child(i).Bound()[j].Contains( @@ -177,7 +177,7 @@ inline size_t RStarTreeDescentHeuristic::ChooseDescentNode( { ElemType v1 = 1.0; ElemType v2 = 1.0; - for (size_t j = 0; j < node->Child(i).Bound().Dim(); j++) + for (size_t j = 0; j < node->Child(i).Bound().Dim(); ++j) { v1 *= node->Child(i).Bound()[j].Width(); v2 *= node->Child(i).Bound()[j].Contains(insertedNode->Bound()[j]) ? diff --git a/src/mlpack/core/tree/rectangle_tree/r_star_tree_split_impl.hpp b/src/mlpack/core/tree/rectangle_tree/r_star_tree_split_impl.hpp index 0a196dad09..f4d46dc128 100644 --- a/src/mlpack/core/tree/rectangle_tree/r_star_tree_split_impl.hpp +++ b/src/mlpack/core/tree/rectangle_tree/r_star_tree_split_impl.hpp @@ -94,7 +94,7 @@ void RStarTreeSplit::PickLeafSplit(TreeType* tree, /** * Check each dimension, to find which dimension is best to split on. */ - for (size_t j = 0; j < tree->Bound().Dim(); j++) + for (size_t j = 0; j < tree->Bound().Dim(); ++j) { ElemType axisScore = 0.0; @@ -130,7 +130,7 @@ void RStarTreeSplit::PickLeafSplit(TreeType* tree, areas[i] = bound1.Volume() + bound2.Volume(); overlaps[i] = bound1.Overlap(bound2); - for (size_t k = 0; k < bound1.Dim(); k++) + for (size_t k = 0; k < bound1.Dim(); ++k) margins[i] += bound1[k].Width() + bound2[k].Width(); axisScore += margins[i]; @@ -289,7 +289,7 @@ bool RStarTreeSplit::SplitNonLeafNode( /** * Check over each dimension to see which is best to use for splitting. */ - for (size_t j = 0; j < tree->Bound().Dim(); j++) + for (size_t j = 0; j < tree->Bound().Dim(); ++j) { ElemType axisLoScore = 0.0; ElemType axisHiScore = 0.0; @@ -347,7 +347,7 @@ bool RStarTreeSplit::SplitNonLeafNode( overlaps[2 * i + 1] = hb1.Overlap(hb2); // Now calculate margins for each. - for (size_t k = 0; k < lb1.Dim(); k++) + for (size_t k = 0; k < lb1.Dim(); ++k) { margins[2 * i] += lb1[k].Width() + lb2[k].Width(); margins[2 * i + 1] += hb1[k].Width() + hb2[k].Width(); diff --git a/src/mlpack/core/tree/rectangle_tree/r_tree_descent_heuristic_impl.hpp b/src/mlpack/core/tree/rectangle_tree/r_tree_descent_heuristic_impl.hpp index 47029f6716..6c1ca6f416 100644 --- a/src/mlpack/core/tree/rectangle_tree/r_tree_descent_heuristic_impl.hpp +++ b/src/mlpack/core/tree/rectangle_tree/r_tree_descent_heuristic_impl.hpp @@ -33,7 +33,7 @@ inline size_t RTreeDescentHeuristic::ChooseDescentNode(const TreeType* node, { ElemType v1 = 1.0; ElemType v2 = 1.0; - for (size_t j = 0; j < node->Child(i).Bound().Dim(); j++) + for (size_t j = 0; j < node->Child(i).Bound().Dim(); ++j) { v1 *= node->Child(i).Bound()[j].Width(); v2 *= node->Child(i).Bound()[j].Contains(node->Dataset().col(point)[j]) ? @@ -77,7 +77,7 @@ inline size_t RTreeDescentHeuristic::ChooseDescentNode( { ElemType v1 = 1.0; ElemType v2 = 1.0; - for (size_t j = 0; j < node->Child(i).Bound().Dim(); j++) + for (size_t j = 0; j < node->Child(i).Bound().Dim(); ++j) { v1 *= node->Child(i).Bound()[j].Width(); v2 *= node->Child(i).Bound()[j].Contains(insertedNode->Bound()[j]) ? diff --git a/src/mlpack/core/tree/rectangle_tree/r_tree_split_impl.hpp b/src/mlpack/core/tree/rectangle_tree/r_tree_split_impl.hpp index 8eda6ae1b0..0fe3cfde6e 100644 --- a/src/mlpack/core/tree/rectangle_tree/r_tree_split_impl.hpp +++ b/src/mlpack/core/tree/rectangle_tree/r_tree_split_impl.hpp @@ -172,7 +172,7 @@ void RTreeSplit::GetPointSeeds(const TreeType *tree, int& iRet, int& jRet) typename TreeType::ElemType worstPairScore = -1.0; for (size_t i = 0; i < tree->Count(); ++i) { - for (size_t j = i + 1; j < tree->Count(); j++) + for (size_t j = i + 1; j < tree->Count(); ++j) { const typename TreeType::ElemType score = arma::prod(arma::abs( tree->Dataset().col(tree->Point(i)) - @@ -201,10 +201,10 @@ void RTreeSplit::GetBoundSeeds(const TreeType *tree, int& iRet, int& jRet) ElemType worstPairScore = -1.0; for (size_t i = 0; i < tree->NumChildren(); ++i) { - for (size_t j = i + 1; j < tree->NumChildren(); j++) + for (size_t j = i + 1; j < tree->NumChildren(); ++j) { ElemType score = 1.0; - for (size_t k = 0; k < tree->Bound().Dim(); k++) + for (size_t k = 0; k < tree->Bound().Dim(); ++k) { const ElemType hiMax = std::max(tree->Child(i).Bound()[k].Hi(), tree->Child(j).Bound()[k].Hi()); @@ -375,7 +375,7 @@ void RTreeSplit::AssignNodeDestNode(TreeType* oldTree, assert(intI != intJ); for (size_t i = 0; i < oldTree->NumChildren(); ++i) - for (size_t j = i + 1; j < oldTree->NumChildren(); j++) + for (size_t j = i + 1; j < oldTree->NumChildren(); ++j) assert(oldTree->children[i] != oldTree->children[j]); InsertNodeIntoTree(treeOne, oldTree->children[intI]); @@ -398,7 +398,7 @@ void RTreeSplit::AssignNodeDestNode(TreeType* oldTree, assert(treeTwo->NumChildren() == 1); for (size_t i = 0; i < end; ++i) - for (size_t j = i + 1; j < end; j++) + for (size_t j = i + 1; j < end; ++j) assert(oldTree->children[i] != oldTree->children[j]); for (size_t i = 0; i < end; ++i) @@ -512,11 +512,11 @@ void RTreeSplit::AssignNodeDestNode(TreeType* oldTree, } for (size_t i = 0; i < treeOne->NumChildren(); ++i) - for (size_t j = i + 1; j < treeOne->NumChildren(); j++) + for (size_t j = i + 1; j < treeOne->NumChildren(); ++j) assert(treeOne->children[i] != treeOne->children[j]); for (size_t i = 0; i < treeTwo->NumChildren(); ++i) - for (size_t j = i + 1; j < treeTwo->NumChildren(); j++) + for (size_t j = i + 1; j < treeTwo->NumChildren(); ++j) assert(treeTwo->children[i] != treeTwo->children[j]); } diff --git a/src/mlpack/core/tree/rectangle_tree/rectangle_tree_impl.hpp b/src/mlpack/core/tree/rectangle_tree/rectangle_tree_impl.hpp index e0705a387c..e8aac1742c 100644 --- a/src/mlpack/core/tree/rectangle_tree/rectangle_tree_impl.hpp +++ b/src/mlpack/core/tree/rectangle_tree/rectangle_tree_impl.hpp @@ -703,7 +703,7 @@ bool RectangleTreeBound().Dim(); j++) + for (size_t j = 0; j < node->Bound().Dim(); ++j) contains &= Child(i).Bound()[j].Contains(node->Bound()[j]); if (contains) @@ -1125,7 +1125,7 @@ void RectangleTreeAuxiliaryInfo().UpdateAuxiliaryInfo(root); // Reinsert the points at the root node. - for (size_t j = 0; j < count; j++) + for (size_t j = 0; j < count; ++j) root->InsertPoint(points[j], relevels); // This will check the minFill of the parent. @@ -1144,7 +1144,7 @@ void RectangleTreeNumChildren(); j++) + for (size_t j = 0; j < parent->NumChildren(); ++j) { if (parent->children[j] == this) { @@ -1269,7 +1269,7 @@ bool RectangleTree::max(); - for (size_t j = 0; j < count; j++) + for (size_t j = 0; j < count; ++j) { if (dataset->col(points[j])[i] < min) min = dataset->col(points[j])[i]; @@ -1288,7 +1288,7 @@ bool RectangleTree::lowest(); - for (size_t j = 0; j < count; j++) + for (size_t j = 0; j < count; ++j) { if (dataset->col(points[j])[i] > max) max = dataset->col(points[j])[i]; @@ -1313,7 +1313,7 @@ bool RectangleTree::max(); - for (size_t j = 0; j < numChildren; j++) + for (size_t j = 0; j < numChildren; ++j) { if (children[j]->Bound()[i].Lo() < min) min = children[j]->Bound()[i].Lo(); @@ -1328,7 +1328,7 @@ bool RectangleTree::lowest(); - for (size_t j = 0; j < numChildren; j++) + for (size_t j = 0; j < numChildren; ++j) { if (children[j]->Bound()[i].Hi() > max) max = children[j]->Bound()[i].Hi(); diff --git a/src/mlpack/core/tree/rectangle_tree/x_tree_split_impl.hpp b/src/mlpack/core/tree/rectangle_tree/x_tree_split_impl.hpp index a4ff61c36b..2b7409d2ba 100644 --- a/src/mlpack/core/tree/rectangle_tree/x_tree_split_impl.hpp +++ b/src/mlpack/core/tree/rectangle_tree/x_tree_split_impl.hpp @@ -148,7 +148,7 @@ bool XTreeSplit::SplitNonLeafNode(TreeType *tree, std::vector& relevels) // See if we can use a new dimension. for (size_t i = lastDim + 1; i < axes.size(); ++i) { - for (size_t j = 0; j < tree->NumChildren(); j++) + for (size_t j = 0; j < tree->NumChildren(); ++j) axes[i] = axes[i] & tree->Child(j).AuxiliaryInfo().SplitHistory().history[i]; if (axes[i] == true) @@ -163,7 +163,7 @@ bool XTreeSplit::SplitNonLeafNode(TreeType *tree, std::vector& relevels) for (size_t i = 0; i < lastDim + 1; ++i) { axes[i] = true; - for (size_t j = 0; j < tree->NumChildren(); j++) + for (size_t j = 0; j < tree->NumChildren(); ++j) axes[i] = axes[i] & tree->Child(j).AuxiliaryInfo().SplitHistory().history[i]; if (axes[i] == true) @@ -190,7 +190,7 @@ bool XTreeSplit::SplitNonLeafNode(TreeType *tree, std::vector& relevels) ElemType overlapBestAreaAxis = 0; ElemType areaBestAreaAxis = 0; - for (size_t j = 0; j < tree->Bound().Dim(); j++) + for (size_t j = 0; j < tree->Bound().Dim(); ++j) { ElemType axisScore = 0.0; @@ -239,7 +239,7 @@ bool XTreeSplit::SplitNonLeafNode(TreeType *tree, std::vector& relevels) ElemType area2 = bound2.Volume(); ElemType oArea = bound1.Overlap(bound2); - for (size_t k = 0; k < bound1.Dim(); k++) + for (size_t k = 0; k < bound1.Dim(); ++k) margins[i] += bound1[k].Width() + bound2[k].Width(); areas[i] += area1 + area2; @@ -296,7 +296,7 @@ bool XTreeSplit::SplitNonLeafNode(TreeType *tree, std::vector& relevels) } // Now we do the same thing using Bound().Hi() and choose the best of the two. - for (size_t j = 0; j < tree->Bound().Dim(); j++) + for (size_t j = 0; j < tree->Bound().Dim(); ++j) { ElemType axisScore = 0.0; @@ -344,7 +344,7 @@ bool XTreeSplit::SplitNonLeafNode(TreeType *tree, std::vector& relevels) ElemType area2 = bound2.Volume(); ElemType oArea = bound1.Overlap(bound2); - for (size_t k = 0; k < bound1.Dim(); k++) + for (size_t k = 0; k < bound1.Dim(); ++k) margins[i] += bound1[k].Width() + bound2[k].Width(); diff --git a/src/mlpack/methods/adaboost/adaboost_impl.hpp b/src/mlpack/methods/adaboost/adaboost_impl.hpp index 14941fc523..c0bd1a318d 100644 --- a/src/mlpack/methods/adaboost/adaboost_impl.hpp +++ b/src/mlpack/methods/adaboost/adaboost_impl.hpp @@ -127,7 +127,7 @@ double AdaBoost::Train( // buildClassificationMatrix(ht, predictedLabels); // Now, calculate alpha(t) using ht. - for (size_t j = 0; j < D.n_cols; j++) // instead of D, ht + for (size_t j = 0; j < D.n_cols; ++j) // instead of D, ht { if (predictedLabels(j) == labels(j)) rt += arma::accu(D.col(j)); @@ -157,12 +157,12 @@ double AdaBoost::Train( wl.push_back(w); // Now start modifying the weights. - for (size_t j = 0; j < D.n_cols; j++) + for (size_t j = 0; j < D.n_cols; ++j) { const double expo = exp(alphat); if (predictedLabels(j) == labels(j)) { - for (size_t k = 0; k < D.n_rows; k++) + for (size_t k = 0; k < D.n_rows; ++k) { // We calculate zt, the normalization constant. D(k, j) /= expo; @@ -178,7 +178,7 @@ double AdaBoost::Train( } else { - for (size_t k = 0; k < D.n_rows; k++) + for (size_t k = 0; k < D.n_rows; ++k) { // We calculate zt, the normalization constant. D(k, j) *= expo; @@ -234,7 +234,7 @@ void AdaBoost::Classify( { wl[i].Classify(test, tempPredictedLabels); - for (size_t j = 0; j < tempPredictedLabels.n_cols; j++) + for (size_t j = 0; j < tempPredictedLabels.n_cols; ++j) probabilities(tempPredictedLabels(j), j) += alpha[i]; } diff --git a/src/mlpack/methods/amf/termination_policies/simple_tolerance_termination.hpp b/src/mlpack/methods/amf/termination_policies/simple_tolerance_termination.hpp index e19fece5b5..c156aee501 100644 --- a/src/mlpack/methods/amf/termination_policies/simple_tolerance_termination.hpp +++ b/src/mlpack/methods/amf/termination_policies/simple_tolerance_termination.hpp @@ -80,7 +80,7 @@ class SimpleToleranceTermination size_t count = 0; for (size_t i = 0; i < n; ++i) { - for (size_t j = 0; j < m; j++) + for (size_t j = 0; j < m; ++j) { double temp = 0; if ((temp = (*V)(i, j)) != 0) diff --git a/src/mlpack/methods/amf/update_rules/nmf_mult_div.hpp b/src/mlpack/methods/amf/update_rules/nmf_mult_div.hpp index ec40feda44..05601264c0 100644 --- a/src/mlpack/methods/amf/update_rules/nmf_mult_div.hpp +++ b/src/mlpack/methods/amf/update_rules/nmf_mult_div.hpp @@ -132,7 +132,7 @@ class NMFMultiplicativeDivergenceUpdate t1 = W * H; for (size_t i = 0; i < H.n_rows; ++i) { - for (size_t j = 0; j < H.n_cols; j++) + for (size_t j = 0; j < H.n_cols; ++j) { // Writing this as a single expression does not work as of Armadillo // 3.920. This should be fixed in a future release, and then the code diff --git a/src/mlpack/methods/amf/update_rules/svd_batch_learning.hpp b/src/mlpack/methods/amf/update_rules/svd_batch_learning.hpp index 5e1180c01d..0fd3fbccd5 100644 --- a/src/mlpack/methods/amf/update_rules/svd_batch_learning.hpp +++ b/src/mlpack/methods/amf/update_rules/svd_batch_learning.hpp @@ -102,7 +102,7 @@ class SVDBatchLearning deltaW.zeros(n, r); for (size_t i = 0; i < n; ++i) { - for (size_t j = 0; j < m; j++) + for (size_t j = 0; j < m; ++j) { const double val = V(i, j); if (val != 0) @@ -145,7 +145,7 @@ class SVDBatchLearning // Compute the step. arma::mat deltaH; deltaH.zeros(r, m); - for (size_t j = 0; j < m; j++) + for (size_t j = 0; j < m; ++j) { for (size_t i = 0; i < n; ++i) { diff --git a/src/mlpack/methods/ann/layer/bilinear_interpolation_impl.hpp b/src/mlpack/methods/ann/layer/bilinear_interpolation_impl.hpp index 3ee5ae2c39..24605486c8 100644 --- a/src/mlpack/methods/ann/layer/bilinear_interpolation_impl.hpp +++ b/src/mlpack/methods/ann/layer/bilinear_interpolation_impl.hpp @@ -87,7 +87,7 @@ void BilinearInterpolation::Forward( double deltaR = i * scaleRow - rOrigin; if (deltaR > 1) deltaR = 1.0; - for (size_t j = 0; j < outColSize; j++) + for (size_t j = 0; j < outColSize; ++j) { // Scaled distance of the interpolated point from the leftmost column. size_t cOrigin = (size_t) std::floor(j * scaleCol); @@ -102,7 +102,7 @@ void BilinearInterpolation::Forward( coeffs[2] = (1 - deltaR) * deltaC; coeffs[3] = deltaR * deltaC; - for (size_t k = 0; k < depth * batchSize; k++) + for (size_t k = 0; k < depth * batchSize; ++k) { outputAsCube(i, j, k) = arma::accu(inputAsCube.slice(k).submat( rOrigin, cOrigin, rOrigin + 1, cOrigin + 1) % coeffs); @@ -150,7 +150,7 @@ void BilinearInterpolation::Backward( if (rOrigin > outRowSize - 2) rOrigin = outRowSize - 2; double deltaR = i * scaleRow - rOrigin; - for (size_t j = 0; j < inColSize; j++) + for (size_t j = 0; j < inColSize; ++j) { size_t cOrigin = (size_t) std::floor(j * scaleCol); @@ -163,7 +163,7 @@ void BilinearInterpolation::Backward( coeffs[2] = (1 - deltaR) * deltaC; coeffs[3] = deltaR * deltaC; - for (size_t k = 0; k < depth * batchSize; k++) + for (size_t k = 0; k < depth * batchSize; ++k) { outputAsCube(i, j, k) = arma::accu(gradientAsCube.slice(k).submat( rOrigin, cOrigin, rOrigin + 1, cOrigin + 1) % coeffs); diff --git a/src/mlpack/methods/ann/layer/concat_performance_impl.hpp b/src/mlpack/methods/ann/layer/concat_performance_impl.hpp index 96894bc404..32eb5c081d 100644 --- a/src/mlpack/methods/ann/layer/concat_performance_impl.hpp +++ b/src/mlpack/methods/ann/layer/concat_performance_impl.hpp @@ -83,7 +83,7 @@ void ConcatPerformance< output = arma::zeros(subOutput.n_elem, inSize); output.col(0) = subOutput; - for (size_t i = elements, j = 0; i < input.n_elem; i+= elements, j++) + for (size_t i = elements, j = 0; i < input.n_elem; i+= elements, ++j) { subInput = input.submat(i, 0, i + elements - 1, 0); outputLayer.Backward(subInput, target, subOutput); diff --git a/src/mlpack/methods/ann/layer/glimpse.hpp b/src/mlpack/methods/ann/layer/glimpse.hpp index c2700e6c7a..9ecf3e12e7 100644 --- a/src/mlpack/methods/ann/layer/glimpse.hpp +++ b/src/mlpack/methods/ann/layer/glimpse.hpp @@ -198,9 +198,9 @@ class Glimpse { arma::mat t = w; - for (size_t i = 0, k = 0; i < w.n_elem; k++) + for (size_t i = 0, k = 0; i < w.n_elem; ++k) { - for (size_t j = 0; j < w.n_cols; j++, ++i) + for (size_t j = 0; j < w.n_cols; ++j, ++i) { w(k, j) = t(i); } diff --git a/src/mlpack/methods/ann/layer/glimpse_impl.hpp b/src/mlpack/methods/ann/layer/glimpse_impl.hpp index 10ab509f83..7e2c3710e7 100644 --- a/src/mlpack/methods/ann/layer/glimpse_impl.hpp +++ b/src/mlpack/methods/ann/layer/glimpse_impl.hpp @@ -138,7 +138,7 @@ void Glimpse::Backward( location = locationParameter.back(); locationParameter.pop_back(); - for (size_t s = 0, j = 0; s < mappedError.n_slices; s+= gy.n_cols, j++) + for (size_t s = 0, j = 0; s < mappedError.n_slices; s+= gy.n_cols, ++j) { for (size_t i = 0; i < gy.n_cols; ++i) { diff --git a/src/mlpack/methods/ann/layer/minibatch_discrimination_impl.hpp b/src/mlpack/methods/ann/layer/minibatch_discrimination_impl.hpp index 0601abe90b..8b27e3226b 100644 --- a/src/mlpack/methods/ann/layer/minibatch_discrimination_impl.hpp +++ b/src/mlpack/methods/ann/layer/minibatch_discrimination_impl.hpp @@ -63,7 +63,7 @@ void MiniBatchDiscrimination::Forward( for (size_t i = 0; i < M.n_slices; ++i) { output.col(i).ones(); - for (size_t j = 0; j < M.n_slices; j++) + for (size_t j = 0; j < M.n_slices; ++j) { if (j < i) { @@ -96,7 +96,7 @@ void MiniBatchDiscrimination::Backward( for (size_t i = 0; i < M.n_slices; ++i) { - for (size_t j = 0; j < M.n_slices; j++) + for (size_t j = 0; j < M.n_slices; ++j) { if (i == j) { diff --git a/src/mlpack/methods/ann/rbm/rbm_impl.hpp b/src/mlpack/methods/ann/rbm/rbm_impl.hpp index d03253a43a..0bbc1c337a 100644 --- a/src/mlpack/methods/ann/rbm/rbm_impl.hpp +++ b/src/mlpack/methods/ann/rbm/rbm_impl.hpp @@ -247,7 +247,7 @@ void RBM::Gibbs( SampleVisible(std::move(gibbsTemporary), std::move(output)); } - for (size_t j = 1; j < this->steps; j++) + for (size_t j = 1; j < this->steps; ++j) { SampleHidden(std::move(output), std::move(gibbsTemporary)); SampleVisible(std::move(gibbsTemporary), std::move(output)); diff --git a/src/mlpack/methods/ann/rbm/spike_slab_rbm_impl.hpp b/src/mlpack/methods/ann/rbm/spike_slab_rbm_impl.hpp index 9e268380c4..d1c9809b77 100644 --- a/src/mlpack/methods/ann/rbm/spike_slab_rbm_impl.hpp +++ b/src/mlpack/methods/ann/rbm/spike_slab_rbm_impl.hpp @@ -161,7 +161,7 @@ RBM::SampleVisible( VisibleMean(std::move(input), std::move(visibleMean)); output.set_size(visibleSize, 1); - for (k = 0; k < numMaxTrials; k++) + for (k = 0; k < numMaxTrials; ++k) { for (size_t i = 0; i < visibleSize; ++i) { @@ -297,7 +297,7 @@ RBM::SampleSlab( { for (size_t i = 0; i < hiddenSize; ++i) { - for (size_t j = 0; j < poolSize; j++) + for (size_t j = 0; j < poolSize; ++j) { slab(j, i) = math::RandNormal(slabMean(j, i), 1.0 / slabPenalty); } diff --git a/src/mlpack/methods/ann/regularizer/orthogonal_regularizer_impl.hpp b/src/mlpack/methods/ann/regularizer/orthogonal_regularizer_impl.hpp index a9ec9a7e97..b578622fdf 100644 --- a/src/mlpack/methods/ann/regularizer/orthogonal_regularizer_impl.hpp +++ b/src/mlpack/methods/ann/regularizer/orthogonal_regularizer_impl.hpp @@ -31,7 +31,7 @@ void OrthogonalRegularizer::Evaluate(const MatType& weight, MatType& gradient) for (size_t i = 0; i < weight.n_rows; ++i) { - for (size_t j = 0; j < weight.n_rows; j++) + for (size_t j = 0; j < weight.n_rows; ++j) { if (i == j) { diff --git a/src/mlpack/methods/cf/interpolation_policies/regression_interpolation.hpp b/src/mlpack/methods/cf/interpolation_policies/regression_interpolation.hpp index 8096caaf57..a6ed127c3b 100644 --- a/src/mlpack/methods/cf/interpolation_policies/regression_interpolation.hpp +++ b/src/mlpack/methods/cf/interpolation_policies/regression_interpolation.hpp @@ -130,7 +130,7 @@ class RegressionInterpolation { // Calculate coefficient. arma::vec iPrediction; - for (size_t j = i; j < neighborNum; j++) + for (size_t j = i; j < neighborNum; ++j) { if (a(neighbors(i), neighbors(j)) != 0) { diff --git a/src/mlpack/methods/decision_stump/decision_stump_impl.hpp b/src/mlpack/methods/decision_stump/decision_stump_impl.hpp index 7d471d835b..8fe4e09c50 100644 --- a/src/mlpack/methods/decision_stump/decision_stump_impl.hpp +++ b/src/mlpack/methods/decision_stump/decision_stump_impl.hpp @@ -477,13 +477,13 @@ double DecisionStump::CalculateEntropy( if (UseWeights) { - for (j = 0; j < labels.n_elem; j++) + for (j = 0; j < labels.n_elem; ++j) { numElem(labels(j)) += weights(j); accWeight += weights(j); } - for (j = 0; j < numClasses; j++) + for (j = 0; j < numClasses; ++j) { const double p1 = ((double) numElem(j) / accWeight); @@ -495,10 +495,10 @@ double DecisionStump::CalculateEntropy( } else { - for (j = 0; j < labels.n_elem; j++) + for (j = 0; j < labels.n_elem; ++j) numElem(labels(j))++; - for (j = 0; j < numClasses; j++) + for (j = 0; j < numClasses; ++j) { const double p1 = ((double) numElem(j) / labels.n_elem); diff --git a/src/mlpack/methods/det/dt_utils_impl.hpp b/src/mlpack/methods/det/dt_utils_impl.hpp index 6e5355b48a..9ff8bcb498 100644 --- a/src/mlpack/methods/det/dt_utils_impl.hpp +++ b/src/mlpack/methods/det/dt_utils_impl.hpp @@ -231,7 +231,7 @@ DTree* Trainer(MatType& dataset, { // Compute test values for this state of the tree. double cvVal = 0.0; - for (size_t j = 0; j < test.n_cols; j++) + for (size_t j = 0; j < test.n_cols; ++j) { arma::vec testPoint = test.unsafe_col(j); cvVal += cvDTree.ComputeValue(testPoint); diff --git a/src/mlpack/methods/fastmks/fastmks_impl.hpp b/src/mlpack/methods/fastmks/fastmks_impl.hpp index 4529acaada..22fe3f656d 100644 --- a/src/mlpack/methods/fastmks/fastmks_impl.hpp +++ b/src/mlpack/methods/fastmks/fastmks_impl.hpp @@ -446,7 +446,7 @@ void FastMKS::Search( } } - for (size_t j = 1; j <= k; j++) + for (size_t j = 1; j <= k; ++j) { indices(k - j, q) = pqueue.top().second; kernels(k - j, q) = pqueue.top().first; @@ -586,7 +586,7 @@ void FastMKS::Search( } } - for (size_t j = 1; j <= k; j++) + for (size_t j = 1; j <= k; ++j) { indices(k - j, q) = pqueue.top().second; kernels(k - j, q) = pqueue.top().first; diff --git a/src/mlpack/methods/fastmks/fastmks_rules_impl.hpp b/src/mlpack/methods/fastmks/fastmks_rules_impl.hpp index 69b57c3965..bd67a399bf 100644 --- a/src/mlpack/methods/fastmks/fastmks_rules_impl.hpp +++ b/src/mlpack/methods/fastmks/fastmks_rules_impl.hpp @@ -75,7 +75,7 @@ void FastMKSRules::GetResults( for (size_t i = 0; i < querySet.n_cols; ++i) { CandidateList& pqueue = candidates[i]; - for (size_t j = 1; j <= k; j++) + for (size_t j = 1; j <= k; ++j) { indices(k - j, i) = pqueue.top().second; products(k - j, i) = pqueue.top().first; diff --git a/src/mlpack/methods/gmm/diagonal_gmm.cpp b/src/mlpack/methods/gmm/diagonal_gmm.cpp index 45f4604560..f9d120d86c 100644 --- a/src/mlpack/methods/gmm/diagonal_gmm.cpp +++ b/src/mlpack/methods/gmm/diagonal_gmm.cpp @@ -170,7 +170,7 @@ double DiagonalGMM::LogLikelihood( } // Now sum over every point. - for (size_t j = 0; j < observations.n_cols; j++) + for (size_t j = 0; j < observations.n_cols; ++j) { if (accu(likelihoods.col(j)) == 0) Log::Info << "Likelihood of point " << j << " is 0! It is probably an " diff --git a/src/mlpack/methods/gmm/gmm.cpp b/src/mlpack/methods/gmm/gmm.cpp index 125e7d86c9..1e3f19533c 100644 --- a/src/mlpack/methods/gmm/gmm.cpp +++ b/src/mlpack/methods/gmm/gmm.cpp @@ -176,7 +176,7 @@ double GMM::LogLikelihood( } // Now sum over every point. - for (size_t j = 0; j < data.n_cols; j++) + for (size_t j = 0; j < data.n_cols; ++j) loglikelihood += mlpack::math::AccuLog(logLikelihoods.col(j)); return loglikelihood; } diff --git a/src/mlpack/methods/hmm/hmm_impl.hpp b/src/mlpack/methods/hmm/hmm_impl.hpp index 57fe29f9b7..6a6cded19c 100644 --- a/src/mlpack/methods/hmm/hmm_impl.hpp +++ b/src/mlpack/methods/hmm/hmm_impl.hpp @@ -486,7 +486,7 @@ double HMM::Predict(const arma::mat& dataSeq, // Assemble the state probability for this element. // Given that we are in state j, we use state with the highest probability // of being the previous state. - for (size_t j = 0; j < logTransition.n_rows; j++) + for (size_t j = 0; j < logTransition.n_rows; ++j) { arma::vec prob = logStateProb.col(t - 1) + logTransition.row(j).t(); logStateProb(j, t) = prob.max(index) + @@ -606,7 +606,7 @@ void HMM::Forward(const arma::mat& dataSeq, // Now compute the probabilities for each successive observation. for (size_t t = 1; t < dataSeq.n_cols; t++) { - for (size_t j = 0; j < logTransition.n_rows; j++) + for (size_t j = 0; j < logTransition.n_rows; ++j) { // The forward probability of state j at time t is the sum over all states // of the probability of the previous state transitioning to the current @@ -639,7 +639,7 @@ void HMM::Backward(const arma::mat& dataSeq, // Now step backwards through all other observations. for (size_t t = dataSeq.n_cols - 2; t + 1 > 0; t--) { - for (size_t j = 0; j < logTransition.n_rows; j++) + for (size_t j = 0; j < logTransition.n_rows; ++j) { // The backward probability of state j at time t is the sum over all state // of the probability of the next state having been a transition from the diff --git a/src/mlpack/methods/kmeans/kmeans_impl.hpp b/src/mlpack/methods/kmeans/kmeans_impl.hpp index 4f3564e0b7..84c7e850d6 100644 --- a/src/mlpack/methods/kmeans/kmeans_impl.hpp +++ b/src/mlpack/methods/kmeans/kmeans_impl.hpp @@ -321,7 +321,7 @@ Cluster(const MatType& data, double minDistance = std::numeric_limits::infinity(); size_t closestCluster = centroids.n_cols; // Invalid value. - for (size_t j = 0; j < centroids.n_cols; j++) + for (size_t j = 0; j < centroids.n_cols; ++j) { const double distance = metric.Evaluate(data.col(i), centroids.col(j)); diff --git a/src/mlpack/methods/kmeans/max_variance_new_cluster_impl.hpp b/src/mlpack/methods/kmeans/max_variance_new_cluster_impl.hpp index ac17fb813f..f74273baaa 100644 --- a/src/mlpack/methods/kmeans/max_variance_new_cluster_impl.hpp +++ b/src/mlpack/methods/kmeans/max_variance_new_cluster_impl.hpp @@ -131,7 +131,7 @@ void MaxVarianceNewCluster::Precalculate(const MatType& data, double minDistance = std::numeric_limits::infinity(); size_t closestCluster = oldCentroids.n_cols; // Invalid value. - for (size_t j = 0; j < oldCentroids.n_cols; j++) + for (size_t j = 0; j < oldCentroids.n_cols; ++j) { const double distance = metric.Evaluate(data.col(i), oldCentroids.col(j)); diff --git a/src/mlpack/methods/kmeans/naive_kmeans_impl.hpp b/src/mlpack/methods/kmeans/naive_kmeans_impl.hpp index d04ed48f85..9ab74a118b 100644 --- a/src/mlpack/methods/kmeans/naive_kmeans_impl.hpp +++ b/src/mlpack/methods/kmeans/naive_kmeans_impl.hpp @@ -55,7 +55,7 @@ double NaiveKMeans::Iterate(const arma::mat& centroids, double minDistance = std::numeric_limits::infinity(); size_t closestCluster = centroids.n_cols; // Invalid value. - for (size_t j = 0; j < centroids.n_cols; j++) + for (size_t j = 0; j < centroids.n_cols; ++j) { const double distance = metric.Evaluate(dataset.col(i), centroids.unsafe_col(j)); diff --git a/src/mlpack/methods/lars/lars.cpp b/src/mlpack/methods/lars/lars.cpp index 083ea6eca5..cc9bc37942 100644 --- a/src/mlpack/methods/lars/lars.cpp +++ b/src/mlpack/methods/lars/lars.cpp @@ -325,7 +325,7 @@ double LARS::Train(const arma::mat& matX, { arma::mat matGramActive = arma::mat(activeSet.size(), activeSet.size()); for (size_t i = 0; i < activeSet.size(); ++i) - for (size_t j = 0; j < activeSet.size(); j++) + for (size_t j = 0; j < activeSet.size(); ++j) matGramActive(i, j) = (*matGram)(activeSet[i], activeSet[j]); // Check for singularity. @@ -614,7 +614,7 @@ void LARS::CholeskyDelete(const size_t colToKill) matUtriCholFactor.shed_col(colToKill); // remove column colToKill n--; - for (size_t k = colToKill; k < n; k++) + for (size_t k = colToKill; k < n; ++k) { arma::mat matG; arma::vec::fixed<2> rotatedVec; diff --git a/src/mlpack/methods/lmnn/constraints_impl.hpp b/src/mlpack/methods/lmnn/constraints_impl.hpp index 9cb6d91cdf..813b10370d 100644 --- a/src/mlpack/methods/lmnn/constraints_impl.hpp +++ b/src/mlpack/methods/lmnn/constraints_impl.hpp @@ -105,7 +105,7 @@ void Constraints::TargetNeighbors(arma::Mat& outputMatrix, ReorderResults(distances, neighbors, norms); // Re-map neighbors to their index. - for (size_t j = 0; j < neighbors.n_elem; j++) + for (size_t j = 0; j < neighbors.n_elem; ++j) neighbors(j) = indexSame[i].at(neighbors(j)); // Store target neihbors. @@ -153,7 +153,7 @@ void Constraints::TargetNeighbors(arma::Mat& outputMatrix, ReorderResults(distances, neighbors, norms); // Re-map neighbors to their index. - for (size_t j = 0; j < neighbors.n_elem; j++) + for (size_t j = 0; j < neighbors.n_elem; ++j) neighbors(j) = indexSame[i].at(neighbors(j)); // Store target neighbors. @@ -189,7 +189,7 @@ void Constraints::Impostors(arma::Mat& outputMatrix, ReorderResults(distances, neighbors, norms); // Re-map neighbors to their index. - for (size_t j = 0; j < neighbors.n_elem; j++) + for (size_t j = 0; j < neighbors.n_elem; ++j) neighbors(j) = indexDiff[i].at(neighbors(j)); // Store impostors. @@ -227,7 +227,7 @@ void Constraints::Impostors(arma::Mat& outputNeighbors, ReorderResults(distances, neighbors, norms); // Re-map neighbors to their index. - for (size_t j = 0; j < neighbors.n_elem; j++) + for (size_t j = 0; j < neighbors.n_elem; ++j) neighbors(j) = indexDiff[i].at(neighbors(j)); // Store impostors. @@ -276,7 +276,7 @@ void Constraints::Impostors(arma::Mat& outputMatrix, ReorderResults(distances, neighbors, norms); // Re-map neighbors to their index. - for (size_t j = 0; j < neighbors.n_elem; j++) + for (size_t j = 0; j < neighbors.n_elem; ++j) neighbors(j) = indexDiff[i].at(neighbors(j)); // Store impostors. @@ -325,7 +325,7 @@ void Constraints::Impostors(arma::Mat& outputNeighbors, ReorderResults(distances, neighbors, norms); // Re-map neighbors to their index. - for (size_t j = 0; j < neighbors.n_elem; j++) + for (size_t j = 0; j < neighbors.n_elem; ++j) neighbors(j) = indexDiff[i].at(neighbors(j)); // Store impostors. @@ -374,7 +374,7 @@ void Constraints::Impostors(arma::Mat& outputNeighbors, ReorderResults(distances, neighbors, norms); // Re-map neighbors to their index. - for (size_t j = 0; j < neighbors.n_elem; j++) + for (size_t j = 0; j < neighbors.n_elem; ++j) neighbors(j) = indexDiff[i].at(neighbors(j)); // Store impostors. @@ -406,7 +406,7 @@ void Constraints::Triplets(arma::Mat& outputMatrix, for (size_t i = 0, r = 0; i < N; ++i) { - for (size_t j = 0; j < k; j++) + for (size_t j = 0; j < k; ++j) { for (size_t l = 0; l < k; l++, r++) { diff --git a/src/mlpack/methods/lmnn/lmnn_function_impl.hpp b/src/mlpack/methods/lmnn/lmnn_function_impl.hpp index 6bfd0ed8ad..78f0852d77 100644 --- a/src/mlpack/methods/lmnn/lmnn_function_impl.hpp +++ b/src/mlpack/methods/lmnn/lmnn_function_impl.hpp @@ -259,7 +259,7 @@ double LMNNFunction::Evaluate(const arma::mat& transformation) for (size_t i = 0; i < dataset.n_cols; ++i) { - for (size_t j = 0; j < k ; j++) + for (size_t j = 0; j < k ; ++j) { // Calculate cost due to distance between target neighbors & data point. double eval = metric.Evaluate(transformedDataset.col(i), @@ -386,7 +386,7 @@ double LMNNFunction::Evaluate(const arma::mat& transformation, for (size_t i = begin; i < begin + batchSize; ++i) { - for (size_t j = 0; j < k ; j++) + for (size_t j = 0; j < k ; ++j) { // Calculate cost due to distance between target neighbors & data point. double eval = metric.Evaluate(transformedDataset.col(i), @@ -651,7 +651,7 @@ void LMNNFunction::Gradient(const arma::mat& transformation, for (size_t i = begin; i < begin + batchSize; ++i) { - for (size_t j = 0; j < k ; j++) + for (size_t j = 0; j < k ; ++j) { // Calculate gradient due to target neighbors. arma::vec diff = dataset.col(i) - dataset.col(targetNeighbors(j, i)); @@ -797,7 +797,7 @@ double LMNNFunction::EvaluateWithGradient( for (size_t i = 0; i < dataset.n_cols; ++i) { - for (size_t j = 0; j < k ; j++) + for (size_t j = 0; j < k ; ++j) { // Calculate cost due to distance between target neighbors & data point. double eval = metric.Evaluate(transformedDataset.col(i), @@ -933,7 +933,7 @@ double LMNNFunction::EvaluateWithGradient( for (size_t i = begin; i < begin + batchSize; ++i) { - for (size_t j = 0; j < k ; j++) + for (size_t j = 0; j < k ; ++j) { // Calculate cost due to distance between target neighbors & data point. double eval = metric.Evaluate(transformedDataset.col(i), @@ -1022,7 +1022,7 @@ inline void LMNNFunction::Precalculate() for (size_t i = 0; i < dataset.n_cols; ++i) { - for (size_t j = 0; j < k ; j++) + for (size_t j = 0; j < k ; ++j) { // Calculate gradient due to target neighbors. arma::vec diff = dataset.col(i) - dataset.col(targetNeighbors(j, i)); diff --git a/src/mlpack/methods/lmnn/lmnn_main.cpp b/src/mlpack/methods/lmnn/lmnn_main.cpp index faf27f609e..5f50ddbaa2 100644 --- a/src/mlpack/methods/lmnn/lmnn_main.cpp +++ b/src/mlpack/methods/lmnn/lmnn_main.cpp @@ -203,7 +203,7 @@ double KNNAccuracy(const arma::mat& dataset, arma::vec Map; Map.zeros(uniqueLabels.n_cols); - for (size_t j = 0; j < k; j++) + for (size_t j = 0; j < k; ++j) { Map(labels(neighbors(j, i))) += 1 / std::pow(distances(j, i) + 1, 2); diff --git a/src/mlpack/methods/lsh/lsh_search_impl.hpp b/src/mlpack/methods/lsh/lsh_search_impl.hpp index 1d7ff8d9f5..9b4525c078 100644 --- a/src/mlpack/methods/lsh/lsh_search_impl.hpp +++ b/src/mlpack/methods/lsh/lsh_search_impl.hpp @@ -320,7 +320,7 @@ void LSHSearch::Train(MatType referenceSet, { // Insert the point in the corresponding row to its bucket in the // 'secondHashTable'. - for (size_t j = 0; j < secondHashVectors.n_cols; j++) + for (size_t j = 0; j < secondHashVectors.n_cols; ++j) { // This is the bucket number. size_t hashInd = (size_t) secondHashVectors(i, j); @@ -388,7 +388,7 @@ void LSHSearch::BaseCase( } } - for (size_t j = 1; j <= k; j++) + for (size_t j = 1; j <= k; ++j) { neighbors(k - j, queryIndex) = pqueue.top().second; distances(k - j, queryIndex) = pqueue.top().first; @@ -431,7 +431,7 @@ void LSHSearch::BaseCase( } } - for (size_t j = 1; j <= k; j++) + for (size_t j = 1; j <= k; ++j) { neighbors(k - j, queryIndex) = pqueue.top().second; distances(k - j, queryIndex) = pqueue.top().first; diff --git a/src/mlpack/methods/nca/nca_softmax_error_function_impl.hpp b/src/mlpack/methods/nca/nca_softmax_error_function_impl.hpp index d0e90bb3ad..5e589cba5e 100644 --- a/src/mlpack/methods/nca/nca_softmax_error_function_impl.hpp +++ b/src/mlpack/methods/nca/nca_softmax_error_function_impl.hpp @@ -131,7 +131,7 @@ void SoftmaxErrorFunction::Gradient(const arma::mat& coordinates, sum.zeros(stretchedDataset.n_rows, stretchedDataset.n_rows); for (size_t i = 0; i < stretchedDataset.n_cols; ++i) { - for (size_t k = (i + 1); k < stretchedDataset.n_cols; k++) + for (size_t k = (i + 1); k < stretchedDataset.n_cols; ++k) { // Calculate p_ik and p_ki first. double eval = exp(-metric.Evaluate(stretchedDataset.unsafe_col(i), @@ -267,7 +267,7 @@ void SoftmaxErrorFunction::Precalculate( denominators.zeros(stretchedDataset.n_cols); for (size_t i = 0; i < stretchedDataset.n_cols; ++i) { - for (size_t j = (i + 1); j < stretchedDataset.n_cols; j++) + for (size_t j = (i + 1); j < stretchedDataset.n_cols; ++j) { // Evaluate exp(-d(x_i, x_j)). double eval = exp(-metric.Evaluate(stretchedDataset.unsafe_col(i), diff --git a/src/mlpack/methods/neighbor_search/neighbor_search_impl.hpp b/src/mlpack/methods/neighbor_search/neighbor_search_impl.hpp index 9b759cc37c..7627e59e6e 100644 --- a/src/mlpack/methods/neighbor_search/neighbor_search_impl.hpp +++ b/src/mlpack/methods/neighbor_search/neighbor_search_impl.hpp @@ -548,7 +548,7 @@ DualTreeTraversalType, SingleTreeTraversalType>::Search( distances.col(oldFromNewQueries[i]) = distancePtr->col(i); // Map indices of neighbors. - for (size_t j = 0; j < distances.n_rows; j++) + for (size_t j = 0; j < distances.n_rows; ++j) { neighbors(j, oldFromNewQueries[i]) = oldFromNewReferences[(*neighborPtr)(j, i)]; @@ -584,7 +584,7 @@ DualTreeTraversalType, SingleTreeTraversalType>::Search( // Map indices of neighbors. for (size_t i = 0; i < neighbors.n_cols; ++i) - for (size_t j = 0; j < neighbors.n_rows; j++) + for (size_t j = 0; j < neighbors.n_rows; ++j) neighbors(j, i) = oldFromNewReferences[(*neighborPtr)(j, i)]; // Finished with temporary matrix. @@ -670,7 +670,7 @@ DualTreeTraversalType, SingleTreeTraversalType>::Search( // Map indices of neighbors. for (size_t i = 0; i < neighbors.n_cols; ++i) - for (size_t j = 0; j < neighbors.n_rows; j++) + for (size_t j = 0; j < neighbors.n_rows; ++j) neighbors(j, i) = oldFromNewReferences[(*neighborPtr)(j, i)]; // Finished with temporary matrix. diff --git a/src/mlpack/methods/neighbor_search/neighbor_search_rules_impl.hpp b/src/mlpack/methods/neighbor_search/neighbor_search_rules_impl.hpp index 212feb719a..e990cd3628 100644 --- a/src/mlpack/methods/neighbor_search/neighbor_search_rules_impl.hpp +++ b/src/mlpack/methods/neighbor_search/neighbor_search_rules_impl.hpp @@ -70,7 +70,7 @@ void NeighborSearchRules::GetResults( for (size_t i = 0; i < querySet.n_cols; ++i) { CandidateList& pqueue = candidates[i]; - for (size_t j = 1; j <= k; j++) + for (size_t j = 1; j <= k; ++j) { neighbors(k - j, i) = pqueue.top().second; distances(k - j, i) = pqueue.top().first; diff --git a/src/mlpack/methods/perceptron/perceptron_impl.hpp b/src/mlpack/methods/perceptron/perceptron_impl.hpp index 414ba7381f..1aac981775 100644 --- a/src/mlpack/methods/perceptron/perceptron_impl.hpp +++ b/src/mlpack/methods/perceptron/perceptron_impl.hpp @@ -163,7 +163,7 @@ void Perceptron::Train( converged = true; // Now this inner loop is for going through the dataset in each iteration. - for (j = 0; j < data.n_cols; j++) + for (j = 0; j < data.n_cols; ++j) { // Multiply for each variable and check whether the current weight vector // correctly classifies this. diff --git a/src/mlpack/methods/radical/radical.cpp b/src/mlpack/methods/radical/radical.cpp index b38c40f78f..7fa2592c06 100644 --- a/src/mlpack/methods/radical/radical.cpp +++ b/src/mlpack/methods/radical/radical.cpp @@ -142,7 +142,7 @@ void Radical::DoRadical(const mat& matXT, mat& matY, mat& matW) for (size_t i = 0; i < nDims - 1; ++i) { - for (size_t j = i + 1; j < nDims; j++) + for (size_t j = i + 1; j < nDims; ++j) { Log::Debug << "RADICAL 2D on dimensions " << i << " and " << j << "." << std::endl; diff --git a/src/mlpack/methods/range_search/range_search_impl.hpp b/src/mlpack/methods/range_search/range_search_impl.hpp index 269cc79859..75514caaf8 100644 --- a/src/mlpack/methods/range_search/range_search_impl.hpp +++ b/src/mlpack/methods/range_search/range_search_impl.hpp @@ -398,7 +398,7 @@ void RangeSearch::Search( // Copy each neighbor individually, because we need to map it. neighbors[queryMapping].resize(distances[queryMapping].size()); - for (size_t j = 0; j < distances[queryMapping].size(); j++) + for (size_t j = 0; j < distances[queryMapping].size(); ++j) neighbors[queryMapping][j] = oldFromNewReferences[(*neighborPtr)[i][j]]; } @@ -436,7 +436,7 @@ void RangeSearch::Search( for (size_t i = 0; i < neighbors.size(); ++i) { neighbors[i].resize((*neighborPtr)[i].size()); - for (size_t j = 0; j < neighbors[i].size(); j++) + for (size_t j = 0; j < neighbors[i].size(); ++j) neighbors[i][j] = oldFromNewReferences[(*neighborPtr)[i][j]]; } @@ -508,7 +508,7 @@ void RangeSearch::Search( for (size_t i = 0; i < neighbors.size(); ++i) { neighbors[i].resize((*neighborPtr)[i].size()); - for (size_t j = 0; j < neighbors[i].size(); j++) + for (size_t j = 0; j < neighbors[i].size(); ++j) neighbors[i][j] = oldFromNewReferences[(*neighborPtr)[i][j]]; } @@ -606,7 +606,7 @@ void RangeSearch::Search( // Copy each neighbor individually, because we need to map it. neighbors[refMapping].resize(distances[refMapping].size()); - for (size_t j = 0; j < distances[refMapping].size(); j++) + for (size_t j = 0; j < distances[refMapping].size(); ++j) { neighbors[refMapping][j] = oldFromNewReferences[(*neighborPtr)[i][j]]; } diff --git a/src/mlpack/methods/rann/ra_search_impl.hpp b/src/mlpack/methods/rann/ra_search_impl.hpp index 37d095bca8..d803014ae1 100644 --- a/src/mlpack/methods/rann/ra_search_impl.hpp +++ b/src/mlpack/methods/rann/ra_search_impl.hpp @@ -385,7 +385,7 @@ Search(const MatType& querySet, distances.col(oldFromNewQueries[i]) = distancePtr->col(i); // Map indices of neighbors. - for (size_t j = 0; j < distances.n_rows; j++) + for (size_t j = 0; j < distances.n_rows; ++j) { neighbors(j, oldFromNewQueries[i]) = oldFromNewReferences[(*neighborPtr)(j, i)]; @@ -421,7 +421,7 @@ Search(const MatType& querySet, // Map indices of neighbors. for (size_t i = 0; i < neighbors.n_cols; ++i) - for (size_t j = 0; j < neighbors.n_rows; j++) + for (size_t j = 0; j < neighbors.n_rows; ++j) neighbors(j, i) = oldFromNewReferences[(*neighborPtr)(j, i)]; // Finished with temporary matrix. @@ -482,7 +482,7 @@ void RASearch::Search( // Map indices of neighbors. for (size_t i = 0; i < neighbors.n_cols; ++i) - for (size_t j = 0; j < neighbors.n_rows; j++) + for (size_t j = 0; j < neighbors.n_rows; ++j) neighbors(j, i) = oldFromNewReferences[(*neighborPtr)(j, i)]; // Finished with temporary matrix. diff --git a/src/mlpack/methods/rann/ra_search_rules_impl.hpp b/src/mlpack/methods/rann/ra_search_rules_impl.hpp index 0f82f0fe0b..7746589146 100644 --- a/src/mlpack/methods/rann/ra_search_rules_impl.hpp +++ b/src/mlpack/methods/rann/ra_search_rules_impl.hpp @@ -91,7 +91,7 @@ RASearchRules(const arma::mat& referenceSet, for (size_t i = 0; i < querySet.n_cols; ++i) { math::ObtainDistinctSamples(0, n, numSamplesReqd, distinctSamples); - for (size_t j = 0; j < distinctSamples.n_elem; j++) + for (size_t j = 0; j < distinctSamples.n_elem; ++j) BaseCase(i, (size_t) distinctSamples[j]); } } @@ -108,7 +108,7 @@ void RASearchRules::GetResults( for (size_t i = 0; i < querySet.n_cols; ++i) { CandidateList& pqueue = candidates[i]; - for (size_t j = 1; j <= k; j++) + for (size_t j = 1; j <= k; ++j) { neighbors(k - j, i) = pqueue.top().second; distances(k - j, i) = pqueue.top().first; @@ -513,7 +513,7 @@ inline double RASearchRules::Score( const size_t queryIndex = queryNode.Descendant(i); math::ObtainDistinctSamples(0, referenceNode.NumDescendants(), samplesReqd, distinctSamples); - for (size_t j = 0; j < distinctSamples.n_elem; j++) + for (size_t j = 0; j < distinctSamples.n_elem; ++j) // The counting of the samples are done in the 'BaseCase' function // so no book-keeping is required here. BaseCase(queryIndex, @@ -543,7 +543,7 @@ inline double RASearchRules::Score( const size_t queryIndex = queryNode.Descendant(i); math::ObtainDistinctSamples(0, referenceNode.NumDescendants(), samplesReqd, distinctSamples); - for (size_t j = 0; j < distinctSamples.n_elem; j++) + for (size_t j = 0; j < distinctSamples.n_elem; ++j) // The counting of the samples are done in the 'BaseCase' // function so no book-keeping is required here. BaseCase(queryIndex, @@ -718,7 +718,7 @@ Rescore(TreeType& queryNode, const size_t queryIndex = queryNode.Descendant(i); math::ObtainDistinctSamples(0, referenceNode.NumDescendants(), samplesReqd, distinctSamples); - for (size_t j = 0; j < distinctSamples.n_elem; j++) + for (size_t j = 0; j < distinctSamples.n_elem; ++j) // The counting of the samples are done in the 'BaseCase' // function so no book-keeping is required here. BaseCase(queryIndex, referenceNode.Descendant(distinctSamples[j])); @@ -747,7 +747,7 @@ Rescore(TreeType& queryNode, const size_t queryIndex = queryNode.Descendant(i); math::ObtainDistinctSamples(0, referenceNode.NumDescendants(), samplesReqd, distinctSamples); - for (size_t j = 0; j < distinctSamples.n_elem; j++) + for (size_t j = 0; j < distinctSamples.n_elem; ++j) // The counting of the samples are done in BaseCase() so no // book-keeping is required here. BaseCase(queryIndex, diff --git a/src/mlpack/methods/rann/ra_util.cpp b/src/mlpack/methods/rann/ra_util.cpp index 92aa2e3b7a..1a0fdde9ce 100644 --- a/src/mlpack/methods/rann/ra_util.cpp +++ b/src/mlpack/methods/rann/ra_util.cpp @@ -132,7 +132,7 @@ double mlpack::neighbor::RAUtil::SuccessProbability(const size_t n, sum = std::pow(eps, (double) m); } - for (size_t j = lb; j < ub; j++) + for (size_t j = lb; j < ub; ++j) { // Compute Choose(m, j). double mCj = (double) m; diff --git a/src/mlpack/methods/softmax_regression/softmax_regression.cpp b/src/mlpack/methods/softmax_regression/softmax_regression.cpp index f3bc28df8b..e80a315d1d 100644 --- a/src/mlpack/methods/softmax_regression/softmax_regression.cpp +++ b/src/mlpack/methods/softmax_regression/softmax_regression.cpp @@ -42,7 +42,7 @@ void SoftmaxRegression::Classify(const arma::mat& dataset, for (size_t i = 0; i < dataset.n_cols; ++i) { // For each class. - for (size_t j = 0; j < numClasses; j++) + for (size_t j = 0; j < numClasses; ++j) { // If a higher class probability is encountered, change prediction. if (probabilities(j, i) > maxProbability) @@ -72,7 +72,7 @@ void SoftmaxRegression::Classify(const arma::mat& dataset, for (size_t i = 0; i < dataset.n_cols; ++i) { // For each class. - for (size_t j = 0; j < numClasses; j++) + for (size_t j = 0; j < numClasses; ++j) { // If a higher class probability is encountered, change prediction. if (probabilities(j, i) > maxProbability) diff --git a/src/mlpack/methods/sparse_coding/sparse_coding.cpp b/src/mlpack/methods/sparse_coding/sparse_coding.cpp index 402c2827b2..e6cff0503e 100644 --- a/src/mlpack/methods/sparse_coding/sparse_coding.cpp +++ b/src/mlpack/methods/sparse_coding/sparse_coding.cpp @@ -242,7 +242,7 @@ double SparseCoding::OptimizeDictionary(const arma::mat& data, // Project each atom of the dictionary back into the unit ball (if necessary). void SparseCoding::ProjectDictionary() { - for (size_t j = 0; j < atoms; j++) + for (size_t j = 0; j < atoms; ++j) { double atomNorm = arma::norm(dictionary.col(j), 2); if (atomNorm > 1) diff --git a/src/mlpack/tests/bias_svd_test.cpp b/src/mlpack/tests/bias_svd_test.cpp index 74d6504e27..7f02ecf5c7 100644 --- a/src/mlpack/tests/bias_svd_test.cpp +++ b/src/mlpack/tests/bias_svd_test.cpp @@ -52,7 +52,7 @@ BOOST_AUTO_TEST_CASE(BiasSVDFunctionRandomEvaluate) // Calculate cost by summing up cost of each example. double cost = 0; - for (size_t j = 0; j < numRatings; j++) + for (size_t j = 0; j < numRatings; ++j) { const size_t user = data(0, j); const size_t item = data(1, j) + numUsers; @@ -107,7 +107,7 @@ BOOST_AUTO_TEST_CASE(BiasSVDFunctionRegularizationEvaluate) // each rating and sum them up. double smallRegTerm = 0; double bigRegTerm = 0; - for (size_t j = 0; j < numRatings; j++) + for (size_t j = 0; j < numRatings; ++j) { const size_t user = data(0, j); const size_t item = data(1, j) + numUsers; @@ -168,7 +168,7 @@ BOOST_AUTO_TEST_CASE(BiasSVDFunctionGradient) for (size_t i = 0; i < rank; ++i) { - for (size_t j = 0; j < numUsers + numItems; j++) + for (size_t j = 0; j < numUsers + numItems; ++j) { // Perturb parameter with a positive constant and get costs. parameters(i, j) += epsilon; diff --git a/src/mlpack/tests/cosine_tree_test.cpp b/src/mlpack/tests/cosine_tree_test.cpp index b65d465f60..bd3819b244 100644 --- a/src/mlpack/tests/cosine_tree_test.cpp +++ b/src/mlpack/tests/cosine_tree_test.cpp @@ -107,7 +107,7 @@ BOOST_AUTO_TEST_CASE(CosineNodeCosineSplit) for (i = 0; i < leftIndices.size(); ++i) cosines(i) = arma::norm_dot(data.col(leftIndices[i]), splitPoint); - for (j = 0, k = i; j < rightIndices.size(); j++, k++) + for (j = 0, k = i; j < rightIndices.size(); ++j, ++k) cosines(k) = arma::norm_dot(data.col(rightIndices[j]), splitPoint); // Check if the columns assigned to the children agree with the splitting @@ -128,7 +128,7 @@ BOOST_AUTO_TEST_CASE(CosineNodeCosineSplit) BOOST_REQUIRE_LT(cosineMax - cosines(i), cosines(i) - cosineMin + precision); - for (j = 0, k = i; j < rightIndices.size(); j++, k++) + for (j = 0, k = i; j < rightIndices.size(); ++j, ++k) BOOST_REQUIRE_GT(cosineMax - cosines(k), cosines(k) - cosineMin - precision); } @@ -142,7 +142,7 @@ BOOST_AUTO_TEST_CASE(CosineNodeCosineSplit) if (cosineMax - cosines(i) >= cosines(i) - cosineMin + precision) numMax1Errors++; - for (j = 0, k = i; j < rightIndices.size(); j++, k++) + for (j = 0, k = i; j < rightIndices.size(); ++j, ++k) if (cosineMax - cosines(k) <= cosines(k) - cosineMin - precision) numMax1Errors++; @@ -151,7 +151,7 @@ BOOST_AUTO_TEST_CASE(CosineNodeCosineSplit) if (cosineMax2 - cosines(i) >= cosines(i) - cosineMin + precision) numMax2Errors++; - for (j = 0, k = i; j < rightIndices.size(); j++, k++) + for (j = 0, k = i; j < rightIndices.size(); ++j, ++k) if (cosineMax2 - cosines(k) <= cosines(k) - cosineMin - precision) numMax2Errors++; @@ -198,7 +198,7 @@ BOOST_AUTO_TEST_CASE(CosineTreeModifiedGramSchmidt) CosineNodeQueue::const_iterator j = basisQueue.begin(); CosineTree* currentNode; - for (; j != basisQueue.end(); j++) + for (; j != basisQueue.end(); ++j) { currentNode = *j; BOOST_REQUIRE_SMALL(arma::dot(currentNode->BasisVector(), newBasisVector), diff --git a/src/mlpack/tests/distribution_test.cpp b/src/mlpack/tests/distribution_test.cpp index 04a5d2c97f..7431d52dc6 100644 --- a/src/mlpack/tests/distribution_test.cpp +++ b/src/mlpack/tests/distribution_test.cpp @@ -286,7 +286,7 @@ BOOST_AUTO_TEST_CASE(GaussianDistributionDistributionConstructor) BOOST_REQUIRE_CLOSE(d.Mean()[i], mean[i], 1e-5); for (size_t i = 0; i < 3; ++i) - for (size_t j = 0; j < 3; j++) + for (size_t j = 0; j < 3; ++j) BOOST_REQUIRE_CLOSE(d.Covariance()(i, j), covariance(i, j), 1e-5); } @@ -505,7 +505,7 @@ BOOST_AUTO_TEST_CASE(GaussianDistributionTrainTest) BOOST_REQUIRE_SMALL(d.Mean()[i] - actualMean[i], 1e-5); for (size_t i = 0; i < 4; ++i) - for (size_t j = 0; j < 4; j++) + for (size_t j = 0; j < 4; ++j) BOOST_REQUIRE_SMALL(d.Covariance()(i, j) - actualCov(i, j), 1e-5); } @@ -605,7 +605,7 @@ BOOST_AUTO_TEST_CASE(GaussianDistributionTrainWithTwoDistProbabilitiesTest) // Fill even numbered columns with random points from dist1 and odd numbered // columns with random points from dist2. - for (size_t j = 0; j < N; j++) + for (size_t j = 0; j < N; ++j) { if (j % 2 == 0) rdata.col(j) = dist1.Random(); @@ -696,7 +696,7 @@ BOOST_AUTO_TEST_CASE(GammaDistributionTrainWithProbabilitiesTest) size_t d = 2; arma::mat rdata(d, N); - for (size_t j = 0; j < d; j++) + for (size_t j = 0; j < d; ++j) for (size_t i = 0; i < N; ++i) rdata(j, i) = dist(math::randGen); @@ -740,7 +740,7 @@ BOOST_AUTO_TEST_CASE(GammaDistributionTrainAllProbabilities1Test) size_t d = 2; arma::mat rdata(d, N); - for (size_t j = 0; j < d; j++) + for (size_t j = 0; j < d; ++j) for (size_t i = 0; i < N; ++i) rdata(j, i) = dist(math::randGen); @@ -785,7 +785,7 @@ BOOST_AUTO_TEST_CASE(GammaDistributionTrainTwoDistProbabilities1Test) arma::vec probabilities(N); // Draw points alternately from the two different distributions. - for (size_t j = 0; j < d; j++) + for (size_t j = 0; j < d; ++j) { for (size_t i = 0; i < N; ++i) { diff --git a/src/mlpack/tests/gmm_test.cpp b/src/mlpack/tests/gmm_test.cpp index f9e913e303..a4cf3fec7e 100644 --- a/src/mlpack/tests/gmm_test.cpp +++ b/src/mlpack/tests/gmm_test.cpp @@ -1170,7 +1170,7 @@ BOOST_AUTO_TEST_CASE(DiagonalGMMLoadSaveTest) for (size_t i = 0; i < gmm.Gaussians(); ++i) { - for (size_t j = 0; j < gmm.Dimensionality(); j++) + for (size_t j = 0; j < gmm.Dimensionality(); ++j) { BOOST_REQUIRE_CLOSE(gmm.Component(i).Mean()[j], gmm2.Component(i).Mean()[j], 1e-3); diff --git a/src/mlpack/tests/hmm_test.cpp b/src/mlpack/tests/hmm_test.cpp index de37811f5c..14f3721d2e 100644 --- a/src/mlpack/tests/hmm_test.cpp +++ b/src/mlpack/tests/hmm_test.cpp @@ -1472,7 +1472,7 @@ BOOST_AUTO_TEST_CASE(DiagonalGMMHMMOneGaussianUnlabeledTrainingTest) // Check the transition probability matrix. for (size_t i = 0; i < 2; ++i) - for (size_t j = 0; j < 2; j++) + for (size_t j = 0; j < 2; ++j) BOOST_REQUIRE_SMALL(hmm.Transition()(i, j) - transProbs(i, j), 0.08); // Check the estimated weights of the each emission distribution. @@ -1554,7 +1554,7 @@ BOOST_AUTO_TEST_CASE(DiagonalGMMHMMOneGaussianLabeledTrainingTest) // Check the transition probability matrix. for (size_t i = 0; i < 3; ++i) - for (size_t j = 0; j < 3; j++) + for (size_t j = 0; j < 3; ++j) BOOST_REQUIRE_SMALL(hmm.Transition()(i, j) - transProbs(i, j), 0.03); // Check the estimated weights of the each emission distribution. @@ -1633,7 +1633,7 @@ BOOST_AUTO_TEST_CASE(DiagonalGMMHMMMultipleGaussiansUnlabeledTrainingTest) // Check the transition probability matrix. for (size_t i = 0; i < 2; ++i) - for (size_t j = 0; j < 2; j++) + for (size_t j = 0; j < 2; ++j) BOOST_REQUIRE_SMALL(hmm.Transition()(i, j) - transProbs(i, j), 0.08); // Sort by the estimated weights of the first emission distribution. @@ -1737,7 +1737,7 @@ BOOST_AUTO_TEST_CASE(DiagonalGMMHMMMultipleGaussiansLabeledTrainingTest) // Check the transition probability matrix. for (size_t i = 0; i < 2; ++i) - for (size_t j = 0; j < 2; j++) + for (size_t j = 0; j < 2; ++j) BOOST_REQUIRE_SMALL(hmm.Transition()(i, j) - transProbs(i, j), 0.03); // Sort by the estimated weights of the first emission distribution. @@ -1792,7 +1792,7 @@ BOOST_AUTO_TEST_CASE(DiagonalGMMHMMLoadSaveTest) HMM hmm(3, DiagonalGMM(4, 3)); // Generate intial random values. - for (size_t j = 0; j < hmm.Emission().size(); j++) + for (size_t j = 0; j < hmm.Emission().size(); ++j) { hmm.Emission()[j].Weights().randu(); for (size_t i = 0; i < hmm.Emission()[j].Gaussians(); ++i) @@ -1824,7 +1824,7 @@ BOOST_AUTO_TEST_CASE(DiagonalGMMHMMLoadSaveTest) // Remove clutter. remove("test-hmm-save.xml"); - for (size_t j = 0; j < hmm.Emission().size(); j++) + for (size_t j = 0; j < hmm.Emission().size(); ++j) { // Check the number of Gaussians. BOOST_REQUIRE_EQUAL(hmm.Emission()[j].Gaussians(), diff --git a/src/mlpack/tests/init_rules_test.cpp b/src/mlpack/tests/init_rules_test.cpp index e8114c3d33..90192377af 100644 --- a/src/mlpack/tests/init_rules_test.cpp +++ b/src/mlpack/tests/init_rules_test.cpp @@ -62,14 +62,14 @@ BOOST_AUTO_TEST_CASE(OrthogonalInitTest) weights *= weights.t(); for (size_t i = 0; i < weights.n_rows; ++i) - for (size_t j = 0; j < weights.n_cols; j++) + for (size_t j = 0; j < weights.n_cols; ++j) BOOST_REQUIRE_SMALL(weights.at(i, j) - orthogonalWeights.at(i, j), 1e-3); orthogonalInit.Initialize(weights, 200, 100); weights = weights.t() * weights; for (size_t i = 0; i < weights.n_rows; ++i) - for (size_t j = 0; j < weights.n_cols; j++) + for (size_t j = 0; j < weights.n_cols; ++j) BOOST_REQUIRE_SMALL(weights.at(i, j) - orthogonalWeights.at(i, j), 1e-3); } @@ -89,7 +89,7 @@ BOOST_AUTO_TEST_CASE(OrthogonalInitGainTest) weights *= weights.t(); for (size_t i = 0; i < weights.n_rows; ++i) - for (size_t j = 0; j < weights.n_cols; j++) + for (size_t j = 0; j < weights.n_cols; ++j) BOOST_REQUIRE_SMALL(weights.at(i, j) - orthogonalWeights.at(i, j), 1e-3); } diff --git a/src/mlpack/tests/kmeans_test.cpp b/src/mlpack/tests/kmeans_test.cpp index 53f7feb11d..6b82ae3b6b 100644 --- a/src/mlpack/tests/kmeans_test.cpp +++ b/src/mlpack/tests/kmeans_test.cpp @@ -206,7 +206,7 @@ BOOST_AUTO_TEST_CASE(MaxVarianceNewClusterTest) double minDistance = std::numeric_limits::infinity(); size_t closestCluster = centroids.n_cols; // Invalid value. - for (size_t j = 0; j < centroids.n_cols; j++) + for (size_t j = 0; j < centroids.n_cols; ++j) { const double distance = metric.Evaluate(data.col(i), centroids.col(j)); diff --git a/src/mlpack/tests/krann_search_test.cpp b/src/mlpack/tests/krann_search_test.cpp index db8da43172..7b0e7a3c8c 100644 --- a/src/mlpack/tests/krann_search_test.cpp +++ b/src/mlpack/tests/krann_search_test.cpp @@ -689,7 +689,7 @@ BOOST_AUTO_TEST_CASE(RAModelTest) { arma::mat queryCopy(queryData); models[i].Search(std::move(queryCopy), 1, neighbors, distances); - for (size_t k = 0; k < queryData.n_cols; k++) + for (size_t k = 0; k < queryData.n_cols; ++k) if (qrRanks(k, neighbors(0, k)) < expectedRankErrorUB) numSuccessRounds[k]++; @@ -702,7 +702,7 @@ BOOST_AUTO_TEST_CASE(RAModelTest) size_t threshold = floor(numRounds * (0.95 - (1.96 * sqrt(0.95 * 0.05 / numRounds)))); size_t numQueriesFail = 0; - for (size_t k = 0; k < queryData.n_cols; k++) + for (size_t k = 0; k < queryData.n_cols; ++k) if (numSuccessRounds[k] < threshold) numQueriesFail++; diff --git a/src/mlpack/tests/lars_test.cpp b/src/mlpack/tests/lars_test.cpp index abf0c4258e..ad8fccfa35 100644 --- a/src/mlpack/tests/lars_test.cpp +++ b/src/mlpack/tests/lars_test.cpp @@ -35,7 +35,7 @@ void LARSVerifyCorrectness(arma::vec beta, arma::vec errCorr, double lambda) { size_t nDims = beta.n_elem; const double tol = 1e-10; - for (size_t j = 0; j < nDims; j++) + for (size_t j = 0; j < nDims; ++j) { if (beta(j) == 0) { diff --git a/src/mlpack/tests/lin_alg_test.cpp b/src/mlpack/tests/lin_alg_test.cpp index c213066d03..8cfcacb326 100644 --- a/src/mlpack/tests/lin_alg_test.cpp +++ b/src/mlpack/tests/lin_alg_test.cpp @@ -180,7 +180,7 @@ BOOST_AUTO_TEST_CASE(TestSvecSmat) BOOST_REQUIRE_EQUAL(Xtest.n_rows, 3); BOOST_REQUIRE_EQUAL(Xtest.n_cols, 3); for (size_t i = 0; i < 3; ++i) - for (size_t j = 0; j < 3; j++) + for (size_t j = 0; j < 3; ++j) BOOST_REQUIRE_CLOSE(X(i, j), Xtest(i, j), 1e-7); } @@ -227,7 +227,7 @@ BOOST_AUTO_TEST_CASE(TestSymKronIdSimple) Svec(Rhs, rhs); BOOST_REQUIRE_EQUAL(lhs.n_elem, rhs.n_elem); - for (size_t j = 0; j < lhs.n_elem; j++) + for (size_t j = 0; j < lhs.n_elem; ++j) BOOST_REQUIRE_CLOSE(lhs(j), rhs(j), 1e-5); } @@ -253,7 +253,7 @@ BOOST_AUTO_TEST_CASE(TestSymKronId) Svec(Rhs, rhs); BOOST_REQUIRE_EQUAL(lhs.n_elem, rhs.n_elem); - for (size_t j = 0; j < lhs.n_elem; j++) + for (size_t j = 0; j < lhs.n_elem; ++j) BOOST_REQUIRE_CLOSE(lhs(j), rhs(j), 1e-5); } } diff --git a/src/mlpack/tests/lmnn_test.cpp b/src/mlpack/tests/lmnn_test.cpp index c4e6187b22..f4b22ebe2f 100644 --- a/src/mlpack/tests/lmnn_test.cpp +++ b/src/mlpack/tests/lmnn_test.cpp @@ -414,7 +414,7 @@ double KnnAccuracy(const arma::mat& dataset, arma::vec Map; Map.zeros(uniqueLabels.n_cols); - for (size_t j = 0; j < k; j++) + for (size_t j = 0; j < k; ++j) Map(labels(neighbors(j, i))) += 1 / std::pow(distances(j, i) + 1, 2); diff --git a/src/mlpack/tests/local_coordinate_coding_test.cpp b/src/mlpack/tests/local_coordinate_coding_test.cpp index f9ba49414f..e59120ad21 100644 --- a/src/mlpack/tests/local_coordinate_coding_test.cpp +++ b/src/mlpack/tests/local_coordinate_coding_test.cpp @@ -29,7 +29,7 @@ void VerifyCorrectness(const vec& beta, const vec& errCorr, double lambda) { const double tol = 0.1; size_t nDims = beta.n_elem; - for (size_t j = 0; j < nDims; j++) + for (size_t j = 0; j < nDims; ++j) { if (beta(j) == 0) { @@ -74,7 +74,7 @@ BOOST_AUTO_TEST_CASE(LocalCoordinateCodingTestCodingStep) for (uword i = 0; i < nPoints; ++i) { vec sqDists = vec(nAtoms); - for (uword j = 0; j < nAtoms; j++) + for (uword j = 0; j < nAtoms; ++j) { sqDists[j] = arma::norm(D.col(j) - X.col(i)); } diff --git a/src/mlpack/tests/main_tests/gmm_train_test.cpp b/src/mlpack/tests/main_tests/gmm_train_test.cpp index b385c21755..e3379a67a9 100644 --- a/src/mlpack/tests/main_tests/gmm_train_test.cpp +++ b/src/mlpack/tests/main_tests/gmm_train_test.cpp @@ -554,11 +554,11 @@ BOOST_AUTO_TEST_CASE(GmmTrainDiagCovariance) arma::uvec sortedIndices = sort_index(gmm->Weights()); - for (size_t k = 0; k < sortedIndices.n_elem; k++) + for (size_t k = 0; k < sortedIndices.n_elem; ++k) { arma::mat diagCov(gmm->Component(sortedIndices[k]).Covariance()); for (size_t i = 0; i < diagCov.n_rows; ++i) - for (size_t j = 0; j < diagCov.n_cols; j++) + for (size_t j = 0; j < diagCov.n_cols; ++j) if (i != j && diagCov(i, j) != (double) 0) BOOST_FAIL("Covariance is not diagonal"); } diff --git a/src/mlpack/tests/main_tests/hmm_train_test.cpp b/src/mlpack/tests/main_tests/hmm_train_test.cpp index 93aac8b005..1cba70fdd7 100644 --- a/src/mlpack/tests/main_tests/hmm_train_test.cpp +++ b/src/mlpack/tests/main_tests/hmm_train_test.cpp @@ -102,7 +102,7 @@ inline void ApproximatelyEqual(HMMModel& h1, size_t states = d1.size(); for (size_t i = 0; i < states; ++i) - for (size_t j = 0; j < d1[i].Dimensionality(); j++) + for (size_t j = 0; j < d1[i].Dimensionality(); ++j) CheckMatrices(d1[i].Probabilities(j)*100, d2[i].Probabilities(j)*100, tolerance); @@ -153,7 +153,7 @@ inline void ApproximatelyEqual(HMMModel& h1, { BOOST_REQUIRE_EQUAL(d1[i].Gaussians(), d2[i].Gaussians()); size_t gaussians = d1[i].Gaussians(); - for (size_t j=0; j>& vec1, BOOST_REQUIRE_EQUAL(vec1[i].size(), vec2[i].size()); std::sort(vec1[i].begin(), vec1[i].end()); std::sort(vec2[i].begin(), vec2[i].end()); - for (size_t j = 0 ; j < vec1[i].size(); j++) + for (size_t j = 0 ; j < vec1[i].size(); ++j) { BOOST_REQUIRE_CLOSE(vec1[i][j], vec2[i][j], tolerance); } @@ -70,7 +70,7 @@ inline void CheckMatrices(std::vector>& vec1, BOOST_REQUIRE_EQUAL(vec1[i].size(), vec2[i].size()); std::sort(vec1[i].begin(), vec1[i].end()); std::sort(vec2[i].begin(), vec2[i].end()); - for (size_t j = 0; j < vec1[i].size(); j++) + for (size_t j = 0; j < vec1[i].size(); ++j) { BOOST_REQUIRE_EQUAL(vec1[i][j], vec2[i][j]); } diff --git a/src/mlpack/tests/nbc_test.cpp b/src/mlpack/tests/nbc_test.cpp index 192d76a738..7e33f5c7c8 100644 --- a/src/mlpack/tests/nbc_test.cpp +++ b/src/mlpack/tests/nbc_test.cpp @@ -45,7 +45,7 @@ BOOST_AUTO_TEST_CASE(NaiveBayesClassifierTest) for (size_t i = 0; i < dimension; ++i) { - for (size_t j = 0; j < classes; j++) + for (size_t j = 0; j < classes; ++j) { calcMat(i, j) = nbcTest.Means()(i, j); calcMat(i + dimension, j) = nbcTest.Variances()(i, j); @@ -56,7 +56,7 @@ BOOST_AUTO_TEST_CASE(NaiveBayesClassifierTest) calcMat(2 * dimension, i) = nbcTest.Probabilities()(i); for (size_t i = 0; i < calcMat.n_rows; ++i) - for (size_t j = 0; j < classes; j++) + for (size_t j = 0; j < classes; ++j) BOOST_REQUIRE_CLOSE(trainRes(i, j) + .00001, calcMat(i, j), 0.01); arma::mat testData; @@ -113,7 +113,7 @@ BOOST_AUTO_TEST_CASE(NaiveBayesClassifierIncrementalTest) for (size_t i = 0; i < dimension; ++i) { - for (size_t j = 0; j < classes; j++) + for (size_t j = 0; j < classes; ++j) { calcMat(i, j) = nbcTest.Means()(i, j); calcMat(i + dimension, j) = nbcTest.Variances()(i, j); @@ -124,7 +124,7 @@ BOOST_AUTO_TEST_CASE(NaiveBayesClassifierIncrementalTest) calcMat(2 * dimension, i) = nbcTest.Probabilities()(i); for (size_t i = 0; i < calcMat.n_cols; ++i) - for (size_t j = 0; j < classes; j++) + for (size_t j = 0; j < classes; ++j) BOOST_REQUIRE_CLOSE(trainRes(j, i) + .00001, calcMat(j, i), 0.01); arma::mat testData; diff --git a/src/mlpack/tests/range_search_test.cpp b/src/mlpack/tests/range_search_test.cpp index 923004cf12..27c99f89a8 100644 --- a/src/mlpack/tests/range_search_test.cpp +++ b/src/mlpack/tests/range_search_test.cpp @@ -36,7 +36,7 @@ void SortResults(const vector>& neighbors, for (size_t i = 0; i < neighbors.size(); ++i) { output[i].resize(neighbors[i].size()); - for (size_t j = 0; j < neighbors[i].size(); j++) + for (size_t j = 0; j < neighbors[i].size(); ++j) output[i][j] = make_pair(distances[i][j], neighbors[i][j]); // Now that it's constructed, sort it. @@ -489,7 +489,7 @@ BOOST_AUTO_TEST_CASE(DualTreeVsNaive1) { BOOST_REQUIRE(sortedTree[i].size() == sortedNaive[i].size()); - for (size_t j = 0; j < sortedTree[i].size(); j++) + for (size_t j = 0; j < sortedTree[i].size(); ++j) { BOOST_REQUIRE(sortedTree[i][j].second == sortedNaive[i][j].second); BOOST_REQUIRE_CLOSE(sortedTree[i][j].first, sortedNaive[i][j].first, @@ -538,7 +538,7 @@ BOOST_AUTO_TEST_CASE(DualTreeVsNaive2) { BOOST_REQUIRE(sortedTree[i].size() == sortedNaive[i].size()); - for (size_t j = 0; j < sortedTree[i].size(); j++) + for (size_t j = 0; j < sortedTree[i].size(); ++j) { BOOST_REQUIRE(sortedTree[i][j].second == sortedNaive[i][j].second); BOOST_REQUIRE_CLOSE(sortedTree[i][j].first, sortedNaive[i][j].first, @@ -587,7 +587,7 @@ BOOST_AUTO_TEST_CASE(SingleTreeVsNaive) { BOOST_REQUIRE(sortedTree[i].size() == sortedNaive[i].size()); - for (size_t j = 0; j < sortedTree[i].size(); j++) + for (size_t j = 0; j < sortedTree[i].size(); ++j) { BOOST_REQUIRE(sortedTree[i][j].second == sortedNaive[i][j].second); BOOST_REQUIRE_CLOSE(sortedTree[i][j].first, sortedNaive[i][j].first, diff --git a/src/mlpack/tests/rectangle_tree_test.cpp b/src/mlpack/tests/rectangle_tree_test.cpp index 9828815cdc..869fab872d 100644 --- a/src/mlpack/tests/rectangle_tree_test.cpp +++ b/src/mlpack/tests/rectangle_tree_test.cpp @@ -105,12 +105,12 @@ BOOST_AUTO_TEST_CASE(RectangleTreeConstructionRepeatTest) std::vector allPoints = GetAllPointsInTree(tree); for (size_t i = 0; i < allPoints.size(); ++i) { - for (size_t j = i + 1; j < allPoints.size(); j++) + for (size_t j = i + 1; j < allPoints.size(); ++j) { arma::vec v1 = *(allPoints[i]); arma::vec v2 = *(allPoints[j]); bool same = true; - for (size_t k = 0; k < v1.n_rows; k++) + for (size_t k = 0; k < v1.n_rows; ++k) same &= (v1[k] == v2[k]); BOOST_REQUIRE_NE(same, true); @@ -141,7 +141,7 @@ void CheckContainment(const TreeType& tree) { for (size_t i = 0; i < tree.NumChildren(); ++i) { - for (size_t j = 0; j < tree.Bound().Dim(); j++) + for (size_t j = 0; j < tree.Bound().Dim(); ++j) { // All children should be covered by the parent node. // Some children can be empty (only in case of the R++ tree) @@ -171,7 +171,7 @@ void CheckExactContainment(const TreeType& tree) { double min = DBL_MAX; double max = -1.0 * DBL_MAX; - for (size_t j = 0; j < tree.Count(); j++) + for (size_t j = 0; j < tree.Count(); ++j) { if (tree.Dataset().col(tree.Point(j))[i] < min) min = tree.Dataset().col(tree.Point(j))[i]; @@ -188,7 +188,7 @@ void CheckExactContainment(const TreeType& tree) { double min = DBL_MAX; double max = -1.0 * DBL_MAX; - for (size_t j = 0; j < tree.NumChildren(); j++) + for (size_t j = 0; j < tree.NumChildren(); ++j) { if (tree.Child(j).Bound()[i].Lo() < min) min = tree.Child(j).Bound()[i].Lo(); @@ -396,12 +396,12 @@ BOOST_AUTO_TEST_CASE(PointDeletion) std::vector allPoints = GetAllPointsInTree(tree); for (size_t i = 0; i < allPoints.size(); ++i) { - for (size_t j = i + 1; j < allPoints.size(); j++) + for (size_t j = i + 1; j < allPoints.size(); ++j) { arma::vec v1 = *(allPoints[i]); arma::vec v2 = *(allPoints[j]); bool same = true; - for (size_t k = 0; k < v1.n_rows; k++) + for (size_t k = 0; k < v1.n_rows; ++k) same &= (v1[k] == v2[k]); BOOST_REQUIRE(!same); @@ -480,12 +480,12 @@ BOOST_AUTO_TEST_CASE(PointDynamicAdd) std::vector allPoints = GetAllPointsInTree(tree); for (size_t i = 0; i < allPoints.size(); ++i) { - for (size_t j = i + 1; j < allPoints.size(); j++) + for (size_t j = i + 1; j < allPoints.size(); ++j) { arma::vec v1 = *(allPoints[i]); arma::vec v2 = *(allPoints[j]); bool same = true; - for (size_t k = 0; k < v1.n_rows; k++) + for (size_t k = 0; k < v1.n_rows; ++k) same &= (v1[k] == v2[k]); BOOST_REQUIRE(!same); @@ -958,7 +958,7 @@ void CheckOverlap(const TreeType& tree) { success = true; - for (size_t j = 0; j < tree.NumChildren(); j++) + for (size_t j = 0; j < tree.NumChildren(); ++j) { if (j == i) continue; @@ -1050,7 +1050,7 @@ void CheckRPlusPlusTreeBound(const TreeType& tree) bool success = true; // Ensure that the maximum bounding rectangle contains all children. - for (size_t k = 0; k < tree.Bound().Dim(); k++) + for (size_t k = 0; k < tree.Bound().Dim(); ++k) { BOOST_REQUIRE_LE(tree.Bound()[k].Hi(), tree.AuxiliaryInfo().OuterBound()[k].Hi()); @@ -1075,7 +1075,7 @@ void CheckRPlusPlusTreeBound(const TreeType& tree) const Bound& bound1 = tree.Child(i).AuxiliaryInfo().OuterBound(); success = true; - for (size_t j = 0; j < tree.NumChildren(); j++) + for (size_t j = 0; j < tree.NumChildren(); ++j) { if (j == i) continue; diff --git a/src/mlpack/tests/recurrent_network_test.cpp b/src/mlpack/tests/recurrent_network_test.cpp index 3c8e62b91d..cbf97179aa 100644 --- a/src/mlpack/tests/recurrent_network_test.cpp +++ b/src/mlpack/tests/recurrent_network_test.cpp @@ -487,7 +487,7 @@ arma::Mat GenerateReberGrammarData( else GenerateReber(transitions, trainReber); - for (size_t j = 0; j < trainReber.length() - 1; j++) + for (size_t j = 0; j < trainReber.length() - 1; ++j) { ReberTranslation(trainReber[j], translation); trainInput(0, i) = arma::join_cols(trainInput(0, i), translation); @@ -506,7 +506,7 @@ arma::Mat GenerateReberGrammarData( else GenerateReber(transitions, testReber); - for (size_t j = 0; j < testReber.length() - 1; j++) + for (size_t j = 0; j < testReber.length() - 1; ++j) { ReberTranslation(testReber[j], translation); testInput(0, i) = arma::join_cols(testInput(0, i), translation); @@ -576,7 +576,7 @@ void ReberGrammarTestNetwork(ModelType& model, arma::cube inputTemp, labelsTemp; for (size_t iteration = 0; iteration < (iterations + offset); iteration++) { - for (size_t j = 0; j < trainReberGrammarCount; j++) + for (size_t j = 0; j < trainReberGrammarCount; ++j) { // Each sequence may be a different length, so we need to extract them // manually. We will reshape them into a cube with each slice equal to @@ -609,7 +609,7 @@ void ReberGrammarTestNetwork(ModelType& model, size_t reberError = 0; - for (size_t j = 0; j < (prediction.n_elem / reberGrammerSize); j++) + for (size_t j = 0; j < (prediction.n_elem / reberGrammerSize); ++j) { char predictedSymbol, inputSymbol; std::string reberChoices; @@ -820,7 +820,7 @@ void DistractedSequenceRecallTestNetwork( arma::cube inputTemp, labelsTemp; for (size_t iteration = 0; iteration < (9 + offset); iteration++) { - for (size_t j = 0; j < trainDistractedSequenceCount; j++) + for (size_t j = 0; j < trainDistractedSequenceCount; ++j) { inputTemp = arma::cube(trainInput.at(0, j).memptr(), inputSize, 1, trainInput.at(0, j).n_elem / inputSize, false, true); @@ -1103,7 +1103,7 @@ void ReberGrammarTestCustomNetwork(const size_t hiddenSize = 4, arma::cube inputTemp, labelsTemp; for (size_t iteration = 0; iteration < (iterations + offset); iteration++) { - for (size_t j = 0; j < trainReberGrammarCount; j++) + for (size_t j = 0; j < trainReberGrammarCount; ++j) { // Each sequence may be a different length, so we need to extract them // manually. We will reshape them into a cube with each slice equal to @@ -1136,7 +1136,7 @@ void ReberGrammarTestCustomNetwork(const size_t hiddenSize = 4, size_t reberError = 0; - for (size_t j = 0; j < (prediction.n_elem / reberGrammerSize); j++) + for (size_t j = 0; j < (prediction.n_elem / reberGrammerSize); ++j) { char predictedSymbol, inputSymbol; std::string reberChoices; diff --git a/src/mlpack/tests/regularized_svd_test.cpp b/src/mlpack/tests/regularized_svd_test.cpp index 4c7e38ab6b..6f16365a47 100644 --- a/src/mlpack/tests/regularized_svd_test.cpp +++ b/src/mlpack/tests/regularized_svd_test.cpp @@ -52,7 +52,7 @@ BOOST_AUTO_TEST_CASE(RegularizedSVDFunctionRandomEvaluate) // Calculate cost by summing up cost of each example. double cost = 0; - for (size_t j = 0; j < numRatings; j++) + for (size_t j = 0; j < numRatings; ++j) { const size_t user = data(0, j); const size_t item = data(1, j) + numUsers; @@ -104,7 +104,7 @@ BOOST_AUTO_TEST_CASE(RegularizedSVDFunctionRegularizationEvaluate) // each rating and sum them up. double smallRegTerm = 0; double bigRegTerm = 0; - for (size_t j = 0; j < numRatings; j++) + for (size_t j = 0; j < numRatings; ++j) { const size_t user = data(0, j); const size_t item = data(1, j) + numUsers; @@ -164,7 +164,7 @@ BOOST_AUTO_TEST_CASE(RegularizedSVDFunctionGradient) for (size_t i = 0; i < rank; ++i) { - for (size_t j = 0; j < numUsers + numItems; j++) + for (size_t j = 0; j < numUsers + numItems; ++j) { // Perturb parameter with a positive constant and get costs. parameters(i, j) += epsilon; diff --git a/src/mlpack/tests/softmax_regression_test.cpp b/src/mlpack/tests/softmax_regression_test.cpp index a56d3bf22b..97d73e435c 100644 --- a/src/mlpack/tests/softmax_regression_test.cpp +++ b/src/mlpack/tests/softmax_regression_test.cpp @@ -50,7 +50,7 @@ BOOST_AUTO_TEST_CASE(SoftmaxRegressionFunctionEvaluate) double logLikelihood = 0; // Compute error for each training example. - for (size_t j = 0; j < points; j++) + for (size_t j = 0; j < points; ++j) { arma::mat hypothesis, probabilities; @@ -145,7 +145,7 @@ BOOST_AUTO_TEST_CASE(SoftmaxRegressionFunctionGradient) // For each parameter. for (size_t i = 0; i < numClasses; ++i) { - for (size_t j = 0; j < inputSize; j++) + for (size_t j = 0; j < inputSize; ++j) { // Perturb parameter with a positive constant and get costs. parameters(i, j) += epsilon; diff --git a/src/mlpack/tests/sparse_autoencoder_test.cpp b/src/mlpack/tests/sparse_autoencoder_test.cpp index 3f885310df..ffba552bb9 100644 --- a/src/mlpack/tests/sparse_autoencoder_test.cpp +++ b/src/mlpack/tests/sparse_autoencoder_test.cpp @@ -83,7 +83,7 @@ BOOST_AUTO_TEST_CASE(SparseAutoencoderFunctionRandomEvaluate) double reconstructionError = 0; // Compute error for each training example. - for (size_t j = 0; j < points; j++) + for (size_t j = 0; j < points; ++j) { arma::mat hiddenLayer, outputLayer, diff; @@ -177,7 +177,7 @@ BOOST_AUTO_TEST_CASE(SparseAutoencoderFunctionKLDivergenceEvaluate) rhoCap.zeros(hSize, 1); // Compute hidden layer activations for each example. - for (size_t j = 0; j < points; j++) + for (size_t j = 0; j < points; ++j) { arma::mat hiddenLayer; @@ -238,7 +238,7 @@ BOOST_AUTO_TEST_CASE(SparseAutoencoderFunctionGradient) // For each parameter. for (size_t i = 0; i <= l3; ++i) { - for (size_t j = 0; j <= l2; j++) + for (size_t j = 0; j <= l2; ++j) { // Perturb parameter with a positive constant and get costs. parameters(i, j) += epsilon; diff --git a/src/mlpack/tests/sparse_coding_test.cpp b/src/mlpack/tests/sparse_coding_test.cpp index fb259c692c..e8fc335bac 100644 --- a/src/mlpack/tests/sparse_coding_test.cpp +++ b/src/mlpack/tests/sparse_coding_test.cpp @@ -30,7 +30,7 @@ void SCVerifyCorrectness(vec beta, vec errCorr, double lambda) { const double tol = 1e-12; size_t nDims = beta.n_elem; - for (size_t j = 0; j < nDims; j++) + for (size_t j = 0; j < nDims; ++j) { if (beta(j) == 0) { diff --git a/src/mlpack/tests/string_encoding_test.cpp b/src/mlpack/tests/string_encoding_test.cpp index e6ce85f88c..5174b9f1f8 100644 --- a/src/mlpack/tests/string_encoding_test.cpp +++ b/src/mlpack/tests/string_encoding_test.cpp @@ -70,7 +70,7 @@ void CheckVectors(const vector>& a, { BOOST_REQUIRE_EQUAL(a[i].size(), b[i].size()); - for (size_t j = 0; j < a[i].size(); j++) + for (size_t j = 0; j < a[i].size(); ++j) BOOST_REQUIRE_CLOSE(a[i][j], b[i][j], tolerance); } } diff --git a/src/mlpack/tests/svdplusplus_test.cpp b/src/mlpack/tests/svdplusplus_test.cpp index f363a9199a..49fc7318fe 100644 --- a/src/mlpack/tests/svdplusplus_test.cpp +++ b/src/mlpack/tests/svdplusplus_test.cpp @@ -55,7 +55,7 @@ BOOST_AUTO_TEST_CASE(SVDPlusPlusEvaluate) // Calculate cost by summing up cost of each example. double cost = 0; - for (size_t j = 0; j < data.n_cols; j++) + for (size_t j = 0; j < data.n_cols; ++j) { const size_t user = data(0, j); const size_t item = data(1, j) + numUsers; @@ -136,7 +136,7 @@ BOOST_AUTO_TEST_CASE(SVDPlusPlusFunctionRegularizationEvaluate) // each rating and sum them up. double smallRegTerm = 0; double bigRegTerm = 0; - for (size_t j = 0; j < data.n_cols; j++) + for (size_t j = 0; j < data.n_cols; ++j) { const size_t user = data(0, j); const size_t item = data(1, j) + numUsers; @@ -221,7 +221,7 @@ BOOST_AUTO_TEST_CASE(SVDPlusPlusFunctionGradient) for (size_t i = 0; i < rank; ++i) { - for (size_t j = 0; j < numUsers + numItems; j++) + for (size_t j = 0; j < numUsers + numItems; ++j) { // Perturb parameter with a positive constant and get costs. parameters(i, j) += epsilon; diff --git a/src/mlpack/tests/tree_test.cpp b/src/mlpack/tests/tree_test.cpp index 455e280920..ef79273eb6 100644 --- a/src/mlpack/tests/tree_test.cpp +++ b/src/mlpack/tests/tree_test.cpp @@ -429,7 +429,7 @@ BOOST_AUTO_TEST_CASE(HRectBoundRangeDistanceBound) lo_b.randu(); width_b.randu(); - for (size_t j = 0; j < dim; j++) + for (size_t j = 0; j < dim; ++j) { a[j] = Range(loA[j], loA[j] + widthA[j]); b[j] = Range(lo_b[j], lo_b[j] + width_b[j]); @@ -473,11 +473,11 @@ BOOST_AUTO_TEST_CASE(HRectBoundRangeDistancePoint) loA.randu(); widthA.randu(); - for (size_t j = 0; j < dim; j++) + for (size_t j = 0; j < dim; ++j) a[j] = Range(loA[j], loA[j] + widthA[j]); // Now run the test on a few points. - for (int j = 0; j < 10; j++) + for (int j = 0; j < 10; ++j) { arma::vec point(dim); @@ -952,7 +952,7 @@ BOOST_AUTO_TEST_CASE(HRectBoundRootRangeDistanceBound) lo_b.randu(); width_b.randu(); - for (size_t j = 0; j < dim; j++) + for (size_t j = 0; j < dim; ++j) { a[j] = Range(loA[j], loA[j] + widthA[j]); b[j] = Range(lo_b[j], lo_b[j] + width_b[j]); @@ -996,11 +996,11 @@ BOOST_AUTO_TEST_CASE(HRectBoundRootRangeDistancePoint) loA.randu(); widthA.randu(); - for (size_t j = 0; j < dim; j++) + for (size_t j = 0; j < dim; ++j) a[j] = Range(loA[j], loA[j] + widthA[j]); // Now run the test on a few points. - for (int j = 0; j < 10; j++) + for (int j = 0; j < 10; ++j) { arma::vec point(dim); @@ -1324,7 +1324,7 @@ BOOST_AUTO_TEST_CASE(KdTreeTest) // Check the forward and backward mappings for correctness. for (size_t i = 0; i < size; ++i) { - for (size_t j = 0; j < dimensions; j++) + for (size_t j = 0; j < dimensions; ++j) { BOOST_REQUIRE_EQUAL(treeset(j, i), dataset(j, newToOld[i])); BOOST_REQUIRE_EQUAL(treeset(j, oldToNew[i]), dataset(j, i)); @@ -1344,7 +1344,7 @@ BOOST_AUTO_TEST_CASE(KdTreeTest) while (depth < v.size()) { for (size_t i = depth; i < 2 * depth && i < v.size(); ++i) - for (size_t j = i + 1; j < 2 * depth && j < v.size(); j++) + for (size_t j = i + 1; j < 2 * depth && j < v.size(); ++j) if (v[i] != NULL && v[j] != NULL) BOOST_REQUIRE(!v[i]->Bound().Contains(v[j]->Bound())); @@ -1393,7 +1393,7 @@ BOOST_AUTO_TEST_CASE(MaxRPTreeTest) // Check the forward and backward mappings for correctness. for (size_t i = 0; i < size; ++i) { - for (size_t j = 0; j < dimensions; j++) + for (size_t j = 0; j < dimensions; ++j) { BOOST_REQUIRE_EQUAL(treeset(j, i), dataset(j, newToOld[i])); BOOST_REQUIRE_EQUAL(treeset(j, oldToNew[i]), dataset(j, i)); @@ -1426,7 +1426,7 @@ bool CheckHyperplaneSplit(const TreeType& tree) for (size_t i = 0; i < tree.Left()->NumDescendants(); ++i) { - for (size_t k = 0; k < dataset.n_rows; k++) + for (size_t k = 0; k < dataset.n_rows; ++k) mat(k, i) = - dataset(k, tree.Left()->Descendant(i)); mat(dataset.n_rows, i) = -1; @@ -1434,7 +1434,7 @@ bool CheckHyperplaneSplit(const TreeType& tree) for (size_t i = 0; i < tree.Right()->NumDescendants(); ++i) { - for (size_t k = 0; k < dataset.n_rows; k++) + for (size_t k = 0; k < dataset.n_rows; ++k) mat(k, i + tree.Left()->NumDescendants()) = dataset(k, tree.Right()->Descendant(i)); @@ -1456,7 +1456,7 @@ bool CheckHyperplaneSplit(const TreeType& tree) for (size_t it = 0; it < numIters; it++) { success = true; - for (size_t k = 0; k < tree.Count(); k++) + for (size_t k = 0; k < tree.Count(); ++k) { ElemType result = arma::dot(mat.col(k), x); if (result > 0) @@ -1535,7 +1535,7 @@ BOOST_AUTO_TEST_CASE(RPTreeTest) // Check the forward and backward mappings for correctness. for (size_t i = 0; i < size; ++i) { - for (size_t j = 0; j < dimensions; j++) + for (size_t j = 0; j < dimensions; ++j) { BOOST_REQUIRE_EQUAL(treeset(j, i), dataset(j, newToOld[i])); BOOST_REQUIRE_EQUAL(treeset(j, oldToNew[i]), dataset(j, i)); @@ -1557,7 +1557,7 @@ void CheckRPTreeSplit(const TreeType& tree) arma::Col center; tree.Left()->Bound().Center(center); ElemType maxDist = 0; - for (size_t k =0; k < tree.Left()->NumDescendants(); k++) + for (size_t k =0; k < tree.Left()->NumDescendants(); ++k) { ElemType dist = MetricType::Evaluate(center, tree.Dataset().col(tree.Left()->Descendant(k))); @@ -1566,7 +1566,7 @@ void CheckRPTreeSplit(const TreeType& tree) maxDist = dist; } - for (size_t k =0; k < tree.Right()->NumDescendants(); k++) + for (size_t k =0; k < tree.Right()->NumDescendants(); ++k) { ElemType dist = MetricType::Evaluate(center, tree.Dataset().col(tree.Right()->Descendant(k))); @@ -1650,7 +1650,7 @@ BOOST_AUTO_TEST_CASE(BallTreeTest) // Check the forward and backward mappings for correctness. for (size_t i = 0; i < size; ++i) { - for (size_t j = 0; j < dimensions; j++) + for (size_t j = 0; j < dimensions; ++j) { BOOST_REQUIRE_EQUAL(treeset(j, i), dataset(j, newToOld[i])); BOOST_REQUIRE_EQUAL(treeset(j, oldToNew[i]), dataset(j, i)); @@ -1755,7 +1755,7 @@ BOOST_AUTO_TEST_CASE(ExhaustiveSparseKDTreeTest) // Check the forward and backward mappings for correctness. for (size_t i = 0; i < size; ++i) { - for (size_t j = 0; j < dimensions; j++) + for (size_t j = 0; j < dimensions; ++j) { BOOST_REQUIRE_EQUAL(treeset(j, i), dataset(j, newToOld[i])); BOOST_REQUIRE_EQUAL(treeset(j, oldToNew[i]), dataset(j, i)); @@ -1775,7 +1775,7 @@ BOOST_AUTO_TEST_CASE(ExhaustiveSparseKDTreeTest) while (depth < v.size()) { for (size_t i = depth; i < 2 * depth && i < v.size(); ++i) - for (size_t j = i + 1; j < 2 * depth && j < v.size(); j++) + for (size_t j = i + 1; j < 2 * depth && j < v.size(); ++j) if (v[i] != NULL && v[j] != NULL) BOOST_REQUIRE(!v[i]->Bound().Contains(v[j]->Bound())); diff --git a/src/mlpack/tests/ub_tree_test.cpp b/src/mlpack/tests/ub_tree_test.cpp index ddc055f8b0..8aa5f06286 100644 --- a/src/mlpack/tests/ub_tree_test.cpp +++ b/src/mlpack/tests/ub_tree_test.cpp @@ -44,7 +44,7 @@ BOOST_AUTO_TEST_CASE(AddressTest) addr::PointToAddress(address, dataset.col(i)); addr::AddressToPoint(point, address); - for (size_t k = 0; k < dataset.n_rows; k++) + for (size_t k = 0; k < dataset.n_rows; ++k) BOOST_REQUIRE_CLOSE(dataset(k, i), point[k], 1e-13); } } @@ -122,10 +122,10 @@ void CheckBound(const TreeType& tree) // Ensure that there is a hyperrectangle that contains the point. bool success = false; - for (size_t j = 0; j < tree.Bound().NumBounds(); j++) + for (size_t j = 0; j < tree.Bound().NumBounds(); ++j) { success = true; - for (size_t k = 0; k < loBound.n_rows; k++) + for (size_t k = 0; k < loBound.n_rows; ++k) { if (point[k] < loBound(k, j) - 1e-14 * std::fabs(loBound(k, j)) || point[k] > hiBound(k, j) + 1e-14 * std::fabs(hiBound(k, j))) @@ -173,7 +173,7 @@ void CheckDistance(TreeType& tree, TreeType* node = NULL) CheckDistance(tree, node); - for (size_t j = 0; j < tree.Dataset().n_cols; j++) + for (size_t j = 0; j < tree.Dataset().n_cols; ++j) { const arma::Col& point = tree. Dataset().col(j); ElemType maxDist = 0; @@ -216,7 +216,7 @@ void CheckDistance(TreeType& tree, TreeType* node = NULL) ElemType maxDist = 0; ElemType minDist = std::numeric_limits::max(); for (size_t i = 0; i < tree.NumDescendants(); ++i) - for (size_t j = 0; j < node->NumDescendants(); j++) + for (size_t j = 0; j < node->NumDescendants(); ++j) { ElemType dist = MetricType::Evaluate( tree.Dataset().col(tree.Descendant(i)), @@ -294,7 +294,7 @@ BOOST_AUTO_TEST_CASE(UBTreeTest) // Check the forward and backward mappings for correctness. for (size_t i = 0; i < size; ++i) { - for (size_t j = 0; j < dimensions; j++) + for (size_t j = 0; j < dimensions; ++j) { BOOST_REQUIRE_EQUAL(treeset(j, i), dataset(j, newToOld[i])); BOOST_REQUIRE_EQUAL(treeset(j, oldToNew[i]), dataset(j, i)); diff --git a/src/mlpack/tests/vantage_point_tree_test.cpp b/src/mlpack/tests/vantage_point_tree_test.cpp index c4f2c6b874..6380b38972 100644 --- a/src/mlpack/tests/vantage_point_tree_test.cpp +++ b/src/mlpack/tests/vantage_point_tree_test.cpp @@ -222,7 +222,7 @@ BOOST_AUTO_TEST_CASE(VPTreeTest) // Check the forward and backward mappings for correctness. for (size_t i = 0; i < size; ++i) { - for (size_t j = 0; j < dimensions; j++) + for (size_t j = 0; j < dimensions; ++j) { BOOST_REQUIRE_EQUAL(treeset(j, i), dataset(j, newToOld[i])); BOOST_REQUIRE_EQUAL(treeset(j, oldToNew[i]), dataset(j, i)); From a7542b15735830a444d1113e9a99da9240f94571 Mon Sep 17 00:00:00 2001 From: Omar Shrit Date: Sat, 20 Jun 2020 01:20:15 +0200 Subject: [PATCH 03/16] Use post increment for indices Signed-off-by: Omar Shrit --- src/mlpack/core/math/columns_to_blocks.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/mlpack/core/math/columns_to_blocks.cpp b/src/mlpack/core/math/columns_to_blocks.cpp index eeb4469886..4cdab32668 100644 --- a/src/mlpack/core/math/columns_to_blocks.cpp +++ b/src/mlpack/core/math/columns_to_blocks.cpp @@ -77,7 +77,7 @@ void ColumnsToBlocks::Transform(const arma::mat& maximalInputs, const size_t maxCol = j * colOffset + blockWidth; output.submat(minRow, minCol, maxRow, maxCol) = - arma::reshape(maximalInputs.col(++k), blockHeight, blockWidth); + arma::reshape(maximalInputs.col(k++), blockHeight, blockWidth); if (k >= maxSize) break; From 27fcbd69415596bcca10e79a35f5bd9512979f49 Mon Sep 17 00:00:00 2001 From: Omar Shrit Date: Sat, 20 Jun 2020 13:17:53 +0200 Subject: [PATCH 04/16] Remove early_stop_at_min_loss callbacks for mlpack A better version is implemented in ensmallen Signed-off-by: Omar Shrit --- .../ann/callbacks/early_stop_at_min_loss.hpp | 126 ------------------ 1 file changed, 126 deletions(-) delete mode 100644 src/mlpack/methods/ann/callbacks/early_stop_at_min_loss.hpp diff --git a/src/mlpack/methods/ann/callbacks/early_stop_at_min_loss.hpp b/src/mlpack/methods/ann/callbacks/early_stop_at_min_loss.hpp deleted file mode 100644 index d6b86d7515..0000000000 --- a/src/mlpack/methods/ann/callbacks/early_stop_at_min_loss.hpp +++ /dev/null @@ -1,126 +0,0 @@ -/** - * @file early_stop_at_min_loss.hpp - * @author Marcus Edel - * @author Omar Shrit - * - * Implementation of the early stop at minimum loss callback function. - * - * mlpack is free software; you may redistribute it and/or modify it under - * the terms of the 3-clause BSD license. You should have received a copy of - * the 3-clause BSD license along with mlpack. If not, see - * http://www.opensource.org/licenses/BSD-3-Clause for more information. - */ -#ifndef MLPACK_CALLBACKS_EARLY_STOP_AT_MIN_LOSS_HPP -#define MLPACK_CALLBACKS_EARLY_STOP_AT_MIN_LOSS_HPP - -namespace mlpack { -namespace ann /** Artificial Neural Network. */ { - -/** - * Early stopping to terminate the optimization process early if the loss stops - * decreasing. - */ -class EarlyStopAtMinLoss -{ - public: - /** - * Set up the early stop at min loss class, which keeps track of the minimum - * loss and stops the optimization process if the loss stops decreasing. - * - * @param patienceIn The number of epochs to wait after the minimum loss has - * been reached or no improvement has been made (Default: 10). - */ - EarlyStopAtMinLoss(const size_t patienceIn = 10, - std::ostream& output = arma::get_cout_stream()) : - patience(patienceIn), - bestObjective(std::numeric_limits::max()), - steps(0), - output(output) - { /* Nothing to do here */ } - - /** - * Set up the early stop at min class, which keeps track - * of the minimum loss and stops the optimization process if the loss stops - * decreasing on a specific validation set. - * - * @param predictors: data matrix used to predict the responses. - * @param responses: data matrix used to evaluate the predictions. - * @param patienceIn The number of epochs to wait after the minimum loss has - * been reached or no improvement has been made (Default: 10). - */ - EarlyStopAtMinLoss(const arma::mat& predictors, - const arma::mat& responses, - const size_t patienceIn = 10, - std::ostream& output = arma::get_cout_stream()) : - patience(patienceIn), - bestObjective(std::numeric_limits::max()), - steps(0), - output(output) - { - this->predictors = predictors; - this->responses = responses; - } - - /** - * Callback function called at the end of a pass over the data. - * - * @param optimizer The optimizer used to update the function. - * @param function Function to optimize. - * @param coordinates Starting point. - * @param epoch The index of the current epoch. - * @param objective Objective value of the current point. - */ - template - bool EndEpoch(OptimizerType& /* optimizer */, - FunctionType& function, - const MatType& /* coordinates */, - const size_t /* epoch */, - double objective) - { - if ((!predictors.empty()) and (!responses.empty())) - { - objective = function.Evaluate(predictors, responses); - output << "Validation loss: "<< objective << std::endl; - } - - if (objective < bestObjective) - { - steps = 0; - bestObjective = objective; - return false; - } - - steps++; - if (steps >= patience) - { - Log::Info << "Minimum loss reached; terminate optimization." << std::endl; - return true; - } - - return false; - } - - private: - //! The number of epochs to wait before terminating the optimization process. - size_t patience; - - //! Locally-stored best objective. - double bestObjective; - - //! Locally-stored number of steps since the loss improved. - size_t steps; - - //! The output stream that all data is to be sent to; example: std::cout. - std::ostream& output; - - //! The matrix of data points (predictors). - arma::mat predictors; - - //! The matrix of responses to the input data points. - arma::mat responses; -}; - -} -} - -#endif From 61514625df943760af1925b91c258b0ff57427a6 Mon Sep 17 00:00:00 2001 From: shrit Date: Sat, 27 Jun 2020 00:01:37 +0200 Subject: [PATCH 05/16] Update style in src/mlpack/tests/main_tests/hmm_train_test.cpp Co-authored-by: Ryan Curtin --- src/mlpack/tests/main_tests/hmm_train_test.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/mlpack/tests/main_tests/hmm_train_test.cpp b/src/mlpack/tests/main_tests/hmm_train_test.cpp index 1cba70fdd7..11395cc780 100644 --- a/src/mlpack/tests/main_tests/hmm_train_test.cpp +++ b/src/mlpack/tests/main_tests/hmm_train_test.cpp @@ -64,7 +64,7 @@ inline void CheckMatricesDiffer(arma::mat& a, arma::mat& b, double tolerance) bool valsEqual = true; if (dimsEqual) { - for (size_t i=0; i Date: Sat, 27 Jun 2020 00:05:12 +0200 Subject: [PATCH 06/16] Remove knn_low_resource_main Signed-off-by: Omar Shrit --- .../neighbor_search/knn_low_resource_main.cpp | 189 ------------------ 1 file changed, 189 deletions(-) delete mode 100644 src/mlpack/methods/neighbor_search/knn_low_resource_main.cpp diff --git a/src/mlpack/methods/neighbor_search/knn_low_resource_main.cpp b/src/mlpack/methods/neighbor_search/knn_low_resource_main.cpp deleted file mode 100644 index aa7ddfaf17..0000000000 --- a/src/mlpack/methods/neighbor_search/knn_low_resource_main.cpp +++ /dev/null @@ -1,189 +0,0 @@ -/** - * @file knn_main.cpp - * @author Ryan Curtin - * @author Omar Shrit - * - * Implementation of the kNN executable. Allows some number of standard - * options. - * This implementation is intended to be used on low resource devices - * - * - * mlpack is free software; you may redistribute it and/or modify it under the - * terms of the 3-clause BSD license. You should have received a copy of the - * 3-clause BSD license along with mlpack. If not, see - * http://www.opensource.org/licenses/BSD-3-Clause for more information. - */ -#include -#include -#include -#include -#include - -// #include -// #include -// #include - -#include "neighbor_search.hpp" -#include "ns_model.hpp" -#include "unmap.hpp" - -using namespace std; -using namespace mlpack; -using namespace mlpack::neighbor; -using namespace mlpack::tree; -using namespace mlpack::metric; -using namespace mlpack::util; - -// Convenience typedef. -typedef NSModel KNNModel; - -// Information about the program itself. -PROGRAM_INFO( - "k-Nearest-Neighbors Search", - // Short description. - "An implementation of k-nearest-neighbor search using " - "dual-tree algorithms. Given a set of reference points and query points, " - "this can find the k nearest neighbors in the reference set of each query " - "point using trees; trees that are built can be saved for future use.", - // Long description. - "This program will calculate the k-nearest-neighbors of a set of " - "points using kd-trees or cover trees (cover tree support is experimental " - "and may be slow). You may specify a separate set of " - "reference points and query points, or just a reference set which will be " - "used as both the reference and query set." - "\n\n" - "For example, the following command will calculate the 5 nearest neighbors " - "of each point in " + - PRINT_DATASET("input") + - " and store the distances " - "in " + - PRINT_DATASET("distances") + " and the neighbors in " + - PRINT_DATASET("neighbors") + - ": " - "\n\n" + - PRINT_CALL("knn", - "k", - 5, - "reference", - "input", - "neighbors", - "neighbors", - "distances", - "distances") + - "\n\n" - "The output is organized such that row i and column j in the neighbors " - "output matrix corresponds to the index of the point in the reference set " - "which is the j'th nearest neighbor from the point in the query set with " - "index i. Row j and column i in the distances output matrix corresponds to" - " the distance between those two points.", - SEE_ALSO("NeighborSearch tutorial (k-nearest-neighbors)", - "@doxygen/nstutorial.html"), - SEE_ALSO("Tree-independent dual-tree algorithms (pdf)", - "http://proceedings.mlr.press/v28/curtin13.pdf"), - SEE_ALSO("mlpack::neighbor::NeighborSearch C++ class documentation", - "@doxygen/classmlpack_1_1neighbor_1_1NeighborSearch.html")); - - // Define our input parameters that this program will take. - PARAM_MATRIX_OUT("distances", "Matrix to output distances into.", "d"); - PARAM_UMATRIX_OUT("neighbors", "Matrix to output neighbors into.", "n"); - - // The option exists to load or save models. -// PARAM_MODEL_IN(KNNModel, "input_model", "Pre-trained kNN model.", "m"); - - // The user may specify a query file of query points and a number of nearest - // neighbors to search for. - PARAM_MATRIX_IN("query", "Matrix containing query points (optional).", "q"); - PARAM_INT_IN("k", "Number of nearest neighbors to find.", "k", 0); - -static void -mlpackMain() -{ - // ReportIgnoredParam({ { "input_model", true } }, "tree_type"); - // ReportIgnoredParam({ { "input_model", true } }, "random_basis"); - - // // The user should give something to do... - // RequireAtLeastOnePassed( - // { "k", "output_model" }, false, "no results will be saved"); - - // // If the user specifies k but no output files, they should be warned. - // if (CLI::HasParam("k")) { - // RequireAtLeastOnePassed( - // { "neighbors", "distances" }, - // false, - // "nearest neighbor search results will not be saved"); - // } - - // // If the user specifies output files but no k, they should be warned. - // ReportIgnoredParam({ { "k", false } }, "neighbors"); - // ReportIgnoredParam({ { "k", false } }, "distances"); - // ReportIgnoredParam({ { "k", false } }, "query"); - - KNNModel* knn = new KNNModel(); - - // Load the model from file. - // knn = CLI::GetParam("input_model"); - - // // Adjust search mode. - // // Use the dual tree mode as a default mode - // knn->SearchMode() = DUAL_TREE_MODE; - - // Log::Info << "Loaded kNN model from '" - // << CLI::GetPrintableParam("input_model") - // << "' (trained on " << knn->Dataset().n_rows << "x" - // << knn->Dataset().n_cols << " dataset)." << endl; - - // // Perform search, if desired. - // if (CLI::HasParam("k")) { - // const size_t k = (size_t)CLI::GetParam("k"); - - // arma::mat queryData; - // if (CLI::HasParam("query")) { - // Log::Info << "Using query data from " - // << CLI::GetPrintableParam("query") << "." << endl; - // queryData = std::move(CLI::GetParam("query")); - // if (queryData.n_rows != knn->Dataset().n_rows) { - // // Clean memory if needed before crashing. - // const size_t dimensions = knn->Dataset().n_rows; - // if (CLI::HasParam("reference")) - // delete knn; - // Log::Fatal << "Query has invalid dimensions(" << queryData.n_rows - // << "); should be " << dimensions << "!" << endl; - // } - // } - - // // Sanity check on k value: must be greater than 0, must be less than or - // // equal to the number of reference points. Since it is unsigned, - // // we only test the upper bound. - // if (k > knn->Dataset().n_cols) { - // // Clean memory if needed before crashing. - // const size_t referencePoints = knn->Dataset().n_cols; - - // // Sanity check on k value: must not be equal to the number of reference - // // points when query data has not been provided. - // if (!CLI::HasParam("query") && k == knn->Dataset().n_cols) { - // // Clean memory if needed before crashing. - // const size_t referencePoints = knn->Dataset().n_cols; - // if (CLI::HasParam("reference")) - // delete knn; - // Log::Fatal << "Invalid k: " << k << "; must be less than the number of " - // << "reference points (" << referencePoints - // << ") if query data has " - // << "not been provided." << endl; - // } - - // // Now run the search. - // arma::Mat neighbors; - // arma::mat distances; - - // if (CLI::HasParam("query")) - // knn->Search(std::move(queryData), k, neighbors, distances); - // else - // knn->Search(k, neighbors, distances); - // Log::Info << "Search complete." << endl; - - // // Save output. - // CLI::GetParam>("neighbors") = std::move(neighbors); - // CLI::GetParam("distances") = std::move(distances); - // } - // } -} From b24e1166a13c7ff440bd3f59fa09083076d8b6fe Mon Sep 17 00:00:00 2001 From: Omar Shrit Date: Sat, 27 Jun 2020 00:05:40 +0200 Subject: [PATCH 07/16] Remove ann_low_resource_main Signed-off-by: Omar Shrit --- .../methods/ann/ann_low_resource_main.cpp | 176 ------------------ 1 file changed, 176 deletions(-) delete mode 100644 src/mlpack/methods/ann/ann_low_resource_main.cpp diff --git a/src/mlpack/methods/ann/ann_low_resource_main.cpp b/src/mlpack/methods/ann/ann_low_resource_main.cpp deleted file mode 100644 index ad1770954e..0000000000 --- a/src/mlpack/methods/ann/ann_low_resource_main.cpp +++ /dev/null @@ -1,176 +0,0 @@ -/** - * An example of using Feed Forward Neural Network (FFN) for - * solving Digit Recognizer problem from Kaggle website. - * - * The full description of a problem as well as datasets for training - * and testing are available here https://www.kaggle.com/c/digit-recognizer - * - * mlpack is free software; you may redistribute it and/or modify it under the - * terms of the 3-clause BSD license. You should have received a copy of the - * 3-clause BSD license along with mlpack. If not, see - * http://www.opensource.org/licenses/BSD-3-Clause for more information. - * - * @author Eugene Freyman - * @author Omar Shrit - */ - -#include -#include -#include - -#include -#include - -#include -#include -#include - -#include -#include - -using namespace mlpack::ann; - -using namespace arma; -using namespace mlpack::util; -using namespace ens; - -arma::Row getLabels(arma::mat predOut) -{ - arma::Row predLabels(predOut.n_cols); - for (arma::uword i = 0; i < predOut.n_cols; ++i) - { - predLabels(i) = predOut.col(i).index_max() + 1; - } - return predLabels; -} - -static void -mlpackMain() -{ - // Dataset is randomly split into validation - // and training parts in the following ratio. - constexpr double RATIO = 0.1; - // The number of neurons in the first layer. - constexpr int H1 = 200; - // The number of neurons in the second layer. - constexpr int H2 = 100; - // Step size of the optimizer. - constexpr double STEP_SIZE = 5e-3; - // Number of data points in each iteration of SGD - constexpr size_t BATCH_SIZE = 64; - // Allow infinite number of iterations until we stopped by EarlyStopAtMinLoss. - const int MAX_ITERATIONS = 0; - - // Labeled dataset that contains data for training is loaded from CSV file, - // rows represent features, columns represent data points. - arma::mat dataset; - mlpack::data::Load("../data/train.csv", dataset, true); - - // Originally on Kaggle dataset CSV file has header, so it's necessary to - // get rid of the this row, in Armadillo representation it's the first column. - arma::mat headerLessDataset = - dataset.submat(0, 1, dataset.n_rows - 1, dataset.n_cols - 1); - - // Splitting the training dataset on training and validation parts. - arma::mat train, valid; - mlpack::data::Split(headerLessDataset, train, valid, RATIO); - - // Getting training and validating dataset with features only and then - // normalising - const arma::mat trainX = - train.submat(1, 0, train.n_rows - 1, train.n_cols - 1) / 255.0; - const arma::mat validX = - valid.submat(1, 0, valid.n_rows - 1, valid.n_cols - 1) / 255.0; - - // According to NegativeLogLikelihood output layer of NN, labels should - // specify class of a data point and be in the interval from 1 to - // number of classes (in this case from 1 to 10). - - // Creating labels for training and validating dataset. - const arma::mat trainY = train.row(0) + 1; - const arma::mat validY = valid.row(0) + 1; - - // Specifying the NN model. NegativeLogLikelihood is the output layer that - // is used for classification problem. GlorotInitialization means that - // initial weights in neurons are a uniform gaussian distribution. - FFN, GlorotInitialization> model; - // This is intermediate layer that is needed for connection between input - // data and relu layer. Parameters specify the number of input features - // and number of neurons in the next layer. - model.Add>(trainX.n_rows, H1); - // The first relu layer. - model.Add>(); - // Intermediate layer between relu layers. - model.Add>(H1, H2); - // The second relu layer. - model.Add>(); - // Dropout layer for regularization. First parameter is the probability of - // setting a specific value to 0. - model.Add>(0.2); - // Intermediate layer. - model.Add>(H2, 10); - // LogSoftMax layer is used together with NegativeLogLikelihood for mapping - // output values to log of probabilities of being a specific class. - model.Add>(); - - std::cout << "Start training ..." << std::endl; - - // Set parameters for the Adam optimizer. - ens::Adam optimizer( - STEP_SIZE, // Step size of the optimizer. - BATCH_SIZE, // Batch size. Number of data points that are used in each iteration. - 0.9, // Exponential decay rate for the first moment estimates. - 0.999, // Exponential decay rate for the weighted infinity norm estimates. - 1e-8, // Value used to initialise the mean squared gradient parameter. - MAX_ITERATIONS, // Max number of iterations. - 1e-8, // Tolerance. - true); - - // Train neural network. If this is the first iteration, weights are - // random, using current values as starting point otherwise. - model.Train(trainX, - trainY, - optimizer, - ens::PrintLoss(), - ens::ProgressBar(), - // Stop the training using Early Stop at min loss. - ens::EarlyStopAtMinLoss()); - - mat predOut; - // Getting predictions on training data points. - model.Predict(trainX, predOut); - // Calculating accuracy on training data points. - arma::Row predLabels = getLabels(predOut); - double trainAccuracy = arma::accu(predLabels == trainY) / (double)trainY.n_elem * 100; - // Getting predictions on validating data points. - model.Predict(validX, predOut); - // Calculating accuracy on validating data points. - predLabels = getLabels(predOut); - double validAccuracy = arma::accu(predLabels == validY) / (double)validY.n_elem * 100; - - std::cout << "Accuracy: train = " << trainAccuracy << "%," - << "\t valid = " << validAccuracy << "%" << endl; - - mlpack::data::Save("model.bin", "model", model, false); - - // Loading test dataset (the one whose predicted labels - // should be sent to kaggle website). - arma::mat testingDataset; - mlpack::data::Load("../data/test.csv", testingDataset, true); - - // As before, it's necessary to get rid of header. - arma::mat testX = testingDataset.submat( - 0, 1, testingDataset.n_rows - 1, testingDataset.n_cols - 1); - - std::cout << "Predicting ..." << endl; - mat testPredOut; - // Getting predictions on test data points. - model.Predict(testX, testPredOut); - // Generating labels for the test dataset. - Row testPred = getLabels(testPredOut); - std::cout << "Saving predicted labels to \"results.csv\" ..." << std::endl; - - testPred.save("results.csv", arma::csv_ascii); - std::cout << "Neural network model is saved to \"model.bin\"" << std::endl; - std::cout << "Finished" << std::endl; -} From ba8e4e93bfd61c7f40aa5cf797ee434a1b64de2c Mon Sep 17 00:00:00 2001 From: Omar Shrit Date: Sat, 27 Jun 2020 00:08:13 +0200 Subject: [PATCH 08/16] Use post increment for indecies Signed-off-by: Omar Shrit --- src/mlpack/core/tree/cosine_tree/cosine_tree.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/mlpack/core/tree/cosine_tree/cosine_tree.cpp b/src/mlpack/core/tree/cosine_tree/cosine_tree.cpp index 6865eca93a..52c17450ba 100644 --- a/src/mlpack/core/tree/cosine_tree/cosine_tree.cpp +++ b/src/mlpack/core/tree/cosine_tree/cosine_tree.cpp @@ -451,7 +451,7 @@ double CosineTree::MonteCarloError(CosineTree* node, // If two additional vectors are passed, take their projections. if (addBasisVector1 && addBasisVector2) { - projection(++k) = arma::dot(dataset.col(sampledIndices[i]), + projection(k++) = arma::dot(dataset.col(sampledIndices[i]), *addBasisVector1); projection(k) = arma::dot(dataset.col(sampledIndices[i]), *addBasisVector2); From 9e2b81796b94b7d898d13f409390d486bc7a73e8 Mon Sep 17 00:00:00 2001 From: Omar Shrit Date: Sun, 28 Jun 2020 18:02:19 +0200 Subject: [PATCH 09/16] Remove non required assert Signed-off-by: Omar Shrit --- .../core/tree/rectangle_tree/hilbert_r_tree_split_impl.hpp | 3 --- 1 file changed, 3 deletions(-) diff --git a/src/mlpack/core/tree/rectangle_tree/hilbert_r_tree_split_impl.hpp b/src/mlpack/core/tree/rectangle_tree/hilbert_r_tree_split_impl.hpp index a558fc22c5..58503e48f3 100644 --- a/src/mlpack/core/tree/rectangle_tree/hilbert_r_tree_split_impl.hpp +++ b/src/mlpack/core/tree/rectangle_tree/hilbert_r_tree_split_impl.hpp @@ -76,7 +76,6 @@ void HilbertRTreeSplit::SplitLeafNode(TreeType* tree, firstSibling = (lastSibling > splitOrder ? lastSibling - splitOrder : 0); assert(lastSibling - firstSibling <= splitOrder); - assert(firstSibling >= 0); assert(lastSibling < parent->NumChildren()); // Redistribute the points among (splitOrder + 1) cooperating siblings evenly. @@ -141,7 +140,6 @@ SplitNonLeafNode(TreeType* tree, std::vector& relevels) lastSibling - splitOrder : 0); assert(lastSibling - firstSibling <= splitOrder); - assert(firstSibling >= 0); assert(lastSibling < parent->NumChildren()); // Redistribute children among (splitOrder + 1) cooperating siblings evenly. @@ -203,7 +201,6 @@ bool HilbertRTreeSplit::FindCooperatingSiblings( } assert(lastSibling - firstSibling <= splitOrder - 1); - assert(firstSibling >= 0); assert(lastSibling < parent->NumChildren()); return true; From 486b3db8ef79c78e3d93f1b5d9a094325b294504 Mon Sep 17 00:00:00 2001 From: Omar Shrit Date: Sun, 28 Jun 2020 18:11:56 +0200 Subject: [PATCH 10/16] Delete pointer of already allocated Signed-off-by: Omar Shrit --- .../core/tree/rectangle_tree/discrete_hilbert_value_impl.hpp | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/mlpack/core/tree/rectangle_tree/discrete_hilbert_value_impl.hpp b/src/mlpack/core/tree/rectangle_tree/discrete_hilbert_value_impl.hpp index b8b90881d3..6a9d316020 100644 --- a/src/mlpack/core/tree/rectangle_tree/discrete_hilbert_value_impl.hpp +++ b/src/mlpack/core/tree/rectangle_tree/discrete_hilbert_value_impl.hpp @@ -436,6 +436,9 @@ template DiscreteHilbertValue& DiscreteHilbertValue:: operator=(const DiscreteHilbertValue& val) { + if (ownsLocalHilbertValues) + delete localHilbertValues; + localHilbertValues = const_cast* > (val.LocalHilbertValues()); ownsLocalHilbertValues = false; From c7feb4eca63915a2f6509e3e006b09321edce240 Mon Sep 17 00:00:00 2001 From: Omar Shrit Date: Sun, 28 Jun 2020 18:14:43 +0200 Subject: [PATCH 11/16] Add some if define if using arma HDF5 Signed-off-by: Omar Shrit --- src/mlpack/core/data/save_impl.hpp | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/src/mlpack/core/data/save_impl.hpp b/src/mlpack/core/data/save_impl.hpp index b90315ca63..ca45fd0bcb 100644 --- a/src/mlpack/core/data/save_impl.hpp +++ b/src/mlpack/core/data/save_impl.hpp @@ -158,10 +158,14 @@ bool Save(const std::string& filename, { arma::Mat tmp = trans(matrix); +#ifdef ARMA_USE_HDF5 // We can't save with streams for HDF5. const bool success = (saveType == arma::hdf5_binary) ? tmp.quiet_save(filename, saveType) : tmp.quiet_save(stream, saveType); +#else + const bool success = tmp.quiet_save(stream, saveType); +#endif if (!success) { Timer::Stop("saving_data"); @@ -175,10 +179,14 @@ bool Save(const std::string& filename, } else { +#ifdef ARMA_USE_HDF5 // We can't save with streams for HDF5. const bool success = (saveType == arma::hdf5_binary) ? matrix.quiet_save(filename, saveType) : matrix.quiet_save(stream, saveType); +#else + const bool success = tmp.quiet_save(stream, saveType); +#endif if (!success) { Timer::Stop("saving_data"); From 11ef838d11c67212f97b23e6aea51db2b78462c8 Mon Sep 17 00:00:00 2001 From: Omar Shrit Date: Sun, 28 Jun 2020 18:20:09 +0200 Subject: [PATCH 12/16] Fix memory leaks in cellbound_impl Signed-off-by: Omar Shrit --- src/mlpack/core/tree/cellbound_impl.hpp | 1 + 1 file changed, 1 insertion(+) diff --git a/src/mlpack/core/tree/cellbound_impl.hpp b/src/mlpack/core/tree/cellbound_impl.hpp index 9842b3a1a7..d593966a7f 100644 --- a/src/mlpack/core/tree/cellbound_impl.hpp +++ b/src/mlpack/core/tree/cellbound_impl.hpp @@ -90,6 +90,7 @@ inline CellBound< if (dim != other.Dim()) { // Reallocation is necessary. + delete[] bounds; dim = other.Dim(); bounds = new math::RangeType[dim]; From 4b7f55b5b5280e00d2fa9d163b2e81f3c25ad66e Mon Sep 17 00:00:00 2001 From: Omar Shrit Date: Sun, 28 Jun 2020 18:20:29 +0200 Subject: [PATCH 13/16] Initialize logDevCot Signed-off-by: Omar Shrit --- src/mlpack/core/dists/gaussian_distribution.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/mlpack/core/dists/gaussian_distribution.cpp b/src/mlpack/core/dists/gaussian_distribution.cpp index 37009e7c91..24343b4351 100644 --- a/src/mlpack/core/dists/gaussian_distribution.cpp +++ b/src/mlpack/core/dists/gaussian_distribution.cpp @@ -19,7 +19,7 @@ using namespace mlpack::distribution; GaussianDistribution::GaussianDistribution(const arma::vec& mean, const arma::mat& covariance) - : mean(mean) + : mean(mean), logDetCov(0.0) { Covariance(covariance); } From d726940422dfb73a87aa2df4b52943a9055fd84b Mon Sep 17 00:00:00 2001 From: Omar Shrit Date: Sun, 28 Jun 2020 18:24:00 +0200 Subject: [PATCH 14/16] Add equality check Signed-off-by: Omar Shrit --- src/mlpack/core/tree/cellbound_impl.hpp | 5 ++++- src/mlpack/core/tree/hrectbound_impl.hpp | 3 +++ 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/src/mlpack/core/tree/cellbound_impl.hpp b/src/mlpack/core/tree/cellbound_impl.hpp index d593966a7f..358eea49fe 100644 --- a/src/mlpack/core/tree/cellbound_impl.hpp +++ b/src/mlpack/core/tree/cellbound_impl.hpp @@ -87,7 +87,10 @@ inline CellBound< ElemType>& CellBound::operator=( const CellBound& other) { - if (dim != other.Dim()) + if (this == &other) + return *this; + + if (dim != other.Dim()) { // Reallocation is necessary. delete[] bounds; diff --git a/src/mlpack/core/tree/hrectbound_impl.hpp b/src/mlpack/core/tree/hrectbound_impl.hpp index 7c10c00159..beeb020283 100644 --- a/src/mlpack/core/tree/hrectbound_impl.hpp +++ b/src/mlpack/core/tree/hrectbound_impl.hpp @@ -65,6 +65,9 @@ inline HRectBound< ElemType>& HRectBound::operator=(const HRectBound& other) { + if (this == &other) + return *this; + if (dim != other.Dim()) { // Reallocation is necessary. From b39ded1dc4b969d906b2d6bad9112e28cfda1c7d Mon Sep 17 00:00:00 2001 From: Omar Shrit Date: Sun, 28 Jun 2020 18:30:40 +0200 Subject: [PATCH 15/16] Fix typo Signed-off-by: Omar Shrit --- src/mlpack/core/data/save_impl.hpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/mlpack/core/data/save_impl.hpp b/src/mlpack/core/data/save_impl.hpp index ca45fd0bcb..fbcd142036 100644 --- a/src/mlpack/core/data/save_impl.hpp +++ b/src/mlpack/core/data/save_impl.hpp @@ -185,7 +185,7 @@ bool Save(const std::string& filename, matrix.quiet_save(filename, saveType) : matrix.quiet_save(stream, saveType); #else - const bool success = tmp.quiet_save(stream, saveType); + const bool success = matrix.quiet_save(stream, saveType); #endif if (!success) { From 57ad5c3e128649417ee15c8ceca3668b76d38fe4 Mon Sep 17 00:00:00 2001 From: Omar Shrit Date: Tue, 30 Jun 2020 13:06:11 +0200 Subject: [PATCH 16/16] Correct the last checking error Signed-off-by: Omar Shrit --- .../core/tree/rectangle_tree/discrete_hilbert_value_impl.hpp | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/mlpack/core/tree/rectangle_tree/discrete_hilbert_value_impl.hpp b/src/mlpack/core/tree/rectangle_tree/discrete_hilbert_value_impl.hpp index 6a9d316020..02441006cc 100644 --- a/src/mlpack/core/tree/rectangle_tree/discrete_hilbert_value_impl.hpp +++ b/src/mlpack/core/tree/rectangle_tree/discrete_hilbert_value_impl.hpp @@ -436,6 +436,9 @@ template DiscreteHilbertValue& DiscreteHilbertValue:: operator=(const DiscreteHilbertValue& val) { + if (this == &val) + return *this; + if (ownsLocalHilbertValues) delete localHilbertValues;