From f24bf466c8adc6745519ae5b10b1d656754ff8ef Mon Sep 17 00:00:00 2001 From: Relintai Date: Sat, 11 Feb 2023 09:32:49 +0100 Subject: [PATCH] Rename the GAN class in gan_old.h and cpp to GANOld. --- mlpp/gan/gan_old.cpp | 36 ++++++++++++++++++------------------ mlpp/gan/gan_old.h | 6 +++--- 2 files changed, 21 insertions(+), 21 deletions(-) diff --git a/mlpp/gan/gan_old.cpp b/mlpp/gan/gan_old.cpp index 3076658..84f9a8d 100644 --- a/mlpp/gan/gan_old.cpp +++ b/mlpp/gan/gan_old.cpp @@ -14,20 +14,20 @@ #include #include -MLPPGAN::MLPPGAN(real_t k, std::vector> outputSet) : +MLPPGANOld::MLPPGANOld(real_t k, std::vector> outputSet) : outputSet(outputSet), n(outputSet.size()), k(k) { } -MLPPGAN::~MLPPGAN() { +MLPPGANOld::~MLPPGANOld() { delete outputLayer; } -std::vector> MLPPGAN::generateExample(int n) { +std::vector> MLPPGANOld::generateExample(int n) { MLPPLinAlg alg; return modelSetTestGenerator(alg.gaussianNoise(n, k)); } -void MLPPGAN::gradientDescent(real_t learning_rate, int max_epoch, bool UI) { +void MLPPGANOld::gradientDescent(real_t learning_rate, int max_epoch, bool UI) { class MLPPCost cost; MLPPLinAlg alg; real_t cost_prev = 0; @@ -68,7 +68,7 @@ void MLPPGAN::gradientDescent(real_t learning_rate, int max_epoch, bool UI) { forwardPass(); if (UI) { - MLPPGAN::UI(epoch, cost_prev, MLPPGAN::y_hat, alg.onevec(n)); + MLPPGANOld::UI(epoch, cost_prev, MLPPGANOld::y_hat, alg.onevec(n)); } epoch++; @@ -78,14 +78,14 @@ void MLPPGAN::gradientDescent(real_t learning_rate, int max_epoch, bool UI) { } } -real_t MLPPGAN::score() { +real_t MLPPGANOld::score() { MLPPLinAlg alg; MLPPUtilities util; forwardPass(); return util.performance(y_hat, alg.onevec(n)); } -void MLPPGAN::save(std::string fileName) { +void MLPPGANOld::save(std::string fileName) { MLPPUtilities util; if (!network.empty()) { util.saveParameters(fileName, network[0].weights, network[0].bias, false, 1); @@ -98,7 +98,7 @@ void MLPPGAN::save(std::string fileName) { } } -void MLPPGAN::addLayer(int n_hidden, std::string activation, std::string weightInit, std::string reg, real_t lambda, real_t alpha) { +void MLPPGANOld::addLayer(int n_hidden, std::string activation, std::string weightInit, std::string reg, real_t lambda, real_t alpha) { MLPPLinAlg alg; if (network.empty()) { network.push_back(MLPPOldHiddenLayer(n_hidden, activation, alg.gaussianNoise(n, k), weightInit, reg, lambda, alpha)); @@ -109,7 +109,7 @@ void MLPPGAN::addLayer(int n_hidden, std::string activation, std::string weightI } } -void MLPPGAN::addOutputLayer(std::string weightInit, std::string reg, real_t lambda, real_t alpha) { +void MLPPGANOld::addOutputLayer(std::string weightInit, std::string reg, real_t lambda, real_t alpha) { MLPPLinAlg alg; if (!network.empty()) { outputLayer = new MLPPOldOutputLayer(network[network.size() - 1].n_hidden, "Sigmoid", "LogLoss", network[network.size() - 1].a, weightInit, reg, lambda, alpha); @@ -118,7 +118,7 @@ void MLPPGAN::addOutputLayer(std::string weightInit, std::string reg, real_t lam } } -std::vector> MLPPGAN::modelSetTestGenerator(std::vector> X) { +std::vector> MLPPGANOld::modelSetTestGenerator(std::vector> X) { if (!network.empty()) { network[0].input = X; network[0].forwardPass(); @@ -131,7 +131,7 @@ std::vector> MLPPGAN::modelSetTestGenerator(std::vector MLPPGAN::modelSetTestDiscriminator(std::vector> X) { +std::vector MLPPGANOld::modelSetTestDiscriminator(std::vector> X) { if (!network.empty()) { for (uint32_t i = network.size() / 2 + 1; i < network.size(); i++) { if (i == network.size() / 2 + 1) { @@ -147,7 +147,7 @@ std::vector MLPPGAN::modelSetTestDiscriminator(std::vectora; } -real_t MLPPGAN::Cost(std::vector y_hat, std::vector y) { +real_t MLPPGANOld::Cost(std::vector y_hat, std::vector y) { MLPPReg regularization; class MLPPCost cost; real_t totalRegTerm = 0; @@ -161,7 +161,7 @@ real_t MLPPGAN::Cost(std::vector y_hat, std::vector y) { return (cost.*cost_function)(y_hat, y) + totalRegTerm + regularization.regTerm(outputLayer->weights, outputLayer->lambda, outputLayer->alpha, outputLayer->reg); } -void MLPPGAN::forwardPass() { +void MLPPGANOld::forwardPass() { MLPPLinAlg alg; if (!network.empty()) { network[0].input = alg.gaussianNoise(n, k); @@ -179,7 +179,7 @@ void MLPPGAN::forwardPass() { y_hat = outputLayer->a; } -void MLPPGAN::updateDiscriminatorParameters(std::vector>> hiddenLayerUpdations, std::vector outputLayerUpdation, real_t learning_rate) { +void MLPPGANOld::updateDiscriminatorParameters(std::vector>> hiddenLayerUpdations, std::vector outputLayerUpdation, real_t learning_rate) { MLPPLinAlg alg; outputLayer->weights = alg.subtraction(outputLayer->weights, outputLayerUpdation); @@ -196,7 +196,7 @@ void MLPPGAN::updateDiscriminatorParameters(std::vector>> hiddenLayerUpdations, real_t learning_rate) { +void MLPPGANOld::updateGeneratorParameters(std::vector>> hiddenLayerUpdations, real_t learning_rate) { MLPPLinAlg alg; if (!network.empty()) { @@ -209,7 +209,7 @@ void MLPPGAN::updateGeneratorParameters(std::vector>>, std::vector> MLPPGAN::computeDiscriminatorGradients(std::vector y_hat, std::vector outputSet) { +std::tuple>>, std::vector> MLPPGANOld::computeDiscriminatorGradients(std::vector y_hat, std::vector outputSet) { class MLPPCost cost; MLPPActivation avn; MLPPLinAlg alg; @@ -245,7 +245,7 @@ std::tuple>>, std::vector> M return { cumulativeHiddenLayerWGrad, outputWGrad }; } -std::vector>> MLPPGAN::computeGeneratorGradients(std::vector y_hat, std::vector outputSet) { +std::vector>> MLPPGANOld::computeGeneratorGradients(std::vector y_hat, std::vector outputSet) { class MLPPCost cost; MLPPActivation avn; MLPPLinAlg alg; @@ -274,7 +274,7 @@ std::vector>> MLPPGAN::computeGeneratorGradients return cumulativeHiddenLayerWGrad; } -void MLPPGAN::UI(int epoch, real_t cost_prev, std::vector y_hat, std::vector outputSet) { +void MLPPGANOld::UI(int epoch, real_t cost_prev, std::vector y_hat, std::vector outputSet) { MLPPUtilities::CostInfo(epoch, cost_prev, Cost(y_hat, outputSet)); std::cout << "Layer " << network.size() + 1 << ": " << std::endl; MLPPUtilities::UI(outputLayer->weights, outputLayer->bias); diff --git a/mlpp/gan/gan_old.h b/mlpp/gan/gan_old.h index 7e68751..a88d593 100644 --- a/mlpp/gan/gan_old.h +++ b/mlpp/gan/gan_old.h @@ -20,10 +20,10 @@ #include #include -class MLPPGAN { +class MLPPGANOld { public: - MLPPGAN(real_t k, std::vector> outputSet); - ~MLPPGAN(); + MLPPGANOld(real_t k, std::vector> outputSet); + ~MLPPGANOld(); std::vector> generateExample(int n); void gradientDescent(real_t learning_rate, int max_epoch, bool UI = false); real_t score();