From fe232225235170a60cfad9d53d34f4dfd2f312e9 Mon Sep 17 00:00:00 2001 From: Omar Shrit Date: Sun, 14 Jan 2024 20:13:49 +0100 Subject: [PATCH] Chnage arma::square to square in methods Signed-off-by: Omar Shrit --- src/mlpack/methods/ann/dists/normal_distribution_impl.hpp | 8 ++++---- .../ann/layer/not_adapted/virtual_batch_norm_impl.hpp | 6 +++--- .../ann/loss_functions/mean_squared_error_impl.hpp | 2 +- .../mean_squared_logarithmic_error_impl.hpp | 2 +- .../methods/ann/not_adapted/rbm/spike_slab_rbm_impl.hpp | 2 +- src/mlpack/methods/decision_tree/mse_gain.hpp | 6 +++--- src/mlpack/methods/local_coordinate_coding/lcc_impl.hpp | 2 +- src/mlpack/methods/sparse_coding/sparse_coding_impl.hpp | 2 +- 8 files changed, 15 insertions(+), 15 deletions(-) diff --git a/src/mlpack/methods/ann/dists/normal_distribution_impl.hpp b/src/mlpack/methods/ann/dists/normal_distribution_impl.hpp index 353829f478..c395c69c6d 100644 --- a/src/mlpack/methods/ann/dists/normal_distribution_impl.hpp +++ b/src/mlpack/methods/ann/dists/normal_distribution_impl.hpp @@ -45,8 +45,8 @@ DataType NormalDistribution::LogProbability( const DataType& observation) const { const DataType v1 = arma::log(sigma) + std::log(std::sqrt(2 * M_PI)); - const DataType v2 = arma::square(observation - mean) / - (2 * arma::square(sigma)); + const DataType v2 = square(observation - mean) / + (2 * square(sigma)); return (-v1 - v2); } @@ -56,9 +56,9 @@ void NormalDistribution::ProbBackward( DataType& dmu, DataType& dsigma) const { - dmu = (observation - mean) / (arma::square(sigma)) % Probability(observation); + dmu = (observation - mean) / (square(sigma)) % Probability(observation); dsigma = (- 1.0 / sigma + - (arma::square(observation - mean) / arma::pow(sigma, 3))) + (square(observation - mean) / arma::pow(sigma, 3))) % Probability(observation); } diff --git a/src/mlpack/methods/ann/layer/not_adapted/virtual_batch_norm_impl.hpp b/src/mlpack/methods/ann/layer/not_adapted/virtual_batch_norm_impl.hpp index b78f02163b..cfea304119 100644 --- a/src/mlpack/methods/ann/layer/not_adapted/virtual_batch_norm_impl.hpp +++ b/src/mlpack/methods/ann/layer/not_adapted/virtual_batch_norm_impl.hpp @@ -38,7 +38,7 @@ VirtualBatchNormType::VirtualBatchNormType( loading(false) { referenceBatchMean = arma::mean(referenceBatch, 1); - referenceBatchMeanSquared = arma::mean(arma::square(referenceBatch), 1); + referenceBatchMeanSquared = arma::mean(square(referenceBatch), 1); newCoefficient = 1.0 / (referenceBatch.n_cols + 1); oldCoefficient = 1 - newCoefficient; } @@ -68,12 +68,12 @@ void VirtualBatchNormType::Forward( inputParameter = input; InputType inputMean = arma::mean(input, 1); - InputType inputMeanSquared = arma::mean(arma::square(input), 1); + InputType inputMeanSquared = arma::mean(square(input), 1); mean = oldCoefficient * referenceBatchMean + newCoefficient * inputMean; OutputType meanSquared = oldCoefficient * referenceBatchMeanSquared + newCoefficient * inputMeanSquared; - variance = meanSquared - arma::square(mean); + variance = meanSquared - square(mean); // Normalize the input. output = input.each_col() - mean; inputSubMean = output; diff --git a/src/mlpack/methods/ann/loss_functions/mean_squared_error_impl.hpp b/src/mlpack/methods/ann/loss_functions/mean_squared_error_impl.hpp index fd9a027843..2448deaac5 100644 --- a/src/mlpack/methods/ann/loss_functions/mean_squared_error_impl.hpp +++ b/src/mlpack/methods/ann/loss_functions/mean_squared_error_impl.hpp @@ -30,7 +30,7 @@ typename MatType::elem_type MeanSquaredErrorType::Forward( const MatType& target) { typename MatType::elem_type lossSum = - arma::accu(arma::square(prediction - target)); + arma::accu(square(prediction - target)); if (reduction) return lossSum; diff --git a/src/mlpack/methods/ann/loss_functions/mean_squared_logarithmic_error_impl.hpp b/src/mlpack/methods/ann/loss_functions/mean_squared_logarithmic_error_impl.hpp index 429db21db8..5212247be9 100644 --- a/src/mlpack/methods/ann/loss_functions/mean_squared_logarithmic_error_impl.hpp +++ b/src/mlpack/methods/ann/loss_functions/mean_squared_logarithmic_error_impl.hpp @@ -31,7 +31,7 @@ typename MatType::elem_type MeanSquaredLogarithmicErrorType::Forward( const MatType& target) { typename MatType::elem_type lossSum = - arma::accu(arma::square(arma::log(1.0 + target) - + arma::accu(square(arma::log(1.0 + target) - arma::log(1.0 + prediction))); if (reduction) diff --git a/src/mlpack/methods/ann/not_adapted/rbm/spike_slab_rbm_impl.hpp b/src/mlpack/methods/ann/not_adapted/rbm/spike_slab_rbm_impl.hpp index 8cd8525739..503f8a70a8 100644 --- a/src/mlpack/methods/ann/not_adapted/rbm/spike_slab_rbm_impl.hpp +++ b/src/mlpack/methods/ann/not_adapted/rbm/spike_slab_rbm_impl.hpp @@ -76,7 +76,7 @@ RBM::FreeEnergy( for (size_t i = 0; i < hiddenSize; ++i) { - ElemType sum = arma::accu(arma::square(input.t() * weight.slice(i))) / + ElemType sum = arma::accu(square(input.t() * weight.slice(i))) / (2.0 * slabPenalty); freeEnergy -= SoftplusFunction::Fn(spikeBias(i) - sum); } diff --git a/src/mlpack/methods/decision_tree/mse_gain.hpp b/src/mlpack/methods/decision_tree/mse_gain.hpp index 09dcb12b03..ff59b90885 100644 --- a/src/mlpack/methods/decision_tree/mse_gain.hpp +++ b/src/mlpack/methods/decision_tree/mse_gain.hpp @@ -70,7 +70,7 @@ class MSEGain Sum(values, begin, end, mean); mean /= (double) (end - begin); - mse = arma::accu(arma::square(values.subvec(begin, end - 1) - mean)); + mse = arma::accu(square(values.subvec(begin, end - 1) - mean)); mse /= (double) (end - begin); } @@ -164,7 +164,7 @@ class MSEGain if (UseWeights) { - totalSumSquares = arma::accu(weights % arma::square(responses)); + totalSumSquares = arma::accu(weights % square(responses)); for (size_t i = 0; i < minimum - 1; ++i) { const WType w = weights[i]; @@ -192,7 +192,7 @@ class MSEGain } else { - totalSumSquares = arma::accu(arma::square(responses)); + totalSumSquares = arma::accu(square(responses)); for (size_t i = 0; i < minimum - 1; ++i) { const RType x = responses[i]; diff --git a/src/mlpack/methods/local_coordinate_coding/lcc_impl.hpp b/src/mlpack/methods/local_coordinate_coding/lcc_impl.hpp index 6189b192c9..44f7e33b62 100644 --- a/src/mlpack/methods/local_coordinate_coding/lcc_impl.hpp +++ b/src/mlpack/methods/local_coordinate_coding/lcc_impl.hpp @@ -329,7 +329,7 @@ inline double LocalCoordinateCoding::Objective( const size_t pointInd = (size_t) (adjacencies(l) / atoms); weightedL1NormZ += fabs(codes(atomInd, pointInd)) * arma::as_scalar( - arma::sum(arma::square(dictionary.col(atomInd) - data.col(pointInd)))); + arma::sum(square(dictionary.col(atomInd) - data.col(pointInd)))); } double froNormResidual = norm(data - dictionary * codes, "fro"); diff --git a/src/mlpack/methods/sparse_coding/sparse_coding_impl.hpp b/src/mlpack/methods/sparse_coding/sparse_coding_impl.hpp index 3346674a60..fb76444f81 100644 --- a/src/mlpack/methods/sparse_coding/sparse_coding_impl.hpp +++ b/src/mlpack/methods/sparse_coding/sparse_coding_impl.hpp @@ -182,7 +182,7 @@ inline double SparseCoding::OptimizeDictionary(const arma::mat& data, arma::mat matAInvZXT = solve(A, codesXT); - arma::vec gradient = -arma::sum(arma::square(matAInvZXT), 1); + arma::vec gradient = -arma::sum(square(matAInvZXT), 1); gradient += 1; arma::mat hessian = -(-2 * (matAInvZXT * trans(matAInvZXT)) % inv(A));