From 73e22e5a7ccc331c3aae3c670e66b075519e9cca Mon Sep 17 00:00:00 2001 From: Relintai Date: Fri, 10 Feb 2023 21:41:05 +0100 Subject: [PATCH] Fixed warnings in MLPPMANN. --- mlpp/mann/mann.cpp | 19 +++++++++---------- 1 file changed, 9 insertions(+), 10 deletions(-) diff --git a/mlpp/mann/mann.cpp b/mlpp/mann/mann.cpp index ff81663..e466a8f 100644 --- a/mlpp/mann/mann.cpp +++ b/mlpp/mann/mann.cpp @@ -13,7 +13,6 @@ #include - MLPPMANN::MLPPMANN(std::vector> inputSet, std::vector> outputSet) : inputSet(inputSet), outputSet(outputSet), n(inputSet.size()), k(inputSet[0].size()), n_output(outputSet[0].size()) { } @@ -27,7 +26,7 @@ std::vector> MLPPMANN::modelSetTest(std::vector> MLPPMANN::modelSetTest(std::vector MLPPMANN::modelTest(std::vector x) { if (!network.empty()) { network[0].Test(x); - for (int i = 1; i < network.size(); i++) { + for (uint32_t i = 1; i < network.size(); i++) { network[i].Test(network[i - 1].a_test); } outputLayer->Test(network[network.size() - 1].a_test); @@ -89,9 +88,9 @@ void MLPPMANN::gradientDescent(real_t learning_rate, int max_epoch, bool UI) { network[network.size() - 1].bias = alg.subtractMatrixRows(network[network.size() - 1].bias, alg.scalarMultiply(learning_rate / n, network[network.size() - 1].delta)); for (int i = network.size() - 2; i >= 0; i--) { - auto hiddenLayerAvn = network[i].activation_map[network[i].activation]; + hiddenLayerAvn = network[i].activation_map[network[i].activation]; network[i].delta = alg.hadamard_product(alg.matmult(network[i + 1].delta, network[i + 1].weights), (avn.*hiddenLayerAvn)(network[i].z, 1)); - std::vector> hiddenLayerWGrad = alg.matmult(alg.transpose(network[i].input), network[i].delta); + hiddenLayerWGrad = alg.matmult(alg.transpose(network[i].input), network[i].delta); network[i].weights = alg.subtraction(network[i].weights, alg.scalarMultiply(learning_rate / n, hiddenLayerWGrad)); network[i].weights = regularization.regWeights(network[i].weights, network[i].lambda, network[i].alpha, network[i].reg); network[i].bias = alg.subtractMatrixRows(network[i].bias, alg.scalarMultiply(learning_rate / n, network[i].delta)); @@ -121,16 +120,16 @@ void MLPPMANN::gradientDescent(real_t learning_rate, int max_epoch, bool UI) { } real_t MLPPMANN::score() { - MLPPUtilities util; + MLPPUtilities util; forwardPass(); return util.performance(y_hat, outputSet); } void MLPPMANN::save(std::string fileName) { - MLPPUtilities util; + MLPPUtilities util; if (!network.empty()) { util.saveParameters(fileName, network[0].weights, network[0].bias, 0, 1); - for (int i = 1; i < network.size(); i++) { + for (uint32_t i = 1; i < network.size(); i++) { util.saveParameters(fileName, network[i].weights, network[i].bias, 1, i + 1); } util.saveParameters(fileName, outputLayer->weights, outputLayer->bias, 1, network.size() + 1); @@ -164,7 +163,7 @@ real_t MLPPMANN::Cost(std::vector> y_hat, std::vectorcost_map[outputLayer->cost]; if (!network.empty()) { - for (int i = 0; i < network.size() - 1; i++) { + for (uint32_t i = 0; i < network.size() - 1; i++) { totalRegTerm += regularization.regTerm(network[i].weights, network[i].lambda, network[i].alpha, network[i].reg); } } @@ -176,7 +175,7 @@ void MLPPMANN::forwardPass() { network[0].input = inputSet; network[0].forwardPass(); - for (int i = 1; i < network.size(); i++) { + for (uint32_t i = 1; i < network.size(); i++) { network[i].input = network[i - 1].a; network[i].forwardPass(); }